fix: constrain hydrated action redirects#127
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Implements a security hardening for hydrated action redirects by normalizing redirect strings against the current page, restricting redirects to same-origin http(s), and only navigating using the computed pathname/search/hash portion.
Changes:
- Add
normalizeActionRedirect()to validate redirect destinations (http/https + same origin) and strip topathname/search/hash. - Route enhanced action navigation through the normalized redirect value rather than the raw envelope string.
- Add jsdom regression tests to ensure unsafe redirect schemes/hosts are rejected and do not trigger navigation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/jsdom/actions/actions.test.tsx | Adds regression coverage rejecting cross-origin, protocol-relative, javascript:, and data: redirects for enhanced actions. |
| src/actions/index.tsx | Normalizes and constrains action redirects to same-origin http(s), and passes only pathname/search/hash to location.assign(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Closes #126.
Normalizes response redirects against the current page and permits only http(s) destinations on the current origin. Navigation receives pathname/search/hash rather than an untrusted absolute string.
Regression proof rejects cross-origin absolute and protocol-relative URLs plus javascript: and data: schemes while preserving the existing safe relative redirect contract. Focused action tests and the full local npm run check pass.