Skip to content

Commit b9bb2b2

Browse files
committed
fix(oidc): fail close at validating c_hash and at_hash
1 parent 1b0a1d9 commit b9bb2b2

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

authlib/oidc/core/claims.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,6 @@ def get_claim_cls_by_response_type(response_type):
303303

304304
def _verify_hash(signature, s, alg):
305305
hash_value = create_half_hash(s, alg)
306-
if not hash_value:
307-
return True
306+
if hash_value is None:
307+
return False
308308
return hmac.compare_digest(hash_value, to_bytes(signature))

tests/core/test_oidc/test_core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ def test_validate_at_hash():
9999
)
100100
claims.params = {"access_token": "a"}
101101

102-
# invalid alg won't raise
102+
# invalid alg will raise too
103103
claims.header = {"alg": "HS222"}
104-
claims.validate(1000)
104+
with pytest.raises(InvalidClaimError):
105+
claims.validate(1000)
105106

106107
claims.header = {"alg": "HS256"}
107108
with pytest.raises(InvalidClaimError):
@@ -143,10 +144,11 @@ def test_hybrid_id_token():
143144
with pytest.raises(MissingClaimError):
144145
claims.validate(1000)
145146

146-
# invalid alg won't raise
147+
# invalid alg will raise too
147148
claims.header = {"alg": "HS222"}
148149
claims["c_hash"] = "a"
149-
claims.validate(1000)
150+
with pytest.raises(InvalidClaimError):
151+
claims.validate(1000)
150152

151153
claims.header = {"alg": "HS256"}
152154
with pytest.raises(InvalidClaimError):

0 commit comments

Comments
 (0)