fix(bedrock): sign rerank requests with the shared, header-filtered SigV4 helper - #36462
Conversation
…igV4 helper BedrockRerankHandler._prepare_request duplicated ad-hoc SigV4 signing instead of using BaseAWSLLM.get_request_headers, the helper every other Bedrock handler (embeddings, converse, invoke, image) already uses. The duplicate skipped header filtering before signing, so any forwarded header (e.g. x-forwarded-for) got included in the signed set and could invalidate the signature if rewritten downstream between signing and delivery, the same class of bug fixed for the invoke path in BerriAI#19111.
Greptile SummaryThe PR routes Bedrock rerank signing through the shared header-filtering helper while preserving forwarded headers unsigned
Confidence Score: 5/5The PR appears safe to merge No blocking failure remains, and the previously reported class-level credential monkeypatch has been removed
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/rerank/handler.py | Uses the shared Bedrock signing helper to exclude forwarded headers from the signature while retaining them on the request |
| tests/test_litellm/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py | Verifies forwarded headers remain present but unsigned, with credentials supplied through the normal instance request path |
Reviews (2): Last reviewed commit: "test(bedrock): drop class-level monkeypa..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Pass static AWS credentials through optional_params so the real credential-resolution path runs locally instead of patching BedrockRerankHandler._get_boto_credentials_from_optional_params.
|
@greptileai please re-review, the test now injects static AWS credentials instead of monkeypatching the credential-resolution method. |
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit d80608e. Configure here.
| endpoint_url=proxy_endpoint_url, | ||
| data=body, | ||
| headers=headers, | ||
| ) |
There was a problem hiding this comment.
Bearer path breaks Bedrock rerank auth
High Severity
Routing rerank through get_request_headers also picks up its AWS_BEARER_TOKEN_BEDROCK branch. Bedrock API keys are not valid for Agents Runtime APIs such as /rerank, so when that env var is set the handler sends Bearer auth instead of SigV4 and AWS rejects the call. Previously this path always signed with SigV4.
Reviewed by Cursor Bugbot for commit d80608e. Configure here.


TLDR
Problem this solves:
How it solves it:
get_request_headershelper other Bedrock handlers already useUser Flow
Before: an admin whose proxy forwards client headers to backend LLM APIs (
forward_client_headers_to_llm_api) gets every Bedrock rerank call rejected by AWScohere.rerank-v3-5:0After: the same call succeeds
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
I don't have access to a proxy deployment with header forwarding enabled and a live Bedrock rerank model to capture end-to-end curl output for this one, so I can't post real request/response logs. What I can show:
Deterministic before/after on the actual signing code, not a mock of it:
tests/test_litellm/llms/bedrock/rerank/test_bedrock_rerank_header_forwarding.py::test_bedrock_rerank_forwarded_headers_excluded_from_sigv4_signaturebuilds a realAWSRequestthroughBedrockRerankHandler._prepare_requestwith a forwardedx-forwarded-forheader and inspects the actual computedAuthorizationheader.Before the fix (checked out at
3726bceb53, the commit this branch is based on):SignedHeadersincludesx-forwarded-for, so any hop that rewrites that header between LiteLLM signing the request and AWS receiving it invalidates the signature.After the fix (this branch):
SignedHeadersiscontent-type;host;x-amz-date;x-amz-security-token, no longer includingx-forwarded-for, while the header itself is still present and forwarded on the wire.For anyone who can reproduce this against real AWS, this is the config that should trigger it (a Bedrock rerank deployment behind a proxy forwarding client headers):
Type
🐛 Bug Fix
Caveats (if any)
general_settingsor a way to deploy a patched build to itFinal Attestation
Note
Medium Risk
Touches AWS request signing for Bedrock rerank. Behavior is aligned with other Bedrock handlers and covered by a signature-inspection test, but a signing bug would break all rerank calls.
Overview
Fixes Bedrock rerank SigV4 mismatches when the proxy forwards client headers (
forward_client_headers_to_llm_api). Headers likex-forwarded-forwere previously signed, then rewritten in transit, so AWS rejected the request.BedrockRerankHandler._prepare_requestnow uses the sharedget_request_headershelper instead of signing every header inline. Forwarded headers still go to Bedrock, but they are excluded fromSignedHeaders.Adds a unit test that inspects the real
Authorizationheader and assertsx-forwarded-foris present but unsigned.Reviewed by Cursor Bugbot for commit d80608e. Bugbot is set up for automated code reviews on this repo. Configure here.