Skip to content

fix: check per-chart edit_post capability in chart_data REST field - #1348

Open
lucadobrescu wants to merge 1 commit into
developmentfrom
fix/605-chart-data-cap-check
Open

fix: check per-chart edit_post capability in chart_data REST field#1348
lucadobrescu wants to merge 1 commit into
developmentfrom
fix/605-chart-data-cap-check

Conversation

@lucadobrescu

Copy link
Copy Markdown
Contributor

Any logged-in user with the edit_posts capability (Contributor and above) could read the full backend configuration of any chart on the site — data source query, series/settings, and JSON endpoint URLs with their authentication headers — via GET /wp-json/wp/v2/visualizer/{chart_id}, because the chart_data REST field callback only checked the generic edit_posts capability. Reported in Codeinwp/visualizer-pro#605.

What changed

  • chart_data REST field guardget_visualizer_data() now checks current_user_can( 'edit_post', $post['id'] ) against the requested chart instead of the generic current_user_can( 'edit_posts' ). Access now follows the standard post capability map: the chart's author, or users with edit_others_posts (Editor and above).

  • Regression testtests/test-chart-data-permissions.php asserts a Contributor gets false for another user's chart and that the chart author still receives the data.

chart_data request flow

flowchart LR
    A[GET /wp/v2/visualizer/id] --> B[chart_data field callback]
    B --> C{Changed:<br/>can edit_post<br/>this chart?}:::changed
    C -- Yes --> D[Return chart config]
    C -- No --> E[Return false]

    classDef changed fill:#9a6700,color:#fff,stroke:#5c3d00,stroke-width:3px,stroke-dasharray:6 3
Loading

QA

  1. As an Administrator, create and publish a chart, and note its post ID.

  2. As a Contributor, request the chart over REST (e.g. from the browser console while logged in):

    wp.apiFetch( { path: '/wp/v2/visualizer/<chart_id>' } ).then( console.log );

    Expect: chart_data is false — no source query, settings, or endpoint headers in the response.

  3. As the chart's author (or an Editor/Administrator), repeat the same request.
    Expect: chart_data contains the chart configuration and the chart still loads normally in the Gutenberg block editor.

🤖 Generated with Claude Code

The chart_data REST field callback only checked the generic edit_posts
capability, so any contributor could read the full backend configuration
of any chart (data source query, settings, JSON endpoint auth headers)
via GET /wp-json/wp/v2/visualizer/{id}.

Check edit_post on the requested chart instead, so access follows the
standard post capability map (author or edit_others_posts).

Fixes Codeinwp/visualizer-pro#605

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lucadobrescu lucadobrescu self-assigned this Jul 27, 2026
@lucadobrescu lucadobrescu added the pr-checklist-skip Allow this Pull Request to skip checklist. label Jul 27, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Jul 27, 2026
@pirate-bot

Copy link
Copy Markdown
Contributor

Plugin build for 2bcb43e is ready 🛎️!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants