Skip to content

fix(embedded): redact database errors in API responses to guest users - #42796

Merged
msyavuz merged 2 commits into
apache:masterfrom
msyavuz:msyavuz/fix/redact-embedded-db-errors
Aug 10, 2026
Merged

msyavuz merged 2 commits into
apache:masterfrom
msyavuz:msyavuz/fix/redact-embedded-db-errors

Conversation

@msyavuz

@msyavuz msyavuz commented Aug 5, 2026

Copy link
Copy Markdown
Member

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_type is normalized to GENERIC_BACKEND_ERROR, and extra (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 and handle_api_exception
  • chart data 400/422 responses (ChartDataQueryFailedError carried the raw engine text as its message)
  • the per-query error / stacktrace fields in a 200 chart data payload — next to the existing guest strip of query
  • async (GLOBAL_ASYNC_QUERIES) job errors; guest detection works in the worker because the job restores the guest user from its guest_token

Design 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:

# before
400 {"message": "Error: no such table: table_that_does_not_exist"}
# after
400 {"message": "An error occurred while fetching the data."}

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.py

test_get_data_response_redacts_a_real_engine_error_for_guests drives 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/data returns the generic message. Load the same chart as a logged-in user and the engine's error is unchanged.

ADDITIONAL INFORMATION

  • Has associated issue: No
  • Required feature flags: EMBEDDED_SUPERSET — the redaction only applies to guest-token principals, which only exist when embedding is enabled
  • Changes UI: No — backend only. An embedded viewer sees a different error string; no component changes.
  • Includes DB Migration: No
  • Introduces new feature or API: No — behavior change on existing endpoints, noted in UPDATING.md
  • Removes existing feature or API: No

@dosubot dosubot Bot added authentication:access-control Rlated to access control change:backend Requires changing the backend embedded labels Aug 5, 2026
@bito-code-review

Copy link
Copy Markdown
Contributor

AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).

@github-actions github-actions Bot added api Related to the REST API doc Namespace | Anything related to documentation and removed embedded labels Aug 5, 2026
@netlify

netlify Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit c223bf8
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a79e8b9e3742f0008edfbc6
😎 Deploy Preview https://deploy-preview-42796--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.

@codecov

codecov Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.40%. Comparing base (9e2cb69) to head (c223bf8).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
superset/utils/error_sanitization.py 41.66% 25 Missing and 3 partials ⚠️
superset/charts/data/api.py 16.66% 5 Missing ⚠️
superset/views/error_handling.py 60.00% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
hive 38.21% <35.00%> (-0.01%) ⬇️
mysql 57.76% <41.66%> (-0.01%) ⬇️
postgres 57.81% <41.66%> (-0.02%) ⬇️
presto 40.18% <35.00%> (-0.01%) ⬇️
python 59.20% <41.66%> (-0.02%) ⬇️
sqlite 57.43% <41.66%> (-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.

Comment thread superset/utils/error_sanitization.py Outdated
``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:

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.

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.

Fix in Cursor Fix in VSCode Claude

(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 fix
👍 | 👎

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.

Do you think this is relevant?

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.

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.

Comment thread superset/views/error_handling.py Outdated
Comment on lines +90 to +95
elif isinstance(error_details, str):
payload["error"] = error_details
payload["error"] = (
error_details
if status in SAFE_STATUSES
else sanitize_error_message(error_details)
)

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.

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.

Fix in Cursor Fix in VSCode Claude

(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 fix
👍 | 👎

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.

What do you think of this 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.

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.
@msyavuz
msyavuz force-pushed the msyavuz/fix/redact-embedded-db-errors branch from 4eb3ade to f8ce847 Compare August 10, 2026 12:45

@alexandrusoare alexandrusoare 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.

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.
@msyavuz
msyavuz merged commit daf1718 into apache:master Aug 10, 2026
68 checks passed
@bito-code-review

Copy link
Copy Markdown
Contributor

Bito Automatic Review Skipped – PR Already Merged

Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.
No action is needed if you didn't intend to review it. To get a review, you can type /review in a comment and save it

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 change:backend Requires changing the backend doc Namespace | Anything related to documentation size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants