From a3f06ab0b1a9911e05a2404903c8653ae0ef5eb2 Mon Sep 17 00:00:00 2001 From: yucheng-berri <293926326+yucheng-berri@users.noreply.github.com> Date: Wed, 14 Oct 2026 18:46:45 -0700 Subject: [PATCH] fix(auth): extend FIPS-gated read-side grace to stored symmetric HS* signing algs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit litereview round on ff348d1be4: a stored client_assertion_signing_alg=HS256 with a shared secret in client_private_key produced a working client_secret_jwt-style assertion before the allowlist; coercing it to RS256 guarantees failure since an HMAC secret cannot sign RSA, and the boot log claimed it was 'using RS256'. Apply the same FIPS-gated read-side grace as stored EdDSA: outside FIPS the stored HS* value is honoured with a rotate-to-approved warning so the secret keeps signing; inside FIPS the RS256 fallback stands with an honest cannot-sign warning so the exchange fails loudly. Write-side New/Update validators still 422 HS*, and the verification-side allowlists (allowed_jwt_algorithms / jwks_keys_for) are untouched — oct/HS256 JWKS keys stay dropped in every mode. Also: the guardrail EdDSA deprecation notice now fires only after the signature verifies (Bugbot: a failed EdDSA token no longer logs 'accepted'), and the integration JWKS allowlist suite pins the new flag-off EdDSA-verifies behaviour (the OKP rejection cell moved to unit level where LITELLM_FIPS_MODE can be set without the boot-time FIPS runtime checks refusing a non-FIPS OpenSSL). --- .../mcp_server/mcp_server_manager.py | 25 ++++++++++ .../mcp_jwt_signer/mcp_jwt_signer.py | 9 ++-- litellm/types/proxy/auth/jwt_algorithms.py | 12 +++-- .../test_mcp_client_assertion_signing_alg.py | 3 +- .../mcp/test_mcp_jwt_signer_jwks_allowlist.py | 24 +++++++++- .../test_token_endpoint.py | 31 ++++++++++++ .../mcp_server/test_mcp_server_manager.py | 48 ++++++++++++++----- 7 files changed, 131 insertions(+), 21 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index b78fb5c261a..41487614552 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -229,6 +229,7 @@ from litellm.types.mcp_server.mcp_server_manager import ( from litellm.types.proxy.auth.jwt_algorithms import ( APPROVED_JWT_ALGORITHMS, LEGACY_JWT_ALGORITHMS, + SYMMETRIC_JWT_ALGORITHMS, StoredJwtAlgorithm, ) from litellm.types.utils import CallTypes @@ -1634,6 +1635,30 @@ def _stored_client_assertion_signing_alg(value: object, server_name: str) -> Sto value, ) return "RS256" + if isinstance(value, str) and value in SYMMETRIC_JWT_ALGORITHMS: + # Symmetric HS*: pre-allowlist a stored HS* with a shared secret in client_private_key + # produced a working client_secret_jwt-style assertion, so this is a working legacy + # config, not a typo. The same FIPS-gated grace applies — honoured outside FIPS so the + # secret keeps signing, refused inside FIPS where the RS256 fallback (which an HMAC + # secret cannot sign) fails the exchange loudly until the server is reconfigured. + if not is_fips_mode(): + verbose_logger.warning( + "MCP server %s: client_assertion_signing_alg %r is symmetric and not FIPS 140-3 approved; " + "accepted outside FIPS mode, so the stored shared secret keeps signing; rotate to an approved " + "RSA/EC key (see APPROVED_JWT_ALGORITHMS) — non-approved algorithm support ends in the next " + "major release", + server_name, + value, + ) + return value + verbose_logger.warning( + "MCP server %s: client_assertion_signing_alg %r is not approved for signing; the stored shared " + "secret cannot sign the RS256 fallback, so token exchange will fail until the server is " + "reconfigured with an approved RSA/EC key (see APPROVED_JWT_ALGORITHMS)", + server_name, + value, + ) + return "RS256" if value is not None: verbose_logger.warning( "MCP server %s: client_assertion_signing_alg %r is not an approved algorithm, using RS256", diff --git a/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py b/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py index a23d867cf82..eba5aab3044 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py +++ b/litellm/proxy/guardrails/guardrail_hooks/mcp_jwt_signer/mcp_jwt_signer.py @@ -495,10 +495,6 @@ class MCPJWTSigner(CustomGuardrail): # PyJWT populates algorithm_name from the key's `alg` field; when absent # it infers from the key type (RSAPublicKey → RS256). alg: Final = getattr(signing_jwk, "algorithm_name", None) or "RS256" - if alg == "EdDSA": - # Only reachable outside FIPS mode (inside it the filter above drops EdDSA keys); - # same once-per-process deprecation notice the main JWT entrance emits. - _log_eddsa_deprecation() decode_options: Final[Options] = {"verify_exp": True} decode_kwargs: Final[_JWTDecodeKwargs] = { @@ -514,6 +510,11 @@ class MCPJWTSigner(CustomGuardrail): decode_kwargs["issuer"] = self.verify_issuer payload: Final[dict[str, object]] = jwt.decode(raw_token, signing_jwk.key, **decode_kwargs) + if alg == "EdDSA": + # Only reachable outside FIPS mode (inside it the filter above drops EdDSA keys) and + # only after the signature verified — same once-per-process deprecation notice the + # main JWT entrance emits after its own successful decode. + _log_eddsa_deprecation() return payload async def _introspect_opaque_token(self, token: str) -> dict[str, object]: diff --git a/litellm/types/proxy/auth/jwt_algorithms.py b/litellm/types/proxy/auth/jwt_algorithms.py index 0b19d94fccd..5557a5eec39 100644 --- a/litellm/types/proxy/auth/jwt_algorithms.py +++ b/litellm/types/proxy/auth/jwt_algorithms.py @@ -20,6 +20,12 @@ LegacyJwtAlgorithm: TypeAlias = Literal["EdDSA"] LEGACY_JWT_ALGORITHMS: Final[tuple[LegacyJwtAlgorithm, ...]] = ("EdDSA",) -StoredJwtAlgorithm: TypeAlias = ApprovedJwtAlgorithm | LegacyJwtAlgorithm -"""A value read back from stored/declared config: approved, or legacy EdDSA carried under -read-side grace outside FIPS mode (write-side validation stays approved-only).""" +SymmetricJwtAlgorithm: TypeAlias = Literal["HS256", "HS384", "HS512"] + +SYMMETRIC_JWT_ALGORITHMS: Final[tuple[SymmetricJwtAlgorithm, ...]] = ("HS256", "HS384", "HS512") + +StoredJwtAlgorithm: TypeAlias = ApprovedJwtAlgorithm | LegacyJwtAlgorithm | SymmetricJwtAlgorithm +"""A value read back from stored/declared config: approved, or a not-approved value (legacy +EdDSA, symmetric HS*) carried under FIPS-gated read-side grace so a pre-allowlist row keeps +signing outside FIPS mode. Write-side validation and the verification-side allowlists stay +approved-only (plus EdDSA outside FIPS); nothing here widens them.""" diff --git a/tests/integration/mcp/test_mcp_client_assertion_signing_alg.py b/tests/integration/mcp/test_mcp_client_assertion_signing_alg.py index 6f400aeae6a..652e748833b 100644 --- a/tests/integration/mcp/test_mcp_client_assertion_signing_alg.py +++ b/tests/integration/mcp/test_mcp_client_assertion_signing_alg.py @@ -95,7 +95,8 @@ def test_approved_client_assertion_signing_alg_round_trips(gateway: Gateway) -> def test_server_row_with_stale_client_assertion_signing_alg_still_loads(gateway: Gateway) -> None: """A row persisted before the allowlist (credentials.client_assertion_signing_alg = "HS256") - must keep loading with the RS256 fallback instead of disappearing on upgrade.""" + must keep loading on upgrade instead of disappearing; outside FIPS mode its stored value is + honoured under read-side grace (write-side requests still refuse HS*).""" identity: Final = "stalealg" + uuid.uuid4().hex[:8] with psycopg.connect(os.environ["DATABASE_URL"]) as connection: connection.execute( diff --git a/tests/integration/mcp/test_mcp_jwt_signer_jwks_allowlist.py b/tests/integration/mcp/test_mcp_jwt_signer_jwks_allowlist.py index 1b5cdf091b8..30be34732ff 100644 --- a/tests/integration/mcp/test_mcp_jwt_signer_jwks_allowlist.py +++ b/tests/integration/mcp/test_mcp_jwt_signer_jwks_allowlist.py @@ -116,10 +116,15 @@ def _call_with_bearer( ) -@pytest.mark.parametrize("key_and_token", (_hs256_key_and_token, _eddsa_key_and_token), ids=("oct-HS256", "OKP-EdDSA")) +@pytest.mark.parametrize("key_and_token", (_hs256_key_and_token,), ids=("oct-HS256",)) def test_jwks_key_with_non_approved_alg_cannot_verify_the_incoming_token( signer_gateway: Gateway, key_and_token: Callable[[], tuple[dict[str, object], str]] ) -> None: + """HS256 is never allowed: the JWKS filter drops oct keys in every mode, so the call 401s. + + (EdDSA is the legacy exception — accepted outside FIPS mode; see the test below. The + FIPS-on refusal is pinned at the unit level, where LITELLM_FIPS_MODE can be flipped + without the boot-time FIPS runtime checks refusing a non-FIPS OpenSSL.)""" jwks_key, token = key_and_token() with _idp_server([jwks_key]) as discovery_uri, _jwt_signer_guardrail(signer_gateway, discovery_uri): with mcp_peer() as peer, signer_gateway.scenario() as scenario: @@ -134,6 +139,23 @@ def test_jwks_key_with_non_approved_alg_cannot_verify_the_incoming_token( assert tool_calls(peer.drain()) == (), "rejected call reached the peer" +def test_jwks_eddsa_key_verifies_the_incoming_token_outside_fips_mode(signer_gateway: Gateway) -> None: + """Legacy read-side grace mirroring handle_jwt: the integration proxy runs with + LITELLM_FIPS_MODE unset, so an OKP/Ed25519-only IdP still verifies instead of 401ing.""" + jwks_key, token = _eddsa_key_and_token() + with _idp_server([jwks_key]) as discovery_uri, _jwt_signer_guardrail(signer_gateway, discovery_uri): + with mcp_peer() as peer, signer_gateway.scenario() as scenario: + alias: Final = "jwksed" + uuid.uuid4().hex[:8] + identity: Final = register_mcp(scenario, peer, alias) + key: Final = scenario.key(object_permission={"mcp_servers": [identity]}) + name: Final = tool_names(signer_gateway, key, identity)["add"] + peer.drain() + response: Final = _call_with_bearer(signer_gateway, key, identity, name, {"a": 4, "b": 5}, token) + assert response.status_code == 200, response.text + assert response.json()["content"][0]["text"] == "9", response.text + assert len(tool_calls(peer.drain())) == 1, "accepted call never reached the peer" + + def test_jwks_rs256_key_still_verifies_the_incoming_token(signer_gateway: Gateway) -> None: jwks_key, token = _rs256_key_and_token() with _idp_server([jwks_key]) as discovery_uri, _jwt_signer_guardrail(signer_gateway, discovery_uri): diff --git a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py b/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py index b8a6d9bf4a2..a9040e5b160 100644 --- a/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py +++ b/tests/unit/proxy/_experimental/mcp_server/outbound_credentials/test_token_endpoint.py @@ -185,6 +185,37 @@ async def test_fetch_signs_eddsa_client_assertion_for_ed25519_key(): assert decoded["sub"] == _CLIENT_ID +@pytest.mark.asyncio +async def test_fetch_signs_hs256_client_assertion_for_stored_shared_secret(): + """Read-side grace for symmetric HS*: a pre-allowlist row with an HMAC secret in + client_private_key keeps producing a valid client_secret_jwt-style assertion.""" + secret = "integration-hs256-client-secret-0123456789abcdef" + client = _client(_resp()) + with patch(_PATCH_TARGET, return_value=client): + await TokenEndpointClient().fetch( + _ENDPOINT, + _CLIENT_ID, + {"grant_type": "g"}, + PrivateKeyJwtAuth( + private_key=SecretStr(secret), + key_id="sym-kid", + signing_alg="HS256", + ), + ) + + data = _posted_data(client) + assert data["client_assertion_type"] == CLIENT_ASSERTION_TYPE + assert jwt.get_unverified_header(data["client_assertion"])["alg"] == "HS256" + decoded = jwt.decode( + data["client_assertion"], + secret, + algorithms=["HS256"], + audience=_ENDPOINT, + ) + assert decoded["iss"] == _CLIENT_ID + assert decoded["sub"] == _CLIENT_ID + + @pytest.mark.asyncio async def test_fetch_http_error_maps_to_upstream_unavailable_with_status(): error_resp = MagicMock() diff --git a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py index c252aabe302..b22ecb9550e 100644 --- a/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py +++ b/tests/unit/proxy/_experimental/mcp_server/test_mcp_server_manager.py @@ -17819,16 +17819,38 @@ class TestSharedIdentifierPrefixWarning: assert "'shared'" in shared_warnings[0] -def test_stored_client_assertion_signing_alg_falls_back_to_rs256_for_non_approved(caplog): +def test_stored_client_assertion_signing_alg_falls_back_to_rs256_for_non_approved(monkeypatch, caplog): + """FIPS on (and for unrecognized garbage in any mode): the RS256 fallback with a warning — + a value nothing can sign stays refused rather than silently running.""" + monkeypatch.setenv("LITELLM_FIPS_MODE", "true") from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( _stored_client_assertion_signing_alg, ) with caplog.at_level(logging.WARNING, logger="LiteLLM"): assert _stored_client_assertion_signing_alg("HS256", "srv") == "RS256" + assert _stored_client_assertion_signing_alg("bogus", "srv") == "RS256" assert "client_assertion_signing_alg" in caplog.text and "HS256" in caplog.text and "srv" in caplog.text +def test_stored_client_assertion_signing_alg_keeps_hs256_outside_fips_mode(monkeypatch, caplog): + """FIPS off: a stored symmetric HS* value passes through verbatim. Pre-allowlist a stored + HS256 with a shared secret in client_private_key produced a working client_secret_jwt-style + assertion; coercing it to RS256 guarantees failure since an HMAC secret cannot sign RSA, so + read-side grace keeps it signing outside FIPS (write-side still refuses HS*).""" + monkeypatch.delenv("LITELLM_FIPS_MODE", raising=False) + from litellm.proxy._experimental.mcp_server.mcp_server_manager import ( + _stored_client_assertion_signing_alg, + ) + + with caplog.at_level(logging.WARNING, logger="LiteLLM"): + assert _stored_client_assertion_signing_alg("HS256", "srv") == "HS256" + assert "HS256" in caplog.text and "srv" in caplog.text + assert "rotate" in caplog.text.lower() + # Unrecognized garbage never gains grace in either mode. + assert _stored_client_assertion_signing_alg("bogus", "srv") == "RS256" + + def test_stored_client_assertion_signing_alg_warns_eddsa_key_cannot_sign_fallback(monkeypatch, caplog): """FIPS on: a stored EdDSA server keeps today's behavior — coerced to the RS256 fallback with the rotate-your-key warning, since its Ed25519 key cannot produce RS256, so the exchange fails @@ -17873,9 +17895,10 @@ def test_stored_client_assertion_signing_alg_passes_through_approved(caplog): def test_mcp_server_model_rejects_non_approved_client_assertion_signing_alg(): - """The runtime (read-side) model still refuses non-legacy garbage; the legacy EdDSA value is - admitted read-side (widened via LEGACY_JWT_ALGORITHMS) while the write-side request - validators in litellm.proxy._types stay strict and 422 it (see test__types.py).""" + """The runtime (read-side) model still refuses unrecognized garbage; the legacy EdDSA and + symmetric HS* values are admitted read-side (widened via StoredJwtAlgorithm, FIPS-gated in + mcp_server_manager._stored_client_assertion_signing_alg) while the write-side request + validators in litellm.proxy._types stay strict and 422 them (see test__types.py).""" from pydantic import ValidationError with pytest.raises(ValidationError) as exc: @@ -17883,17 +17906,18 @@ def test_mcp_server_model_rejects_non_approved_client_assertion_signing_alg(): server_id="srv", name="srv", transport="http", - client_assertion_signing_alg="HS256", + client_assertion_signing_alg="bogus", ) assert "client_assertion_signing_alg" in str(exc.value) - server = MCPServer( - server_id="srv", - name="srv", - transport="http", - client_assertion_signing_alg="EdDSA", - ) - assert server.client_assertion_signing_alg == "EdDSA" + for stored in ("EdDSA", "HS256"): + server = MCPServer( + server_id="srv", + name="srv", + transport="http", + client_assertion_signing_alg=stored, + ) + assert server.client_assertion_signing_alg == stored @pytest.mark.asyncio