fix: strip tags from chart custom CSS at render time - #1355
Open
lucadobrescu wants to merge 2 commits into
Open
Conversation
lucadobrescu
marked this pull request as ready for review
July 29, 2026 10:46
Contributor
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
lucadobrescu
force-pushed
the
fix/custom-css-sanitize
branch
from
July 29, 2026 10:54
734b625 to
dce188c
Compare
lucadobrescu
force-pushed
the
fix/wizard-endpoint-auth
branch
from
July 29, 2026 10:54
2773045 to
d58f689
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Sanitizes chart custom CSS during rendering to prevent stored XSS across all CSS output paths.
Changes:
- Strips HTML tags from generated custom CSS rules.
- Adds an authenticated E2E helper for planting payloads.
- Tests sanitization and legitimate CSS preservation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
classes/Visualizer/Module.php |
Sanitizes generated CSS rules. |
tests/e2e/specs/custom-css.spec.js |
Verifies XSS prevention and CSS preservation. |
tests/e2e/config/plant-chart-settings.php |
Adds the test-data REST helper. |
.wp-env.json |
Loads the E2E helper as an MU plugin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Author
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.
Chart authors control the
customcsschart setting, and its contents were concatenated into a<style>block echoed without escaping on every page that renders chart CSS — including the admin Chart Library that aggregates CSS from all charts. This strips tags from each generated rule block at the single point where the CSS is built.What changed
CSS builder —
get_inline_custom_css()now passes each chart's generated rule block throughwp_strip_all_tags(). Before: acustomcssvalue containing</style><script>…</script>broke out of the style element and executed for anyone viewing WP Admin → Visualizer → Chart Library (admins) or a frontend page embedding the chart (visitors). After: markup is removed, legitimate declarations pass through untouched.Coverage — fixing at the builder covers all four sinks at once: Chart Library, chart editor data page, chart iframe render, and the frontend render.
Note
wp_strip_all_tags()removes anything tag-shaped, so CSS values can no longer contain literal tag-like strings (e.g. incontent:) — these never occur in the plugin's custom-CSS fields. Pure CSS-level injection (e.g.url()references) is out of scope; this closes the script-injection vector.QA
Expect: no alert fires. In DevTools, the chart's
<style id="customcss-visualizer-<CHART_ID>">block contains only CSS declarations (font-size: 12px !important;is still present).Expect: custom styles still apply in both places.