Allow SVG pointer-events and vector-effect presentation attributes - #1567
Open
Jaybhade wants to merge 1 commit into
Open
Allow SVG pointer-events and vector-effect presentation attributes#1567Jaybhade wants to merge 1 commit into
Jaybhade wants to merge 1 commit into
Conversation
Both are keyword-only SVG presentation attributes but were missing from the SVG attribute allow-list, so DOMPurify stripped e.g. <rect pointer-events="none"> and <circle vector-effect="non-scaling-stroke">. Their siblings in the same family are already allow-listed (shape-rendering, image-rendering, text-rendering, color-rendering, paint-order, visibility, display, overflow, mask-type), and both added attributes are enum-only with no script or URL surface. The identical styling is already reachable through the allow-listed style attribute, so neither addition grants a capability DOMPurify does not already permit. Neither attribute is added to the URI-safe set, so values still go through the regular IS_ALLOWED_URI screening.
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.
Summary
This pull request adds the
pointer-eventsandvector-effectSVG presentation attributes to the SVG attribute allow-list. Both are keyword-only presentation attributes, and both were being stripped from otherwise valid SVG.Background & Context
The SVG list already allow-lists every other keyword-only rendering/interaction presentation attribute in this family —
shape-rendering,image-rendering,text-rendering,color-rendering,paint-order,visibility,display,overflow,mask-type, and (since #1526)dominant-baselineandtext-orientation.pointer-eventsandvector-effectare the two remaining Baseline-widely-available members of that group that were still missing, so this is a consistency gap rather than a new capability.The practical symptom is silent visual breakage in generated SVG.
vector-effect="non-scaling-stroke"is what keeps a stroke width constant under a transform; dropping it makes strokes scale with the shape. This was reported for Fabric.js output in #447 — that issue was closed by its reporter, who moved the property intostyleas a workaround, so the allow-list itself was never revisited.pointer-events="none"is the standard way to make an overlay non-interactive and is emitted routinely by charting libraries.On the security side, neither attribute widens the attack surface:
pointer-eventstakesbounding-box | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | none;vector-effecttakesnone | non-scaling-stroke | non-scaling-size | non-rotation | fixed-position. Neither accepts a FuncIRI, a URL, or script.styleis allow-listed, sostyle="pointer-events:none"andstyle="vector-effect:non-scaling-stroke"already survive sanitization unchanged. This repository's own fixtures rely on that — the#137SVG image payload intest/fixtures/expect.mjscarriesvector-effect: non-scaling-strokeinsidestyle, and the#33payload carriespointer-events:none. Allowing the presentation-attribute form grants nothing that is not already permitted.IS_ALLOWED_URIscreening rather than bypassing it.FORBID_ATTR: ['pointer-events']still removes it,USE_PROFILES: { html: true }still drops the SVG element entirely, and event handlers andjavascript:URLs on the same element are still stripped.As with the other entries in
ATTRS.svg, these names become allow-listed for HTML elements too under the default configuration — the same asfill,display, andvisibilitytoday. They remain inert CSS in that position.Tasks
pointer-eventsandvector-effecttoATTRS.svginsrc/attrs.ts, in their alphabetical positionstest/fixtures/expect.mjscovering both attributes, using the payload shape from Adding vector-effect to svg whitelist #447dist/— the bundle diff is exactly the two added strings, with no other build driftnpm run lint(xo) passes cleanDependencies