security: validate browser origins at the authenticated websocket proxy

This commit is contained in:
2026-10-20 15:48:02 +01:00
parent c6695e5e90
commit 1cf5156c77
4 changed files with 40 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
// The upstream has an Origin check, but a same-origin proxy must remove Origin
// before forwarding. Enforce it at the browser-facing boundary first instead
// of accidentally trusting any cookie-bearing WebSocket upgrade.
export function sameOriginUpgrade(origin, host) {
if (origin == null) return true; // non-browser clients have no Origin
try {
const url = new URL(origin);
return (url.protocol === "http:" || url.protocol === "https:") && url.host.toLowerCase() === String(host ?? "").toLowerCase();
} catch {
return false;
}
}