Skip to content

Limit the stored rows of an unpublished post-type chart to users who can read the post type - #1430

Open
vytisbulkevicius wants to merge 11 commits into
developmentfrom
bugfix/pro/669
Open

vytisbulkevicius wants to merge 11 commits into
developmentfrom
bugfix/pro/669

Conversation

@vytisbulkevicius

@vytisbulkevicius vytisbulkevicius commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

A post-type chart of the Pro plugin stores the rows of its last query. The free plugin gave these stored rows to each user who can edit the chart. The rows of an unpublished post-type chart now go only to users who can read every post of that post type.

What changed

  • Stored rows rule — new Visualizer_Module::can_read_chart_rows(). It applies to a chart that has a post-type query (visualizer-filter-config) and is not published. The user must be able to read every post of the type: the post type has an admin screen, and the user has its edit_others_posts and read_private_posts capabilities. This is the rule that the Pro plugin has for the query.

  • Visualizer_Module::get_chart_data() — returns an empty array when the rule refuses the user. The chart editor, the chart library, the get-chart ability, the exports, the shortcode and the Elementor widget read the rows through this method.

  • Block editor data — the REST field chart_data returns empty visualizer-data in the same case.

  • Revisions — a chart revision follows the status of its chart. The revision comparison screen of WordPress shows no chart content when the rule refuses the user for one of the two compared versions.

  • Chart image — the chart settings come without the rendered picture (chart-img) when the rule refuses the user. An unpublished chart with a post-type query keeps no saved image. The image is not saved, and it is deleted when the chart is unpublished or gets the query. A one-time upgrade step deletes such images of earlier versions.

  • Data uploads — when the rule refuses the user, a manual editor save, a file upload or a URL import shows a message and changes nothing. The post-type query stays until a user who can read the rows replaces it.

Note

A published chart is not changed: it shows its stored rows to each user who can see it. A chart without a post-type query is not changed. The chart type, series and settings still load for a refused user; only the rows are empty.

Note

A chart with a post-type query loses its saved image when it is unpublished, also when it is moved to the trash. The next save of the published chart creates the image again.

Note

Tracked in Codeinwp/visualizer-pro#669.

Review responses

  • Readers in the Pro plugin — Codeinwp/visualizer-pro#660 applies the same rule to the Pro readers. This PR covers the free plugin.
  • Revision without a post-type query — Visualizer_Module_Admin::addRevision() copies the query to each chart revision, so the rule reads it from the revision. No reader of the free plugin gives the rows of a revision.

QA

This needs Visualizer Pro with a license that has the post-type data source (Import from WordPress).

  1. Log in as an administrator. Go to WP Admin → Posts and add a post with the title PRIVATE-TITLE and the visibility Private.

  2. Go to WP Admin → Users and add the user rows-test with the role Editor.

  3. Log in as rows-test. Go to WP Admin → Visualizer → Chart Library → Add New Chart and create a chart. In the chart editor, open Source → Import from WordPress, click Create Parameters, select the post type Posts and the field post_title, and save the chart. Note the chart ID.

  4. As the administrator, make the chart unpublished and change the role of rows-test to Author:

    wp post update <chart id> --post_status=draft
    wp user set-role rows-test author
  5. Log in as rows-test. Go to WP Admin → Visualizer → Chart Library, and open the chart for edit.

    Expect: the library and the chart editor show the chart without data. The page source does not contain PRIVATE-TITLE.

  6. In the chart editor, open Source → Manual Data. Select the Text editor and click Edit Data. Then click Show Chart.

    Expect: a message says that you cannot change the data of this chart.

  7. Log in as the administrator and open the same chart.

    Expect: the chart shows its data, with PRIVATE-TITLE.

  8. Publish the chart again (wp post update <chart id> --post_status=publish). Log in as rows-test and open the library.

    Expect: the chart shows its stored data, as before this change.

🤖 Generated with Claude Code

…sers who can read every post of the type

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

pirate-bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Plugin build for 8f6eb6c is ready 🛎️!

vytisbulkevicius and others added 3 commits December 1, 2026 22:41
…tor reads

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…nual editor

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

@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 new rule still lets refused users read the rows through revision diffs and saved chart images, and a crafted upload skips the refusal.

  • classes/Visualizer/Module/Chart.php:1763-1811 — security The saved chart image stays public while the chart is unpublished. With the image option on, the editor writes visualization-<id>.png into uploads. It registers an attachment with status inherit and no parent. The media REST API lets any visitor read such an attachment and its URL. The labels in the image can show private post titles. This assumes that the site serves its uploads folder publicly. Do not keep a public image of an unpublished chart that has a post-type query, including images saved before. Add a case to tests/test-chart-rows-permissions.php that reads the media REST route as a visitor.
Validation details
  • Files reviewed: 4/4 changed files. Two history questions stay open: background runs without a user, and editing paths that keep stored values.
  • PHPUnit with WordPress 7.1.5 on PHP 8.3 ran the new test class: cd /repo && set -o pipefail; timeout 600 vendor/bin/phpunit --do-not-cache-result --filter 'Test_Visualizer_Chart_Rows_P… printed Tests: 9, Assertions: 25, Errors: 2 (run R3)
  • Against pr-base, the reader and manual-editor cases fail on the private title. That base run has no record.
  • A revision diff as the Author returned the private title [R9].
  • The block REST settings kept chart-img for the refused Author [R13].
