fix(auth): measure Windows keychain limit in UTF-16 bytes and clear stale entry on fallback#12
Merged
Conversation
…tale entry on fallback
The Windows Credential Manager guard used UTF-8 str::len() against the
2560-byte limit, but keyring's windows-native backend stores the password
as UTF-16 and rejects values whose UTF-16 blob exceeds 2560 bytes. For
ASCII that is 2x too lenient: a token JSON of ~1281-2560 chars passed the
guard, reached the keychain, failed the write, and silently fell back to
file storage while leaving the old keychain entry in place. Reads are
keychain-first, so the stale entry shadowed the fresh file token and its
rotated refresh token was rejected on the next refresh ("Session expired
and token refresh failed").
- Measure the blob via credman_blob_bytes (UTF-16 bytes), matching keyring.
- Clear any stale keychain entry on every file-storage fallback so it can
never shadow the file token on read.
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
The Windows Credential Manager guard measured the token blob with UTF-8
str::len()against the 2560-byte limit, but keyring'swindows-nativebackend stores the password as a UTF-16 blob and rejects values whose UTF-16 byte length exceeds 2560. For ASCII that guard is 2× too lenient: a token JSON of ~1281–2560 chars passed the check, reached the keychain, failed the write, and silently fell back to file storage while leaving the old keychain entry in place.Reads are keychain-first, so the stale entry shadowed the fresh file token — its rotated refresh token was then sent on the next refresh and the server rejected it (
Session expired and token refresh failed). Windows-only; it surfaced as token JSONs grew past ~1280 chars.Fix
credman_blob_bytes(UTF-16 bytes), matching keyring's own check.Tests
credman_blob_bytesis twice the ASCII length.