Files
pipelines/web/src/proxySecurity.js
T

13 lines
555 B
JavaScript

// 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;
}
}