Skip to content

Allow SVG dominant-baseline and text-orientation presentation attributes#1526

Open
Develop-KIM wants to merge 1 commit into
cure53:mainfrom
Develop-KIM:fix/svg-text-adaption-attrs
Open

Allow SVG dominant-baseline and text-orientation presentation attributes#1526
Develop-KIM wants to merge 1 commit into
cure53:mainfrom
Develop-KIM:fix/svg-text-adaption-attrs

Conversation

@Develop-KIM

Copy link
Copy Markdown

Fixes #1525.

dominant-baseline was missing from the SVG attribute allow-list, so DOMPurify stripped it (e.g. <text dominant-baseline="middle">), even though its baseline siblings alignment-baseline and baseline-shift are already allowed. This adds it, plus text-orientation from the same W3C SVG2 text property adaptions group. Both are enum-only presentation attributes with no script or URL surface.

Before / after (default config):

IN : <svg><text dominant-baseline="middle">x</text></svg>
OUT: <svg><text>x</text></svg>            // before
OUT: <svg><text dominant-baseline="middle">x</text></svg>   // after

You mentioned being happy to add a few safe ones in bulk. I checked the rest of that spec section and deliberately left out unicode-bidi (its bidi-override value is a text-reordering/spoofing surface, so it felt like your call) and the deprecated glyph-orientation-horizontal / glyph-orientation-vertical. Happy to add any of those if you'd like.

Added two regression fixtures to test/fixtures/expect.mjs. Lint and the jsdom suite pass locally.

Implemented with AI assistance; I've reviewed and verified every change.

Both are pure presentation attributes from the W3C SVG2 text property
adaptions but were missing from the SVG attribute allow-list, so
DOMPurify stripped e.g. <text dominant-baseline="middle">. Their
baseline siblings alignment-baseline and baseline-shift are already
allow-listed; both added attributes are enum-only with no script/URL
surface.

Fixes cure53#1525

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 10, 2026 01:06
@Develop-KIM Develop-KIM requested a review from x00mario as a code owner July 10, 2026 01:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates DOMPurify’s SVG attribute allow-list to preserve two safe SVG2 text presentation attributes (dominant-baseline and text-orientation) that were previously stripped, and adds regression fixtures to prevent regressions.

Changes:

  • Add dominant-baseline and text-orientation to the SVG allowed attributes list (src/attrs.ts).
  • Add two regression fixtures covering both attributes (test/fixtures/expect.mjs).
  • Regenerate distribution bundles (dist/*) to reflect the updated allow-list.

Reviewed changes

Copilot reviewed 2 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/fixtures/expect.mjs Adds regression fixtures ensuring the two SVG attributes are preserved.
src/attrs.ts Extends the SVG attribute allow-list with dominant-baseline and text-orientation.
dist/purify.js Rebuilt distribution bundle incorporating the updated SVG allow-list.
dist/purify.es.mjs Rebuilt ESM distribution bundle incorporating the updated SVG allow-list.
dist/purify.cjs.js Rebuilt CJS distribution bundle incorporating the updated SVG allow-list.
dist/purify.min.js Rebuilt minified distribution bundle incorporating the updated SVG allow-list.
dist/purify.min.js.map Updated sourcemap corresponding to the rebuilt minified bundle.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG attribute dominant-baseline gets removed

2 participants