-
Notifications
You must be signed in to change notification settings - Fork 2
🔒 Fix Potential Open Redirect in Auth Router #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sunnylqm
wants to merge
1
commit into
main
Choose a base branch
from
fix-open-redirect-auth-router-5167146257682080570
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
Do browser URL parsers / the History API strip ASCII tab or newline characters from URL inputs, and can a decoded path like "/%09/evil.com" or "/%0A/evil.com" normalize to a protocol-relative URL?💡 Result:
Yes—literal ASCII tab/newline characters in a URL input string are stripped by the WHATWG URL parser (used by modern browsers).
history.pushState/replaceState) parses the providedurlby running “encoding-parsing a URL” relative to the relevant settings object, which goes through URL parsing (and therefore gets the same tab/newline stripping behavior). (html.spec.whatwg.org)Can
"/%09/evil.com"or"/%0A/evil.com"normalize to a protocol-relative URL?Not by the browser’s URL parser alone.
/%09/evil.comand/%0A/evil.comcontain the percent sign + hex digits, not literal tab/newline characters, so the parser’s “strip ASCII tab/newline” step does not remove%09/%0A. (url.spec.whatwg.org)//(e.g.//evil.com). Your examples start with/%09/...or/%0A/..., so they remain ordinary paths.When could it become protocol-relative?
Only if something percent-decodes first (turning
%09into a literal TAB or%0Ainto a literal LF) and then the browser parses that decoded string. For example, if an application decodes to the literal string"/\t/evil.com", the URL parser will strip the tab, producing"//evil.com", which is protocol-relative. (url.spec.whatwg.org)Citations:
🏁 Script executed:
Repository: reactnativecn/pushy-admin
Length of output: 3259
🏁 Script executed:
Repository: reactnativecn/pushy-admin
Length of output: 548
Reject ASCII control characters before prefix validation to prevent normalization bypass.
loginFromis decoded byURLSearchParams, so encoded control characters like%09(tab) and%0A(newline) reach this validator as literal control characters. The current prefix-only checks pass strings like"/%09/evil.com", but when passed torouter.navigate(), the browser's URL parser strips the literal tab per the WHATWG specification, normalizing it to"//evil.com"(a protocol-relative URL) and enabling an open redirect.🔐 Hardening required
export const isSafeRedirect = (url: string | null | undefined): boolean => { if (!url) return false; - // Ensure it starts with / and not // or \ - return url.startsWith('/') && !url.startsWith('//') && !url.startsWith('/\\'); + // Reject characters that URL parsers strip or normalize. + if (/[\u0000-\u001F\u007F]/.test(url)) return false; + // Only allow app-internal absolute paths. + return /^\/(?![\\/])/.test(url); };🤖 Prompt for AI Agents