Untested areas
  • Background runs without a logged-in user, and editing paths that must keep stored values: not settled.
  • Pro readers and Pro data filters: Pro source is not available.
  • The chart editor and chart library test cases error on tsdk_utmify() in the sandbox.
  • Elementor output and WordPress versions between 5.2 and 7.1 were not checked.
  • The variant pass did not settle these places, where the fixed cause may still reach:
    • classes/Visualizer/Elementor/Widget.php:304-335,358-422 — unverified: Another settings-output route embeds all settings, including saved chart-img, despite guarded row data. The selector lists only published charts (:204-208); an existing selection c…
    • classes/Visualizer/Module/Sources.php:91-100,115-121 — unverified: The REST field runs source/filter callbacks after substituting empty rows. Whether a Pro source restores refused stored rows requires unavailable Pro source.

🤖 Automated review · run code-review-agent_6b0fccfa051e73.19755403.


🤖 Review agent — review posted ✅ on f05ac707 · changes requested · 4 findings · 37 min

Run code-review-agent_6b0fccfa051e73.19755403 · trail

Comment on lines +892 to +904
public static function can_read_chart_rows( $chart_id ) {
$filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true );
$parent_id = wp_is_post_revision( $chart_id );
if ( empty( $filter_config ) || 'publish' === get_post_status( $parent_id ? $parent_id : $chart_id ) ) {
return true;
}

$post_type = is_array( $filter_config ) && isset( $filter_config['type'] ) && is_string( $filter_config['type'] ) ? get_post_type_object( $filter_config['type'] ) : null;
return $post_type instanceof WP_Post_Type
&& $post_type->show_ui
&& current_user_can( $post_type->cap->edit_others_posts )
&& current_user_can( $post_type->cap->read_private_posts );
}

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.

correctness The rows still reach a refused user through the core revision diff. An Author who owns an unpublished post-type chart can post action=get-revision-diffs&post_id=<chart>&compare[]=0:<chart> to admin-ajax.php. Core checks only edit_post and diffs the chart's own post_content against empty text. The response contains the private post titles. Opening the chart in the editor creates the revision that this request needs. Filter wp_get_revision_ui_diff, and drop the post_content field whenever can_read_chart_rows() refuses the compared post or its parent chart. Add a case to tests/test-chart-rows-permissions.php that calls wp_ajax_get_revision_diffs() as the Author and asserts the private title is absent.

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.

Fixed in d3b6643 and 88c1d05. remove_unreadable_rows_from_revision_diff() on wp_get_revision_ui_diff drops the content field when the rule refuses the user for one of the two compared versions. test_revision_comparison_gives_rows_only_to_a_user_who_passes_the_rule and test_revision_comparison_keeps_the_rows_of_an_older_revision cover it.

apply_filters(
Visualizer_Plugin::FILTER_GET_CHART_DATA,
Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ),
Visualizer_Module::can_read_chart_rows( $post_id ) ? Visualizer_Module::decode_content( html_entity_decode( get_post_field( 'post_content', $post_id, 'raw' ) ) ) : array(),

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.

correctness The gate empties the rows but keeps the rendered chart image. The editor renders the chart to a PNG data URI and saves it in the chart-img setting when it posts the settings. The block REST field, the chart editor and the chart library send all settings, so a refused Author still gets a picture of the private titles. The shortcode with use_image="yes" and AMP also return the saved image attachment despite the row refusal. Whenever can_read_chart_rows() refuses, remove chart-img from every settings output and skip the saved image. Add cases to tests/test-chart-rows-permissions.php for the REST settings and the use_image shortcode as the Author.

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.

Fixed in d3b6643 and 8f6eb6c. remove_image_of_unreadable_rows() on the chart settings filter removes chart-img for a refused user; the block REST field case is test_reader_gives_the_chart_image_only_to_a_user_who_passes_the_rule. For the saved attachment there is one rule in place of a check in each reader: an unpublished chart with a post-type query keeps no saved image (see the reply to the image finding of the review). test_image_is_deleted_when_the_chart_is_unpublished renders the use_image shortcode as the Author.

Comment thread classes/Visualizer/Module/Chart.php Outdated
Comment on lines +1318 to +1319
$from_new_query = isset( $_POST['chart_data_src'] ) && Visualizer_Plugin::CF_SOURCE_FILTER === $_POST['chart_data_src'];
if ( $can_die && ! $from_new_query && ! self::can_read_chart_rows( $chart_id ) ) {

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.

correctness A refused user can skip this refusal by adding chart_data_src=visualizer-source-filter to any upload. The check trusts that field alone. The file, URL and editor branches below (lines 1359-1385) still run and replace post_content, series and source at lines 1394-1415. The PR promises that such an upload changes nothing. Whenever can_read_chart_rows() refuses, refuse every request that carries a file, a URL or editor data, whatever chart_data_src says. Add cases to tests/test-chart-rows-permissions.php as the refused Author. Post the filter value with a file, and with editor data. Assert the refusal message and the unchanged post_content.

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.

Fixed in d3b6643. uploadData() now checks can_read_chart_rows() for each request of a user, whatever source the request names. The manual editor test has the case with chart_data_src set to the post-type query source.

vytisbulkevicius and others added 7 commits December 2, 2026 10:37
…t image setting

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
# Conflicts:
#	classes/Visualizer/Module/Setup.php
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@vytisbulkevicius

Copy link
Copy Markdown
Contributor Author

Review item M1 (saved chart image): fixed in 8f6eb6c. save_chart_image() saves no image for an unpublished chart with a post-type query. delete_image_of_private_rows() deletes the image when the chart is no longer published or gets the query, and a one-time upgrade step deletes the images that earlier versions saved. Four new cases in tests/test-chart-rows-permissions.php read the media REST route as a visitor.

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