Fix: Enhanced ?next= parameter URL validation and anti-loop protections#633
Open
mhdgning131 wants to merge 2 commits intochithi-dev:mainfrom
Open
Fix: Enhanced ?next= parameter URL validation and anti-loop protections#633mhdgning131 wants to merge 2 commits intochithi-dev:mainfrom
mhdgning131 wants to merge 2 commits intochithi-dev:mainfrom
Conversation
baseplate-admin
requested changes
Apr 3, 2026
Collaborator
baseplate-admin
left a comment
There was a problem hiding this comment.
Just one small change required :)
Comment on lines
+15
to
+31
| export function validateRedirectUrl(url: string, origin: string): string { | ||
| try { | ||
| const parsed = new URL(url, origin); | ||
|
|
||
| if (parsed.origin !== origin) { | ||
| throw new Error('External redirects are not allowed.'); | ||
| } | ||
|
|
||
| if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') { | ||
| throw new Error('Invalid protocol.'); | ||
| } | ||
| return parsed.pathname + parsed.search + parsed.hash; | ||
| } catch (e) { | ||
| if (e instanceof Error) throw e; | ||
| throw new Error('Malformed redirect URL.'); | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
This should live in src/lib/functions/urls.ts
83d6504 to
0b5d135
Compare
updated: src/frontend/src/routes/(needs_onboarding)/login/+page.svelte updated: src/frontend/src/routes/(needs_onboarding)/logout/+page.server.ts
0b5d135 to
d060e65
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements stricter security controls and robustness for "next" parameter redirection logic across the login and logout flows with stricter
validateRedirectUrlutilityEnforces a strict same-origin policy using the
new URL()constructor with a trusted base.Automatically strips the domain, protocol, and host from absolute URLs to ensure all redirects stay within the internal site structure (
pathname + search + hash)Blocks non-HTTP/S protocols such as
javascript:ordata:Added explicit
/adminpath checks at redirect points to prevent infinite loop scenarios