[HOTFIX] fix(tldraw): allow data:image/svg+xml on <image> with recursive sanitization#8088
Merged
MitjaBezensek merged 1 commit intohotfixesfrom Feb 25, 2026
Merged
[HOTFIX] fix(tldraw): allow data:image/svg+xml on <image> with recursive sanitization#8088MitjaBezensek merged 1 commit intohotfixesfrom
MitjaBezensek merged 1 commit intohotfixesfrom
Conversation
…ization (#8087) When you export shapes as SVG, paste back (creates image shape), then export again with other shapes — the second export wraps the first SVG as `<image href="data:image/svg+xml;base64,...">`. On paste, `sanitizeSvg()` strips this href because `sanitizeUri` only allows raster data URIs on `<image>` elements. Result: blank image. This PR decodes the embedded SVG, runs `sanitizeSvg()` recursively (strips scripts/XSS), then re-encodes. Fully malicious embedded SVGs (no safe content left) are still blocked. Also adds a `MAX_NODE_DEPTH=100` cap on `sanitizeNode` recursion to prevent DoS from deeply nested elements. ### Change type - [x] `bugfix` ### Test plan 1. Export a geo shape as SVG 2. Paste it back (creates image shape) 3. Select that image shape + another shape, export as SVG 4. Paste the resulting SVG — the image should render correctly, not be blank - [x] Unit tests ### Release notes - Fixed SVG sanitizer stripping embedded SVG data URIs on `<image>` elements. Nested SVGs (from re-exporting pasted SVG images) are now recursively sanitized instead of blocked. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches XSS-sensitive SVG sanitization logic and introduces recursive decoding/encoding of data URIs, so subtle parsing/encoding or missed edge cases could create security or rendering regressions. > > **Overview** > Fixes a regression where exported SVGs containing nested `<image href="data:image/svg+xml;base64,...">` were being blanked by the sanitizer. > > `sanitizeSvg` now allows `data:image/svg+xml` on `<image>`/`<feImage>` by decoding the embedded SVG, re-running sanitization recursively, and re-encoding the sanitized result (dropping the `href` entirely if the embedded SVG has no safe content). Adds an embed recursion depth limit and new unit tests covering safe embedded SVG preservation and script-stripping behavior. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8297037. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
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.
This is an automated hotfix PR for dotcom deployment.
Original PR: #8087
with recursive sanitization
Original Title: fix(tldraw): allow data:image/svg+xml on
Original Author: @MitjaBezensek
This PR cherry-picks the changes from the original PR to the hotfixes branch for immediate dotcom deployment.
/cc @MitjaBezensek
Note
Medium Risk
Touches XSS-hardening logic and changes which
data:URIs are permitted on<image>, so mistakes could reintroduce injection vectors or break image rendering; recursion depth limiting reduces worst-case risk.Overview
sanitizeSvgnow allowsdata:image/svg+xmlURLs on<image>/<feImage>by decoding and recursively sanitizing the embedded SVG, then re-encoding it as a data URI; unsafe/invalid embedded SVG (or overly deep nesting) causes thehrefto be removed.This introduces helpers for data-URI decode/encode, threads a recursion
depththrough node/attribute sanitization, and expands tests to cover preserving safe embedded SVG, stripping scripts from mixed-content embeds, and continuing to block fully malicious embeds.Written by Cursor Bugbot for commit aa36002. This will update automatically on new commits. Configure here.