Repository navigation
fix(embedded): honor "can view query" permission for guest users - #43151
Conversation
The chart data API stripped the `query` key from every JSON response as
soon as the requester was a guest user, so "View query" on an embedded
dashboard always returned `{"result": [{"language": "sql"}]}` no matter
which permissions the guest role had been granted. Gate the removal on
the "can view query on Dashboard" permission the frontend already uses to
expose the action; stacktraces and driver errors stay redacted for guests
either way.
Closes apache#43100
Code Review Agent Run #04f0e4Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #43151 +/- ##
=======================================
Coverage 66.67% 66.67%
=======================================
Files 2871 2871
Lines 163328 163322 -6
Branches 37674 37675 +1
=======================================
- Hits 108904 108903 -1
+ Misses 52296 52289 -7
- Partials 2128 2130 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes embedded “View query” for guest users by only stripping the query field from chart-data JSON responses when the guest role lacks the FAB permission ("can_view_query", "Dashboard"), aligning backend redaction behavior with the frontend action gating. Error/stacktrace redaction remains enforced for guests regardless of this permission.
Changes:
- Gate guest
queryremoval inChartDataRestApi._send_chart_response()onsecurity_manager.can_access("can_view_query", "Dashboard"). - Add unit tests to ensure permitted guests receive SQL while still getting errors/stacktraces redacted.
- Update/add integration tests to cover both permitted and denied guest behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
superset/charts/data/api.py |
Conditionally preserves query for guest users based on can_view_query permission while continuing to redact stacktraces/errors. |
tests/unit_tests/charts/test_chart_data_api.py |
Adds/updates unit tests validating the new permission-gated behavior and continued error redaction. |
tests/integration_tests/charts/data/api_tests.py |
Updates existing guest test and adds a new one for guests allowed to view query (with can_access patched). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The guest chart data tests replaced security_manager.can_access wholesale,
so every other permission check in the request got a stubbed answer, and the
stub only accepted positional arguments. Force the answer for
("can_view_query", "Dashboard") only and delegate everything else to the real
security manager. Also fixes an "inlcude" typo in the existing docstring.
|
Pushed a follow-up for the review bots' points on the integration test. The old mock replaced security_manager.can_access for the whole request, so every other permission check got a stubbed answer too, and the lambda would have blown up on a keyword-argument call. It now forces only ("can_view_query", "Dashboard") and delegates the rest to the real security manager. Docstring typo fixed as well. I left the @pytest.mark.skip on TestGetChartDataApi alone. It is skipped on master for an unrelated DuckDB example-data reason, so unskipping it here is out of scope for this fix. The behaviour is covered by the unit tests in tests/unit_tests/charts/test_chart_data_api.py, which do run in CI. Verified with ruff 0.9.7 (check and format, both clean). I could not run the Python suite locally, no superset env on this machine, so I am relying on CI for that. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #83ff95Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
The chart data API omits the `query` field from responses for embedded (guest token) viewers unless their guest-token role has "can view query on Dashboard" (#43151), so the generated SQL is only returned to guests granted that permission. The `/datasource/samples` endpoint behind Drill to detail — opened to embedded guests in #34319 — did not apply the same rule, so its response still carried `query` (and `stacktrace`) for guests regardless of that permission. Extract the chart-data redaction into a shared `redact_sensitive_query_fields` helper and apply it to the samples response too, so Drill to detail matches the chart data behavior for guests. A guest with "can view query on Dashboard" still receives the SQL from both; stacktraces and raw driver errors remain redacted for guests regardless. Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Comments: the helper fails closed for a guest whose principal can't be resolved (not for any unresolvable principal), and the "can view query on Dashboard" gate dates from #43151 rather than the CVE-2025-55673 strip. - Samples real-helper test: assert on the response as serialized when `json_response` is called, instead of the dict mutated in place, so the test fails if the redaction ever runs after the response is built. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The chart data API dropped the
querykey from every response as soon as the requester was a guest user. There was no permission check first, so "View query" on an embedded dashboard came back empty even when the guest role had "can view query on Dashboard" granted. That is the same permission the frontend uses to show the action, so granting it did nothing.Now the key is only removed when
can_access("can_view_query", "Dashboard")is false. Stacktraces and driver errors are still stripped for guests either way, since those leak details about the deployment.Worth testing on a real embedded dashboard both ways: a guest role with the permission should get the SQL back, one without it should not. Unit tests are in tests/unit_tests/charts/test_chart_data_api.py. I also updated the integration tests in tests/integration_tests/charts/data/api_tests.py, but that class is skipped in the repo so they did not run.
Closes #43100