Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
1234567891011121314151617181920// post-login targets are attacker-controlled (login links, stored pending// state), so resolve against an opaque origin and only accept paths that// stay on it. also covers network-path forms like "/\evil.com" that the url// parser turns into a foreign hostconst SAFE_BASE = "https://return-to.invalid";
export const safeReturnTo = (value: unknown): string => { if (typeof value !== "string" || value.trim() === "") return "/";
let resolved: URL; try { resolved = new URL(value, SAFE_BASE); } catch { return "/"; } if (resolved.origin !== SAFE_BASE) return "/";
return `${resolved.pathname}${resolved.search}${resolved.hash}`;};