Skip to content

auth, envsec: don't panic on missing or unparseable ID tokens - #615

Merged
mikeland73 merged 2 commits into
mainfrom
claude/admiring-hamilton-rpyrh3-auth
Nov 11, 2026
Merged

mikeland73 merged 2 commits into
mainfrom
claude/admiring-hamilton-rpyrh3-auth

Conversation

@mikeland73

Copy link
Copy Markdown
Contributor

Summary

Fixes P0 bugs #4 and #5 from specs/bug-scan.md.

  • [nixtest] Add related work section to README #4 – token refresh panic (pkg/auth/auth.go): refresh did newToken.Extra("id_token").(string) without checking the type. Many OIDC providers leave id_token out of refresh responses, so every CLI using pkg/auth (including envsec) panicked once the access token expired. The assertion is now comma-ok, and when the refresh response has no id_token the existing one is kept, as OIDC intends. session.getRawIDToken had the same unchecked assertion and gets the same fix.
  • Add workflow using Copybara to publish nixtest #5 – nil IDClaims() dereferences: IDClaims() returns nil for an empty or unparseable ID token.
    • pkg/auth: added nil checks in LoginFlowIfNeededForOrg and the whoami command.
    • envsec: added internal/claims.FromToken, which returns an actionable "please log in again" error instead of nil. It is used in envcli/flags.go, envsec/init.go, envsec/auth.go (whoami) and internal/flow/init.go.
    • The tokenstore call sites listed in the scan were already fixed on main in auth/tokenstore: don't panic on tokens without ID claims #603.

How was it tested?

  • New pkg/auth/auth_test.go runs refresh against an httptest OIDC issuer:
    • When the refresh response has no id_token, the call succeeds and keeps the old ID token. On main, this test panics with interface conversion: interface {} is nil, not string.
    • When the response has an id_token, it replaces the old one.
  • New envsec/internal/claims/claims_test.go covers a nil token, an empty ID token and an unparseable ID token.
  • go vet and go test pass for pkg/auth/... and all of envsec.

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

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
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR prevents auth panics when ID tokens are missing or cannot be parsed.

  • Token refresh keeps the session's ID token when a provider leaves it out.
  • Commands handle missing ID claims without crashing.

Reviews (2) · Last reviewed commit: "specs/bug-scan: mark P0 #4, #5 as fixed" · Reviewed by Greptile

@mikeland73
mikeland73 merged commit db91909 into main Nov 11, 2026
10 checks passed
@mikeland73
mikeland73 deleted the claude/admiring-hamilton-rpyrh3-auth branch November 11, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants