Skip to content

Scope chart data access boundaries - #1411

Merged
vytisbulkevicius merged 5 commits into
developmentfrom
codex/security-review
Nov 15, 2026
Merged

vytisbulkevicius merged 5 commits into
developmentfrom
codex/security-review

Conversation

@selul

@selul selul commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Chart rendering and report imports now keep data and settings inside their supported boundaries.

What changed

  • Chart settings — maps supported nested DataTables settings without dynamic evaluation.

  • Chart cells — applies the WordPress post-markup boundary after source filters, on the front end, in the block editor, in the print view and in the import and query previews. CSV and Excel exports, the text editor, the editable data table, the AI builder and the chart ability keep the stored values; the text editor and preview headers are escaped.

  • Report imports — retains the user who authorized scheduled report access. Saving a different JSON endpoint records the saving user instead; copies of a chart do not carry it.

  • Schedules — WooCommerce report fetches need report access. Visualizer Pro (Codeinwp/visualizer-pro#646) supplies it for scheduled refreshes. A failed WooCommerce report fetch keeps the stored chart data and records the error.

  • Dependencies — refreshes the directly used merge and UUID packages.

Note

Release together with Codeinwp/visualizer-pro#646. Pro keeps scheduled WooCommerce charts refreshing with this version and with older Visualizer versions.

Review responses

  • Import previews (F2) — fixed in f407907. The JSON preview, the JSON save, CSV upload and query save previews, and the database query preview pass their rows through Visualizer_Module::sanitize_chart_data(). test_json_preview_removes_event_attributes, test_json_save_preview_removes_event_attributes, test_csv_upload_preview_removes_event_attributes and test_query_preview_removes_event_attributes each fail with their change reverted and pass at HEAD. The query save preview has no test: saveQuery() reads the chart ID with filter_input( INPUT_GET ), which the PHPUnit AJAX harness cannot set (the existing import test is skipped for the same reason); it uses the same call as the CSV upload preview.
  • internal_title comment (F4) — fixed in f407907; the comment now says why the label is dropped.
  • format_chart_data() — it runs on the block editor data after sanitizing, for tabular charts, and converts number, boolean and time-of-day columns by series type; string columns pass through unchanged (corrected: there is no date case).
  • Pro DataTable setting names — checked against inc/types/DataTable.php in Pro. After the _bool/_int suffix is stripped its fields are select_style, select_items, select_info (nested select) and single names such as searching and lengthChange; all of them still map.
  • Print view — traced in source; _getDataAs( …, 'print' ) now reads sanitized rows (test_exports_and_editor_keep_stored_cells).
  • tests/js — no CI job runs it; it passes locally with node --test tests/js/.
  • Behaviour note — a live (unscheduled) chart that reads a same-site WooCommerce endpoint through the token no longer refreshes for visitors without report access; it keeps showing its stored data. Charts with stored API keys refresh as before.
  • Second WooCommerce read (round 2) — the refresh now checks the error after the last read; covered by test_refresh_keeps_stored_data_when_second_woocommerce_read_fails (fails with the old order).
  • Chart duplication meta order (round 2) — the clone and translation copy no longer copy the report user, so order does not matter; both paths have a test.
  • AI builder preview (round 2) — it receives stored rows, as its upload responses already did; the preview runs the chart's stored D3 code, which is outside this PR and noted for the owner.
  • Codex — the external Codex pass was skipped for both fix rounds because of a usage limit; each fix was mutation-checked instead.
  • Ability save and the report user (approval note) — the visualizer/set-data-source ability clears the source meta before it writes the endpoint, so saving through the ability always records the saving user, even for the same URL. That is deliberate: an ability save replaces the whole source configuration, so the saving user takes over report access. The editor's same-URL re-save keeps the earlier user because it edits columns of the existing source.

@pirate-bot

pirate-bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Plugin build for 765ab3b 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.

🟡 Changes requested

The sanitizer misses tags without a closing > and skips the import previews, and the new WooCommerce gate can wipe live-refresh charts.

  • classes/Visualizer/Module/Chart.php:225 — security The new cell boundary skips the import previews. getJsonData() passes getRawData() straight to Visualizer_Render_Layout::show(). Layout.php:511-515 echoes non-editable cells raw, and js/frame.js inserts them with .html(). The JSON save, CSV/URL upload and query save previews pass getRawData() to Visualizer_Render_Page_Update, and DataTables writes the cells with innerHTML. A remote endpoint or CSV file with <img src=x onerror=…> runs script in the importing user's admin session. Pass the rows through Visualizer_Module::sanitize_chart_data() before each preview at Chart.php:218-225, 306-310, 1423-1426 and 1680-1688. Add a tests/test-ajax.php case that checks the preview table has no event attribute.
  • js/render-datatables.js:141 — comments The comment // remove this so that the eval does not fail. above delete chart.settings['internal_title'] is now false. This change removes the eval. Delete the comment, or state the real reason internal_title is dropped before the settings loop.
Validation details
  • Files reviewed: 12/12 changed files. One open question remains: how format_chart_data() handles the sanitized cells.
  • The sanitizer ran on PHP 8.3.36 and WordPress 7.1.4: cp /repo/classes/Visualizer/Module.php /workspace/checks/LC1/Module.php; timeout 30 wp eval 'require "/workspace/checks/… (run R5, exit 0) and git rev-parse HEAD; cp classes/Visualizer/Module.php /workspace/checks/LC2/Module.php; timeout 30 php /workspace/checks/… (run R7, exit 0).
  • The base-tree PHPUnit runs show that the new denial, sanitization and contributor-token tests fail without the change.
  • The node test of nested settings fails on the base renderer cd /repo; D=/workspace/checks/R1/jsbase; rm -rf $D; mkdir -p $D/js $D/tests/js; git show pr-base:js/render-datatables.js… (run R3, exit 0).
  • The merge 2.1.1 and uuid 11.1.1 imports match their documented exports.
Untested areas
  • The consumer question "format_chart_data() receives the changed data" was not settled. The formatter was read, but its effect was not run.
  • Visualizer Pro DataTable setting names were not checked. The Pro source is outside this repository.
  • The print-button exploit is traced in source only.
  • No CI job runs tests/js.

🤖 Automated review · run code-review-agent_6af70662c81753.78352976.


🤖 Review agent — review posted ✅ on 6f437694 · changes requested · 8 findings · 41 min

Run code-review-agent_6af70662c81753.78352976 · trail

Comment thread classes/Visualizer/Module.php Resolved
Comment thread classes/Visualizer/Source/Json.php Resolved
Comment thread classes/Visualizer/Source/Json.php Resolved
Comment thread classes/Visualizer/Module/Chart.php Resolved
Comment thread tests/test-chart-data-sanitization.php Resolved
Comment thread classes/Visualizer/Module.php Resolved
…n failed refreshes

Normalize every tag opening in rendered cells, sanitize import and query
previews, and keep exports and the data editor on the stored values.
Record the user who sets a JSON endpoint as its report user, and keep the
stored data when a WooCommerce report fetch fails.

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

🟡 Changes requested

The earlier findings are fixed, but imported markup still reaches the text editor and JSON preview, and three data paths need fixes.

Validation details
  • Files reviewed: 9/9 files changed since the prior review. The other 5 reuse run code-review-agent_6af70662c81753.78352976, not rerun.
  • The 14 new or changed tests pass at HEAD on PHP 8.3.36 (run R6).
  • Sandbox probes on WordPress 7.1.4 show the raw JSON key header, the textarea breakout and the Q1Q4 reads (run R14).
  • The import preview cell fix and the internal_title comment fix from the prior review are confirmed in source.
  • Visualizer Pro #646 checks the recorded user's report capability before it grants access.
Untested areas
  • The second-fetch failure is traced in source only.
  • The pr-base and prior-head test runs have no run record.
  • Chart duplication meta order was not checked.
  • Question: the PR text says format_chart_data() converts date columns, but the code has no date case.

🤖 Automated review · run code-review-agent_6af7afa251cd93.89987607.


🤖 Review agent — review posted ✅ on f407907a · changes requested · 5 findings · 49 min

Run code-review-agent_6af7afa251cd93.89987607 · trail

Comment thread classes/Visualizer/Module.php Resolved
Comment thread classes/Visualizer/Module/Chart.php Resolved
Comment thread classes/Visualizer/Module.php Resolved
Comment thread classes/Visualizer/Source/Json.php Resolved
Comment thread classes/Visualizer/Module/Chart.php Resolved
Return stored rows to the AI builder and the chart ability, escape the text
editor and preview headers, check refresh errors after the last read, and
record the report user only when a user saves a different endpoint. Copies
of a chart do not carry the original report user.

@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 PR because the five earlier findings are fixed. One note asks whether an ability save should keep the report user.

Validation details
  • Files reviewed: 9/9 files changed since the prior review. Other files reuse run code-review-agent_6af7afa251cd93.89987607, not rerun.
  • The 9 new tests pass at HEAD on PHP 8.3.36.
  • Each new test fails at the prior head f407907.
  • Every JSON endpoint writer goes through update_json_url(). Clone, translation copy and revision restore only copy stored meta.
  • The text editor and preview header outputs are escaped.
Untested areas
  • Visualizer Pro #646 at its latest commit was not read. The coordinated release was not verified.
  • Four report-user tests cannot run at pr-base, because the meta constant is missing there.
  • The row "Visualizer_Source_Query::html() return changed" reuses the prior run's test result and was not rerun.

🤖 Automated review · run code-review-agent_6af7bff4d71f07.37444990.


🤖 Review agent — review posted ✅ on 765ab3b2 · approved · 0 findings · 15 min

Run code-review-agent_6af7bff4d71f07.37444990 · trail

update_post_meta( $chart->ID, Visualizer_Plugin::CF_EDITABLE_TABLE, true );
$this->persistSource( $chart->ID, $source );
update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_URL, $params['url'] );
self::update_json_url( $chart->ID, $params['url'] );

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 set-data-source ability deletes the stored JSON URL in clearSourceMeta() before it calls update_json_url(). So a save with the same endpoint always records the calling user as the report user. If that user lacks report access, the scheduled WooCommerce refresh stops and keeps old data. Is this call meant to re-authorize the schedule it recreates? If yes, it is safe. If not, compare against the URL read before clearSourceMeta().

@vytisbulkevicius
vytisbulkevicius merged commit 7f99490 into development Nov 15, 2026
26 checks passed
@vytisbulkevicius
vytisbulkevicius deleted the codex/security-review branch November 15, 2026 21:41
@pirate-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.0.11 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants