Skip to content

Commit 3447f0c

Browse files
committed
Non-numeric 'iat' now raises InvalidIssuedAtError on decode()
1 parent 8f3a2a8 commit 3447f0c

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
- Renamed commandline script `jwt` to `jwt-cli` to avoid issues with the script clobbering the `jwt` module in some circumstances.
1212
- Better error messages when using an algorithm that requires the cryptography package, but it isn't available [#230][230]
1313
- Tokens with future 'iat' values are no longer rejected [#190][190]
14+
- Non-numeric 'iat' values now raise InvalidIssuedAtError instead of DecodeError
15+
1416

1517
### Fixed
1618

docs/usage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ Issued At Claim (iat)
180180
This claim can be used to determine the age of the JWT. Its value MUST be a
181181
number containing a NumericDate value. Use of this claim is OPTIONAL.
182182

183+
If the `iat` claim is not a number, an `jwt.InvalidIssuedAtError` exception will be raised.
184+
183185
.. code-block:: python
184186
185187
jwt.encode({'iat': 1371720939}, 'secret')

jwt/api_jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _validate_iat(self, payload, now, leeway):
123123
try:
124124
int(payload['iat'])
125125
except ValueError:
126-
raise DecodeError('Issued At claim (iat) must be an integer.')
126+
raise InvalidIssuedAtError('Issued At claim (iat) must be an integer.')
127127

128128
def _validate_nbf(self, payload, now, leeway):
129129
try:

tests/test_api_jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def test_decode_raises_exception_if_iat_is_not_int(self, jwt):
142142
'eyJpYXQiOiJub3QtYW4taW50In0.'
143143
'H1GmcQgSySa5LOKYbzGm--b1OmRbHFkyk8pq811FzZM')
144144

145-
with pytest.raises(DecodeError):
145+
with pytest.raises(InvalidIssuedAtError):
146146
jwt.decode(example_jwt, 'secret')
147147

148148
def test_decode_raises_exception_if_nbf_is_not_int(self, jwt):

0 commit comments

Comments
 (0)