Repository navigation
auth, envsec: don't panic on missing or unparseable ID tokens - #615
Merged
Merged
Conversation
Fixes bug-scan P0 #4 and #5 from specs/bug-scan.md. - #4: pkg/auth refresh used an unchecked `Extra("id_token").(string)` assertion. Many OIDC providers omit id_token from refresh responses, so every CLI using pkg/auth panicked when the access token expired. Use a comma-ok assertion and keep the existing ID token when the refresh response doesn't include one. Same fix in session.getRawIDToken. - #5: IDClaims() returns nil when the ID token is empty or can't be parsed. Nil-check it in pkg/auth (LoginFlowIfNeededForOrg, whoami) and in envsec (ls/flags, init, whoami, init flow) via a new internal/claims helper that returns an actionable "please log in again" error. The tokenstore call sites were already fixed in #603. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
Adds the status as its own line under the matching "Suggested fix order" item so it doesn't conflict with the other P0 fix PRs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bqy92pq662Fgv5A4GoaUD2
[Medium impact] The PR appears safe to merge; no new actionable issues were found.
|
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.
Summary
Fixes P0 bugs #4 and #5 from
specs/bug-scan.md.pkg/auth/auth.go):refreshdidnewToken.Extra("id_token").(string)without checking the type. Many OIDC providers leaveid_tokenout of refresh responses, so every CLI usingpkg/auth(including envsec) panicked once the access token expired. The assertion is now comma-ok, and when the refresh response has noid_tokenthe existing one is kept, as OIDC intends.session.getRawIDTokenhad the same unchecked assertion and gets the same fix.IDClaims()dereferences:IDClaims()returns nil for an empty or unparseable ID token.pkg/auth: added nil checks inLoginFlowIfNeededForOrgand thewhoamicommand.internal/claims.FromToken, which returns an actionable "please log in again" error instead of nil. It is used inenvcli/flags.go,envsec/init.go,envsec/auth.go(whoami) andinternal/flow/init.go.How was it tested?
pkg/auth/auth_test.gorunsrefreshagainst anhttptestOIDC issuer:id_token, the call succeeds and keeps the old ID token. On main, this test panics withinterface conversion: interface {} is nil, not string.id_token, it replaces the old one.envsec/internal/claims/claims_test.gocovers a nil token, an empty ID token and an unparseable ID token.go vetandgo testpass forpkg/auth/...and all ofenvsec.Community Contribution License
All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.
By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.
Generated by Claude Code