Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Active SVG-import regressions lose text and inherited styles, produce incorrect opacity and geometry offsets, and turn empty fragments into unintended page requests.
7 open issues
Treat blank SVG fragments as empty input, not URLs · New Match only the style attribute when parsing CSS declarations · New Include shape normalization offsets in manual matrices · New Forward parent styles through nested SVG readers · New Forward parent styles to rounded-rectangle readers · New Resolve currentColor and inherit from imported styles · New Avoid applying inherited fill and stroke opacity to groups · New
What changed in this PR
This PR hardens Two.load() against untrusted SVG markup, addressing the loading path reported in #797 while retaining the trusted-input contract for interpret().
Changes:
- Adds detached SVG sanitization, restricted references, and opt-in external images.
- Updates import handling, error reporting, TypeScript declarations, and migration documentation.
- Adds cross-browser regression coverage and CI, updates build processing, and regenerates the bundle.
| File | Description |
|---|---|
| wiki/svg-import/README.md | Documents the import contract and migration steps. |
| wiki/docs/two/README.md | Updates loader options and trust boundaries. |
| utils/file-sizes.json | Records increased bundle sizes. |
| utils/build.js | Uses literal metadata replacement and reports build failures. |
| tests/typescript/index.ts | Exercises loader options and callback types. |
| tests/browser/svg-import.spec.js | Adds security and drawing regression coverage. |
| tests/browser/playwright.config.js | Configures three browsers and local serving. |
| tests/browser/interpreter.html | Hosts existing interpreter regressions. |
| tests/browser/import.html | Provides the SVG import test page. |
| tests/browser/fixtures/hostile.svg | Supplies hostile markup test cases. |
| tests/browser/fixtures/drawing.svg | Supplies supported drawing feature cases. |
| src/utils/xhr.js | Reports request failures and exposes response metadata. |
| src/utils/xhr.d.ts | Updates request callback declarations. |
| src/utils/svg-import.js | Implements sanitization and resource restrictions. |
| src/utils/svg-import.d.ts | Declares SVG import utilities. |
| src/utils/interpret-svg.js | Adapts interpretation for detached, isolated imports. |
| src/utils/dom.js | Removes the live-DOM loading container. |
| src/utils/dom.d.ts | Aligns declarations with remaining DOM helpers. |
| src/two.js | Integrates sanitized loading and error handling. |
| src/two.d.ts | Types loader options and sanitized callback nodes. |
| src/events.js | Adds the error event name. |
| src/events.d.ts | Declares the error event name. |
| README.md | Introduces SVG loading security guidance. |
| package.json | Adds sanitizer and browser-test dependencies. |
| package-lock.json | Locks added dependencies. |
| build/two.js | Regenerates the distributable with import hardening. |
| .gitignore | Excludes browser-test reports and artifacts. |
| .github/workflows/browser-tests.yml | Runs browser regressions in GitHub Actions. |
Review effort: Balanced
This branch has not been deployed
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.

Two.load()currently parses supplied markup inside a temporary element attached todocument.head, allowing source content to affect the page before SVG interpretation. This change imports a restricted SVG drawing format through DOMPurify and a detached document, without inserting source markup into the page.Addresses the loading path in #797. The report's separate renderer attribute-injection and SSRF severity claims remain unconfirmed;
interpret()and programmatic renderer utilities retain their trusted-input contract.Changes
<use>references to the imported document.allowExternalImages: truefor HTTP(S) images. Resolve relative image URLs against the final SVG response URL.options.onErrorand anerrorevent for asynchronous failures; handle HTTP and network failures and support source URLs with query strings or no.svgsuffix.currentColorandinheritwithin the imported style chain, forward styles through nested SVGs and rounded rectangles, and avoid applying paint opacity twice through groups. Fix manual matrix conversion, connectAutoCalculateImportedMatricesto the interpreter flag, and preserve referenced image URLs when expanding<use>.Compatibility
load()output. Move supported styling into inline presentation styles or attributes; useinterpret()only for trusted DOM when page styles are required.HTMLCollection.See the SVG import contract and migration guide.
Validation
Local validation, including the Copilot review fixes:
npm cinpm run test:browser: 87 passed across Chromium, Firefox, and WebKit, including existing QUnit SVG interpreter regressions, an executable control for the previous injection behavior, hostile inline/fetched inputs across all renderers, pixel checks, image policy, reference isolation, callback lifecycle, failure recovery, blank fragments, italic text, nested and rounded-shape inheritance, imported color keywords and opacity, and normalized manual-transform bounds.npx eslint .npm run types:checknpm run docs:buildnpm audit --omit=dev: zero findings.