Repository navigation
feat(runtime): configurable inbound-header forwarding policy with default infra/platform denylist - #5783
Merged
Conversation
…rwarded inbound headers When a request hits the /run path, inbound headers are forwarded to the agent. Previously, forwarded inbound headers could clobber the server-configured agent.headers on a key collision, letting a client override server-set values (e.g. authorization). This is the #5712 bug. Introduce mergeForwardableHeaders (header-utils.ts): a case-insensitive merge where server-configured agent.headers always win on collision, regardless of header-name casing. agent-utils.ts now uses this helper on the /run path so server-configured values are authoritative and inbound headers only fill keys the server did not set. Fixes #5712
…ward-looking plumbing The /connect path now builds the same server-wins merged headers as the /run path and passes them into runner.connect(). This does NOT fix connect-path auth: no shipped runner consumes the headers field of AgentRunnerConnectRequest today. The in-memory, intelligence, telemetry, and sqlite runners all read only threadId from the connect request and ignore headers entirely. The real outbound header forwarding lives on the /run path, where agent.headers is mutated before the agent runs. Passing merged headers here is the correct argument shape for a future outbound-connecting runner, and keeps the connect path's merge semantics consistent with /run. The comments and JSDoc are rewritten to state this plainly rather than implying an active auth fix: the connect-site cloneAgentForRequest call is documented as the sole agentId-existence guard (the intelligence branch never re-validates the id), and cloneAgentForRequest's AbstractAgent | Response (404) dual-return contract that both callers depend on is now documented.
…-* uniqueness, agent-undefined forwarding Cover the #5712 header-precedence behavior across both paths: - agent-header-precedence.test.ts: server-configured agent.headers win over forwarded inbound headers on collision (case-insensitive), with single-key uniqueness assertions for both authorization and the x-* family (exactly one surviving key carrying the SERVER value). - agent-utils-header-forwarding.test.ts: the /run path merges via mergeForwardableHeaders so server values are authoritative and inbound headers fill only unset keys. - sse/__tests__/sse-connect-agent-id.test.ts: the /connect path applies the same merge, plus the agent-undefined case (no server agent.headers) degrades to forwarding allowlisted inbound headers only and does not crash.
… mergeForwardableHeaders
When an agent is configured with both case-variants of the same header
in agent.headers (e.g. Authorization and authorization), the prior
{ ...base } spread kept both keys — the exact undici comma-join hazard
the function guards against for inbound collisions. Collapse server-self
case-collisions to a single first-occurrence-wins entry; server-wins-over
-inbound and case-insensitive inbound suppression are unchanged.
…ault infra/platform denylist Tighten which inbound HTTP headers the v2 runtime forwards onto the outgoing agent call. The old `authorization` + `x-*` allowlist leaked infrastructure, proxy, and platform headers (x-forwarded-*, x-real-ip, x-amzn-trace-id, x-vercel-*, and the Copilot Cloud platform key x-copilotcloud-public-api-key) to arbitrary configured agent URLs (#5712, breadth half). - header-utils.ts: add DEFAULT_DENY_HEADER_NAMES + DEFAULT_DENY_HEADER_PREFIXES constants and a policy-aware shouldForwardHeader; thread ResolvedForwardHeadersPolicy through extractForwardableHeaders and mergeForwardableHeaders. Add the public ForwardHeadersConfig and resolveForwardHeadersPolicy (useDefaultDenylist defaults to true; deny/denyPrefixes extend the default; allow switches to allowlist mode). Server-wins precedence and server-self case-dedup are unchanged. - runtime.ts: add forwardHeaders?: ForwardHeadersConfig to BaseCopilotRuntimeOptions, resolve it once in the constructor into forwardHeadersPolicy (mirroring the debug -> ResolvedDebugConfig resolve-once), expose it on CopilotRuntimeLike / BaseCopilotRuntime, and add a passthrough getter on the CopilotRuntime shim. - Apply the resolved policy at both call sites: /run (configureAgentForRequest) and /connect (handleSseConnect), so the two paths can never diverge. Default-on in a minor with { useDefaultDenylist: false } as the documented opt-out.
…th paths (#5712) - header-utils.test.ts: new coverage for the default denylist (exact names + prefix families, case-insensitive), custom x-* still forwarding, config overrides (useDefaultDenylist:false, deny, denyPrefixes, allow allowlist mode), and the breadth/precedence interaction. Migrate the inverting assertions (x-request-id / X-Forwarded-For now stripped; extract result drops x-request-id) and add the new required policy arg to all call sites. - agent-utils-header-forwarding.test.ts + sse-connect-agent-id.test.ts: /run and /connect integration coverage — denylisted infra/platform headers dropped, custom x-* + authorization still forward, and a runtime-supplied forwardHeaders policy is actually applied (plumb-through). Swap denylisted filler headers for non-denylisted custom headers in the precedence regression tests. - handle-run / handle-connect / intelligence-run-telemetry / get-runtime-info: add the resolved forwardHeadersPolicy to mock runtimes that route through the header merge so they satisfy the now-required policy.
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/bot
@copilotkit/bot-discord
@copilotkit/bot-slack
@copilotkit/bot-teams
@copilotkit/bot-telegram
@copilotkit/bot-ui
@copilotkit/bot-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
Contributor
|
Size Change: 0 B Total Size: 1.16 MB ℹ️ View Unchanged
|
The published CopilotRuntimeLike interface (v2 export surface) added forwardHeadersPolicy as a REQUIRED field, which breaks any external implementor of the interface — inconsistent with the minor-release classification. The /run (agent-utils) and /connect (sse/connect) read sites dereferenced runtime.forwardHeadersPolicy with no coalesce, so a policy-less object crashed with "Cannot read properties of undefined (reading 'allow')". Make the field optional on the interface and coalesce both read sites to the default resolved policy (resolveForwardHeadersPolicy(undefined), default-on denylist) when absent. Concrete runtimes (BaseCopilotRuntime) still always resolve and set it, so behavior is identical for all real runtimes; the interface is now non-breaking and crash-proof. Adds a red-green test driving configureAgentForRequest with a runtime whose forwardHeadersPolicy is undefined: asserts no throw and that the default denylist applies (x-forwarded-for dropped, custom x-* and authorization forwarded).
…ase-collision, allowlist boundary - agent-utils: assert configureAgentForRequest does not mutate the shared registered agent; only the per-request clone carries merged inbound headers (guards against a cross-request bearer-token leak, #5712). - header-utils: direct mergeForwardableHeaders unit test for server Authorization vs inbound lowercase authorization with a different value — exactly one authorization-family key survives carrying the server value (#5712). - header-utils: shouldForwardHeader boundary tests for the bare 'x' name and the empty-string name under both denylist and allowlist policies.
`shouldForwardHeader` returned early on `policy.allow` and silently ignored
the integrator's `deny`/`denyPrefixes`, so a header listed in BOTH `allow`
and `deny` still forwarded — a footgun on a security feature.
Rework the predicate so the integrator's own `deny`/`denyPrefixes` (exact,
case-insensitive, and prefix) always strip, including in allowlist mode:
`allow` selects the candidate set, `deny` subtracts from it. The built-in
default denylist is unchanged and still applies only in denylist mode (an
explicit `allow` is a deliberate opt-in), so only the integrator's OWN deny
subtracts from an allowlist.
Also harden `resolveForwardHeadersPolicy`: trim and drop empty/whitespace-only
entries from `deny`/`denyPrefixes`/`allow`. A stray `denyPrefixes:[""]` made
`startsWith("")` true for every header (silently denying ALL forwarding), and
`allow:[""]`/`allow:[" "]` seeded the exclusive allowlist with an entry that
could never match — both integrator typos that now can't silently break
forwarding. Entries are lowercased consistently with existing handling.
Empty/whitespace-only allow/deny/denyPrefixes entries are trimmed and dropped before the allowlist-mode decision, so allow: [""] stays in denylist mode rather than switching on exclusive allowlist mode. Also document that allowlist mode bypasses the built-in default denylist, so integrators must not allow-list protected/platform headers unintentionally.
Document the v2 runtime's inbound-header forwarding behavior on the Copilot Runtime page: the default denylist (authorization + x-* minus known infra/proxy/platform headers), the x-request-id upgrade note, server-configured header precedence (#5782), and the forwardHeaders config option (deny/denyPrefixes/allow/useDefaultDenylist) with the allowlist-mode denylist-bypass footgun. Refs #5712, #5783
Contributor
Production Digest-Pinning AuditAll 41 services digest-pinned. Run 2026-07-06 09:24:47 PDT — 0 finding(s). |
AlemTuzlak
previously approved these changes
Jul 6, 2026
jpr5
marked this pull request as ready for review
July 6, 2026 16:35
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
July 6, 2026 16:35
4 of 5 tasks
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.
Problem — the leak
The v2 runtime's
shouldForwardHeaderforwardedauthorizationand any header whose name starts withx-onto the outgoing agent call. In a real deployment the inbound request has already traversed a browser, CDN/edge, load balancer, and hosting platform — each stamping its ownx-*headers — so the widex-*wildcard silently forwarded:x-forwarded-for,x-real-ip,x-forwarded-proto/host/portx-amzn-trace-id,x-amz-cf-id,x-cloud-trace-context,x-azure-*,x-fastly-*,x-request-idx-vercel-*,x-middleware-*x-copilotcloud-public-api-keyThe last item is a real credential-exfiltration concern: a platform key scoped to Copilot Cloud reaching a third-party agent URL. This is the breadth half of #5712 (option 3); the precedence half was fixed in #5782.
Design — denylist default + config knob, both paths
authorization+x-*base eligibility, but strip a curated, greppable set of known infra/proxy/platform headers (exact names + prefix families) before forwarding. Legitimate customx-*application headers (x-tenant-id,x-api-key, …) keep flowing untouched. The authoritative list is a single exported constant inheader-utils.ts.forwardHeadersruntime option).useDefaultDenylist?: boolean(default true) —falserestores the previous wide-open behavior.deny?/denyPrefixes?— extend the default denylist.allow?— opt into strict allowlist mode (only listed headers forward).forwardHeadersinto aforwardHeadersPolicy: ResolvedForwardHeadersPolicyfield (mirroring the existingdebug→ResolvedDebugConfigresolve-once), exposed onCopilotRuntimeLike/BaseCopilotRuntimewith a passthrough getter on theCopilotRuntimeshim.configureAgentForRequest) and /connect (handleSseConnect) viamergeForwardableHeaders, so the two can never diverge. Server-wins precedence and server-self case-dedup from fix(runtime): server-configured agent headers take precedence over forwarded inbound headers #5782 are untouched.Semver
Minor with an opt-out. Removing a leak is a fix, not a contract change, and we ship a documented escape hatch:
new CopilotRuntime({ agents, forwardHeaders: { useDefaultDenylist: false } })restores the prior behavior. Custom-header forwarders (the common case) are unaffected.Red-green proof (real surface, both paths)
RED — with the predicate reverted to the old wide-open
authorization || x-*(policy ignored), the new behavior assertions fail; the leak reproduces (x-forwarded-for: 203.0.113.7forwards on both /run and /connect):GREEN — with the real policy in place:
Full
@copilotkit/runtimesuite: 113 files / 1593 tests passed. Typecheck, oxlint (0 errors), oxfmt, and build all green.Builds on #5782
This branches off #5782's head (
636bcad05) and reuses that PR'smergeForwardableHeaders(server-wins precedence + server-self case-dedup). It should land after #5782. It addresses the forwarding-breadth half of #5712 — #5712's precedence core is fixed by #5782; this is the breadth follow-up (notFixes #5712).