Skip to content

fix: prevent SecurityError from external hash fragments on landing page#1

Draft
tenderdeve wants to merge 1 commit into
mainfrom
fix/7979-sanitize-hash-fragment
Draft

fix: prevent SecurityError from external hash fragments on landing page#1
tenderdeve wants to merge 1 commit into
mainfrom
fix/7979-sanitize-hash-fragment

Conversation

@tenderdeve
Copy link
Copy Markdown
Owner

Opening app.uniswap.org/#//example.org causes a SecurityError because hash.replace('#', '') yields //example.org — a protocol-relative URL — which history.replaceState refuses to set from a different origin. The error overlay appears until the page is reloaded.

The fix adds a guard so the redirect only fires when the stripped hash starts with a single /, preserving all valid legacy hash routes (e.g. #/swap) while safely ignoring any external-looking fragments.

Upstream issue: Uniswap#7979

When a URL like app.uniswap.org/#//example.org is opened, stripping
the '#' leaves '//example.org' which React Router passes to
history.replaceState. The browser rejects protocol-relative URLs from
a different origin, throwing a SecurityError and showing the error overlay.

Only redirect when the resulting path starts with a single '/', which
preserves all valid legacy hash routes like #/swap while ignoring
external-looking fragments.

Fixes Uniswap#7979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant