Skip to content

fix(bedrock): tolerate a missing Connection header when signing#1652

Open
EffortlessSteven wants to merge 1 commit into
anthropics:mainfrom
EffortlessSteven:claude/bedrock-connection-header-robust
Open

fix(bedrock): tolerate a missing Connection header when signing#1652
EffortlessSteven wants to merge 1 commit into
anthropics:mainfrom
EffortlessSteven:claude/bedrock-connection-header-robust

Conversation

@EffortlessSteven
Copy link
Copy Markdown

What this does

get_auth_headers strips Connection from the SigV4-signed set so a proxy that drops it cannot break signature verification. It used del headers["connection"], which raises KeyError on httpx.Headers when the header is absent (a custom http_client may omit or strip it before signing).

Fix: remove the header only if present instead of deleting by an assumed key, so the signed set never includes connection and a missing Connection is a no-op, not a KeyError. Preserves the httpx.Headers container and case-insensitive match.

Verification

Red on main, green after.

Check Result
missing-Connection regression unpatched KeyError, patched signs
present mixed-case Connection stays out of SignedHeaders
ruff format, ruff check clean
pytest test_bedrock_auth + test_aws_auth 62 passed

Review map

  • src/anthropic/lib/bedrock/_auth.py: copy headers, then pop("connection", None) instead of del; sign new_headers.
  • tests/lib/test_bedrock_auth.py: missing-Connection regression; mixed-case Connection excluded from SignedHeaders; sanity.

get_auth_headers stripped the Connection header from the signed set via
del headers["connection"], which raises KeyError on httpx.Headers when
the header is absent (e.g. a custom http_client that omits or strips it).
Filter the header out instead, matching the robust form already used in
lib/aws/_auth.py. Adds unit tests for the bedrock signing helper, covering
the missing-header regression and that a present Connection header stays
out of SignedHeaders.
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.

1 participant