From d57618e8dd947243a60bff0997144c60fcaa6ce2 Mon Sep 17 00:00:00 2001 From: adityajai119 Date: Fri, 13 Nov 2026 00:07:27 +0530 Subject: [PATCH] Match exact trusted origins case-insensitively authenticateOrigin() lowercases the host of the origin and isTrustedOrigin() lowercases the domain of *.example.com entries, but exact entries were compared as written, so an entry with an uppercase letter (for example a Windows host name like DESKTOP-ABC123:8080) never matched and requests from that origin were refused. Fixes #8124 --- src/node/http.ts | 2 +- test/unit/node/http.test.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/node/http.ts b/src/node/http.ts index 4dab2356a0e0..7a689f32e53a 100644 --- a/src/node/http.ts +++ b/src/node/http.ts @@ -368,7 +368,7 @@ export function ensureOrigin(req: express.Request, _?: express.Response, next?: */ export function isTrustedOrigin(origin: string, trustedOrigins: string[]): boolean { return trustedOrigins.some((trusted) => { - if (trusted === "*" || trusted === origin) { + if (trusted === "*" || trusted.toLowerCase() === origin) { return true } // *.example.com style: match origin if it is the domain or a subdomain diff --git a/test/unit/node/http.test.ts b/test/unit/node/http.test.ts index 98d7bb2d17c5..5b247c248e91 100644 --- a/test/unit/node/http.test.ts +++ b/test/unit/node/http.test.ts @@ -26,6 +26,11 @@ describe("http", () => { expect(http.isTrustedOrigin("example.com", ["other.com"])).toBe(false) }) + it("should match exact origins regardless of case", () => { + expect(http.isTrustedOrigin("example.com", ["Example.com"])).toBe(true) + expect(http.isTrustedOrigin("desktop-abc123:8080", ["DESKTOP-ABC123:8080"])).toBe(true) + }) + it("should match the wildcard *", () => { expect(http.isTrustedOrigin("anything.example.com", ["*"])).toBe(true) expect(http.isTrustedOrigin("localhost:8080", ["*"])).toBe(true) @@ -131,6 +136,11 @@ describe("http", () => { host: "other.com", trustedOrigins: ["*"], }, + { + origin: "http://desktop-abc123:8080", + host: "other.com", + trustedOrigins: ["DESKTOP-ABC123:8080"], + }, ].forEach((test) => { ;[ ["host", test.host],