Repository navigation
fix(embedded): redact database errors in API responses to guest users - #42796
Conversation
|
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR). |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #42796 +/- ##
==========================================
- Coverage 66.41% 66.40% -0.01%
==========================================
Files 2859 2860 +1
Lines 161460 161514 +54
Branches 37191 37201 +10
==========================================
+ Hits 107233 107255 +22
- Misses 52189 52218 +29
- Partials 2038 2041 +3
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:
|
| ``extra`` is dropped along with the message: it carries engine names and, for | ||
| some error types, the offending SQL. | ||
| """ | ||
| if not is_sanitization_required() or error.error_type in SAFE_ERROR_TYPES: |
There was a problem hiding this comment.
Suggestion: The allowlist returns the original SupersetError, including extra, so guest responses can still expose sensitive values. For example, OAuth2TokenRefreshError uses an allowlisted type but stores the upstream OAuth response text in extra["error"]; return a sanitized error without extra even for allowlisted types, or explicitly remove sensitive fields while preserving only the data required by the client. [security]
Severity Level: Major ⚠️
- ❌ Embedded OAuth responses can expose provider error details.
- ⚠️ Async job errors preserve sensitive OAuth response fields.
- ⚠️ Error payloads may disclose credentials or provider metadata.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/utils/error_sanitization.py
**Line:** 96:96
**Comment:**
*Security: The allowlist returns the original `SupersetError`, including `extra`, so guest responses can still expose sensitive values. For example, `OAuth2TokenRefreshError` uses an allowlisted type but stores the upstream OAuth response text in `extra["error"]`; return a sanitized error without `extra` even for allowlisted types, or explicitly remove sensitive fields while preserving only the data required by the client.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
Do you think this is relevant?
There was a problem hiding this comment.
Yes, this is relevant. The allowlist currently returns the original error, so extra remains exposed to guest users. This conflicts with the goal of dropping engine/provider details and can leak upstream OAuth response content or metadata.
The sanitizer should preserve the allowlisted message and type but sanitize extra as well—for example, retain only explicitly required OAuth redirect fields (url, tab_id, and redirect_uri) and drop all other fields. For allowlisted types without a documented client requirement, set extra=None.
The existing OAuth test currently asserts that the full extra payload is preserved, so it should be updated to verify that only approved fields remain and add a regression case containing extra["error"]. This should also cover the async serialized-error path, since it uses the same sanitizer.
| elif isinstance(error_details, str): | ||
| payload["error"] = error_details | ||
| payload["error"] = ( | ||
| error_details | ||
| if status in SAFE_STATUSES | ||
| else sanitize_error_message(error_details) | ||
| ) |
There was a problem hiding this comment.
Suggestion: Preserving every bare-string message for statuses in SAFE_STATUSES bypasses the guest redaction policy. Existing callers use status 404 for messages containing database and table names, such as the core view's “Table ... wasn't found in the database ...” response, so an embedded viewer can still receive warehouse metadata. Restrict this bypass to known authorization/routing messages or sanitize these messages based on their originating error type rather than status alone. [security]
Severity Level: Major ⚠️
- ⚠️ Legacy Explore errors disclose warehouse identifiers.
- ⚠️ Embedded viewers can observe supplied database metadata.
- ⚠️ Status alone cannot distinguish routing and backend errors.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/views/error_handling.py
**Line:** 90:95
**Comment:**
*Security: Preserving every bare-string message for statuses in `SAFE_STATUSES` bypasses the guest redaction policy. Existing callers use status 404 for messages containing database and table names, such as the core view's “Table ... wasn't found in the database ...” response, so an embedded viewer can still receive warehouse metadata. Restrict this bypass to known authorization/routing messages or sanitize these messages based on their originating error type rather than status alone.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fixThere was a problem hiding this comment.
What do you think of this comment?
There was a problem hiding this comment.
The comment is valid. Using HTTP status alone is too broad: a 404 can represent either a safe routing/not-found response or a backend/database error containing catalog metadata. Thus, SAFE_STATUSES can leak information the PR intends to redact.
A minimal fix is to remove the status-based bypass and sanitize all bare-string messages for guest users:
elif isinstance(error_details, str):
payload["error"] = sanitize_error_message(error_details)If specific authorization or routing messages must remain visible, they should be converted to structured SupersetError instances with allowlisted error_type values. This preserves the existing type-based allowlist and ensures new or ambiguous bare-string errors are redacted by default. The current SAFE_STATUSES constant and related status handling can then be removed, along with tests that expect arbitrary 403/404 strings to survive.
Engine errors relayed to the client routinely quote catalog, schema, table and column names of the underlying warehouse. That detail is unusable to an embedded viewer and should not leave the deployment. For a guest-token principal only, error messages are replaced with a generic string, error_type is normalized and `extra` is dropped. Errors Superset authors itself -- access denials, OAuth2 redirects, timeouts, payload validation -- are unchanged, as is every response to a non-guest principal. The full error is still logged server-side. Applied at the four points where errors reach a client: json_error_response (the funnel for the app error handlers and handle_api_exception), the chart data 400/422 responses, the per-query `error`/`stacktrace` fields in a 200 chart data payload, and async job errors. This narrows disclosure; it is not on its own a boundary fix.
4eb3ade to
f8ce847
Compare
alexandrusoare
left a comment
There was a problem hiding this comment.
Other than the comments from the bot, the PR looks good to me!
Two holes from review: An allowlisted error type was not a promise that everything hanging off it was safe. OAuth2TokenRefreshError reports the upstream provider's response body in extra["error"] under the allowlisted OAUTH2_REDIRECT type, so it reached a guest untouched. Allowlisted errors now keep their message and type but have extra filtered to the keys the client needs: issue_codes, and the url/tab_id/redirect_uri trio OAuth2RedirectMessage.tsx uses to drive the redirect dance. Bare-string messages no longer survive on the strength of their status. A string carries no error type, so a 404 that is really a routing decision is indistinguishable from one quoting warehouse metadata -- warm_up_cache reports a missing table as "Table %(table)s wasn't found in the database %(db)s" at 404. Status now only selects which generic message reads correctly: 401/403 report a denial, everything else a data error.
|
Bito Automatic Review Skipped – PR Already Merged |
SUMMARY
Errors raised while running a query are relayed to the client verbatim so chart authors can fix them. For an embedded (guest token) viewer that detail is both unusable and sensitive: engine errors routinely quote catalog, schema, table and column names of the underlying warehouse, and a viewer of an embedded dashboard has no way to act on them.
For a guest-token principal only, the error message is replaced with a generic
An error occurred while fetching the data.,error_typeis normalized toGENERIC_BACKEND_ERROR, andextra(engine name, and for some types the offending SQL) is dropped. The full error is still logged server-side.An allowlist keeps errors Superset authors itself verbatim, since those describe an access decision or a client-side condition rather than echoing the database: security/access denials, OAuth2 redirects, timeouts, payload validation, frontend errors. Every response to a non-guest principal is unchanged.
New
superset/utils/error_sanitization.py, applied at the four points where an error reaches a client:json_error_response— the funnel for the app-level error handlers andhandle_api_exception400/422responses (ChartDataQueryFailedErrorcarried the raw engine text as its message)error/stacktracefields in a200chart data payload — next to the existing guest strip ofqueryGLOBAL_ASYNC_QUERIES) job errors; guest detection works in the worker because the job restores the guest user from itsguest_tokenDesign notes: this is an allowlist rather than a denylist, so a newly added error type is redacted by default rather than leaking until someone remembers to list it. Bare-string errors are left alone at
401/403/404/429, which report an authorization or routing decision rather than a query failure.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — no UI change. The response body for a guest changes:
TESTING INSTRUCTIONS
pytest tests/unit_tests/utils/test_error_sanitization.py tests/unit_tests/charts/test_chart_data_api.py tests/unit_tests/views/test_error_handling.py tests/unit_tests/tasks/test_async_queries.pytest_get_data_response_redacts_a_real_engine_error_for_guestsdrives an actual failing query (a dataset pointing at a missing table) rather than a hand-written message, and asserts the object name still reaches an authorized user but not a guest.Manually: enable
EMBEDDED_SUPERSET, embed a dashboard whose chart points at a dropped/renamed table, and load it with a guest token —POST /api/v1/chart/datareturns the generic message. Load the same chart as a logged-in user and the engine's error is unchanged.ADDITIONAL INFORMATION
EMBEDDED_SUPERSET— the redaction only applies to guest-token principals, which only exist when embedding is enabledUPDATING.md