mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
Closes the JSON-DoS finding from the prior security audit
(audit_1776483149979): both bin/cli.js (auto-detect MCP mode) and
bin/mcp-server.js (explicit MCP entry) accumulated stdin into a
buffer with no upper bound before splitting on newlines. A malicious
or runaway client could pipe gigabytes of un-newlined data and
exhaust memory before any JSON.parse ran.
Cap set to 10MB (MCP_MAX_BUFFER_BYTES). Far above legitimate MCP
payloads (largest realistic — full tool descriptions or batch search
results — top out around 1MB). When the cap is hit:
1. Emit a JSON-RPC -32700 error so the client sees the rejection
rather than a silent OOM.
2. Reset the buffer so subsequent newline-terminated messages still
parse.
Functional check: piping 11MB of un-newlined data into bin/cli.js
returns the protocol error and recovers — the parser doesn't hang
or crash.
```
$ node -e "process.stdin.write('a'.repeat(11*1024*1024) + '\n')" \\
| node bin/cli.js
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Buffered stdin exceeds 10485760 bytes without newline; resetting"}}
```
Co-Authored-By: RuFlo <ruv@ruv.net>