Skip to content

fix: strip tags from chart custom CSS at render time - #1355

Open
lucadobrescu wants to merge 2 commits into
fix/wizard-endpoint-authfrom
fix/custom-css-sanitize
Open

fix: strip tags from chart custom CSS at render time#1355
lucadobrescu wants to merge 2 commits into
fix/wizard-endpoint-authfrom
fix/custom-css-sanitize

Conversation

@lucadobrescu

Copy link
Copy Markdown
Contributor

Chart authors control the customcss chart 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 builderget_inline_custom_css() now passes each chart's generated rule block through wp_strip_all_tags(). Before: a customcss value 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. in content:) — 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

  1. Plant a payload on any published chart (UI save flows strip tags, so use wp-cli):
wp eval 'update_post_meta( <CHART_ID>, "visualizer-settings", array( "customcss" => array( "title" => array( "color" => "red</style><script>alert(1)</script><style>", "font-size" => "12px" ) ) ) );'
  1. WP Admin → Visualizer → Chart Library.

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).

  1. Regression — open a chart that uses legitimate custom CSS in WP Admin → Visualizer → Chart Library → edit chart, and on a frontend page containing its shortcode.

Expect: custom styles still apply in both places.

@lucadobrescu lucadobrescu self-assigned this Jul 29, 2026
@lucadobrescu
lucadobrescu marked this pull request as ready for review July 29, 2026 10:46
@pirate-bot

pirate-bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Plugin build for dce188c is ready 🛎️!

lucadobrescu and others added 2 commits July 29, 2026 13:53
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@lucadobrescu
lucadobrescu force-pushed the fix/custom-css-sanitize branch from 734b625 to dce188c Compare July 29, 2026 10:54
@lucadobrescu
lucadobrescu force-pushed the fix/wizard-endpoint-auth branch from 2773045 to d58f689 Compare July 29, 2026 10:54
@Soare-Robert-Daniel Soare-Robert-Daniel added the pr-checklist-skip Allow this Pull Request to skip checklist. label Jul 29, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Jul 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@lucadobrescu

Copy link
Copy Markdown
Contributor Author

The failing E2E test (lazy-render.spec.js › chart renders without artificial script delay) is unrelated to this PR — it fails identically on development itself (run 30446049333: 1 failed / 47 passed) and passes on #1353 and #1354 with these changes applied. All specs added by this stack pass.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

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

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants