Skip to content

Commit 63cda82

Browse files
committed
Merge pull request jpadilla#171 from alexm92/master
Fixed jpadilla#167 throw InvalidAlgorithmError if alg not in header
2 parents 151c84e + d985200 commit 63cda82

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

jwt/api_jws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def _load(self, jwt):
165165
def _verify_signature(self, payload, signing_input, header, signature,
166166
key='', algorithms=None):
167167

168-
alg = header['alg']
168+
alg = header.get('alg')
169169

170170
if algorithms is not None and alg not in algorithms:
171171
raise InvalidAlgorithmError('The specified alg value is not allowed')

tests/test_api_jws.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ def test_verify_signature_with_no_secret(self, jws, payload):
270270

271271
assert 'Signature verification' in str(exc.value)
272272

273+
def test_verify_signature_with_no_algo_header_throws_exception(self, jws, payload):
274+
example_jws = (
275+
b'e30'
276+
b'.eyJhIjo1fQ'
277+
b'.KEh186CjVw_Q8FadjJcaVnE7hO5Z9nHBbU8TgbhHcBY'
278+
)
279+
280+
with pytest.raises(InvalidAlgorithmError):
281+
jws.decode(example_jws, 'secret')
282+
273283
def test_invalid_crypto_alg(self, jws, payload):
274284
with pytest.raises(NotImplementedError):
275285
jws.encode(payload, 'secret', algorithm='HS1024')

0 commit comments

Comments
 (0)