geido opened a new pull request, #45273: URL: https://github.com/apache/superset/pull/45273
### SUMMARY `/api/v1/chart/data` omits the generated SQL (`query`) from responses for embedded (guest-token) viewers unless their guest-token role has `can view query` on `Dashboard` (#43151). The `/datasource/samples` endpoint that backs **Drill to detail** — opened to embedded guests in #34319 — never applied that rule, so its response still returned `query` (and `stacktrace`) to guests regardless of that permission, diverging from chart data. This extracts the chart-data redaction into a shared `redact_sensitive_query_fields` helper in `superset/utils/error_sanitization.py` and applies it to the samples response as well, so Drill to detail matches the chart-data behavior for guests: - A guest **without** `can view query on Dashboard` no longer receives `query` from either endpoint. - A guest **with** `can view query on Dashboard` still receives `query` from both. - `stacktrace` and raw driver `error` text stay redacted for guests regardless (unchanged). The chart-data call site is refactored to use the same helper so the two guest-facing query endpoints can't drift apart again. Behavior for authenticated (non-guest) users is unchanged — the helper is a no-op when guest sanitization isn't required, so Explore's "View samples" still returns the SQL. ### BEFORE/AFTER Embedded guest whose role has the Drill to detail permissions (`can_samples` on Datasource, `can_drill` on Dashboard, `can_get_drill_info` on Dataset) but **not** `can view query on Dashboard`, opening Drill to detail on a chart built on a virtual dataset: | Endpoint | Before | After | | --- | --- | --- | | `POST /datasource/samples` (`result.query`) | generated SQL returned | omitted | | `POST /datasource/samples`, guest also granted `can view query` | generated SQL returned | generated SQL returned | | `POST /api/v1/chart/data` | already omitted | unchanged | ### TESTING INSTRUCTIONS 1. On an embedded dashboard with drilling enabled for the guest role (but without `can view query on Dashboard`), open Drill to detail on a chart. 2. In DevTools, inspect the `datasource/samples` response: `result.query` is absent. 3. Grant the guest role `can view query on Dashboard` and repeat: `result.query` returns, matching `/api/v1/chart/data`. 4. As a normal authenticated user, open Explore → "View samples": `query` is still present (unchanged). Unit tests: - `tests/unit_tests/utils/test_error_sanitization.py` — the shared helper: strips `query` for a guest without the permission, keeps it with the permission, always strips `stacktrace`, sanitizes `error`, preserves the fields the samples grid renders from, and is a no-op for authenticated users. - `tests/unit_tests/views/datasource/views_test.py` — the samples view routes its result through the helper before responding. ### ADDITIONAL INFORMATION - [ ] Has associated issue: - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration - [ ] Introduces new feature or API - [ ] Removes existing feature or API 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
