fix: prevent and recover from JWT token corruption in keyring storage#1358
Merged
ramya18101 merged 5 commits intoOct 16, 2025
Merged
Conversation
kushalshit27
approved these changes
Oct 15, 2025
There was a problem hiding this comment.
Pull Request Overview
This PR fixes JWT token corruption issues in keyring storage by implementing prevention and recovery mechanisms. The corruption was caused by old token chunks not being cleared before storing new ones, leading to contaminated token reconstruction and cryptic authentication errors.
Key changes:
- Added chunk clearing logic in
StoreAccessToken()to prevent token contamination - Implemented JWT validation with proper error handling and user-friendly messages
- Enhanced authentication flow with token validation before API client initialization
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/keyring/keyring.go | Added token validation, chunk clearing logic, and JWT parsing functionality |
| internal/cli/management.go | Enhanced management client initialization with token validation and styled error messages |
| internal/cli/cli.go | Updated to use new token validation during authentication setup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
kushalshit27
previously approved these changes
Oct 15, 2025
duedares-rvj
previously approved these changes
Oct 16, 2025
kushalshit27
approved these changes
Oct 16, 2025
This was referenced May 19, 2026
Closed
bkiran6398
pushed a commit
to sparkling/auth0-cli
that referenced
this pull request
May 21, 2026
… client secret StoreAccessToken's "clear existing chunks" loop deleted the secretClientSecret key on every iteration instead of the indexed secretAccessToken chunks. Two consequences: 1. Stale access-token chunks were never cleared, so re-storing a shorter token left trailing chunks that concatenated into a malformed JWT, surfacing as "authentication token is corrupted". 2. The client secret was deleted immediately after a machine login stored it, so RegenerateAccessToken could no longer refresh the token and client-credentials sessions broke at the first expiry. Delete the indexed access-token chunks (matching DeleteSecretsForTenant and the store/get loops) and leave the client secret untouched. Adds regression tests covering both failure modes. Introduced in auth0#1358.
ramya18101
added a commit
that referenced
this pull request
May 21, 2026
… client secret (#1527) StoreAccessToken's "clear existing chunks" loop deleted the secretClientSecret key on every iteration instead of the indexed secretAccessToken chunks. Two consequences: 1. Stale access-token chunks were never cleared, so re-storing a shorter token left trailing chunks that concatenated into a malformed JWT, surfacing as "authentication token is corrupted". 2. The client secret was deleted immediately after a machine login stored it, so RegenerateAccessToken could no longer refresh the token and client-credentials sessions broke at the first expiry. Delete the indexed access-token chunks (matching DeleteSecretsForTenant and the store/get loops) and leave the client secret untouched. Adds regression tests covering both failure modes. Introduced in #1358. Co-authored-by: Ramya Anusri <62586490+ramya18101@users.noreply.github.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.
🔧 Changes
Problem: JWT access tokens stored in keyring chunks were getting corrupted, causing cryptic authentication failures like "invalid character 'e' looking for beginning of object value". This happened because old token chunks weren't cleared before storing new ones, leading to contaminated token reconstruction.
Solution:
Methods Changed:
StoreAccessToken()- Now clears old chunks before storing new tokensValidateAccessToken()- New method for JWT validation using proper parsinginitializeManagementClientWithTokenValidation()- Enhanced error handling with styled messages📚 References
Also highlighted this issue in one of the older ESD and product-queries
🔬 Testing
Manual Testing:
📝 Checklist