Repository navigation
fix: render sanitized SVG data images in imported HTML - #105
Merged
Merged
Conversation
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.
Reader displays the embedded blue SVG as a broken image when opening the imported HTML reproduced in round 2 and round 3.
The fixture uses an
<img src="data:image/svg+xml,...">with percent-encoded SVG.prepareHtmlDocumentremoved itssrcbecause its image allowlist accepted only base64 raster images. The document CSP already permits data images.Sanitize SVG image payloads with DOMPurify before re-encoding them, removing scripts, event handlers, foreign HTML, animation, styling and external references. Reject malformed XML and omit source doctypes and processing instructions. Preserve local fragment references, quoted paints and non-breaking spaces. Accept SVG data URLs only as image sources, and strip
srcsetcandidates so they cannot bypass sanitization. Preserve safe nested raster data images. Keep the document CSP and iframe sandbox unchanged.Validation:
srcbefore the fix.rpnpm typecheckpassed.386b06bd3c4867830b6c23cd1562554e89de8458: lint, formatting, architecture, typecheck, full test suite, Chromium SVG regression, build and generated-file checks. Renderer HTML: 11 files / 99 tests passed, including 17 SVG sanitizer tests.rpnpm --filter @mdbase-reader/web-capture testpassed: 834 tests. SVG tests use jsdom because DOMPurify explicitly does not support happy-dom.Follow-ups: SVG CSS remains stripped, including inline
styleattributes and class-based<style>rules; supporting those drawings would need CSS sanitization. The existing multi-screen accessibility script times out on its stalegridlocator; the requested main-screen axe checks were run directly. No production testing, daemon access, merge or deployment.