Evaluate token lifetimes against the current time by default - #222
Open
djw8605 wants to merge 1 commit into
Open
Evaluate token lifetimes against the current time by default#222djw8605 wants to merge 1 commit into
djw8605 wants to merge 1 commit into
Conversation
Validator captured std::chrono::system_clock::now() at construction and used that frozen instant (via FixedClock) to evaluate exp/nbf for every subsequent verification. Validators and Enforcers are commonly constructed once and used for the lifetime of a server process, so unless the caller remembered to call validator_set_time / enforcer_set_time before every use, a long-lived Enforcer would accept tokens that expired hours or days earlier (and reject fresh tokens issued after the enforcer was created, due to nbf). Sample the clock at each verification instead, unless the caller explicitly pinned it with set_now() -- the 'validate as of some past time' feature is preserved. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
Validatorcapturesstd::chrono::system_clock::now()at construction and uses that frozen instant (viaFixedClock) to evaluateexp/nbfon every subsequent verification.Validators and Enforcers are commonly constructed once and reused for the lifetime of a server process. Unless the caller remembers to call
validator_set_time/enforcer_set_timebefore every use, a long-livedEnforcer:nbfis after the enforcer was created.The first is a security issue: token expiration is the primary revocation mechanism in this ecosystem.
Fix
Sample the clock at each verification unless the caller explicitly pinned it with
set_now()(tracked by a newm_now_setflag). The documented "validate as if at some time in the past" feature (validator_set_time/enforcer_set_time) is fully preserved — the existingExplicitTimetest covers it.Behavior change
Callers who relied on the frozen construction-time clock (without calling
set_time) will now see expired tokens correctly rejected. That is the safer default; flagging it here explicitly since it is technically observable.Testing
ctestunit, env_config, and monitoring suites pass, includingSerializeTest.ExplicitTime(pinned-clock path) and the expired-token rejection tests.🤖 Generated with Claude Code