Skip to content

Commit b6953e9

Browse files
committed
fix(core): allow host headers with default ports
1 parent a08b32e commit b6953e9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/core/src/http/request.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ export class Parts {
7373
}
7474

7575
const uri = new URL(`${protocol}://${host}${message.url}`);
76+
const inferredPort = uri.port === "" ? (protocol === "http" ? "80" : "443") : uri.port;
7677

77-
if (uri.host !== host) {
78+
if (uri.host !== host && `${uri.hostname}:${inferredPort}` !== host) {
7879
throw new Error(`Host injection discovered: ${host}`);
7980
}
8081

packages/core/test/http/request.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ describe("http:request", () => {
111111
/Host injection discovered: invalid@host/,
112112
);
113113
});
114+
115+
it("fromIncomingMessage throws no error on valid host with default port", () => {
116+
const message = new IncomingMessage();
117+
message.method = "GET";
118+
message.headers["x-forwarded-proto"] = "http";
119+
message.headers["x-forwarded-host"] = "proxy.com:80";
120+
121+
Parts.fromIncomingMessage(message, true);
122+
});
114123
});
115124

116125
describe("HttpRequest", () => {

0 commit comments

Comments
 (0)