fix(client): strip api-key and OpenAI org/project headers before forwarding - #420
Conversation
…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>
|
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
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