You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2026/09/04 20:06:13 UTC

[PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

eschutho opened a new pull request, #43896:
URL: https://github.com/apache/superset/pull/43896

   ### SUMMARY
   
   Follow-up addressing the review of #43834. That PR guarded `is_sanitization_required()` so a raising user loader could no longer turn error responses into bare 500s. On review it was pointed out that the guard **fails open** — it weakens the very feature it protects — and that the same "an error handler must never itself raise" invariant still has gaps elsewhere. This PR addresses those three follow-ups.
   
   **1. The fail-open guard could disclose to real embedded guests**
   
   `is_sanitization_required()` returned `False` ("do not sanitize") whenever `security_manager.is_guest_user()` raised, on the assumption that an unresolvable principal is "by definition not a guest." That assumption is false — the check can raise for a *resolvable* guest:
   
   - `get_guest_user_from_request` calls `get_guest_user_from_token(...)` **outside** its `try/except`, and `get_guest_user_from_token` calls `find_role(...)` — a metadata-DB round trip. A valid, unrevoked guest token on a request whose DB session is already broken (a `PendingRollbackError`, precisely because the error being handled is itself a `SQLAlchemyError`) makes `find_role` raise.
   - `is_guest_user` consults `is_feature_enabled("EMBEDDED_SUPERSET")` first, which routes through a deployment-supplied hook that can dereference `g.user` and raise.
   
   In either case a genuine embedded guest received the raw engine error (e.g. `no such table: ...`) instead of a redacted message — a disclosure that did not exist before #43834 (it was a 500 then).
   
   The fix makes the fallback **incapable of raising** and **fails closed** when a token is actually present: on failure, inside a request context it falls back to whether the request carries a guest token (reading the token header/form field cannot raise). Anyone presenting a token is redacted; a genuinely anonymous request keeps its error, so ordinary failures are not over-sanitized. This is a deliberate availability-over-confidentiality trade-off, and the docstrings (source + the two tests from #43834) are reworded to say so rather than claim a definitional truth.
   
   **Celery nuance:** `sanitize_error_dicts` also runs in a Celery worker (`tasks/async_queries.py`) inside `override_user(...)`, where there is **no request context** and `request.headers` would itself raise. The fallback is guarded with `flask.has_request_context()`; with no request there is no handler-of-a-handler concern and a guest principal may be active via `override_user`, so it **fails closed and redacts** rather than leaking into the job payload delivered to the embedded viewer.
   
   **2. Resolve once / thread the boolean (N+1, log-spam, half-redaction)**
   
   `is_sanitization_required()` was re-invoked per error, so a 10-error response called a raising loader 11× and emitted 11 WARNING tracebacks — for one response, on every 404 including scanners/health probes. `charts/data/api.py` also half-redacted: the raw outer `is_guest_user()` could succeed while the inner guarded `sanitize_error_message` failed, popping `stacktrace` but keeping the raw `error`. The sanitize helpers now take an optional `required: bool | None = None` (None = compute) so `sanitize_superset_errors` / `sanitize_error_dicts` resolve the decision once and thread it down; `charts/data/api.py` computes the guarded decision once and reuses it for both the `stacktrace` pop and the message sanitization. Behavior is identical when sanitization is not required.
   
   **3. Last-resort handler could still 500**
   
   `show_unexpected_exception` called `send_file` for `500.html` without the `try/except FileNotFoundError` its three siblings have. A missing `500.html` (a webpack artifact, absent in API-only/unbuilt deployments) yielded a bare Werkzeug 500 with no SIP-40 body. It now has the same JSON fallback. (A handler-level decorator enforcing "the error handler must never itself raise" generally would be a broader follow-up; this PR fixes the concrete gap minimally, matching the existing sibling handlers.)
   
   Credit to the reviewer's analysis of the fail-open direction, the resolve-once opportunity, and the last-resort handler gap.
   
   ### TESTING INSTRUCTIONS
   
   New unit tests (each verified to fail without its corresponding change and pass with it):
   
   - `tests/unit_tests/utils/test_error_sanitization.py`
     - a request carrying a guest token whose resolution **raises** is still redacted (header and form-field variants), and asserts the patched `is_guest_user` was actually called — locks the fail-closed direction;
     - no-request-context (Celery-style) resolution failure fails closed and redacts;
     - a genuinely anonymous request whose resolution raises is left untouched.
   - `tests/unit_tests/charts/test_chart_data_api.py` — the half-redaction case (outer succeeds, inner raises) now redacts both `stacktrace` and `error` consistently.
   - `tests/unit_tests/views/test_error_handling.py` — `show_unexpected_exception` returns a SIP-40 JSON body when `500.html` is absent; the class docstring is reworded around the trade-off.
   
   Run:
   
   ```bash
   pytest tests/unit_tests/utils/test_error_sanitization.py \
          tests/unit_tests/views/test_error_handling.py \
          tests/unit_tests/charts/test_chart_data_api.py \
          tests/unit_tests/tasks/test_async_queries.py
   ```
   
   All pass; `pre-commit` (ruff, ruff-format, mypy, pylint) is green on the changed files.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-5545911075

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43896?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `24.13793%` with `22 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 57.48%. Comparing base ([`6956da1`](https://app.codecov.io/gh/apache/superset/commit/6956da1de5d10b7b44474c4324ad8db4a79bd035?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`eee8f3b`](https://app.codecov.io/gh/apache/superset/commit/eee8f3b3f4d87897cbe30f4dfa9f2230133e432d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/43896?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/utils/error\_sanitization.py](https://app.codecov.io/gh/apache/superset/pull/43896?src=pr&el=tree&filepath=superset%2Futils%2Ferror_sanitization.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvdXRpbHMvZXJyb3Jfc2FuaXRpemF0aW9uLnB5) | 27.27% | [14 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/superset/pull/43896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/views/error\_handling.py](https://app.codecov.io/gh/apache/superset/pull/43896?src=pr&el=tree&filepath=superset%2Fviews%2Ferror_handling.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvdmlld3MvZXJyb3JfaGFuZGxpbmcucHk=) | 0.00% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/charts/data/api.py](https://app.codecov.io/gh/apache/superset/pull/43896?src=pr&el=tree&filepath=superset%2Fcharts%2Fdata%2Fapi.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY2hhcnRzL2RhdGEvYXBpLnB5) | 33.33% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/superset/pull/43896?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (6956da1) and HEAD (eee8f3b). Click for more details.
   > 
   > <details><summary>HEAD has 8 uploads less than BASE</summary>
   >
   >| Flag | BASE (6956da1) | HEAD (eee8f3b) |
   >|------|------|------|
   >|python|8|1|
   >|presto|2|1|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #43896       +/-   ##
   ===========================================
   - Coverage   79.51%   57.48%   -22.04%     
   ===========================================
     Files        2897     2897               
     Lines      168619   168634       +15     
     Branches    39121    39126        +5     
   ===========================================
   - Hits       134085    96931    -37154     
   - Misses      32030    70802    +38772     
   + Partials     2504      901     -1603     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.57% <24.13%> (-0.01%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.57% <24.13%> (-44.36%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/43896/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43896?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-5963962189

   <!-- Bito Reply -->
   The flagged issue is correct: the current error handling in `superset/views/error_handling.py` is too narrow, as it only catches specific exceptions and allows other filesystem-related errors like `PermissionError` or `NotADirectoryError` to escape, potentially leading to unhandled 500 errors. To resolve this, you should broaden the exception handling to catch a wider range of `OSError` subclasses or simply `OSError` itself, ensuring the application remains resilient to various filesystem failures.
   
   Would you like me to fetch all other comments on this PR to validate them and implement a comprehensive fix for all identified issues?


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-5964072544

   Follow-up in 6eba8b31d4: I've broadened the form-read guard to `except Exception`, so it now fails closed on *any* exception, as you originally asked. My earlier `(HTTPException, OSError)` turned out to be too narrow. When the server terminates the input stream (for example a chunked body under gunicorn), werkzeug reads the server's stream directly. gunicorn parses chunked trailers lazily inside that read and raises `ParseException` subclasses (`InvalidHeaderName`, `ObsoleteFolding`, …) on a malformed trailer. Those are plain `Exception`s, not `OSError`, so they still escaped as a bare 500. The inline comment records why the catch is deliberately broad.
   
   Tests: the unreadable-body test now uses a body with no token, so it can only pass by failing closed. It's parametrized over a real werkzeug `RequestEntityTooLarge` and a server stream whose `read()` raises a plain `Exception` subclass. The second case fails against the narrow catch and passes with the broad one. I also corrected two comments. One overstated the form fallback: a body whose first parse in the request loader already failed part-way re-parses as an empty form and is treated as token-free (no guest was authenticated on that request). The other overstated the chart-data sanitize block.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-6003945213

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers an incremental AI Review.
   - `/review full` - 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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-5963903364

   Thanks @rusackas — both addressed in 197954e969 (after merging master to clear the conflict):
   
   1. **Form-read fallback:** `request.form.get("guest_token")` is now wrapped in its own try/except and fails closed (redacts) if the body can't be read. I checked the pinned werkzeug (3.1.6): first access to `.form` can raise `RequestEntityTooLarge` (over `max_content_length` / `max_form_memory_size` / `max_form_parts`) or `ClientDisconnected` (truncated body) — both `HTTPException`s — plus `OSError` from the WSGI server's input stream (gunicorn's body-read errors are `OSError` subclasses) or the multipart temp-file spool. Parser `ValueError`s are already swallowed since the parser runs with `silent=True`. So the clause catches `(HTTPException, OSError)`. Added a test that drives a real oversized body through it; it raises `RequestEntityTooLarge` without the guard and passes with it.
   2. **Half-redaction test:** now uses a single raising `side_effect` and asserts the lookup happens exactly once, so the raising path the docstring describes is actually exercised.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #43896:
URL: https://github.com/apache/superset/pull/43896


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-6067081827

   ### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">🔨</span> Latest commit | 13c09837e836bbd792706b2a27fe6cb5b70caca8 |
   |<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6ac7e909d674d100091a4bd5 |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-43896--superset-docs-preview.netlify.app](https://deploy-preview-43896--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQzODk2LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.2H1XXYmHm-aE0ckApTvJQuzRom_1eJkeOlr0AkkfL5w)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcvLCYAwDADQXXK2UMEPdQPHiKbFQm1CrIiKu9vbu7wXRHmXAhNAA4tiXrfqwCnxdYrxqqzmwBxLfLBEziZgTIbF5xrIS-J7ploGXEfvrKNh7Ki11roWu4V6-H4) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-43896--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-6001087736

   @rusackas I've rebased onto the latest master to pick up the upstream mypy fix in `importers/v1/utils.py` (#44932). The rebase changed the commit SHAs, so here's where your feedback now lives:
   
   - **Form read in the fallback** (blocking): fixed in 17d2b14b87 (was 6eba8b31d4). `request.form.get("guest_token")` has its own guard and fails closed (redacts) on *any* exception. That covers werkzeug's `RequestEntityTooLarge`/`ClientDisconnected`, and also exceptions raised by the WSGI server's input stream, such as gunicorn's `ParseException` subclasses for a malformed chunked trailer, which aren't `OSError`s. Tests use a body with no token and cover both a real werkzeug 413 and a server stream that raises a plain `Exception`.
   - **`side_effect` nit**: fixed in e44af26edb (was 197954e969). The test uses a single raising `side_effect` and asserts exactly one lookup.
   
   Could you take another look when you have a moment?


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #43896:
URL: https://github.com/apache/superset/pull/43896#discussion_r4223029928


##########
superset/views/error_handling.py:
##########
@@ -318,7 +318,15 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse:
 
         if "text/html" in request.accept_mimetypes and not app.config["DEBUG"]:
             path = files("superset") / "static/assets/500.html"
-            return send_file(path, max_age=0), 500
+            # Try to serve HTML file; fall back to JSON if not built. This is the
+            # last-resort handler, so a missing ``500.html`` (a webpack artifact
+            # absent in API-only/unbuilt deployments) must not raise its own
+            # ``FileNotFoundError`` and collapse the response to a bare 500 with
+            # no SIP-40 body.
+            try:
+                return send_file(path, max_age=0), 500
+            except FileNotFoundError:
+                pass

Review Comment:
   Valid, thanks. Fixed in 13c09837e8: the last-resort `show_unexpected_exception` handler now catches `OSError` around `send_file` rather than only `FileNotFoundError`. Before the change I confirmed that `PermissionError`, `NotADirectoryError` and `IsADirectoryError` all escaped it. The test is now parametrized over all four. I left the sibling handlers alone: if their `send_file` raises, Flask routes the error to this handler, so they still get a SIP-40 JSON 500 rather than a bare one (I checked this for the `CommandException` and `SupersetException` handlers).



##########
superset/utils/error_sanitization.py:
##########
@@ -100,38 +116,75 @@ def is_sanitization_required() -> bool:
         # Never let identifying the principal break the error handler itself.
         logger.warning(
             "Could not resolve the request principal while deciding whether to "
-            "sanitize an error response; treating it as a non-guest request.",
+            "sanitize an error response; falling back to the presence of a guest "
+            "token.",
             exc_info=True,
         )
-        return False
+        if not has_request_context():
+            # No request to inspect (e.g. a Celery worker running under
+            # ``override_user``). Fail closed: a guest principal may be active
+            # and the redacted payload is delivered to the embedded viewer.
+            return True
+        # ``.get`` on the config keeps the header read from raising even if the
+        # key is somehow absent.
+        header_name = current_app.config.get("GUEST_TOKEN_HEADER_NAME")
+        if header_name and request.headers.get(header_name):
+            return True
+        try:
+            # ``request.form`` parses the body lazily on first access. A body
+            # whose first parse (in the request loader) already failed part-way
+            # is left partially consumed and re-parses as an empty form; no guest
+            # was authenticated on such a request, so it is treated as token-free.
+            return bool(request.form.get("guest_token"))

Review Comment:
   I'm leaving this one as is on purpose. The two reads look alike but have different contracts:
   
   - `request_loader` (and the copy in `get_guest_user_from_request`) is the authentication path. It may raise. For example, an oversized body raises a 413 there, which is the right response.
   - This fallback runs inside the error handler after resolving the principal has already failed, so it must never raise, and it fails closed (redacts) when the body can't be read. That's why it uses `current_app.config.get(...)` rather than `get_conf()[...]`, which can raise `KeyError`, and why the form read has its own broad `except`.
   
   A shared helper would have to pick one of those two behaviours. That would either make this fallback able to raise again, which is the bug this PR closes, or make authentication swallow body errors, which changes auth behaviour and is out of scope here. The things that could drift are the `GUEST_TOKEN_HEADER_NAME` config key and the `guest_token` form field. Both are part of the embedded SDK's request format, and the fallback tests build their requests from the same config key and field name.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-6067038563

   I've gone through the automated review comments from the last round:
   
   - **codeant: `send_file` can raise other filesystem errors**: a real gap, fixed in 13c09837e8. The last-resort handler now catches `OSError` and falls back to JSON.
   - **bito: duplicated `send_file` fallback across four handlers**: handled by that same fix rather than a new shared helper. A sibling handler whose `send_file` raises is routed to the last-resort handler, which now always returns a SIP-40 body.
   - **bito: duplicated guest-token detection**: left as is on purpose. The reasoning is in the thread: the authentication-path read may raise, but this fallback must not.
   - **bito: type hints on test locals**: not changed. `test_error_handling.py` doesn't annotate locals anywhere (0 of ~47), and mypy infers these.
   
   @rusackas, your review predates the fixes for your feedback and this round. Could you take another look?


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-6086890242

   @rusackas Rebased onto master again (no code changes) to pick up the new `playwright-tests-gaq` test infra and CI is fully green now. Would appreciate a re-look when you have a chance.


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-6067048652

   ## CodeAnt PR Risk: Low Risk
   
   - The PR appears safe to merge; guest-error redaction uses one decision to avoid removing stack traces while leaking raw messages.
   - The error handler falls back to a SIP-40 JSON response when serving the HTML error page raises an OSError, with tests covering common filesystem failures.
   
   **Assessed commit:** `13c09837e836`


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43896:
URL: https://github.com/apache/superset/pull/43896#discussion_r4225313265


##########
superset/views/error_handling.py:
##########
@@ -318,7 +318,15 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse:
 
         if "text/html" in request.accept_mimetypes and not app.config["DEBUG"]:
             path = files("superset") / "static/assets/500.html"
-            return send_file(path, max_age=0), 500
+            # Try to serve HTML file; fall back to JSON if not built. This is the
+            # last-resort handler, so a missing ``500.html`` (a webpack artifact
+            # absent in API-only/unbuilt deployments) must not raise its own
+            # ``FileNotFoundError`` and collapse the response to a bare 500 with
+            # no SIP-40 body.
+            try:
+                return send_file(path, max_age=0), 500
+            except FileNotFoundError:
+                pass

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved** as of `6f36e71`.
   
   The HTML error-page fallback now catches `OSError` from `send_file` and falls through to the SIP-40 JSON error response.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-5965369566

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers an incremental AI Review.
   - `/review full` - 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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #43896:
URL: https://github.com/apache/superset/pull/43896#discussion_r4189386207


##########
superset/utils/error_sanitization.py:
##########
@@ -100,38 +116,75 @@ def is_sanitization_required() -> bool:
         # Never let identifying the principal break the error handler itself.
         logger.warning(
             "Could not resolve the request principal while deciding whether to "
-            "sanitize an error response; treating it as a non-guest request.",
+            "sanitize an error response; falling back to the presence of a guest "
+            "token.",
             exc_info=True,
         )
-        return False
+        if not has_request_context():
+            # No request to inspect (e.g. a Celery worker running under
+            # ``override_user``). Fail closed: a guest principal may be active
+            # and the redacted payload is delivered to the embedded viewer.
+            return True
+        # ``.get`` on the config keeps the header read from raising even if the
+        # key is somehow absent.
+        header_name = current_app.config.get("GUEST_TOKEN_HEADER_NAME")
+        if header_name and request.headers.get(header_name):
+            return True
+        try:
+            # ``request.form`` parses the body lazily on first access. A body
+            # whose first parse (in the request loader) already failed part-way
+            # is left partially consumed and re-parses as an empty form; no guest
+            # was authenticated on such a request, so it is treated as token-free.
+            return bool(request.form.get("guest_token"))

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Duplicated guest-token detection</b></div>
   <div id="fix">
   
   The new fallback re-implements the guest-token detection already in `security/manager.py` (`request.headers.get(get_conf()["GUEST_TOKEN_HEADER_NAME"]) or request.form.get("guest_token")`). It also diverges: `current_app.config.get(...)` here vs `get_conf()["..."]` there. A future change to the header/field name or config access in one place silently desyncs the other. Consider a shared helper.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #635ee4</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43896:
URL: https://github.com/apache/superset/pull/43896#discussion_r4171042661


##########
superset/views/error_handling.py:
##########
@@ -318,7 +318,15 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse:
 
         if "text/html" in request.accept_mimetypes and not app.config["DEBUG"]:
             path = files("superset") / "static/assets/500.html"
-            return send_file(path, max_age=0), 500
+            # Try to serve HTML file; fall back to JSON if not built. This is the
+            # last-resort handler, so a missing ``500.html`` (a webpack artifact
+            # absent in API-only/unbuilt deployments) must not raise its own
+            # ``FileNotFoundError`` and collapse the response to a bare 500 with
+            # no SIP-40 body.
+            try:
+                return send_file(path, max_age=0), 500
+            except FileNotFoundError:
+                pass

Review Comment:
   **Suggestion:** `send_file` can raise other filesystem errors, such as `PermissionError` or `NotADirectoryError`, which still escape this last-resort error handler.
   
   **Assessment:** 🟠 `Major` · 🔁 `Occurrence: Rarely` · 🏷️ `Possible bug`
   
   [![Use CodeAnt Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [![Fix in Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=e9f9055c8fca4f0eb4867bd3f853c703&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [![Fix in VSCode Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=e9f9055c8fca4f0eb4867bd3f853c703&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/views/error_handling.py
   **Line:** 328:329
   **Comment:**
   	*Possible Bug: `send_file` can raise other filesystem errors, such as `PermissionError` or `NotADirectoryError`, which still escape this last-resort error handler.
   
   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
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43896&comment_hash=4469e858336ab877d5cf022318c4b36b972649951bce1a118b0e81dc3d69a144&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43896&comment_hash=4469e858336ab877d5cf022318c4b36b972649951bce1a118b0e81dc3d69a144&reaction=dislike'>👎</a>



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43896:
URL: https://github.com/apache/superset/pull/43896#discussion_r4223037456


##########
superset/views/error_handling.py:
##########
@@ -318,7 +318,15 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse:
 
         if "text/html" in request.accept_mimetypes and not app.config["DEBUG"]:
             path = files("superset") / "static/assets/500.html"
-            return send_file(path, max_age=0), 500
+            # Try to serve HTML file; fall back to JSON if not built. This is the
+            # last-resort handler, so a missing ``500.html`` (a webpack artifact
+            # absent in API-only/unbuilt deployments) must not raise its own
+            # ``FileNotFoundError`` and collapse the response to a bare 500 with
+            # no SIP-40 body.
+            try:
+                return send_file(path, max_age=0), 500
+            except FileNotFoundError:
+                pass

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved** as of `13c0983`.
   
   The fallback now catches `OSError` from `send_file` and continues to the SIP-40 JSON error response, covering filesystem errors such as `PermissionError` and `NotADirectoryError`.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(embedded): fail closed when the guest-user check can't resolve a principal [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43896:
URL: https://github.com/apache/superset/pull/43896#issuecomment-5545866169

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


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org