mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-26 23:06:37 +00:00
verify redirects are safe before redirecting
This commit is contained in:
18
src/lib/cleanRedirect.ts
Normal file
18
src/lib/cleanRedirect.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
type PatternConfig = {
|
||||
name: string;
|
||||
regex: RegExp;
|
||||
};
|
||||
|
||||
const patterns: PatternConfig[] = [
|
||||
{ name: "Invite Token", regex: /^\/invite\?token=[a-zA-Z0-9-]+$/ },
|
||||
{ name: "Setup", regex: /^\/setup$/ },
|
||||
{ name: "Resource Auth Portal", regex: /^\/auth\/resource\/\d+$/ }
|
||||
];
|
||||
|
||||
export function cleanRedirect(input: string): string {
|
||||
if (!input || typeof input !== "string") {
|
||||
return "/";
|
||||
}
|
||||
const isAccepted = patterns.some((pattern) => pattern.regex.test(input));
|
||||
return isAccepted ? input : "/";
|
||||
}
|
||||
Reference in New Issue
Block a user