Block HS* algorithms when JWTVerifier is configured with JWKS (#3419)

* Block HS* algorithms with JWKS in JWT verifier

🤖 Generated with GPT-5.2-Codex

* Fix ruff format: remove extra blank line in test_supabase.py

🤖 Generated with Claude Code

Co-authored-by: Jeremiah Lowin <jlowin@users.noreply.github.com>

---------

Co-authored-by: Marvin Context Protocol <41898282+Marvin Context Protocol@users.noreply.github.com>
Co-authored-by: Jeremiah Lowin <jlowin@users.noreply.github.com>
This commit is contained in:
Jeremiah Lowin 2026-03-07 11:41:04 -05:00 committed by GitHub
commit 901d8cdd60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 1 deletions

View file

@ -225,6 +225,12 @@ class JWTVerifier(TokenVerifier):
}:
raise ValueError(f"Unsupported algorithm: {algorithm}.")
if jwks_uri and algorithm.startswith("HS"):
raise ValueError(
"HMAC algorithms (HS256/HS384/HS512) require a shared secret via "
"public_key and cannot be used with jwks_uri"
)
# Parse scopes if provided as string
parsed_required_scopes = (
parse_scopes(required_scopes) if required_scopes is not None else None

View file

@ -93,7 +93,7 @@ class TestSupabaseProvider:
@pytest.mark.parametrize(
"algorithm",
["HS256", "RS256", "ES256"],
["RS256", "ES256"],
)
def test_algorithm_configuration(self, algorithm):
"""Test that algorithm can be configured for different JWT signing methods."""
@ -106,6 +106,15 @@ class TestSupabaseProvider:
assert isinstance(provider.token_verifier, JWTVerifier)
assert provider.token_verifier.algorithm == algorithm
def test_algorithm_hs256_rejected(self):
"""Test that HS256 is rejected with Supabase JWKS verification."""
with pytest.raises(ValueError, match="cannot be used with jwks_uri"):
SupabaseProvider(
project_url="https://abc123.supabase.co",
base_url="https://myserver.com",
algorithm="HS256",
)
def test_algorithm_default_es256(self):
"""Test that algorithm defaults to ES256 when not specified."""
provider = SupabaseProvider(

View file

@ -201,6 +201,15 @@ class TestSymmetricKeyJWT:
assert provider.algorithm == "HS256"
assert provider.jwks_uri is None
def test_initialization_rejects_hs_algorithm_with_jwks_uri(self):
"""Test that HMAC algorithms cannot be used with JWKS URI."""
with pytest.raises(ValueError, match="cannot be used with jwks_uri"):
JWTVerifier(
jwks_uri="https://test.example.com/.well-known/jwks.json",
issuer="https://test.example.com",
algorithm="HS256",
)
def test_initialization_with_different_symmetric_algorithms(
self, symmetric_key_helper: SymmetricKeyHelper
):