Skip to content

Commit e73045d

Browse files
committed
Allow algorithm names to be upper- or lower-case
The standard doesn't seem to specify whether algorithm names must be capitalized or lower-case. I had an issue with spurious failures due to a lower-case algorithm name ("hs256"), so here is a patch that converts the incoming name to capital letters before looking it up in the algorithm dictionary.
1 parent 0ee3ee5 commit e73045d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

jwt/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,14 @@ def load(jwt):
220220
def verify_signature(payload, signing_input, header, signature, key='',
221221
verify_expiration=True, leeway=0):
222222
try:
223-
key = prepare_key_methods[header['alg']](key)
224-
if header['alg'].startswith('HS'):
225-
expected = verify_methods[header['alg']](signing_input, key)
223+
algorithm = header['alg'].upper()
224+
key = prepare_key_methods[algorithm](key)
225+
if algorithm.startswith('HS'):
226+
expected = verify_methods[algorithm](signing_input, key)
226227
if not constant_time_compare(signature, expected):
227228
raise DecodeError("Signature verification failed")
228229
else:
229-
if not verify_methods[header['alg']](signing_input, key, signature):
230+
if not verify_methods[algorithm](signing_input, key, signature):
230231
raise DecodeError("Signature verification failed")
231232
except KeyError:
232233
raise DecodeError("Algorithm not supported")

0 commit comments

Comments
 (0)