Skip to content

Commit a7fb714

Browse files
author
Michael Davis
committed
Merge pull request #20 from 0x64746b/feature/catch-jws-errors-in-jwt-decode
Catch `JWSError`s in `jwt.decode()`
2 parents b4b871f + 52def77 commit a7fb714

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

jose/jwt.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from jose import jws
1212

13+
from .exceptions import JWSError
1314
from .exceptions import JWTClaimsError
1415
from .exceptions import JWTError
1516
from .exceptions import ExpiredSignatureError
@@ -112,12 +113,14 @@ def decode(token, key, algorithms=None, options=None, audience=None, issuer=None
112113
defaults.update(options)
113114

114115
verify_signature = defaults.get('verify_signature', True)
115-
payload = jws.verify(token, key, algorithms, verify=verify_signature)
116+
117+
try:
118+
payload = jws.verify(token, key, algorithms, verify=verify_signature)
119+
except JWSError as e:
120+
raise JWTError(e)
116121

117122
try:
118123
claims = json.loads(payload.decode('utf-8'))
119-
except (TypeError, binascii.Error):
120-
raise JWTError('Invalid payload padding')
121124
except ValueError as e:
122125
raise JWTError('Invalid payload string: %s' % e)
123126

0 commit comments

Comments
 (0)