fix(auth): восстанавливать раздел и фильтры после входа Portal

This commit is contained in:
Denozordec committed 2026-10-13 16:09:27 +07:00
1 parent 199910eceb
commit 46de87e213
15 files changed
+275 -17

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
/** Accept an application path, never an external URL or another auth handoff. */
export function safeAuthReturnPath(value: string | null | undefined): string | null {
if (!value || value.length > 2048 || !value.startsWith("/") || value.startsWith("//")) return null
if (/[\\\u0000-\u0020\u007f]/.test(value)) return null
try {
const url = new URL(value, "https://mmapp.invalid")
if (url.origin !== "https://mmapp.invalid" || /%/.test(url.pathname)) return null
if (/^\/(auth|api|access-denied)(\/|$)/.test(url.pathname)) return null
return url.pathname + url.search
} catch {
return null
}
}
export function permittedAuthReturnPath(
value: string | null | undefined,
allowed: (pathname: string) => boolean,
fallback: string,
): string {
const path = safeAuthReturnPath(value)
return path && allowed(new URL(path, "https://mmapp.invalid").pathname) ? path : fallback
}