Skip to content

fix: skip plaintext cache tokens with non-SSO scopes#941

Open
salimesmailjee wants to merge 1 commit into
fwdcloudsec:mainfrom
salimesmailjee:fix/plaintext-cache-scope-filtering
Open

fix: skip plaintext cache tokens with non-SSO scopes#941
salimesmailjee wants to merge 1 commit into
fwdcloudsec:mainfrom
salimesmailjee:fix/plaintext-cache-scope-filtering

Conversation

@salimesmailjee
Copy link
Copy Markdown

@salimesmailjee salimesmailjee commented May 14, 2026

What changed?

GetValidSSOTokenFromPlaintextCache now parses the scopes field of plaintext cache tokens and only accepts tokens that either have no scopes (backwards compatible) or include at least one sso:* 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 like codewhisperer:completions. GetValidSSOTokenFromPlaintextCache matched tokens by startUrl only, so it picked up this unrelated token, stored it to the keychain, and used it for GetRoleCredentials. AWS returned a 401 because the token lacks sso:account:access, and Granted did not fall through to the browser login flow.

How did you test it?

  • Had Amazon Q IDE extension authenticated (token in ~/.aws/sso/cache/ with only codewhisperer:* scopes)
  • Cleared keychain tokens (granted sso-tokens clear --all)
  • Ran assume <profile> — previously got 401, now correctly triggers browser login via device code flow
  • Confirmed successful credential retrieval after browser authentication

Potential 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

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
@salimesmailjee salimesmailjee force-pushed the fix/plaintext-cache-scope-filtering branch from a92ca0d to d380a00 Compare May 14, 2026 10:35
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.

assume fails with 401 when unrelated SSO token exists in plaintext cache

1 participant