fix(proxy): forwardHeaders must not override framing headers#1467
Conversation
`forwardHeaders` is meant as an escape hatch for the "soft" denylist drops (`host`, `accept-encoding`), but it previously won over the entire hop-by-hop denylist and `Connection` nominations. That let a caller force-forward true framing headers (`connection`, `transfer-encoding`, `te`, ...) upstream, which can desync request framing or leak the inbound proxy's credentials. Partition the denylist: `forwardHeaders` may only override soft drops, never the framing set or `Connection`-nominated tokens. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe proxy adds a dedicated set of non-overridable framing headers, restricts ChangesProxy header forwarding
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
pi0x
left a comment
There was a problem hiding this comment.
Verdict: APPROVE (one minor, non-blocking doc nit)
Reviewed independently. Fetched the branch, pnpm install, pnpm vitest run test/proxy.test.ts (104 passed / 24 skipped), and pnpm lint all green.
Correctness — looks right:
- The framing guard is effective:
framingHeadersis a strict subset ofignoredHeaders, so a blocked framing header still falls through to theignoredHeadersdrop rather than leaking. (Worth keeping in mind: if a future entry is added toframingHeadersbut notignoredHeaders, the!framingHeaders.has(name)block would be a no-op since the header would forward via the!ignoredHeaders.has(name)branch. A brief invariant comment could help, but current state is fine.) - Case-insensitivity holds end to end:
forwardHeadersis lowercased up front,framingHeadersentries are lowercase,Headers.entries()yields lowercase names, andconnectionTokens()lowercases. All comparisons align. Connection-nominated tokens are now correctly excluded from the escape hatch (!connectionNominated.has(name)) and still dropped below.- No behavior change when
forwardHeadersis unset:forwardHeaders?.includes(name)short-circuits to falsy, so the added&&clauses never run.
Tests — solid:
- Confirmed the framing regression test genuinely fails without the fix (
expected 'chunked' to be undefined→ received'chunked'), so it's a real guard, not a tautology. - The web-only skip on the framing test is justified: on the node target
t.fetchuses realfetch, which strips forbidden request headers (connection/transfer-encoding/keep-alive) before they ever reach the proxy, so the assertion can't be exercised there. The soft-drop (accept-encoding) test correctly runs on both targets.
Minor nit (non-blocking): the partition leaves three soft drops overridable by forwardHeaders — host, accept-encoding, and also expect (it's in ignoredHeaders but not framingHeaders). The ProxyOptions JSDoc says "Only the 'soft' drops (host, accept-encoding) can be overridden this way", which reads as exhaustive and omits expect. Leaving expect soft is defensible (it isn't in the classic RFC 9110 §7.6.1 hop-by-hop set), but consider either mentioning expect in the doc or moving it into framingHeaders for consistency. Behavior for expect is unchanged by this PR either way.
Style matches AGENTS.md conventions (/* @__PURE__ */ new Set, Set<string> for isolatedDeclarations, RFC-referenced JSDoc).
🤖 Generated with Claude Code
`expect` is in `ignoredHeaders` but not in `framingHeaders`, so it remains overridable via `forwardHeaders` — the soft-drop list read as exhaustive without it. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Addressed the reviewer's doc nit in ebe4157: the |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/proxy.test.ts`:
- Around line 348-382: Replace the runtime-gated test declaration around “does
not force-forward hop-by-hop framing headers via forwardHeaders” with skipIf,
skipping when the target is node. Preserve the test body and its existing
web-target behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e68e6ca5-3209-4bfb-aad1-54c7be0a3a3b
📒 Files selected for processing (3)
src/utils/internal/proxy.tssrc/utils/proxy.tstest/proxy.test.ts
forwardHeadersis documented as an escape hatch for the "soft" denylist drops (host,accept-encoding), but it previously won over the entire hop-by-hop denylist andConnectionnominations. That let a caller force-forward true framing headers (connection,keep-alive,transfer-encoding,te,trailer,upgrade,proxy-authorization,proxy-connection) upstream, which can desync request framing or leak the inbound proxy's credentials.This partitions the denylist into a dedicated
framingHeadersset:forwardHeadersmay now only override the soft drops, never the framing set orConnection-nominated tokens. TheforwardHeadersJSDoc is updated to document the constraint, and regression tests cover both that framing headers stay dropped and that soft drops (e.g.accept-encoding) still forward.🤖 Generated with Claude Code
Summary by CodeRabbit
Accept-Encoding.Transfer-Encoding,Connection, andKeep-Alivewhile continuing to forward valid headers.