Merge tag '3.20.1'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parents 51f960f, b2311c7 · Browse files · 7 files·+67 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+67 added−3 removed
- tests:+52 added−0 removed
- other:+15 added−3 removed
Provenance
- Commit
cd6df76- Tree
f1bb9d0- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
51f960f- Parent 2
b2311c7
7 files changed+67 added−3 removed
modified:lib/request.js+2 added-2 removed
266 unmodified lines267 ? 'https'268 : 'http';269 var trust = this.app.get('trust proxy fn');270 271- if (!trust(this.connection.remoteAddress)) {271+ if (!trust(this.connection.remoteAddress, 0)) {272 return proto;273 }274 275 // Note: X-Forwarded-Proto is normally only ever a101 unmodified lines377 defineGetter(req, 'hostname', function hostname(){378 var trust = this.app.get('trust proxy fn');379 var host = this.get('X-Forwarded-Host');380 381- if (!host || !trust(this.connection.remoteAddress)) {381+ if (!host || !trust(this.connection.remoteAddress, 0)) {382 host = this.get('Host');383 }384 385 if (!host) return;82 unmodified linesmodified:test/req.host.js+18 added
115 unmodified linesExpand all11611711811912012112212312412512612712812913013113213313413513613713813914014115 unmodified lines115 unmodified linesExpand all .get('/') .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(){ it('should ignore X-Forwarded-Host', function(done){15 unmodified linesmodified:test/req.protocol.js+17 added
73 unmodified lines74 request(app)75 .get('/')76 .expect('http', done);77 })78+79+ describe('when trusting hop count', function () {80+ it('should respect X-Forwarded-Proto', function (done) {81+ var app = express();82+83+ app.set('trust proxy', 1);84+85+ app.use(function (req, res) {86+ res.end(req.protocol);87+ });88+89+ request(app)90+ .get('/')91+ .set('X-Forwarded-Proto', 'https')92+ .expect('https', done);93+ })94+ })95 })96 97 describe('when "trust proxy" is disabled', function(){98 it('should ignore X-Forwarded-Proto', function(done){14 unmodified linesmodified:test/req.secure.js+17 added
76 unmodified lines77 .get('/')78 .set('X-Forwarded-Proto', 'https, http')79 .expect('yes', done)80 })81+82+ describe('when "trust proxy" trusting hop count', function () {83+ it('should respect X-Forwarded-Proto', function (done) {84+ var app = express();85+86+ app.set('trust proxy', 1);87+88+ app.get('/', function (req, res) {89+ res.send(req.secure ? 'yes' : 'no');90+ });91+92+ request(app)93+ .get('/')94+ .set('X-Forwarded-Proto', 'https')95+ .expect('yes', done)96+ })97+ })98 })99 })100 })modified:.travis.yml+1 added
12345678language: node_jsnode_js: - "0.10" - "0.12"sudo: falsebefore_install: "npm rm --save-dev connect-redis"script: "npm run-script test-ci"after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"modified:History.md+12 added
1+unreleased2+==========3+4+ * Fix `req.host` when using "trust proxy" hops count5+ * Fix `req.protocol`/`req.secure` when using "trust proxy" hops count6+7 4.12.0 / 2015-02-238 ===================9 10 * Fix `"trust proxy"` setting to inherit when app is mounted696 unmodified lines707 - `app.router()` - returns the app Router instance708 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route709 - Router & Route - public API710 711+3.20.1 / 2015-02-28712+===================713+714+ * Fix `req.host` when using "trust proxy" hops count715+ * Fix `req.protocol`/`req.secure` when using "trust proxy" hops count716+717 3.20.0 / 2015-02-18718 ===================719 720 * Fix `"trust proxy"` setting to inherit when app is mounted1988 unmodified linesmodified:package.json-1 removed
58 unmodified lines59 "marked": "0.3.3",60 "mocha": "~2.1.0",61 "should": "~5.0.1",62 "supertest": "~0.15.0",63- "hjs": "~0.0.6",63 "body-parser": "~1.12.0",64 "connect-redis": "~2.2.0",65 "cookie-parser": "~1.3.4",66 "express-session": "~1.10.3",23 unmodified lines