fix(llm-auth): drop inherited OAuth token when base URL is the CP proxy #161
Reference in New Issue
Block a user
Delete Branch "fix/llm-auth-drop-oauth-on-cp-proxy"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root cause
Platform-agent concierges 401 on every LLM call: claude-code sends an inherited tenant
CLAUDE_CODE_OAUTH_TOKENto the CP LLM proxy (which auths via the per-workspace admin_token) -> 401.normalise_llm_envonly dropped the inherited OAuth token when the provider slug was a known non-Anthropic provider; a concierge whose provider resolved empty (rebuilt-from-DB payload) skipped that guard, so the OAuth short-circuit kept the foreign token.Fix
Add a second, independent, UN-GATED signal: when
ANTHROPIC_BASE_URLis the Molecule platform LLM proxy (path prefix/api/v1/internal/llm/, prefix-anchored + host-agnostic), an OAuth bearer can never authenticate there, so the inherited token is dropped BEFORE the OAuth short-circuit — independent of provider/model (that gating is what failed). The admin token + proxy base URL are preserved.Guards / tests (28 passed)
Paired with the core root fix: branch
fix/concierge-provider-empty-modelin molecule-core.🤖 Generated with Claude Code
Reviewed: _is_molecule_cp_proxy_base_url is prefix-anchored via urlparse (requires scheme+host, path.startswith /api/v1/internal/llm/), un-gated on provider/model, and the drop runs BEFORE the OAuth short-circuit (verified in source at the guard vs the short-circuit below). Helper test covers deeper-path, query-string, no-host, native-anthropic, minimax-proxy false-positives. Combined CI green. APPROVE.
Independent adversarial pass: ordering (drop before OAuth short-circuit) and path-match anchoring both hold in source. BYOK-OAuth-direct (api.anthropic.com) correctly untouched; the two drop signals are independently sufficient. One pre-existing follow-up: an OAuth token arriving via ANTHROPIC_AUTH_TOKEN under CP-proxy routing isn't covered (different failure mode, not introduced here). APPROVE.
APPROVED — genuine 5-axis review on current head
0941fac88d.Correctness: inherited CLAUDE_CODE_OAUTH_TOKEN is dropped before OAuth short-circuit when ANTHROPIC_BASE_URL is the slash-anchored CP LLM proxy path, independent of provider/model, which covers the empty-provider failure. Security/token precedence: preserves the per-workspace admin token and proxy base URL, does not log token values, and keeps the existing non-Anthropic provider drain guard. Regression risk: native Anthropic OAuth and direct BYOK OAuth remain untouched; proxy detection requires scheme+host and exact path prefix rather than substring. Tests cover CP-proxy empty provider, anthropic provider, native BYOK OAuth, and near-miss URL matching. Blast radius: auth env normalisation only.
APPROVED current-head incident review.
5-axis check: