Files
klz-cables.com/.pnpm-store/v10/files/20/4232a248d94a3850081aaf9a93ec477f8035d53641aa5c82818dac855dd459e166afa6e95b94bcc58412bfffc8ac9740135b249eeed519fdbaad14c1bc9af9
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

25 lines
1.4 KiB
Plaintext

export const getSafeRedirect = ({ allowAbsoluteUrls = false, fallbackTo = '/', redirectTo })=>{
if (typeof redirectTo !== 'string') {
return fallbackTo;
}
// Normalize and decode the path
let redirectPath;
try {
redirectPath = decodeURIComponent(redirectTo.trim());
} catch {
return fallbackTo // invalid encoding
;
}
const isSafeRedirect = // Must start with a single forward slash (e.g., "/admin")
redirectPath.startsWith('/') && // Prevent protocol-relative URLs (e.g., "//example.com")
!redirectPath.startsWith('//') && // Prevent encoded slashes that could resolve to protocol-relative
!redirectPath.startsWith('/%2F') && // Prevent backslash-based escape attempts (e.g., "/\\/example.com", "/\\\\example.com", "/\\example.com")
!redirectPath.startsWith('/\\/') && !redirectPath.startsWith('/\\\\') && !redirectPath.startsWith('/\\') && // Prevent javascript-based schemes (e.g., "/javascript:alert(1)")
!redirectPath.toLowerCase().startsWith('/javascript:') && // Prevent attempts to redirect to full URLs using "/http:" or "/https:"
!redirectPath.toLowerCase().startsWith('/http');
const isAbsoluteSafeRedirect = allowAbsoluteUrls && // Must be a valid absolute URL with http or https
/^https?:\/\/\S+$/i.test(redirectPath);
return isSafeRedirect || isAbsoluteSafeRedirect ? redirectPath : fallbackTo;
};
//# sourceMappingURL=getSafeRedirect.js.map