Skip to content

[PR] fix: enforce the CONNECT response header limit after completion - #7166

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-18_connect-header-bound
Nov 20, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-18_connect-header-bound

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7165

Problem

connectThroughProxy checks its existing 64 KiB response-header limit only while the terminating \r\n\r\n is absent. A complete 80 KiB HTTP 200 response head can therefore open a tunnel, while the same oversized head without its final delimiter is rejected. The decision depends on how the response arrives.

Change

Measure the header bytes before choosing the incomplete/complete path: use the buffered length until the first delimiter appears, then use the delimiter's end offset. Reject either form above 64 KiB through the existing error/cleanup path. An exactly 64 KiB head remains accepted, and any bytes after the delimiter remain tunnel data, outside the header budget.

This is enforcement of the existing handshake bound. It does not change status-line handling, deadlines, proxy trust, authentication, configuration or the bytes forwarded through an established tunnel. The shared connection helper runs below both compression modes. No kernel, wire-message schema or model-facing text changes are included.

Validation

Tested on Node 24.22.1, bili 0.1.216, base 548e396022b9391e28a3c9061560be297779b8e8 (current master when checked).

  • Thirteen new real-socket tests exercise 65,535/65,536/65,537/81,920-byte heads, a delayed split delimiter, an unfinished oversized head, and byte-exact preservation of 256 KiB of trailing binary data after both small and exactly bounded heads.
  • The tests also send a real HTTP CONNECT request through setupMitm's blind-tunnel route: a bounded head forwards the complete payload; an oversized complete head returns HTTP 502.
  • Unchanged base: 4 failed, 9 passed. The complete oversized-head cases and the blind-tunnel status check reproduce the bug. Actual TCP read boundaries may coalesce or split writes; every tested expected result is independent of that segmentation.
  • New tests plus buffered-data, premature-close, CONNECT-timeout and upstream-CA-trust suites: 41 passed, no skips.
  • npm run typecheck, npm run build, npm run check:test-import-graph and git diff --check pass.
  • Independent review checked delimiter accounting, payload preservation and cleanup. The authoritative full-suite result remains the remote CI verdict on this head.

Prior work

Checked 258 earlier fork heads (11 complete upstream-proxy.ts versions, five connection-helper versions), 31 upstream file-history revisions and relevant open/closed issues and PRs. None applies the bound to a completed head. The earlier buffered-byte and premature-close changes in #6595 and #6577 address different behavior, retained by the related tests above.

Apply the existing 64 KiB response-header budget whether or not the
terminating delimiter is already buffered. Exclude tunneled payload
bytes, and cover exact limits, split delimiters and the blind tunnel.

Fixes ranxianglei#7165
@ranxianglei ranxianglei changed the title fix: enforce the CONNECT response header limit after completion [PR] fix: enforce the CONNECT response header limit after completion Nov 18, 2026
@ranxianglei
ranxianglei merged commit 10ee8d1 into ranxianglei:master Nov 20, 2026
48 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.

CONNECT response header limit depends on arrival of the final delimiter

2 participants