Repository navigation
Conversation
RFC 7519 section 4.1.5 requires the current time to be after or equal to the nbf claim. The request-time check used a strict comparison, so a valid token whose nbf equalled the current second plus the consumer's lifetime_grace_period was rejected with 401.
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.
Description
jwt-authrejects an otherwise valid token at its not-before instant. RFC 7519 §4.1.5 requires the current time to be after or equal tonbf, but the request-time check uses a strict comparison:So when
nbfequals the current second plus the consumer'slifetime_grace_period, the request gets 401. Issuers commonly setnbfto the issue time, so a client that uses a fresh token within the same second sees an intermittent 401 that goes away on retry.This is a regression from #12944. Before it, the check was done by lua-resty-jwt's
is_not_beforevalidator, which is inclusive (nbf <= ngx.now() + leeway). The rewritten parser also switched to the integerngx.time(), so the strict comparison rejects the token for that whole second. With<=the result matches the previous behavior for integernbfvalues.The
expcheck (exp > now - leeway) is left unchanged: RFC 7519 §4.1.4 requires the current time to be beforeexp.The new test signs the token in the same rewrite phase that verifies it, so both use nginx's cached time and the equality boundary is hit deterministically. It checks before/at/after the boundary with the default leeway and with
lifetime_grace_period: 2. Without the fix, the two "at the boundary" requests return 401.Which issue(s) this PR fixes:
N/A
Checklist