mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-14 08:56:39 +00:00
add post auth url
This commit is contained in:
18
server/lib/normalizePostAuthPath.ts
Normal file
18
server/lib/normalizePostAuthPath.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Normalizes a post-authentication path for safe use when building redirect URLs.
|
||||
* Returns a path that starts with / and does not allow open redirects (no //, no :).
|
||||
*/
|
||||
export function normalizePostAuthPath(path: string | null | undefined): string | null {
|
||||
if (path == null || typeof path !== "string") {
|
||||
return null;
|
||||
}
|
||||
const trimmed = path.trim();
|
||||
if (trimmed === "") {
|
||||
return null;
|
||||
}
|
||||
// Reject protocol-relative (//) or scheme (:) to avoid open redirect
|
||||
if (trimmed.includes("//") || trimmed.includes(":")) {
|
||||
return null;
|
||||
}
|
||||
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
||||
}
|
||||
Reference in New Issue
Block a user