Skip to content

fix(client): strip api-key and OpenAI org/project headers before forwarding - #420

Open
Atharva-Kanherkar wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
Atharva-Kanherkar:fix/reserved-headers-credential-tenant
Open

fix(client): strip api-key and OpenAI org/project headers before forwarding#420
Atharva-Kanherkar wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
Atharva-Kanherkar:fix/reserved-headers-credential-tenant

Conversation

@Atharva-Kanherkar

@Atharva-Kanherkar Atharva-Kanherkar commented Aug 14, 2026

Copy link
Copy Markdown

Fixes #419.

What

RESERVED_HEADERS in crates/libsy-llm-client/src/client.rs strips authorization and x-api-key from forwarded client metadata, but not three headers of the same class:

  • api-key, Azure OpenAI's credential header (the x--less sibling of x-api-key)
  • openai-organization and openai-project, OpenAI's billing and project selectors

forward_metadata_headers copies every non-reserved client header onto the upstream request, so a caller can set those three next to the backend's own credential. An invalid openai-organization makes OpenAI return 401 mismatched_organization; a valid one bills a different org the key can reach; on an Azure deployment a client api-key is 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's extra_headers, which are applied after forwarding and are unaffected.

Change

  • Add api-key, openai-organization, openai-project to RESERVED_HEADERS.
  • Refresh the comment above the list to describe the intent (the old comment pointed at a Python _SENSITIVE_HEADERS list that is not present in this tree).
  • Add 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

cargo test -p switchyard-llm-client

All existing tests pass; the new test and the existing forwards_metadata_headers_except_reserved both cover the reserved set. Reproduction steps for the original behavior are in #419.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented caller-provided metadata from overriding protected Azure and OpenAI authentication headers.
    • Ensured backend authorization remains intact while tenant and credential selector headers are filtered.

@Atharva-Kanherkar
Atharva-Kanherkar requested a review from a team as a code owner August 14, 2026 06:42
…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>
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0367cea1-8628-4db9-8259-dbc4f517378d

📥 Commits

Reviewing files that changed from the base of the PR and between a17efa9 and c747a81.

📒 Files selected for processing (1)
  • crates/libsy-llm-client/src/client.rs

Walkthrough

The client now reserves Azure api-key and OpenAI tenant-selector headers. Caller metadata forwarding excludes these headers, while backend authorization remains applied. An integration test verifies the filtering behavior.

Changes

Reserved header filtering

Layer / File(s) Summary
Reserved header enforcement
crates/libsy-llm-client/src/client.rs
The reserved-header documentation and case-insensitive filter now include api-key, openai-organization, and openai-project. An integration test verifies that these headers are removed and backend authorization remains present.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c747a

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

I’m a rabbit guarding the header gate,
Three sneaky keys now meet their fate.
Tenant tags and Azure clues
Stay out of upstream queues.
The backend key hops safely through—
Hop, hop, the tests approve it too!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: stripping API key and OpenAI organization/project headers before forwarding.
Linked Issues check ✅ Passed The changes satisfy issue #419 by reserving all three headers and adding a regression test while preserving backend authorization.
Out of Scope Changes check ✅ Passed The header-list update, comment refresh, and regression test are directly related to issue #419 and introduce no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Comment @coderabbitai help to get the list of available commands.

@Atharva-Kanherkar
Atharva-Kanherkar force-pushed the fix/reserved-headers-credential-tenant branch from c747a81 to 0e58b27 Compare August 14, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client api-key and OpenAI org/project headers are forwarded upstream

1 participant