Conversation
There was a problem hiding this comment.
Pull request overview
Hotfix to strengthen SVG sanitization against obfuscated/external CSS url(...) references (including CSS hex escapes), and to expand fixture-based test coverage for previously handled cases.
Changes:
- Add CSS-escape decoding + css-tree AST scanning to detect external
url(...)in attributes and<style>blocks. - Extend attribute sanitization to handle multiple
url(...)occurrences and more SVG URI-carrying scenarios. - Add/adjust SVG fixture pairs to validate sanitization behavior across more cases.
Reviewed changes
Copilot reviewed 2 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/scratch-svg-renderer/src/sanitize-svg.js | Adds css-tree-based canonicalization and external url() detection for attributes and <style> elements. |
| packages/scratch-svg-renderer/package.json | Updates css-tree dependency to a newer major line. |
| package-lock.json | Locks updated dependency graph for css-tree upgrade/dedupe. |
| packages/scratch-svg-renderer/test/fixtures/css-escapes.svg | New fixture covering CSS hex-escaped url cases and multiple url() values. |
| packages/scratch-svg-renderer/test/fixtures/css-escapes.sanitized.svg | Expected sanitized output for CSS escape fixture. |
| packages/scratch-svg-renderer/test/fixtures/external-hrefs.svg | New fixture covering external href/xlink:href across more SVG elements. |
| packages/scratch-svg-renderer/test/fixtures/external-hrefs.sanitized.svg | Expected sanitized output for external href fixture. |
| packages/scratch-svg-renderer/test/fixtures/namespace-and-uri-attrs.svg | New fixture for namespace-prefixed href attributes and xml:base behavior. |
| packages/scratch-svg-renderer/test/fixtures/namespace-and-uri-attrs.sanitized.svg | Expected sanitized output for namespace/URI attribute fixture. |
| packages/scratch-svg-renderer/test/fixtures/blocked-elements.svg | New fixture for DOMPurify svgDisallowed elements with URI attributes. |
| packages/scratch-svg-renderer/test/fixtures/blocked-elements.sanitized.svg | Expected sanitized output for blocked-elements fixture. |
| packages/scratch-svg-renderer/test/fixtures/css-links.sanitized.svg | Updates expected <style> serialization after canonicalization/generation changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace our hand-rolled decodeCssEscapes regex with css-tree's built-in ident.decode(). Upgrade css-tree from 1.1.3 to 3.2.1 and update Url node access for the new API (node.value instead of node.value.value).
The previous href check used `currentNode.href.baseVal` (the SVG DOM `SVGURIReference` API), which jsdom does not implement. The check was always falsy, so external href values on <image>, <feImage>, <mpath>, <pattern>, <linearGradient>, and <textPath> were never blocked. Replace with a direct getAttribute-based check in the attribute loop, alongside the existing CSS url() check.
38d96df to
7821a42
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
KManolov3
left a comment
There was a problem hiding this comment.
Looks good! Thanks for turning this around so quickly!
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
89c851d to
9442435
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 14 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This hotfix branch is intended for deployment as-is, and will be merged into
develop(after resolving conflicts) as a followupProposed Changes
Catch more cases, including:
urlin attributes or<style>elementsurl(...)items in one attribute, where the first one is OK and one of the later URLs is an external referenceAlso, add tests for many cases that were already handled correctly.
Reason for Changes
We're seeing some cases in the wild where hex-escaped URLs are being used to add "creative" styling to the project page.
To clarify for those who are ...lurking... 👀
We know this won't block the CSS trickery itself; it just blocks the potential leakage of personal information. That's the super-urgent part of this. Turning the page blue or replacing the Scratch logo is cute and/or annoying, and we do plan to fix that, but the privacy implications of it are limited. I just have too many meetings today to safely do both in one go 😅
Test Coverage
Included.