Skip to content

πŸ›‘οΈ Sentinel: [HIGH] Fix memory exhaustion (DoS) vulnerability in WebSocket server - #28

Closed
pakorn269 wants to merge 1 commit into
mainfrom
sentinel/fix-websocket-dos-14483067199891393425
Closed

pakorn269 wants to merge 1 commit into
mainfrom
sentinel/fix-websocket-dos-14483067199891393425

Conversation

@pakorn269

Copy link
Copy Markdown
Owner

🚨 Severity: HIGH

πŸ’‘ Vulnerability:
The zero-dependency WebSocket server implementation (skills/brainstorming/scripts/server.js) lacked bounds checking on incoming payloads and accumulated buffers in the socket.on('data') handler. This allowed a malicious client to exhaust the server's memory by sending a continuously large payload or an incomplete frame with an artificially large length marker, causing the server to buffer data indefinitely.

🎯 Impact:
A malicious actor could easily perform a Denial of Service (DoS) attack by exhausting available system memory, causing the Node process (and potentially dependent services) to crash.

πŸ”§ Fix:

  1. Introduced a MAX_PAYLOAD_SIZE limit of 10MB.
  2. Modified decodeFrame to explicitly reject any frame claiming a payload size larger than MAX_PAYLOAD_SIZE.
  3. Added a bounds check after processing valid frames in the data event handler. If the remaining incomplete buffer exceeds the allowed max payload size plus headers, the connection is forcefully closed. This prevents unbounded buffer accumulation while correctly handling legitimate streams that contain multiple valid frames in a single chunk.

βœ… Verification:
Verified that the existing WebSocket test suite (tests/brainstorm-server/ws-protocol.test.js and server.test.js) still passes correctly, demonstrating that normal protocol functionality (including large legal payloads up to the limit and boundary conditions) remains intact. Added a new entry to the security journal (.jules/sentinel.md) detailing the vulnerability and the fix.


PR created automatically by Jules for task 14483067199891393425 started by @pakorn269

@google-labs-jules

Copy link
Copy Markdown

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@pakorn269

Copy link
Copy Markdown
Owner Author

Closing β€” conflicts due to server.js β†’ server.cjs rename. The fix is being applied directly to server.cjs.

@pakorn269 pakorn269 closed this Mar 24, 2026
@google-labs-jules

Copy link
Copy Markdown

Closing β€” conflicts due to server.js β†’ server.cjs rename. The fix is being applied directly to server.cjs.

Understood. Acknowledging that this work is closed due to conflicts with the rename to server.cjs and stopping work on this task.

pakorn269 added a commit that referenced this pull request Mar 24, 2026
Security: add 10MB MAX_BUFFER_SIZE cap on WebSocket buffer to prevent
memory exhaustion DoS (closes duplicate PRs #24 #28 #32 #33 #37 #41 #44).

Performance: replace String.prototype.replace() with lastIndexOf+slice in
both wrapInFrame and handleRequest for multi-megabyte HTML payloads
(closes duplicate PRs #19 #22 #26 #29 #30 #35 #38 #39 #42).

Update .jules/sentinel.md and .jules/bolt.md with learnings.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@pakorn269
pakorn269 deleted the sentinel/fix-websocket-dos-14483067199891393425 branch March 24, 2026 13:39
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.

1 participant