Skip to content

fix: reject JWTs with out-of-bounds expiration values to prevent time.Time overflow [FaaFyfxR9WAQrL7FcAgEHJvztd8cVMxvjHRS55rw1nwH] - #5

Open
waterWang wants to merge 1 commit into
heathivorjocelyn6:mainfrom
waterWang:main
Open

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Added validation to reject JWTs with out-of-bounds expiration (exp), not-before (nbf), and issued-at (iat) values that could cause time.Time overflow or undefined behavior.

Changes

  • types.go: Added IsValidNumericDate() helper function with maxUnixTimestamp (253402300799 = year 9999) and minUnixTimestamp (0 = 1970) boundaries
  • validator.go: Added bounds checking in verifyExpiresAt(), verifyNotBefore(), and verifyIssuedAt() — returns ErrTokenInvalidClaims when a timestamp is out of bounds

Acceptance Criteria

  • ✅ JWT parser validates that exp, nbf, iat values can be safely converted to Go time.Time
  • ✅ Tokens with timestamps beyond year 9999 are rejected
  • ✅ Tokens with negative timestamps (pre-1970) are rejected
  • ✅ Tokens with extremely large values (1e20, max int64) are rejected
  • ✅ Returns specific ErrTokenInvalidClaims error for out-of-bounds timestamps
  • ✅ All existing 100+ tests pass

Fixes #1

….Time overflow

Added validation in the validator to check that exp, nbf, and iat claims
contain numeric values within safe bounds for conversion to Go time.Time.

- Added IsValidNumericDate() helper with maxUnixTimestamp (year 9999) and
  minUnixTimestamp (1970) constants
- verifyExpiresAt, verifyNotBefore, verifyIssuedAt now check for out-of-bounds
  timestamps and return ErrTokenInvalidClaims
- All existing tests continue to pass

Fixes heathivorjocelyn6#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🎯 Reject JWTs with Out-of-Bounds Expiration (exp) Values to Prevent time.Time Overflow

1 participant