Fix req.host when using "trust proxy" hops count
This commit is contained in:
parent
20aa12616a
commit
2e0f5e7817
@ -1,6 +1,7 @@
|
||||
3.x
|
||||
===
|
||||
|
||||
* Fix `req.host` when using "trust proxy" hops count
|
||||
* Fix `req.protocol`/`req.secure` when using "trust proxy" hops count
|
||||
|
||||
3.20.0 / 2015-02-18
|
||||
|
@ -491,7 +491,7 @@ req.__defineGetter__('host', function(){
|
||||
var trust = this.app.get('trust proxy fn');
|
||||
var host = this.get('X-Forwarded-Host');
|
||||
|
||||
if (!host || !trust(this.connection.remoteAddress)) {
|
||||
if (!host || !trust(this.connection.remoteAddress, 0)) {
|
||||
host = this.get('Host');
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,24 @@ describe('req', function(){
|
||||
.set('Host', 'example.com')
|
||||
.expect('example.com', done);
|
||||
})
|
||||
|
||||
describe('when trusting hop count', function () {
|
||||
it('should respect X-Forwarded-Host', function (done) {
|
||||
var app = express();
|
||||
|
||||
app.set('trust proxy', 1);
|
||||
|
||||
app.use(function (req, res) {
|
||||
res.end(req.host);
|
||||
});
|
||||
|
||||
request(app)
|
||||
.get('/')
|
||||
.set('Host', 'localhost')
|
||||
.set('X-Forwarded-Host', 'example.com')
|
||||
.expect('example.com', done);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('when "trust proxy" is disabled', function(){
|
||||
|
Loading…
Reference in New Issue
Block a user