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],