security: validate browser origins at the authenticated websocket proxy
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user