Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sanitize javascript: URI in JSON drag-drop deserialization#1293

Merged
flavorjones merged 1 commit into
mainfrom
level-0-input-payload
Mar 26, 2026
Merged

Sanitize javascript: URI in JSON drag-drop deserialization#1293
flavorjones merged 1 commit into
mainfrom
level-0-input-payload

Conversation

@flavorjones
Copy link
Copy Markdown
Member

@flavorjones flavorjones commented Mar 26, 2026

Summary

  • 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
  • Adds DOMPurify.isValidAttribute check to strip invalid hrefs at deserialization time, matching the existing pattern in attachment_view.js and toolbar_controller.js
  • Adds unit tests asserting dangerous hrefs are stripped and safe hrefs are preserved in rendered DOM output

ref: https://3.basecamp.com/2914079/buckets/1666/card_tables/cards/9722870610

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.
Copilot AI review requested due to automatic review settings March 26, 2026 21:59
@flavorjones flavorjones changed the title Fix XSS via javascript: URI in JSON drag-drop deserialization Sanitize javascript: URI in JSON drag-drop deserialization Mar 26, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 href during StringPiece.fromJSON deserialization using DOMPurify.isValidAttribute, removing invalid href values.
  • Add unit tests verifying dangerous javascript: hrefs are stripped while safe https: 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.

Comment thread action_text-trix/app/assets/javascripts/trix.js
Comment thread action_text-trix/app/assets/javascripts/trix.js
Comment thread src/test/unit/document_json_deserialization_test.js
Comment thread src/trix/models/string_piece.js
Comment thread src/trix/models/string_piece.js
@flavorjones flavorjones merged commit 9c0a993 into main Mar 26, 2026
25 checks passed
@flavorjones flavorjones deleted the level-0-input-payload branch March 26, 2026 22:08
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.

2 participants