Skip to content

[6.x] Centralize SVG sanitization and sanitize CSS in style tags#14442

Merged
jasonvarga merged 3 commits into6.xfrom
svg-sanitize
Apr 6, 2026
Merged

[6.x] Centralize SVG sanitization and sanitize CSS in style tags#14442
jasonvarga merged 3 commits into6.xfrom
svg-sanitize

Conversation

@jasonvarga
Copy link
Copy Markdown
Member

Summary

  • Centralized SVG sanitization into Statamic\Support\Svg::sanitize(), replacing duplicated DOMSanitizer usage across four call sites
  • Added CSS content sanitization for <style> tags within SVGs — strips @import rules and external url() references while preserving internal CSS, fragment references (url(#gradient)), and data URIs
  • Updated Assets\Uploader, Assets\Asset, CP\Navigation\NavItem, and Tags\Svg to use the centralized method
  • The {{ svg }} tag's allow_tags/allow_attrs customization continues to work via an optional $sanitizer parameter

Test plan

  • 16 new tests in tests/Support/SvgTest.php covering sanitizeCss() and full SVG pipeline
  • 1 new test in tests/Tags/SvgTagTest.php for CSS injection via {{ svg }} tag
  • Existing asset sanitization tests pass

@jasonvarga jasonvarga marked this pull request as ready for review April 6, 2026 22:03
jasonvarga and others added 2 commits April 6, 2026 18:20
…anitization, consolidate sanitizeCss tests into data provider

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@jasonvarga jasonvarga merged commit f07dd35 into 6.x Apr 6, 2026
17 checks passed
@jasonvarga jasonvarga deleted the svg-sanitize branch April 6, 2026 23:45
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.

1 participant