Skip to content

Escape the attributes of chart action buttons - #1426

Open
vytisbulkevicius wants to merge 2 commits into
developmentfrom
bugfix/pro/654
Open

vytisbulkevicius wants to merge 2 commits into
developmentfrom
bugfix/pro/654

Conversation

@vytisbulkevicius

Copy link
Copy Markdown
Contributor

The action buttons under a chart (Print, CSV, Excel, Copy, Download Image) are built from the chart settings. The front end now renders only the known actions and escapes every attribute of the button.

What changed

  • Action buttons — an action key that the plugin does not know is skipped; no button is rendered for it.

  • Button attributes — the action key, the MIME type, the title and the chart ID pass through esc_attr().

Note

Tracked in Codeinwp/visualizer-pro#654.

QA

  1. Go to WP Admin → Visualizer → Chart Library and edit a chart. Open Settings → General → Frontend Actions → Actions. Turn on Print, CSV, Excel, Copy and Download Image, then save the chart.

  2. Add the chart shortcode to a page and open the page.

    Expect: the five buttons show under the chart, and each one does its action.

🤖 Generated with Claude Code

vytisbulkevicius and others added 2 commits November 26, 2026 16:16
A saved action value is printed into HTML attributes. Escape each part and
skip an action that the plugin does not define.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@pirate-bot

pirate-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Plugin build for b9dbb61 is ready 🛎️!

@pirate-bot pirate-bot 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.

🟢 Approved

This approves the escaping fix; the notes ask a developer to check raw filtered labels and how translated or filtered titles show in tooltips.

  • classes/Visualizer/Module/Frontend.php:492 — note A visualizer_action_buttons callback can return a label with markup, such as </a><img src=x onerror=alert(1)>. Line 492 prints the label without escaping, while the key and title from the same filter are now escaped. Does any callback, for example in Pro, build a label from text a user can enter? If labels are fixed strings, this is safe. If a label carries user text, escape it with esc_html().
Validation details
  • Files reviewed: 2/2 changed files. Unchecked rows: the escaping-twice leads from issues #1210 and #843.
  • The three new tests pass at this commit and fail against the base code (WordPress 7.1.5, PHPUnit 9.6.34).
  • The five sidebar actions render the same five buttons at this commit and at the base, with no PHP errors.
  • Chart saves strip tags from all posted values, so saved settings cannot reach the label.
Untested areas
  • Escaping-twice leads (issues #1210 and #843): the markup run has no run record. See the notes.
  • Pro callbacks of the action filters were not available.
  • Clicking each action in a browser was not run. The markup and scripts are unchanged.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • classes/Visualizer/Module/AMP.php:93-101 — unverified: schema, AMP and inline-CSS filters can return raw markup. The missing fact is whether a callback forwards caller-controlled settings without escaping; Pro callback source is unavai…
    • classes/Visualizer/Module.php:664-667 — unverified: schema, AMP and inline-CSS filters can return raw markup. The missing fact is whether a callback forwards caller-controlled settings without escaping; Pro callback source is unavai…
    • classes/Visualizer/Elementor/Widget.php:397-422 — unverified: the whole settings record also reaches JSON serialization and downstream renderers. WordPress localization is encoded at 5.2 /deps/wordpress/5.2/wp-includes/class.wp-scripts.php:45…
    • classes/Visualizer/Render/Sidebar.php:521-531 — unverified: textarea values are emitted raw. Establishing a remaining injection requires tracing a real settings producer that preserves a closing textarea tag through storage.
    • not reached: producers feeding classes/Visualizer/Render/Page/Update.php:52-55

🤖 Automated review · run code-review-agent_6b099e8eb5e593.12139109.


🤖 Review agent — review posted ✅ on b9dbb610 · approved · 0 findings · 22 min

Run code-review-agent_6b099e8eb5e593.12139109 · trail

$label = $actions[ $key ]['label'];
$title = $actions[ $key ]['title'];
$actions_div .= sprintf( '<a href="#" class="visualizer-action visualizer-action-%s" data-visualizer-type="%s" data-visualizer-chart-id="%s" data-visualizer-container-id="%s" data-visualizer-mime="%s" title="%s"', $key, $key, $atts['id'], $id, $mime, $title );
$actions_div .= sprintf( '<a href="#" class="visualizer-action visualizer-action-%s" data-visualizer-type="%s" data-visualizer-chart-id="%s" data-visualizer-container-id="%s" data-visualizer-mime="%s" title="%s"', esc_attr( $key ), esc_attr( $key ), esc_attr( $atts['id'] ), esc_attr( $id ), esc_attr( $mime ), esc_attr( $title ) );

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.

note The title already comes from esc_html__(), and line 483 now wraps it in esc_attr() too. A translated title with an apostrophe or & could then show an entity such as &amp; as text in the tooltip. A gettext test showed title="Imprimer l&#039;&amp;graphique" at both the base and this commit. Check one real translation with such a character. Safe: the tooltip shows the plain character. Broken: it shows the entity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Checked: esc_attr() does not encode an existing entity a second time (_wp_specialchars() runs with $double_encode = false), so a translated title such as l&#039;&amp; is the same in the markup before and after this change, as the gettext run shows. No change needed.

$label = $actions[ $key ]['label'];
$title = $actions[ $key ]['title'];
$actions_div .= sprintf( '<a href="#" class="visualizer-action visualizer-action-%s" data-visualizer-type="%s" data-visualizer-chart-id="%s" data-visualizer-container-id="%s" data-visualizer-mime="%s" title="%s"', $key, $key, $atts['id'], $id, $mime, $title );
$actions_div .= sprintf( '<a href="#" class="visualizer-action visualizer-action-%s" data-visualizer-type="%s" data-visualizer-chart-id="%s" data-visualizer-container-id="%s" data-visualizer-mime="%s" title="%s"', esc_attr( $key ), esc_attr( $key ), esc_attr( $atts['id'] ), esc_attr( $id ), esc_attr( $mime ), esc_attr( $title ) );

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.

note A visualizer_action_buttons callback can return a title that it has already entity-encoded, for example Save &amp; share. Line 483 now passes that title through esc_attr(). Check that the tooltip of such a filtered action still reads Save & share. Safe: one level of encoding in the markup. Broken: the tooltip shows &amp; as text.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reason as above: an already encoded Save &amp; share stays Save &amp; share in the attribute, so the tooltip reads Save & share. No change needed.

@vytisbulkevicius

Copy link
Copy Markdown
Contributor Author

On the label note (F1): the only other callback of visualizer_action_buttons is in Visualizer Pro (addActionButtons()), and its label is a fixed translated string passed through esc_html__(). No label carries user text, so the label output is unchanged here.

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.

2 participants