Opened 3 months ago
Last modified 11 days ago
#65795 new defect (bug)
Icons: Improve the SVG sanitizer in WP_Icons_Registry
| Reported by: | wildworks | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.3 |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
- Follow-up to #64847.
- Gutenberg PR: https://github.com/WordPress/gutenberg/pull/75550
Core still has no dedicated SVG sanitization function, so the icons registry sanitizes icon content on its own. That sanitizer is incomplete: it strips attributes and elements that are valid SVG markup.
This ticket improves the sanitizer by extracting the root SVG element with WP_HTML_Processor before wp_kses() runs, and by expanding the allow-list to cover SVG-friendly elements and attributes.
Change History (15)
This ticket was mentioned in PR #12197 on WordPress/wordpress-develop by @wildworks.
3 months ago
#1
- Keywords has-patch has-unit-tests added
@mciampini commented on PR #12197:
3 months ago
#2
@t-hamano with https://github.com/WordPress/gutenberg/pull/78808 merged, can you take care of the Core side of things? Ie.
- rebase onto latest trunk
- Add https://github.com/WordPress/gutenberg/pull/78808 to its description (together with https://github.com/WordPress/gutenberg/pull/75550)
- Confirm its tests cover the stroke, style, vector-effect, and clip-rule attributes.
- Anything else to bring it up to date
Thank you 🙏
@retrofox commented on PR #12197:
2 months ago
#3
With WordPress/gutenberg#82540 merged, 21 library icons now draw with <rect> or <circle>, and core/sites is among the ones shipping to core, so the shape entries in this allowlist are needed for those icons to render server-side, not only the stroke attributes. The plugin side is fixed in WordPress/gutenberg#82846 (tracked in WordPress/gutenberg#82841), and it is listed against this PR in the backport changelog.
This ticket was mentioned in PR #13559 on WordPress/wordpress-develop by @wildworks.
2 months ago
#6
This PR is a subset of #12197, focusing only on allowing the SVG elements and attributes needed for core icons to render correctly.
The core icons are now stroke-based, but WP_Icons_Registry::sanitize_icon_content() strips attributes such as stroke-width, vector-effect, and style="fill: none", so the icons render incorrectly. This PR extends the allowlist with the same elements and attributes allowed in Gutenberg:
- Stroke-related attributes and
styleon all allowed elements fill,fill-rule, andclip-ruleonsvgclip-ruleonpathandpolygon, andopacityonpathrectandcircleelements
Related Gutenberg PRs:
- https://github.com/WordPress/gutenberg/pull/78808
- https://github.com/WordPress/gutenberg/pull/82846
test_wp_get_icon_size_null_leaves_dimensions_untouched is also updated, because checking for the width= string now matches the preserved stroke-width attribute.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Porting the Gutenberg changes, writing tests, and drafting this description; reviewed by me.
@wildworks commented on PR #12197:
2 months ago
#7
I created #13559, which extracts some unit tests from this PR, so that I can focus on ensuring the core icon set renders correctly.
We can continue discussing this PR as part of a more comprehensive improvement in the future.
@wildworks commented on PR #13559:
2 months ago
#8
@wildworks commented on PR #13559:
2 months ago
#9
@wildworks commented on PR #13559:
8 weeks ago
#11
This ticket was mentioned in PR #13766 on WordPress/wordpress-develop by @wildworks.
7 weeks ago
#12
Use assertEqualHTML() instead of assertSame() in the icons registry tests that compare sanitized icon markup, so they don't fail on changes that don't affect the resulting HTML, such as attribute order or escaping.
Equivalent to https://github.com/WordPress/gutenberg/pull/83544.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Porting the Gutenberg change and drafting this PR; reviewed by me.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code
## Use of AI Tools
Used for: Initial code skeleton and test suggestions; final implementation and tests were reviewed and edited by me.