fix(aws): stop ambient bearer credentials leaking under skip_auth - #1887
Open
latent-9 wants to merge 1 commit into
Open
fix(aws): stop ambient bearer credentials leaking under skip_auth#1887latent-9 wants to merge 1 commit into
latent-9 wants to merge 1 commit into
Conversation
AnthropicAWS passes auth_token=None to the parent constructor, which then falls back to ANTHROPIC_AUTH_TOKEN from the environment. With skip_auth=True the subclass suppressed its own SigV4 and x-api-key layers, but the parent's env fallback still installed a Bearer token, so requests carried an Authorization header that skip_auth promises will not exist, and the ambient credential leaked to whatever base URL the client targets. Add a _bearer_auth override symmetric with the existing _api_key_auth override: return no header while _skip_auth is set. test_skip_auth_no_auth_headers covers this; it only fails on machines where ANTHROPIC_AUTH_TOKEN is exported (for example Claude Code sessions), which is why CI never caught it.
Author
|
@RobertCraigie sorry to tag directly, but this one seems worth a look sooner rather than later: with Reproduction on main with the existing test, no code changes needed: Same command with this branch: The subclass already suppresses its own SigV4 and x-api-key layers under skip_auth; this adds the symmetric |
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
AnthropicAWSandAsyncAnthropicAWSsuppress their own SigV4 andx-api-keylayers whenskip_auth=True, but the parent constructor's environment fallback forANTHROPIC_AUTH_TOKENstill installed a BearerAuthorizationheader.Why
The subclass passes
auth_token=Noneup to the base constructor, which treats that as "no explicit credential" and falls back toANTHROPIC_AUTH_TOKEN/ANTHROPIC_API_KEYfrom the environment. A client created withskip_auth=Truetherefore sendsAuthorization: Bearer <ambient token>to whatever base URL it targets, which is both a credential leak to a non-AWS host and the exact opposite of whatskip_authpromises.CI never catches this because the test suite runs without those environment variables set; the existing regression test fails deterministically on any machine where they are exported (for example Claude Code sessions).
Change
Add a
_bearer_authoverride symmetric with the existing_api_key_authoverride: return no header while_skip_authis set.test_skip_auth_no_auth_headerscovers this directly: it fails on main whenANTHROPIC_AUTH_TOKENis exported and passes with this change, in both exported and unset environments.