Repository navigation
fix(config): reject a non-numeric exp or nbf in default claims - #458
Open
agustin2606 wants to merge 1 commit into
Open
agustin2606 wants to merge 1 commit into
agustin2606 wants to merge 1 commit into
Conversation
The default exp validation was `&1 > current_time()`. Under Erlang term ordering every non-number compares greater than a number, so a token whose exp is a string, or null (decoded by JOSE as :null), never expired. Guard both exp and nbf with is_number/1. RFC 7519 defines them as a NumericDate, which may be non-integer, so floats are still accepted. Fixes joken-elixir#452
mattmikolay
approved these changes
Nov 4, 2026
mattmikolay
left a comment
Contributor
There was a problem hiding this comment.
Looks great! Thanks for implementing this fix. It would be great if this can ship soon.
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.
Fixes #452
@mattmikolay offered to send a PR for this; picking it up since it's been a month without one. Happy to defer if you had something in progress.
The default
expvalidation was&(&1 > current_time()). Under Erlang term ordering any non-number compares greater than a number, so a token whoseexpis a string never expired. The same happens with"exp": null: JOSE decodes JSONnullas the atom:null, which also sorts above every number.This PR:
expandnbfvalidations withis_number/1, through two private predicates (valid_exp?/1,valid_nbf?/1). RFC 7519 defines both as a NumericDate, which may be non-integer, so floats are still accepted.nbfthe same way. It already rejected non-numbers, but only becausecurrent_time() >= "string"happens to befalse; the guard makes that explicit.expandnbfreject every non-numeric shape a decoded claim can take (string, boolean,nil,:null, list, map), and a test that a floatexpis honoured.[Unreleased]CHANGELOG entry.With the snippet from the issue,
"pizza time"andnullnow return{:error, [message: "Invalid token", claim: "exp", ...]}, and a valid numericexpstill passes.mix test,mix format --check-formatted,mix credo --strictandmix compile --warnings-as-errorspass locally (Elixir 1.20.4 / OTP 29). I didn't run dialyzer.