Skip to content

fix: strip headers listed in Connection header per RFC 7230 Section 6.1#450

Merged
mcollina merged 2 commits intomainfrom
fix/strip-connection-headers-rfc7230
Feb 1, 2026
Merged

fix: strip headers listed in Connection header per RFC 7230 Section 6.1#450
mcollina merged 2 commits intomainfrom
fix/strip-connection-headers-rfc7230

Conversation

@mcollina
Copy link
Copy Markdown
Member

Summary

Per RFC 7230 Section 6.1, a proxy MUST parse the Connection header and remove any headers listed within it before forwarding the request.

Previously, only the Connection header itself was stripped but headers named inside it (e.g., Connection: X-Custom-Header) were forwarded to upstream.

Changes

  • Adds getConnectionHeaders() to parse Connection header values
  • Updates stripHttp1ConnectionHeaders() to also strip listed headers
  • Updates handleHttp1Req() and handleUndici() to strip listed headers
  • Adds tests for the new behavior

Example

Request from client:

GET / HTTP/1.1
Host: localhost
X-Custom-Header: some-value
Connection: X-Custom-Header

Before: Only Connection was stripped; X-Custom-Header was forwarded to upstream.

After: Both Connection and X-Custom-Header are stripped before forwarding.

Test plan

  • Added 6 new tests covering undici and http module scenarios
  • All 154 existing tests pass

Fixes #449

Per RFC 7230 Section 6.1, a proxy MUST parse the Connection header
and remove any headers listed within it before forwarding the request.

Previously, only the Connection header itself was stripped but headers
named inside it (e.g., Connection: X-Custom-Header) were forwarded.

This change:
- Adds getConnectionHeaders() to parse Connection header values
- Updates stripHttp1ConnectionHeaders() to also strip listed headers
- Updates handleHttp1Req() and handleUndici() to strip listed headers
- Adds tests for the new behavior

Fixes #449
@mcollina mcollina requested review from Eomm, climba03003, ilteoood and jsumners and removed request for climba03003 January 27, 2026 11:45
Copy link
Copy Markdown
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers, only suggestions.

Address review comments:
- Remove redundant !connectionHeader check since typeof covers it
- Flip condition order to check comma first (more common case)
@mcollina mcollina merged commit 8c0d65d into main Feb 1, 2026
17 checks passed
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.

Strip headers listed in Connection header per RFC 7230 Section 6.1

3 participants