Skip to content

fix: backport post-v6.23.0 security patches to v6.x#4886

Closed
mcollina wants to merge 11 commits intov6.xfrom
backport-security-fixes-to-v6x
Closed

fix: backport post-v6.23.0 security patches to v6.x#4886
mcollina wants to merge 11 commits intov6.xfrom
backport-security-fixes-to-v6x

Conversation

@mcollina
Copy link
Member

This PR backports post-v6.23.0 security-related fixes from main to v6.x.

Backported commits

  • fix(websocket): add maxDecompressedMessageSize limit for permessage-deflate
  • fix: validate server_max_window_bits range in permessage-deflate
  • fix: validate upgrade header to prevent CRLF injection
  • Fix websocket 64-bit length overflow
  • fix: reject duplicate content-length and host headers
  • test: increase bitness in test/fixtures/*.pem
  • fix: h2 CI (#4395) (adapted to v6.x)

v6.x adaptation commits

  • fix: adapt websocket frame-limit handling for v6 parser
  • test: stabilize h2 and tls-cert-leak under current test runner

Not applicable / skipped

  • fix(deduplicate): stream response chunks to waiting handlers
    • v6.x does not have the same deduplicate interceptor/handler structure, so this patch is not directly applicable.

Validation

  • Ran targeted websocket/security tests during cherry-pick conflict resolution.
  • Ran npm run test:unit on this branch after backport/adaptations.

mcollina and others added 11 commits March 12, 2026 14:45
…eflate

Add protection against decompression bomb attacks in WebSocket
permessage-deflate extension. A malicious server could send a small
compressed payload that expands to an extremely large size, causing
memory exhaustion.

Changes:
- Add maxDecompressedMessageSize option to WebSocket constructor
- Default limit: 4 MB
- Abort decompression immediately when limit exceeded
- Close connection with status code 1009 (Message Too Big)
- Add MessageSizeExceededError (UND_ERR_WS_MESSAGE_SIZE_EXCEEDED)
- Add comprehensive tests for the new limit behavior
- Update TypeScript types and documentation

Signed-off-by: Matteo Collina <hello@matteocollina.com>
(cherry picked from commit 2ee00cb)
The isValidClientWindowBits() function only checked for ASCII digits,
allowing out-of-range values like "1000" to pass validation. When these
values were passed to zlib's createInflateRaw(), it threw an unhandled
RangeError that crashed the process.

Changes:
- Update isValidClientWindowBits() to validate range 8-15 (per RFC 7692)
- Add try-catch around createInflateRaw() as defense in depth
- Add comprehensive tests for windowBits validation

(cherry picked from commit cb79c57)
Add validation for the upgrade option in Request constructor using
isValidHeaderValue() to prevent CRLF injection attacks that could
enable protocol smuggling to internal services.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Co-Authored-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Signed-off-by: Ulises Gascón <ulisesgascongonzalez@gmail.com>
(cherry picked from commit 77594f9)
Signed-off-by: Matteo Collina <hello@matteocollina.com>
(cherry picked from commit 84235c6)
When headers are passed as an array, reject duplicate content-length
and host headers regardless of casing. This prevents malformed HTTP/1.1
requests with multiple Content-Length values from being sent on the wire.

Previously, case-variant duplicates (e.g., 'Content-Length' and
'content-length') would bypass the duplicate check, resulting in
ambiguous HTTP requests that could be interpreted inconsistently
by proxies and backends.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
(cherry picked from commit 74495c6)
Signed-off-by: Matteo Collina <hello@matteocollina.com>
* test: fix key-size pem errors

* chore: use @metcoder95/https-pem

* fix: ci

* fix: ci

(cherry picked from commit 8dd120e)
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina closed this Mar 12, 2026
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.

3 participants