feat(api-proxy): enforce per-request ephemeral token validation on all proxy endpoints#1455
Closed
feat(api-proxy): enforce per-request ephemeral token validation on all proxy endpoints#1455
Conversation
Generate a cryptographically random AWF_PROXY_TOKEN on each awf invocation when --enable-api-proxy is active. The token is shared with both the api-proxy sidecar (AWF_PROXY_TOKEN env var) and the agent container (AWF_PROXY_TOKEN, ANTHROPIC_AUTH_TOKEN, COPILOT_TOKEN, COPILOT_GITHUB_TOKEN). The api-proxy now validates AWF_PROXY_TOKEN on every non-health request via x-api-key or Authorization: Bearer headers, returning HTTP 401 for missing or invalid credentials. Timing-safe comparison prevents oracle attacks. The get-claude-key.sh helper is updated to output $AWF_PROXY_TOKEN instead of the hardcoded placeholder string, so Claude Code's apiKeyHelper returns the actual ephemeral token that the proxy validates. Fixes: Anthropic API proxy enforces per-request credential validation Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/433801b7-5ab7-41d2-a32f-97171bcc2c6e
Addresses code review feedback: requestId is now generated inside rejectUnauthorized() rather than before the auth check, avoiding unnecessary ID generation on the happy path. Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/433801b7-5ab7-41d2-a32f-97171bcc2c6e
Copilot
AI
changed the title
[WIP] Add credential validation for Anthropic API proxy
feat(api-proxy): enforce per-request ephemeral token validation on all proxy endpoints
Mar 26, 2026
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.
The api-proxy sidecar forwarded all requests to upstream LLM APIs regardless of inbound credentials — any process on the
172.30.0.0/24subnet could invoke real Anthropic/OpenAI/Copilot credentials with nox-api-keyor a fabricated key.Approach
Generate a cryptographically random 32-byte token (
AWF_PROXY_TOKEN) per AWF invocation and validate it on every non-/healthrequest. The proxy rejects unauthenticated callers with HTTP 401; ifAWF_PROXY_TOKENis not configured at all, all non-health requests are rejected.Changes
src/cli.ts: Generatecrypto.randomBytes(32).toString('hex')asconfig.proxyTokenwhen--enable-api-proxyis active.src/types.ts: AddproxyToken?: stringtoWrapperConfig.src/docker-manager.ts:AWF_PROXY_TOKENto both the api-proxy and agent container environments.'placeholder-token-for-credential-isolation'strings withconfig.proxyTokenforANTHROPIC_AUTH_TOKEN,COPILOT_TOKEN, andCOPILOT_GITHUB_TOKEN.containers/agent/get-claude-key.sh: Output$AWF_PROXY_TOKENinstead of a static placeholder, so Claude Code'sapiKeyHelpersends the real ephemeral token.containers/api-proxy/server.js:extractInboundToken(req)— extracts token fromx-api-keyorAuthorization: Bearer.validateProxyAuth(req)— timing-safe comparison againstprocess.env.AWF_PROXY_TOKEN; returnsfalseif token absent, wrong, or env var unset.rejectUnauthorized(res, provider)— emits HTTP 401 withWWW-Authenticate: ******"awf-api-proxy"./healthpaths are exempt.Token flow
The real LLM API keys remain exclusively in the api-proxy container. The ephemeral token only authorises access to the proxy itself — not to the upstream provider.
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.