Repository navigation
Escape the attributes of chart action buttons - #1426
vytisbulkevicius wants to merge 2 commits into
Conversation
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>
There was a problem hiding this comment.
🟢 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—noteAvisualizer_action_buttonscallback 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 withesc_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 ) ); |
There was a problem hiding this comment.
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 & as text in the tooltip. A gettext test showed title="Imprimer l'&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.
There was a problem hiding this comment.
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'& 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 ) ); |
There was a problem hiding this comment.
note A visualizer_action_buttons callback can return a title that it has already entity-encoded, for example Save & 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 & as text.
There was a problem hiding this comment.
Same reason as above: an already encoded Save & share stays Save & share in the attribute, so the tooltip reads Save & share. No change needed.
|
On the label note (F1): the only other callback of |
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
Go to
WP Admin → Visualizer → Chart Libraryand edit a chart. OpenSettings → General → Frontend Actions → Actions. Turn on Print, CSV, Excel, Copy and Download Image, then save the chart.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