Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions surfsense_web/lib/auth-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,26 @@ export function getAndClearRedirectPath(): string | null {
if (redirectPath) {
localStorage.removeItem(REDIRECT_PATH_KEY);
}
if (redirectPath && !isValidRedirectPath(redirectPath)) {
return null;
}
return redirectPath;
}

/**
* Validates that a redirect path is a safe, relative URL on the same origin.
* Rejects absolute URLs, protocol-relative URLs, and scheme injections.
*/
function isValidRedirectPath(path: string): boolean {
if (!path.startsWith("/") || path.startsWith("//")) return false;
try {
const url = new URL(path, window.location.origin);
return url.origin === window.location.origin;
} catch {
return false;
}
}

/**
* Gets the bearer token from localStorage
*/
Expand Down
Loading