Repository navigation
Forward only Claude Code's request headers upstream - #3
Open
rayan-mazouz wants to merge 1 commit into
Open
rayan-mazouz wants to merge 1 commit into
rayan-mazouz wants to merge 1 commit into
Conversation
Upstream requests cloned every client header except a short blocklist, so gateway-added headers reached Anthropic and fallback providers: X-Forwarded-For and X-Real-Ip (each end user's address), X-Forwarded-Host and X-Forwarded-Server (this deployment's hostnames), and cookies. Forward an explicit allowlist instead: the headers Claude Code itself sends on /v1/messages, captured from claude-cli 2.1.263, minus auth and transport headers. Credentials are still injected per account or fallback.
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.
Summary
Upstream requests cloned every client header except a short blocklist, so headers added by the gateway were forwarded to
api.anthropic.comand to fallback providers:X-Forwarded-ForandX-Real-Ip: each end user's addressX-Forwarded-HostandX-Forwarded-Server: this deployment's hostnamesThis PR switches to an explicit allowlist of the headers Claude Code itself sends on
/v1/messages, minus auth and transport headers. I captured them fromclaude-cli2.1.263 by pointing it at a local recording server:accept,content-type,user-agent,x-app,x-claude-code-session-id,anthropic-version,anthropic-beta,anthropic-dangerous-direct-browser-access,x-stainless-{arch,lang,os,package-version,retry-count,runtime,runtime-version,timeout}Credentials are still injected per account or per fallback, as before. If a future Claude Code version adds a header, it has to be added to
_FORWARDED_REQUEST_HEADERS.Testing
main.test_api.pypasses.