Files
OneCAD-Draft/src
Karim Jerbi 6c3c266475 fix(rest): cap HTTP request line and headers, answer 431
Bug:
read_request used bare BufRead::read_line for the request line and every
header. A client that connects and streams bytes without ever sending
CRLF grows a single String until the allocator fails and the process
aborts. The 15-second idle timeout never fires while bytes keep
arriving, so one socket is enough.

Reproduce:
1. Start OpenCADStudio with --http 8765.
2. Connect (e.g. nc 127.0.0.1 8765) and write "GET /" followed by
   gigabytes with no newline.
3. Before: memory climbs until "memory allocation failed" aborts the
   process.
4. After: the line hits the 8 KiB cap, a 431 response is written and
   the connection closes; the server keeps serving.

Fix:
The request line and headers are read through capped helpers - 8 KiB per
line, 64 KiB for the whole header block. An over-limit request gets the
standard 431 (Request Header Fields Too Large) written inside
read_request before anything else parses it. The GUI bridge path shares
read_request, so it is covered too. Regression tests stream an oversize
request line and an oversize header block and assert the 431.
2026-09-30 19:15:49 +01:00
..
…
2026-09-28 20:32:02 +03:00
…
…
…