Skip to content

[#1] Add JWT claims validation with overflow-safe timestamp bounds - #9

Open
lincai505011-ops wants to merge 1 commit into
heathivorjocelyn6:mainfrom
lincai505011-ops:bounty-1
Open

[#1] Add JWT claims validation with overflow-safe timestamp bounds#9
lincai505011-ops wants to merge 1 commit into
heathivorjocelyn6:mainfrom
lincai505011-ops:bounty-1

Conversation

@lincai505011-ops

Copy link
Copy Markdown

/claim #1

What

Implement a JWT claims validation library with safe timestamp bounds checking to prevent time.Time overflow, as specified in the acceptance criteria.

Changes

  • jwt/claims.go: Core library with:

    • ParseClaims() — extracts registered claims from raw JWT token
    • ValidateTimestamps() — checks exp/nbf/iat fall within safe Unix range (year 1 to year 9999)
    • Validate() — full validation including expiry and not-before checks with configurable leeway
    • Rejects NaN, Inf, negative overflow, and values beyond MaxUnixTime
    • Specific error types: ErrInvalidEpoch, ErrMalformedClaims, ErrExpired, ErrNotYetValid
  • jwt/claims_test.go: 13 test cases covering:

    • MaxInt64 overflow → rejected
    • Large float (1e21) → rejected
    • Extreme negative → rejected
    • NaN and ±Inf → rejected
    • Valid future date (year 2050) → accepted
    • MaxUnixTime boundary → accepted
    • MinUnixTime boundary → accepted
    • Expired token → rejected with ErrExpired
    • Not-yet-valid token → rejected with ErrNotYetValid
    • Leeway (30s expired, 60s leeway → accepted)
    • All three claims overflow → rejected
    • Zero/unset claims → skipped
    • Full round-trip test

Test Output

=== RUN   TestParseClaims --- PASS
=== RUN   TestParseClaims_Invalid --- PASS
=== RUN   TestValidateTimestamps_Overflow --- PASS
=== RUN   TestValidateTimestamps_LargeFloat --- PASS
=== RUN   TestValidateTimestamps_Negative --- PASS
=== RUN   TestValidateTimestamps_NaN --- PASS
=== RUN   TestValidateTimestamps_Inf --- PASS
=== RUN   TestValidateTimestamps_Valid --- PASS
=== RUN   TestValidate_Expired --- PASS
=== RUN   TestValidate_NotYetValid --- PASS
=== RUN   TestValidate_Leeway --- PASS
=== RUN   TestValidateTimestamps_AllClaimTypes --- PASS
=== RUN   TestValidateTimestamps_Zero --- PASS
=== RUN   TestRoundTrip --- PASS
PASS
ok  	github.com/heathivorjocelyn6/jwt/jwt	0.041s

…mestamp bounds

Signed-off-by: lincai505011-ops <lincai505011@users.noreply.github.com>
@opirebot

opirebot Bot commented Aug 7, 2026

Copy link
Copy Markdown

😅 Unfortunately there are no rewards left to claim in this issue!

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.

1 participant