Skip to content

Commit 475b00c

Browse files
committed
test: add test for ignoring comma-separated X-Forwarded-Host when trust proxy disabled
Verify that req.host ignores comma-separated X-Forwarded-Host values when trust proxy is disabled, ensuring security by using Host header instead of potentially malicious forwarded headers.
1 parent 1ae037a commit 475b00c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/req.host.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,20 @@ describe('req', function(){
167167
.set('X-Forwarded-Host', 'evil')
168168
.expect('localhost', done);
169169
})
170+
171+
it('should ignore comma-separated X-Forwarded-Host', function(done){
172+
var app = express();
173+
174+
app.use(function(req, res){
175+
res.end(req.host);
176+
});
177+
178+
request(app)
179+
.get('/')
180+
.set('Host', 'localhost')
181+
.set('X-Forwarded-Host', 'example.com, foobar.com')
182+
.expect('localhost', done);
183+
})
170184
})
171185
})
172186
})

0 commit comments

Comments
 (0)