Skip to content

fix: reject tokens that are not yet valid and avoid reusing near-expiry cached tokens - #149

Merged
kishore7snehil merged 2 commits into
mainfrom
fix/nbf-check-and-cache-expiry-buffer
Oct 23, 2026
Merged

kishore7snehil merged 2 commits into
mainfrom
fix/nbf-check-and-cache-expiry-buffer

Conversation

@kishore7snehil

@kishore7snehil kishore7snehil commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

📋 Changes

This PR makes verify_access_token() reject tokens that are not valid yet, and stops the token caches from handing back a token that is about to expire.

🐛 Bug Fixes

  • nbf Check: verify_access_token() rejects a token whose nbf claim is in the future. A token without nbf is still accepted, and a non-numeric nbf raises VerifyAccessTokenError.
  • Expiry Buffer: A cached token is reused only while it has more than 30 seconds left. Otherwise a fresh exchange runs, so a cached token is unlikely to expire before the caller uses it. A token issued with an expires_in of 30 seconds or less is never served from the cache. This applies to On Behalf Of, client credentials and Token Vault tokens, including the scope-matching index.

🔧 API Changes

  • verify_access_token() now raises VerifyAccessTokenError with the message "Token is not yet valid" when nbf is in the future. It previously accepted such a token.
  • A cached entry with 30 seconds or less before expiry is now a cache miss. It was previously reused until the moment it expired.

📖 Documentation

  • Added a note on the 30 second reuse window to docs/TokenStorage.md

🧪 Testing

  • This change adds test coverage
  • This change has been tested on the latest version of the platform/language

Contributor Checklist

@kishore7snehil
kishore7snehil requested a review from a team as a code owner October 23, 2026 05:48
Comment thread tests/test_api_client.py Resolved
Comment thread tests/test_api_client.py Resolved
Comment thread src/auth0_api_python/api_client.py Resolved
Comment thread docs/TokenStorage.md Resolved
Adds tests for the exact 30 second buffer and the nbf equal and fractional cases. Lists nbf in the verify_access_token docstring and notes that tokens with expires_in of 30 or less are never served from the cache.
@kishore7snehil
kishore7snehil merged commit 3370899 into main Oct 23, 2026
7 checks passed
@kishore7snehil
kishore7snehil deleted the fix/nbf-check-and-cache-expiry-buffer branch October 23, 2026 12:10
@kishore7snehil kishore7snehil mentioned this pull request Nov 11, 2026
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.

2 participants