Skip to content

Commit 1ae037a

Browse files
committed
test: add test for req.host with comma-separated X-Forwarded-Host
Add test to verify that req.host correctly handles comma-separated values in X-Forwarded-Host header by using only the first value. This ensures the behavior matches req.hostname and properly handles edge cases when proxies send multiple host values.
1 parent 4453d83 commit 1ae037a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/req.host.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ describe('req', function(){
135135
.expect('example.com', done);
136136
})
137137
})
138+
139+
it('should use first value when X-Forwarded-Host has comma', function (done) {
140+
var app = express();
141+
142+
app.enable('trust proxy');
143+
144+
app.use(function (req, res) {
145+
res.end(req.host);
146+
});
147+
148+
request(app)
149+
.get('/')
150+
.set('Host', 'localhost')
151+
.set('X-Forwarded-Host', 'example.com, foobar.com')
152+
.expect('example.com', done);
153+
})
138154
})
139155

140156
describe('when "trust proxy" is disabled', function(){

0 commit comments

Comments
 (0)