Skip to content

The agent that grows with you

fix: a forged JWT bearer is an invalid token, not an auth-provider outage

Teknium5bb155d56888
diff --git a/plugins/dashboard_auth/_shared.py b/plugins/dashboard_auth/_shared.py
index 8d17d0b4a0b..7d2e6859799 100644
--- a/plugins/dashboard_auth/_shared.py
+++ b/plugins/dashboard_auth/_shared.py
@@ -215,6 +215,10 @@ def verify_jwt(
options={"require": ["exp", "iat", "aud", "iss", "sub"]})
except jwt.ExpiredSignatureError as exc:
raise InvalidCodeError(f"{label} expired: {exc}") from exc
+ except jwt.InvalidSignatureError as exc:
+ # A forged/tampered bearer is "not my token", never an IDP outage: a 503 here would let a
+ # remote caller with garbage credentials look like a provider incident (and keep cookies).
+ raise InvalidCodeError(f"{label} signature invalid: {exc}") from exc
except jwt.InvalidTokenError as exc:
# Decoding without verification is safe here: verification already failed and
# these values are surfaced for diagnostics only, never trusted.
diff --git a/tests/plugins/dashboard_auth/test_self_hosted_provider.py b/tests/plugins/dashboard_auth/test_self_hosted_provider.py
index 96601304c31..230373f4c4c 100644
--- a/tests/plugins/dashboard_auth/test_self_hosted_provider.py
+++ b/tests/plugins/dashboard_auth/test_self_hosted_provider.py
@@ -728,3 +728,29 @@ class TestPluginRegister:
registered = ctx.register_dashboard_auth_provider.call_args.args[0]
assert registered._client_secret == "cfg-secret"
+
+
+class TestForgedSignature:
+ """A bearer whose signature does not verify is an invalid token, never a provider outage.
+
+ Live remote-bind probe: a tampered OIDC bearer on the gated API returned 503
+ ``Auth provider 'self-hosted' unreachable`` (cookies kept, no fall-through), so a forged
+ token was indistinguishable from an IDP outage. iss/aud drift keeps its 503 (config drift).
+ """
+
+ def test_tampered_signature_is_invalid_token_not_unreachable(self, rsa_keypair):
+ provider = _make_provider(rsa_keypair)
+ token = _mint_id_token(rsa_keypair)
+ head, body, sig = token.split(".")
+ forged = ".".join((head, body, sig[:-4] + ("AAAA" if not sig.endswith("AAAA") else "BBBB")))
+ assert provider.verify_session(access_token=forged) is None
+
+ def test_wrong_key_signature_is_invalid_token_not_unreachable(self, rsa_keypair):
+ provider = _make_provider(rsa_keypair)
+ other = rsa.generate_private_key(public_exponent=65537, key_size=2048)
+ pem = other.private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8,
+ serialization.NoEncryption())
+ now = int(time.time())
+ token = jwt.encode({"iss": _ISSUER, "aud": _CLIENT_ID, "sub": "usr_abc", "iat": now, "exp": now + 900},
+ pem, algorithm="RS256", headers={"kid": rsa_keypair["kid"]})
+ assert provider.verify_session(access_token=token) is None