Skip to content

fix: bound WebSocket rejection bodies#9

Merged
smiggleworth merged 2 commits into
mainfrom
fix/security-websocket-rejection-limit
Jul 26, 2026
Merged

fix: bound WebSocket rejection bodies#9
smiggleworth merged 2 commits into
mainfrom
fix/security-websocket-rejection-limit

Conversation

@smiggleworth

Copy link
Copy Markdown
Contributor

Closes #8.

Streams rejection bodies into a bounded accumulator, cancels on overflow, defaults the limit to 64 KiB, exposes a validated maxRejectionBodyBytes option, and recomputes the emitted content length.

Regression proof uses a continuing rejection stream with an 8-byte cap and verifies cancellation plus a bounded 500 response. Full local npm run check passes (27 tests, lint, types, build, publint, package checks).

Copilot AI review requested due to automatic review settings July 26, 2026 17:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Issue #8 by preventing unbounded buffering of WebSocket upgrade rejection bodies in the Node adapter, enforcing a configurable byte cap and failing closed when the cap is exceeded.

Changes:

  • Adds bounded streaming accumulation for WebSocket rejection bodies with cancellation on overflow (default 64 KiB).
  • Exposes and validates a maxRejectionBodyBytes WebSocket option.
  • Adds a regression test ensuring oversized rejection bodies are cancelled and replaced with a bounded 500 response.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/node.test.ts Adds a regression test asserting cancellation and bounded 500 response when rejection body exceeds the configured limit.
src/websocket.ts Implements bounded rejection-body reading/cancellation and threads maxRejectionBodyBytes through the rejection path; recomputes emitted content-length.
src/contracts.ts Extends NodeWebSocketOptions with maxRejectionBodyBytes.
README.md Documents the new option and the default 64 KiB rejection-body cap.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/websocket.ts Outdated
@smiggleworth
smiggleworth merged commit e787cc1 into main Jul 26, 2026
3 checks passed
@smiggleworth
smiggleworth deleted the fix/security-websocket-rejection-limit branch July 26, 2026 17:26
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.

Security: bound WebSocket rejection response buffering

2 participants