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

[PR] fix(mcp): handle JWKS fetch network errors during token verification [superset]

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

   ### SUMMARY
   
   In `DetailedJWTVerifier.load_access_token()`, the step that fetches the verification key only caught `ValueError`. When a deployment uses JWKS, that key is fetched over the network (httpx), so a connection/timeout/DNS error would raise an exception type the function didn't handle — it propagated out as an unexpected error rather than being treated as a (transient) verification failure.
   
   This catches `httpx.HTTPError`, `OSError` and `TimeoutError` from the key fetch explicitly: it records a generic failure reason, logs a `warning`, and returns `None` so the request is handled as a normal authentication failure.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A — backend error handling.
   
   ### TESTING INSTRUCTIONS
   
   ```
   pytest tests/unit_tests/mcp_service/test_jwt_verifier.py
   ```
   
   A new test patches the key fetch to raise `httpx.ConnectError` and asserts the call returns `None` with a generic failure reason instead of propagating.
   
   ### 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: 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(mcp): handle JWKS fetch network errors during token verification [superset]

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

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/40869?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 `16.66667%` with `5 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 54.72%. Comparing base ([`507cf93`](https://app.codecov.io/gh/apache/superset/commit/507cf936877b45e98542d27a25345081ac63bcca?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`f2736a1`](https://app.codecov.io/gh/apache/superset/commit/f2736a1871068398675d2952006ff711c2d85610?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/40869?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/mcp\_service/jwt\_verifier.py](https://app.codecov.io/gh/apache/superset/pull/40869?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fjwt_verifier.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2Uvand0X3ZlcmlmaWVyLnB5) | 16.66% | [5 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/40869?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 (507cf93) and HEAD (f2736a1). Click for more details.
   > 
   > <details><summary>HEAD has 37 uploads less than BASE</summary>
   >
   >| Flag | BASE (507cf93) | HEAD (f2736a1) |
   >|------|------|------|
   >|python|34|1|
   >|hive|5|1|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #40869      +/-   ##
   ==========================================
   - Coverage   64.15%   54.72%   -9.43%     
   ==========================================
     Files        2653     2653              
     Lines      143499   143505       +6     
     Branches    33113    33113              
   ==========================================
   - Hits        92058    78532   -13526     
   - Misses      49834    64587   +14753     
   + Partials     1607      386    -1221     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/40869/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/40869/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.51% <16.66%> (-0.01%)` | :arrow_down: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/40869/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/40869/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/40869/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [python](https://app.codecov.io/gh/apache/superset/pull/40869/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.51% <16.66%> (-20.31%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/40869/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/40869/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/40869?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(mcp): handle JWKS fetch network errors during token verification [superset]

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

   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


Re: [PR] fix(mcp): handle JWKS fetch network errors during token verification [superset]

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

   <!-- Bito Reply -->
   The flagged issue is correct. Logging the raw exception object `e` at the WARNING level can expose sensitive network details, violating the module's contract to use generic categories for warnings. To resolve this, log the generic reason string at WARNING level and move the detailed exception to a DEBUG log.
   
   Here is the corrected implementation for `superset/mcp_service/jwt_verifier.py`:
   
   ```python
               except (httpx.HTTPError, OSError, TimeoutError) as e:
                   # Transient failure reaching or reading the JWKS endpoint.
                   reason = "JWKS verification key unavailable"
                   _jwt_failure_reason.set(reason)
                   logger.warning("Could not fetch JWKS verification key: %s", reason)
                   logger.debug("Detailed JWKS fetch error: %s", e)
                   return None
   ```
   
   There are no other comments in the PR to address. Would you like me to perform any other checks?
   
   **superset/mcp_service/jwt_verifier.py**
   ```
   except (httpx.HTTPError, OSError, TimeoutError) as e:
                   # Transient failure reaching or reading the JWKS endpoint.
                   reason = "JWKS verification key unavailable"
                   _jwt_failure_reason.set(reason)
                   logger.warning("Could not fetch JWKS verification key: %s", reason)
                   logger.debug("Detailed JWKS fetch error: %s", e)
                   return None
   ```


-- 
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(mcp): handle JWKS fetch network errors during token verification [superset]

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

   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 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(mcp): handle JWKS fetch network errors during token verification [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 #40869:
URL: https://github.com/apache/superset/pull/40869#discussion_r3375851419


##########
superset/mcp_service/jwt_verifier.py:
##########
@@ -447,6 +448,14 @@ async def load_access_token(self, token: str) -> AccessToken | None:  # noqa: C9
             # Step 2: Get verification key (static or JWKS)
             try:
                 verification_key = await self._get_verification_key(token)
+            except (httpx.HTTPError, OSError, TimeoutError) as e:
+                # Transient failure reaching or reading the JWKS endpoint.
+                # Treat it as an authentication failure (return None) instead of
+                # letting the network error propagate as an unexpected exception.
+                reason = "JWKS verification key unavailable"
+                _jwt_failure_reason.set(reason)

Review Comment:
   **Suggestion:** This warning log includes raw exception text from network/JWKS failures, which can leak endpoint details or untrusted message content at WARNING level and breaks the module's "generic categories only at WARNING" contract. Log only a generic category at WARNING and move sanitized exception details to DEBUG. [security]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ MCP JWT auth logs raw JWKS/network error text.
   - ⚠️ Violates documented WARNING-vs-DEBUG logging contract.
   - ⚠️ May disclose internal JWKS endpoints in auth logs.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Enable the MCP JWT auth path with debug logging so that `DetailedJWTVerifier` is used:
   `superset.mcp_service.server._create_auth_provider()` at `server.py:6-43` calls
   `create_default_mcp_auth_factory(flask_app)` in `mcp_config.py:344-362`, which in turn
   calls `_build_jwt_verifier()` at `mcp_config.py:98-119`. When `MCP_AUTH_ENABLED=True`,
   `MCP_JWKS_URI` is set, and `MCP_JWT_DEBUG_ERRORS=True`, `_build_jwt_verifier()` returns a
   `DetailedJWTVerifier` instance (see `mcp_config.py:105-117` and comment at
   `mcp_config.py:33-40`).
   
   2. Start the MCP server using `run_server()` in `superset/mcp_service/server.py:35-56`. In
   the default configuration branch (`server.py:77-99`), this obtains `auth_provider =
   _create_auth_provider(flask_app)` (`server.py:82-84`) and passes it to
   `init_fastmcp_server(auth=auth_provider, ...)` (`server.py:95-98`), wiring the
   `DetailedJWTVerifier` (or a `CompositeTokenVerifier` wrapping it) into the FastMCP
   authentication pipeline for all MCP HTTP requests.
   
   3. Configure JWT verification to use JWKS (set `MCP_JWKS_URI`) so that key retrieval
   happens over the network (`_build_jwt_verifier()` assigns `jwks_uri` in
   `mcp_config.py:118-120`). Then cause the JWKS endpoint to be unreachable (e.g., DNS or
   connection failure). In the codebase this scenario is concretely exercised by
   `test_jwks_network_error_is_handled` at
   `tests/unit_tests/mcp_service/test_jwt_verifier.py:96-113`, which patches
   `hs256_verifier._get_verification_key` to raise `httpx.ConnectError("connection
   refused")`, modeling a real network failure.
   
   4. With that configuration, send any MCP HTTP request that includes an `Authorization:
   Bearer <token>` header so authentication runs. FastMCP's auth stack invokes
   `DetailedJWTVerifier.load_access_token()` (`jwt_verifier.py:18-64`). In Step 2 of that
   method (`jwt_verifier.py:49-64`), `verification_key = await
   self._get_verification_key(token)` (`line 51`) raises an `httpx.HTTPError` (or
   `OSError`/`TimeoutError`), which is caught by the new `except (httpx.HTTPError, OSError,
   TimeoutError) as e:` block (`jwt_verifier.py:52-58`). That block sets the generic failure
   reason `"JWKS verification key unavailable"` in `_jwt_failure_reason` and then executes
   `logger.warning("Could not fetch JWKS verification key: %s", e)` at `jwt_verifier.py:58`
   (diff line 456). Because this WARNING-level log interpolates the raw exception object `e`
   without using `_sanitize_for_log` and without constraining it to the generic reason
   string, the log can include specific JWKS URL/hostnames or low-level network error text.
   This conflicts with the module's documented logging contract that WARNING should carry
   only generic failure categories (see `DetailedJWTVerifier` docstring at
   `jwt_verifier.py:5-15` and the `_jwt_failure_reason` comment at `jwt_verifier.py:62-67`),
   where detailed exception text is supposed to be reserved for DEBUG-level logging.
   ```
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3b218f63c9c44b4485f579761193b88a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3b218f63c9c44b4485f579761193b88a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/jwt_verifier.py
   **Line:** 456:456
   **Comment:**
   	*Security: This warning log includes raw exception text from network/JWKS failures, which can leak endpoint details or untrusted message content at WARNING level and breaks the module's "generic categories only at WARNING" contract. Log only a generic category at WARNING and move sanitized exception details to DEBUG.
   
   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%2F40869&comment_hash=fa0ddd994b98063815e00a6f76dfd7c4d826d0ae8b6c4bc656ad5ea8a8399b4a&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40869&comment_hash=fa0ddd994b98063815e00a6f76dfd7c4d826d0ae8b6c4bc656ad5ea8a8399b4a&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(mcp): handle JWKS fetch network errors during token verification [superset]

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


-- 
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(mcp): handle JWKS fetch network errors during token verification [superset]

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


##########
superset/mcp_service/jwt_verifier.py:
##########
@@ -447,6 +448,14 @@ async def load_access_token(self, token: str) -> AccessToken | None:  # noqa: C9
             # Step 2: Get verification key (static or JWKS)
             try:
                 verification_key = await self._get_verification_key(token)
+            except (httpx.HTTPError, OSError, TimeoutError) as e:
+                # Transient failure reaching or reading the JWKS endpoint.
+                # Treat it as an authentication failure (return None) instead of
+                # letting the network error propagate as an unexpected exception.
+                reason = "JWKS verification key unavailable"
+                _jwt_failure_reason.set(reason)

Review Comment:
   Good catch. Fixed in 2a029caa94: WARNING now logs only the generic category ("Could not fetch JWKS verification key"), and the sanitized exception detail (which may include the JWKS endpoint host) is moved to DEBUG, consistent with the rest of the module's logging contract.



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