auth: add ClockSkew option to RequireBearerTokenOptions#969
Open
BorisTyshkevich wants to merge 1 commit into
Open
auth: add ClockSkew option to RequireBearerTokenOptions#969BorisTyshkevich wants to merge 1 commit into
BorisTyshkevich wants to merge 1 commit into
Conversation
Resource servers running behind a CDN, in distributed deployments, or communicating with an authorization server whose clock drifts a few seconds need a small positive tolerance when checking token expiration. The default zero value preserves the existing strict comparison. Adds a ClockSkew time.Duration field to RequireBearerTokenOptions plus a TestRequireBearerToken_ClockSkew test covering the four meaningful combinations (fresh accept, strict-expired reject, within-skew accept, beyond-skew reject). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 tasks
Comment on lines
+149
to
+153
| skew := time.Duration(0) | ||
| if opts != nil { | ||
| skew = opts.ClockSkew | ||
| } | ||
| if tokenInfo.Expiration.Add(skew).Before(time.Now()) { |
Contributor
There was a problem hiding this comment.
Suggested change
| skew := time.Duration(0) | |
| if opts != nil { | |
| skew = opts.ClockSkew | |
| } | |
| if tokenInfo.Expiration.Add(skew).Before(time.Now()) { | |
| if opts == nil { | |
| opts = &RequireBearerTokenOptions{} | |
| } | |
| if tokenInfo.Expiration.Add(opts.ClockSkew).Before(time.Now()) { |
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.
Summary
Motivation
Real-world resource servers running behind a CDN, in distributed deployments, or talking to an authorization server whose clock drifts a few seconds (common with cloud-managed IdPs) need a small positive tolerance when checking token expiration. Strict-equality comparison rejects tokens that are valid by the issuer's clock but momentarily appear expired by the verifier's. The reverse case — an issuer's clock running slightly fast at /token issuance — also reaches the verifier as a token whose `exp` lies microseconds in the past.
Test plan