Skip to content

Commit 1f860fb

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 4453d83 commit 1f860fb

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
@@ -151,6 +151,20 @@ describe('req', function(){
151151
.set('X-Forwarded-Host', 'evil')
152152
.expect('localhost', done);
153153
})
154+
155+
it('should ignore comma-separated X-Forwarded-Host', function(done){
156+
var app = express();
157+
158+
app.use(function(req, res){
159+
res.end(req.host);
160+
});
161+
162+
request(app)
163+
.get('/')
164+
.set('Host', 'localhost')
165+
.set('X-Forwarded-Host', 'example.com, foobar.com')
166+
.expect('localhost', done);
167+
})
154168
})
155169
})
156170
})

0 commit comments

Comments
 (0)