Security: same-origin redirect validation#481
Open
nicdavidson wants to merge 3 commits intodevelopfrom
Open
Conversation
The function was reading a URL from sessionStorage (originally captured from the ?redirect= query param) and navigating to it without any origin validation, allowing an attacker to craft a login link that sends the victim — along with their live session token — to an arbitrary external host after authentication. Changes: - Add isSameOriginUrl() that composes isValidHttpUrl() with an explicit window.location.origin comparison, rejecting external, protocol-relative, javascript:, and data: URLs. - Patch handleRedirectIfPresent() to call isSameOriginUrl() before navigating; invalid URLs fall back to '/' instead of following the attacker-controlled destination. - Expand url.spec.ts with 17 new tests covering isSameOriginUrl and the updated handleRedirectIfPresent (same-origin pass, token append, external URL rejection, protocol-relative/javascript:/data: rejection, fallback-to-root behaviour, sessionStorage cleanup on failure).
- Update swagger-ui 4.15.5 → 5.32.2 (fixes DOMPurify XSS/prototype pollution CVEs and Handlebars JS injection CVEs) - Run npm audit fix for semver-compatible security patches Result: 0 critical vulnerabilities (was 3), 58 total (was 77). Remaining 58 are all in Angular 16 toolchain (requires major version upgrade) and transitive dev dependencies.
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.
Summary
handleRedirectIfPresentto prevent open redirect attacksTest plan