Reject out-of-range exp/nbf/iat NumericDate claim values - #1191
Open
pctablet505 wants to merge 3 commits into
Open
pctablet505 wants to merge 3 commits into
pctablet505 wants to merge 3 commits into
Conversation
RFC 7519 defines exp, nbf, and iat as NumericDate values representing an actual UTC date/time. Python's arbitrary-precision integers let a claim like 10**50 pass the plain integer comparisons in _validate_exp, _validate_nbf, and _validate_iat, even though the value can't represent a real date. Applications that reasonably convert an accepted claim with datetime.fromtimestamp() then hit an uncaught OverflowError. Add a bound matching the range datetime can represent (up to year 9999) and reject claims outside it with the existing DecodeError / InvalidIssuedAtError types, consistent with how these validators already report other malformed values. Fixes jpadilla#1171
A claim serialized as float infinity (e.g. jwt.encode({"exp": float("inf")}))
round-trips through JSON and reaches int(payload[...]) in
_validate_exp/_validate_nbf/_validate_iat, where int(float("inf")) raises an
uncaught OverflowError instead of a JWT exception. Catch OverflowError
alongside the existing ValueError handling and reject with the same
out-of-range DecodeError / InvalidIssuedAtError used for oversized integer
values.
Refs jpadilla#1171
pctablet505
marked this pull request as ready for review
July 24, 2026 16:44
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
exp,nbf, andiatare validated with a plainint(payload[claim])comparison. Python integers are arbitrary precision, so a claim like10**50sails through the comparison even though it can't represent a real date:RFC 7519 defines these claims as NumericDate values — seconds since the epoch representing an actual date/time. A value like this doesn't represent one, and code that reasonably converts the accepted claim with
datetime.fromtimestamp()hits an uncaughtOverflowError.Fix
Add a bound matching the range
datetimecan represent (up to year 9999, i.e.253402300799) and rejectexp/nbf/iatvalues outside it with the same exception types these validators already raise for other malformed values (DecodeErrorforexp/nbf,InvalidIssuedAtErrorforiat). No behavior changes for any value in the range real tokens use.Closes #1171.
Testing
Full suite passes locally (378 tests incl. 9 new, 0 skipped with
cryptographyinstalled):pytest tests/.ruff check,ruff format --check, andmypy jwt/api_jwt.pyare clean.