-
Notifications
You must be signed in to change notification settings - Fork 0
fix: restrict client external navigation to http(s) and protocol-relative URLs #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,9 +132,9 @@ export function applyNavigationLocale(url: string, locale?: string): string { | |
| return `/${locale}${url.startsWith("/") ? url : `/${url}`}`; | ||
| } | ||
|
|
||
| /** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */ | ||
| /** Check if a URL is external (http/https, or protocol-relative) */ | ||
| export function isExternalUrl(url: string): boolean { | ||
| return /^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith("//"); | ||
| return /^https?:\/\//i.test(url) || url.startsWith("//"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The same narrowing in the Pages Router Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| /** Check if a href is only a hash change relative to the current URL */ | ||
|
|
||
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.
Restricting
isExternalUrlto onlyhttp(s)and//makes values likemailto:,tel:, andsms:fall into the internal navigation path, souseRouter().push()/replace()reacheshistory.pushStatewith a non-HTTP absolute URL and can throwSecurityErrorin browsers instead of delegating to native navigation. This is a regression from the previous behavior and breaks legitimate external protocol links; only dangerous schemes should be blocked.Useful? React with 👍 / 👎.