You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/06/09 16:34:41 UTC

(superset) branch master updated: fix(mcp): handle JWKS fetch network errors during token verification (#40869)

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b64dd4af4a1 fix(mcp): handle JWKS fetch network errors during token verification (#40869)
b64dd4af4a1 is described below

commit b64dd4af4a1eb9755eed92f3a6220cdb87f90b16
Author: Evan Rusackas <ev...@preset.io>
AuthorDate: Tue Jun 9 09:34:33 2026 -0700

    fix(mcp): handle JWKS fetch network errors during token verification (#40869)
    
    Co-authored-by: Claude Code <no...@anthropic.com>
---
 superset/mcp_service/jwt_verifier.py              | 13 +++++++++++++
 tests/unit_tests/mcp_service/test_jwt_verifier.py | 21 +++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/superset/mcp_service/jwt_verifier.py b/superset/mcp_service/jwt_verifier.py
index 0ad46058965..680388a505d 100644
--- a/superset/mcp_service/jwt_verifier.py
+++ b/superset/mcp_service/jwt_verifier.py
@@ -33,6 +33,7 @@ from collections.abc import Callable
 from contextvars import ContextVar
 from typing import Any, cast
 
+import httpx
 from authlib.jose.errors import (
     BadSignatureError,
     DecodeError,
@@ -447,6 +448,18 @@ class DetailedJWTVerifier(MCPJWTVerifier):
             # 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)
+                # WARNING carries only the generic category (per the module's
+                # logging contract); the sanitized exception detail, which may
+                # include the JWKS endpoint host, is reserved for DEBUG.
+                logger.warning("Could not fetch JWKS verification key")
+                logger.debug("JWKS fetch error detail: %s", _sanitize_for_log(e))
+                return None
             except ValueError as e:
                 reason = "Failed to get verification key"
                 _jwt_failure_reason.set(reason)
diff --git a/tests/unit_tests/mcp_service/test_jwt_verifier.py b/tests/unit_tests/mcp_service/test_jwt_verifier.py
index e6f7aa1fd8a..3fe82fac2eb 100644
--- a/tests/unit_tests/mcp_service/test_jwt_verifier.py
+++ b/tests/unit_tests/mcp_service/test_jwt_verifier.py
@@ -92,6 +92,27 @@ async def test_malformed_token_header(hs256_verifier):
     assert reason == "Malformed token header"
 
 
+@pytest.mark.asyncio
+async def test_jwks_network_error_is_handled(hs256_verifier):
+    """A network error fetching the JWKS key is handled, not propagated."""
+    import httpx
+
+    token = _make_token(
+        {"alg": "HS256", "typ": "JWT"},
+        {"sub": "user1", "iss": "test-issuer", "aud": "test-audience"},
+    )
+
+    with patch.object(
+        hs256_verifier,
+        "_get_verification_key",
+        side_effect=httpx.ConnectError("connection refused"),
+    ):
+        result = await hs256_verifier.load_access_token(token)
+
+    assert result is None
+    assert _jwt_failure_reason.get() == "JWKS verification key unavailable"
+
+
 @pytest.mark.asyncio
 async def test_signature_verification_failed(hs256_verifier):
     """Token with bad signature should report signature failure."""