fix(bedrock): tolerate a missing Connection header when signing#1652
Open
EffortlessSteven wants to merge 1 commit into
Open
fix(bedrock): tolerate a missing Connection header when signing#1652EffortlessSteven wants to merge 1 commit into
EffortlessSteven wants to merge 1 commit into
Conversation
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.
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 this does
get_auth_headersstripsConnectionfrom the SigV4-signed set so a proxy that drops it cannot break signature verification. It useddel headers["connection"], which raisesKeyErroronhttpx.Headerswhen the header is absent (a customhttp_clientmay 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
connectionand a missingConnectionis a no-op, not aKeyError. Preserves thehttpx.Headerscontainer and case-insensitive match.Verification
Red on
main, green after.KeyError, patched signsConnectionSignedHeadersruff format,ruff checkpytest test_bedrock_auth + test_aws_authReview map
src/anthropic/lib/bedrock/_auth.py: copy headers, thenpop("connection", None)instead ofdel; signnew_headers.tests/lib/test_bedrock_auth.py: missing-Connection regression; mixed-caseConnectionexcluded fromSignedHeaders; sanity.