Repository navigation
fix(bedrock): discard stale payload hashes when resigning - #45634
micahmills88 wants to merge 6 commits into
Conversation
Merging this PR will not alter performance1 warning
Comparing Footnotes |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai review this draft |
|
|
@greptileai please review the updated draft after merging main, including the refreshed regression evidence and explanation of the controlled reproduction trigger |
|
bugbot run Please review the current Bedrock signing fix, focused regression coverage, and documented validation limits after merging main |
|
Please rerun mcp-server. Its unrelated cold schema-validation test timed out. The GitHub integration cannot rerun upstream jobs, returning 403 |
a421c9e to
2a12aa1
Compare
|
@greptileai please review the current tip. CLA identity is corrected, code is unchanged, and fresh CI replaces the unrelated timeout |
|
@greptileai added real proxy HTTP proof and the complete harness. The controlled retry returns 403 before and 200 after, with independently verified signatures |
|
bugbot run Please confirm the current commit after the CLA email correction. The previously reviewed code tree is unchanged |
|
The fresh mcp-server run hit the same cold schema-validation timeout. Requested upstream rerun assistance on #45633, whose identical tree previously passed |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2a12aa1. Configure here.
Bedrock retries now discard a previous payload hash before signing a changed request body. This prevents an old hash from invalidating the retry signature. The refreshed proxy proof and regression results are below, with live AWS validation still outstanding
Details
TLDR
Problem this solves:
How it solves it:
User Flow
Before: the reported Bedrock workflow can fail authentication
Expected after the fix; live AWS confirmation is pending
Relevant issues
Related: issue #27513 and merged re-signing fix #32371. This addresses the remaining payload-hash case
Implementation
When native Anthropic Messages retry handling removes rejected thinking blocks, it signs the changed body using the previous attempt's headers. A supplied x-amz-content-sha256 survives both the pre-sign filter and post-sign copy-back. Botocore uses that stale digest in its canonical request. The fix includes the payload hash in SIGV4_COMPUTED_HEADERS and excludes computed headers before signing. Existing restoration exclusions then prevent the stale hash from being reintroduced
Pre-Submission checklist
Screenshots / Proof of Fix
A real local proxy receives
POST /v1/messagesfrom curl and sends HTTP requests to a controlled Bedrock peer. A calibration request captures the initial body digest, which is then supplied through the publicextra_headersrequest option. The peer accepts the first signature and returns a rejected-thinking HTTP 400. The production retry strips the thinking block, changes the body, and signs again. No retry or signing code is patchedThe peer independently recomputes SHA-256 and the SigV4 HMAC using Python's standard library. It rejects mixed credential generations, mismatched payload hashes, and incorrect signatures with HTTP 403. Both before and after use the same peer. This is controlled HTTP integration proof with synthetic credentials and responses. It does not establish live AWS acceptance, IRSA behavior, or production failure frequency
Shared setup uses Python 3.12, curl, and the locked proxy dependencies. Save the script below as
proxy_proof.pyoutside the checkouts. It starts a local proxy and HTTP peer on temporary loopback ports, generates a local master key, runs curl, saves the response and peer observations, and stops its own processes. It makes no live provider callsComplete HTTP reproduction harness
Before (61da6fc)
python proxy_proof.py --repo ../before --case payload --expect fail --output ./proof/payload-before.jsonwith that checkout at the named commit403and this response{ "type": "error", "error": { "type": "permission_error", "message": "litellm.PermissionDeniedError: BedrockException - {\"message\": \"SignatureDoesNotMatch: controlled peer rejected inconsistent signing\"}\n\nLiteLLM: model group 'sigv4-proof' failed with the error above. No fallback was attempted." } }{ "response_status": 403, "credential_fetches": 0, "attempts": [ { "access": "proof-access-static", "token": "proof-token-static", "token_ok": true, "payload_hash_ok": true, "signature_ok": true, "body_sha256": "221e7780cda3fe0d7e5bcf1b906f9b185e565d18d470567e915a5f72e9fc781f" }, { "access": "proof-access-static", "token": "proof-token-static", "token_ok": true, "payload_hash_ok": false, "signature_ok": false, "body_sha256": "7d4a3aca416f27f603e43c55e4219bf2b7f5b0f4b9c42af530afaa6ea9496159" } ] }After (36e7cd3)
python proxy_proof.py --repo ../after --case payload --expect pass --output ./proof/payload-after.jsonwith that checkout at the named commit200and this response{ "id": "msg_controlled_peer", "type": "message", "role": "assistant", "model": "sigv4-proof", "content": [ { "type": "text", "text": "controlled peer accepted signature" } ], "stop_reason": "end_turn", "stop_sequence": null, "usage": { "input_tokens": 10, "output_tokens": 5 } }{ "response_status": 200, "credential_fetches": 0, "attempts": [ { "access": "proof-access-static", "token": "proof-token-static", "token_ok": true, "payload_hash_ok": true, "signature_ok": true, "body_sha256": "221e7780cda3fe0d7e5bcf1b906f9b185e565d18d470567e915a5f72e9fc781f" }, { "access": "proof-access-static", "token": "proof-token-static", "token_ok": true, "payload_hash_ok": true, "signature_ok": true, "body_sha256": "7d4a3aca416f27f603e43c55e4219bf2b7f5b0f4b9c42af530afaa6ea9496159" } ] }Regression validation
The focused checks were rerun at
36e7cd35782a7c2b7c34ab74cd4e40f73ffcacd3on November 2 with refreshed locked dependenciesuv run --no-sync pytest tests/unit/llms/bedrock/test_base_aws_llm.py tests/unit/llms/custom_httpx/test_llm_http_handler.py -k 'sigv4_resign_uses_current_body_hash or anthropic_invalid_thinking_signature_retry_resigns_bedrock_request' -q --tb=short --timeout=30Result:
15 passed, 520 deselected, 5 warnings in 6.54sThe current main signer fails ten hash-present cases while five absent-hash controls pass. Removing either pre-sign filtering or copy-back protection recreates all ten failures
The complete Bedrock base, Invoke, HTTP handler and Mantle Messages test files pass in a fresh Python 3.12 Linux container,
670 passed, 52 warnings in 47.99s. Scoped Ruff with the production and test configurations, production formatting andgit diff --checkagainst main pass. Full repository gates and current-tip coverage are left to hosted CIThe Linux environment uses the native bridge from main's unit workflow. Its artifact digest was verified, and the Rust sources, build configuration and model catalog are identical to main on this PR. This follows CI's shared bridge setup
Type
Bug Fix
Caveats
Medium
Final Attestation
Review status and validation scope
Merged main
61da6fcb4dc02cd58e39cb8c57ab3c99bea39a4fon November 2. The signing fix and focused scope are unchanged. Dependency declarations, lockfiles and OSV exemptions match mainFresh current-tip CI and automated reviews remain pending. Upstream's November 2 OSV scan passes with temporary filelock and MSAL exemptions. These are upstream's exemptions, and the dependency-upgrade PR #49204 remains unmerged. Earlier CI, coverage and review results do not count as approvals of this tip
The proxy/curl proof above was rerun at this merge base and exact tip. It uses a single proxy worker, synthetic credentials and an independent HTTP peer. Redis is omitted because the reproduction exercises standalone request signing. Live AWS acceptance, IRSA behavior and production failure frequency remain untested. Maintainer acceptance of this evidence or additional live validation remains outstanding