Skip to content

fix(embedded): honor "can view query" permission for guest users - #43151

Merged
rusackas merged 2 commits into
apache:masterfrom
NoiceHax:fix/issue-43100
Aug 28, 2026
Merged

rusackas merged 2 commits into
apache:masterfrom
NoiceHax:fix/issue-43100

Conversation

@NoiceHax

@NoiceHax NoiceHax commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

The chart data API dropped the query key 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

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
@dosubot dosubot Bot added api Related to the REST API authentication:access-control Rlated to access control embedded labels Aug 14, 2026
@bito-code-review

bito-code-review Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #04f0e4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 27134ed..27134ed
    • superset/charts/data/api.py
    • tests/integration_tests/charts/data/api_tests.py
    • tests/unit_tests/charts/test_chart_data_api.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@github-actions github-actions Bot removed the embedded label Aug 14, 2026
@codecov

codecov Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.67%. Comparing base (537f0fd) to head (d52b974).
⚠️ Report is 153 commits behind head on master.

Files with missing lines Patch % Lines
superset/charts/data/api.py 0.00% 3 Missing ⚠️
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     
Flag Coverage Δ
hive 38.21% <0.00%> (+<0.01%) ⬆️
mysql 57.92% <0.00%> (+<0.01%) ⬆️
postgres 57.95% <0.00%> (+<0.01%) ⬆️
presto 40.16% <0.00%> (+<0.01%) ⬆️
python 59.34% <0.00%> (+<0.01%) ⬆️
sqlite 57.59% <0.00%> (+<0.01%) ⬆️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI 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.

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 query removal in ChartDataRestApi._send_chart_response() on security_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.
@NoiceHax

Copy link
Copy Markdown
Contributor Author

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.

@netlify

netlify Bot commented Aug 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit d52b974
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a7f60fbfe7c010008264a21
😎 Deploy Preview https://deploy-preview-43151--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #83ff95

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 27134ed..d52b974
    • tests/integration_tests/charts/data/api_tests.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@rusackas
rusackas merged commit 98ec601 into apache:master Aug 28, 2026
73 checks passed
@sadpandajoe sadpandajoe mentioned this pull request Sep 17, 2026
3 tasks done
geido pushed a commit that referenced this pull request Oct 14, 2026
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]>
geido pushed a commit that referenced this pull request Oct 15, 2026
- 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API authentication:access-control Rlated to access control size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

view query is not working on embedded dashboard in web application

3 participants