Sanitize javascript: URI in JSON drag-drop deserialization#1293
Merged
Conversation
StringPiece.fromJSON trusted href attributes from application/x-trix-document JSON payloads, allowing javascript: URIs to reach the DOM via drag-and-drop in Level0InputController. Add DOMPurify.isValidAttribute check to strip invalid hrefs at deserialization time.
There was a problem hiding this comment.
Pull request overview
This PR mitigates an XSS vector where untrusted href values (e.g., javascript:) from drag-and-drop JSON payloads could survive deserialization and later reach the DOM.
Changes:
- Sanitize
hrefduringStringPiece.fromJSONdeserialization usingDOMPurify.isValidAttribute, removing invalidhrefvalues. - Add unit tests verifying dangerous
javascript:hrefs are stripped while safehttps:hrefs remain. - Update the vendored/compiled Rails asset (
action_text-trix) to include the same deserialization sanitization.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/trix/models/string_piece.js |
Sanitizes href at JSON deserialization time to prevent unsafe URIs from propagating to rendering. |
src/test/unit/document_json_deserialization_test.js |
Adds regression tests for stripping javascript: links and preserving safe links. |
src/test/unit.js |
Registers the new unit test module. |
action_text-trix/app/assets/javascripts/trix.js |
Mirrors the deserialization-time href sanitization in the compiled asset shipped for Rails. |
💡 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.
Summary
StringPiece.fromJSONtrustedhrefattributes fromapplication/x-trix-documentJSON payloads, allowingjavascript:URIs to reach the DOM via drag-and-drop inLevel0InputControllerDOMPurify.isValidAttributecheck to strip invalid hrefs at deserialization time, matching the existing pattern inattachment_view.jsandtoolbar_controller.jsref: https://3.basecamp.com/2914079/buckets/1666/card_tables/cards/9722870610