fix(client): strip api-key and OpenAI org/project headers before forwarding - #420
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
WalkthroughThe client now reserves Azure ChangesReserved header filtering
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized change prevents client-supplied credential and organization headers from overriding backend request context; no actionable merge-blocking risk remains after normal checks and review. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
c747a81 to
0e58b27
Compare
…arding RESERVED_HEADERS dropped authorization and x-api-key from forwarded client metadata but left api-key (Azure OpenAI's credential header) and openai-organization / openai-project (OpenAI tenant selectors). A caller could set those on the upstream request next to the backend's own key: an invalid openai-organization makes OpenAI reject the call, a valid one bills a different org the key can reach, and on Azure deployments a client api-key is forwarded as the credential header. Add the three names to RESERVED_HEADERS so forward_metadata_headers drops the client copy. An operator that needs one of them still sets it through the backend's extra_headers, which are applied after forwarding. Signed-off-by: Atharva-Kanherkar <142440039+Atharva-Kanherkar@users.noreply.github.com>
0e58b27 to
21b0474
Compare
|
@nachiketb-nvidia thank you for your review. switchyard is awesome, i use it with opencode + gemini + some custom setup. it has some bugs, but its obvious for a standard new dev project. nice work, please keep this project going:) |
* origin/main: (31 commits) feat(server): add Dockerfile for switchyard-server container image (NVIDIA-NeMo#421) fix: normalize empty content-filter responses instead of raising (NVIDIA-NeMo#358) feat(python): unify LLM classifier bindings (NVIDIA-NeMo#465) feat(libsy): record task_kind and agent_role on the run span (NVIDIA-NeMo#249) fix(translation): accept SSE data fields with no space after the colon (NVIDIA-NeMo#447) fix(client): strip api-key and OpenAI org/project headers before forwarding (NVIDIA-NeMo#420) fix(llm-client): detect native sglang context-overflow messages (NVIDIA-NeMo#426) refactor(protocol): use typed HTTP status codes (NVIDIA-NeMo#457) fix(translation): preserve chat reasoning details (NVIDIA-NeMo#415) docs(changelog): note packaging extras removal in Unreleased (NVIDIA-NeMo#433) docs(changelog): fix broken Metrics Reference link (NVIDIA-NeMo#432) feat(libsy-llm-client): Move retry logic from libsy to libsy-llm-client (NVIDIA-NeMo#431) fix(server): use normalized session IDs in routing stats (NVIDIA-NeMo#430) feat(benchmark): pre-bake hermes agent into dataset images for closed-book runs (NVIDIA-NeMo#350) fix: support json_object classifier responses (NVIDIA-NeMo#411) fix(metrics): extend LLM latency histogram buckets (NVIDIA-NeMo#385) feat(server): forward inbound Anthropic auth (NVIDIA-NeMo#372) fix(protocol): normalize nested metadata strings (NVIDIA-NeMo#422) Revert "ci: base full CI on changed paths (NVIDIA-NeMo#403)" (NVIDIA-NeMo#414) feat: Move `Decision::reasoning` to a log message (NVIDIA-NeMo#413) ... Co-authored-by: Michael Neale <michael.neale@gmail.com> Signed-off-by: Michael Neale <michael.neale@gmail.com> # Conflicts: # crates/switchyard-server/src/config.rs
Fixes #419.
What
RESERVED_HEADERSincrates/libsy-llm-client/src/client.rsstripsauthorizationandx-api-keyfrom forwarded client metadata, but not three headers of the same class:api-key, Azure OpenAI's credential header (thex--less sibling ofx-api-key)openai-organizationandopenai-project, OpenAI's billing and project selectorsforward_metadata_headerscopies every non-reserved client header onto the upstream request, so a caller can set those three next to the backend's own credential. An invalidopenai-organizationmakes OpenAI return401 mismatched_organization; a valid one bills a different org the key can reach; on an Azure deployment a clientapi-keyis forwarded as the credential header.This PR adds the three names to
RESERVED_HEADERS. An operator that legitimately needs one of them upstream still sets it through the backend'sextra_headers, which are applied after forwarding and are unaffected.Change
api-key,openai-organization,openai-projecttoRESERVED_HEADERS._SENSITIVE_HEADERSlist that is not present in this tree).strips_client_credential_and_tenant_headers, a regression test that sends all three as client headers and asserts none reach the upstream while the backend bearer is preserved.Test
All existing tests pass; the new test and the existing
forwards_metadata_headers_except_reservedboth cover the reserved set. Reproduction steps for the original behavior are in #419.Summary by CodeRabbit