fix: gate AI Builder db_query behind super-admin + Pro to match classic path - #1357
Merged
Merged
Conversation
Contributor
Contributor
|
🎉 This PR is included in version 4.0.7 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AI Builder's
db_queryupload branch runs an operator-supplied SQLSELECTthroughVisualizer_Source_Query— the same sink as the classicVisualizer_Module_Chart::getQueryData()/saveQuery()handlers. Those classic handlers gate the feature on administrator and super-admin and an active Pro license; the AI Builder branch did not match that gate. This aligns them.The earlier fix (visualizer-pro#587, PR #1313) added a capability check here, but it was both weaker and incomplete: the two conditions were combined with
&&(so the request was blocked only when the user had neither capability), and the Pro-feature check was missing entirely. Patchstack flagged the fix as not fully closing the report for this reason.What changed
db_querygate — now denies the request unless the user hasmanage_optionsandis_super_admin()and the site is running Visualizer Pro, matching the classic DB-query handlers exactly. Before:! manage_options && ! is_super_admin(passed for anyone holding either cap, and ignored Pro). After:! manage_options || ! is_super_admin || ! is_pro.Note
A super-admin on a Pro site running their own
SELECTis intended feature behavior (the "Import from database" data source), unchanged here. This PR only restores the trust boundary that already governs the classic path — it does not alter what an authorized admin can do.db_query authorization
flowchart LR A[visualizer-ai-upload<br/>source_type=db_query] --> B{Nonce valid?} B -- No --> X[403] B -- Yes --> C{Changed:<br/>manage_options AND<br/>super-admin AND Pro?}:::changed C -- No --> X C -- Yes --> D[Run SELECT via<br/>Visualizer_Source_Query] classDef changed fill:#9a6700,color:#fff,stroke:#5c3d00,stroke-width:3px,stroke-dasharray:6 3QA
WP Admin → Users → Add New: create a Contributor, log in as them in a private window.
WP Admin → Visualizer → Chart Library, open DevTools console, and create a draft chart to obtain an upload nonce:
Then attempt the DB query against it:
Expect:
{ success: false, data: { message: "Action not allowed for this user." } }— no query result returned.On a non-Pro site, repeat step 2 logged in as an Administrator.
Expect: the same
Action not allowed for this user.response — the feature is Pro-only, matching the classic DB-query handlers.On a Pro site, as a super-admin, use Visualizer → Add New → AI Builder → load data from a database query.
Expect: the query runs and the chart populates — the intended feature is unaffected.
Follow-up to PR #1313. Related: visualizer-pro#587, HelpScout 3311008102.