Skip to content

Commit 8f3a2a8

Browse files
committed
Stop rejecting tokens with future 'iat' values
RFC 7519 does not specify or even suggest this type of validation on the 'iat' claim and it has caused issues for several consumers of PyJWT. This change removes the validation on future 'iat' values and leaves such things up to the application developer to implement. Fixes jpadilla#190.
1 parent ceff941 commit 8f3a2a8

File tree

4 files changed

+3
-15
lines changed

4 files changed

+3
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010
- Add support for ECDSA public keys in RFC 4253 (OpenSSH) format [#244][244]
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]
13+
- Tokens with future 'iat' values are no longer rejected [#190][190]
1314

1415
### Fixed
1516

@@ -129,5 +130,6 @@ rarely used. Users affected by this should upgrade to 3.3+.
129130
[174]: https://github.com/jpadilla/pyjwt/pull/174
130131
[182]: https://github.com/jpadilla/pyjwt/pull/182
131132
[183]: https://github.com/jpadilla/pyjwt/pull/183
133+
[190]: https://github.com/jpadilla/pyjwt/pull/190
132134
[213]: https://github.com/jpadilla/pyjwt/pull/214
133135
[244]: https://github.com/jpadilla/pyjwt/pull/244

docs/usage.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ 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 in the future, an `jwt.InvalidIssuedAtError` exception
184-
will be raised.
185-
186183
.. code-block:: python
187184
188185
jwt.encode({'iat': 1371720939}, 'secret')

jwt/api_jwt.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,10 @@ def _validate_required_claims(self, payload, options):
121121

122122
def _validate_iat(self, payload, now, leeway):
123123
try:
124-
iat = int(payload['iat'])
124+
int(payload['iat'])
125125
except ValueError:
126126
raise DecodeError('Issued At claim (iat) must be an integer.')
127127

128-
if iat > (now + leeway):
129-
raise InvalidIssuedAtError('Issued At claim (iat) cannot be in'
130-
' the future.')
131-
132128
def _validate_nbf(self, payload, now, leeway):
133129
try:
134130
nbf = int(payload['nbf'])

tests/test_api_jwt.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ def test_decode_raises_exception_if_nbf_is_not_int(self, jwt):
154154
with pytest.raises(DecodeError):
155155
jwt.decode(example_jwt, 'secret')
156156

157-
def test_decode_raises_exception_if_iat_in_the_future(self, jwt):
158-
now = datetime.utcnow()
159-
token = jwt.encode({'iat': now + timedelta(days=1)}, key='secret')
160-
161-
with pytest.raises(InvalidIssuedAtError):
162-
jwt.decode(token, 'secret')
163-
164157
def test_encode_datetime(self, jwt):
165158
secret = 'secret'
166159
current_datetime = datetime.utcnow()

0 commit comments

Comments
 (0)