fix: skip plaintext cache tokens with non-SSO scopes#941
Open
salimesmailjee wants to merge 1 commit into
Open
Conversation
GetValidSSOTokenFromPlaintextCache matched tokens by startUrl only, causing it to pick up IDE extension tokens (e.g. codewhisperer:* scopes) that lack sso:account:access. This resulted in a 401 UnauthorizedException with no fallback to the browser login flow. Add scope filtering to skip tokens that contain only non-SSO scopes. Fixes fwdcloudsec#940
a92ca0d to
d380a00
Compare
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.
What changed?
GetValidSSOTokenFromPlaintextCachenow parses thescopesfield of plaintext cache tokens and only accepts tokens that either have no scopes (backwards compatible) or include at least onesso:*scope.Why?
When an IDE extension (e.g. AWS Toolkit / Amazon Q for VS Code) is authenticated against the same SSO start URL, it writes a token to
~/.aws/sso/cache/with scopes likecodewhisperer:completions.GetValidSSOTokenFromPlaintextCachematched tokens bystartUrlonly, so it picked up this unrelated token, stored it to the keychain, and used it forGetRoleCredentials. AWS returned a 401 because the token lackssso:account:access, and Granted did not fall through to the browser login flow.How did you test it?
~/.aws/sso/cache/with onlycodewhisperer:*scopes)granted sso-tokens clear --all)assume <profile>— previously got 401, now correctly triggers browser login via device code flowPotential risks
Low. Tokens with no scopes field are still accepted (backwards compatible). Only tokens that explicitly declare scopes and lack any
sso:*scope are skipped. This covers any current or future non-SSO tools writing tokens to the shared cache.Is patch release candidate?
Yes — this is a bugfix for a broken login flow that affects anyone using Granted alongside AWS IDE extensions.
Link to relevant issues
Fixes #940
Co-authored-by: Amazon Q