Skip to content

Commit b3b9714

Browse files
committed
Support X-Forwarded-Host with multiple hosts
Closes #6215.
1 parent 6745a46 commit b3b9714

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/node/http.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,14 @@ function getHost(req: express.Request): string | undefined {
386386
}
387387
}
388388

389-
// Honor X-Forwarded-Host if present.
389+
// Honor X-Forwarded-Host if present. Some reverse proxies will set multiple
390+
// comma-separated hosts.
390391
const xHost = getFirstHeader(req, "x-forwarded-host")
391392
if (xHost) {
392-
return xHost.trim().toLowerCase()
393+
const firstXHost = xHost.split(",")[0]
394+
if (firstXHost) {
395+
return firstXHost.trim().toLowerCase()
396+
}
393397
}
394398

395399
const host = getFirstHeader(req, "host")

test/unit/node/http.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("http", () => {
5858
;[
5959
["host", test.host],
6060
["x-forwarded-host", test.host],
61+
["x-forwarded-host", `${test.host}, ${test.host}`],
6162
["forwarded", `for=127.0.0.1, host=${test.host}, proto=http`],
6263
["forwarded", `for=127.0.0.1;proto=http;host=${test.host}`],
6364
["forwarded", `proto=http;host=${test.host}, for=127.0.0.1`],

0 commit comments

Comments
 (0)