Skip to content

fix: harden WebSocket limits (maxPayload + use TCP peer IP) - #20

Merged
NateIsern merged 1 commit into
mainfrom
codex/propose-fix-for-websocket-dos-vulnerability
Jun 25, 2026
Merged

fix: harden WebSocket limits (maxPayload + use TCP peer IP)#20
NateIsern merged 1 commit into
mainfrom
codex/propose-fix-for-websocket-dos-vulnerability

Conversation

@NateIsern

Copy link
Copy Markdown
Member

Motivation

  • A public /api/ws endpoint accepted large frames (ws default ~100 MiB) and trusted attacker-controlled X-Forwarded-For values for per-IP connection limits, enabling unauthenticated DoS vectors.
  • The change hardens the WebSocket surface by bounding accepted message size and keying connection accounting to the TCP peer address so attackers cannot spoof per-IP buckets.

Description

  • Add a new configurable environment option WEBSOCKET_MAX_PAYLOAD_BYTES (default 65536) and document it in .env.example and README.md.
  • Pass the configured payload limit into the WebSocketServer via its maxPayload option to limit accepted frame size.
  • Replace the previous X-Forwarded-For based logic with a resolveClientIp implementation that returns the TCP peer address (socket.remoteAddress) so per-IP connection caps cannot be bypassed by spoofed headers.
  • All changes are confined to server/index.ts, plus the environment/example docs in .env.example and README.md.

Testing

  • Ran the TypeScript typecheck with npm run typecheck which completed successfully.
  • Executed the test suite with npm test (Vitest) and all tests passed (42 passed).

Codex Task

@NateIsern
NateIsern force-pushed the codex/propose-fix-for-websocket-dos-vulnerability branch from 7d1059e to 90a16a9 Compare June 25, 2026 19:49
@NateIsern
NateIsern merged commit 8fcb960 into main Jun 25, 2026
1 check passed
@NateIsern
NateIsern deleted the codex/propose-fix-for-websocket-dos-vulnerability branch June 25, 2026 19:50
NateIsern added a commit that referenced this pull request Jun 25, 2026
Document the merged hardening PRs and bump version:
- sanitize /api/validate-address response + input (#18)
- limit /api/network-info to public fields (#19)
- cap WebSocket frame size via maxPayload (#20)

Note: #20's TCP-peer WS-IP change was dropped on merge (would break the per-IP
WS cap behind the proxy); #16's trusted-proxy resolution is kept.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant