Repository navigation
Limit the stored rows of an unpublished post-type chart to users who can read the post type - #1430
vytisbulkevicius wants to merge 11 commits into
Conversation
…sers who can read every post of the type Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…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>
There was a problem hiding this comment.
🟡 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—securityThe saved chart image stays public while the chart is unpublished. With the image option on, the editor writesvisualization-<id>.pnginto uploads. It registers an attachment with statusinheritand 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 totests/test-chart-rows-permissions.phpthat 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…printedTests: 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-imgfor 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
| 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 ); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| $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 ) ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…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>
|
Review item M1 (saved chart image): fixed in 8f6eb6c. |
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 itsedit_others_postsandread_private_postscapabilities. 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, theget-chartability, the exports, the shortcode and the Elementor widget read the rows through this method.Block editor data — the REST field
chart_datareturns emptyvisualizer-datain 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
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).
Log in as an administrator. Go to
WP Admin → Postsand add a post with the titlePRIVATE-TITLEand the visibility Private.Go to
WP Admin → Usersand add the userrows-testwith the role Editor.Log in as
rows-test. Go toWP Admin → Visualizer → Chart Library → Add New Chartand create a chart. In the chart editor, openSource → Import from WordPress, click Create Parameters, select the post type Posts and the field post_title, and save the chart. Note the chart ID.As the administrator, make the chart unpublished and change the role of
rows-testto Author:Log in as
rows-test. Go toWP 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.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.
Log in as the administrator and open the same chart.
Expect: the chart shows its data, with
PRIVATE-TITLE.Publish the chart again (
wp post update <chart id> --post_status=publish). Log in asrows-testand open the library.Expect: the chart shows its stored data, as before this change.
🤖 Generated with Claude Code