[Security] ReadFrame/ReadMessage allocate peer-declared frame length, MaxFrameSize defaults 0 -> OOM DoS (read.go:116)
Description
Summary
ws.ReadFrame (read.go:116) and wsutil.ReadMessage (helper.go:48)
pre-allocate a buffer sized by the peer-declared frame length
(make([]byte, h.Length)) with no default cap MaxFrameSize defaults to
0 (unlimited). A post-handshake peer can declare a huge length (up to 2^63-1,
only the MSB is rejected) Go runtime OOM panic process crash. Same family
as CVE-2020-27813 (now fixed for the signed-wrap, but the unbounded-allocation
design remains). DoS only (Go is memory-safe), Low Medium.
Root cause
read.go:116:
f.Payload = make([]byte, int(f.Header.Length)) // peer-declared, no capwsutil/helper.go:48:
p = make([]byte, h.Length) // sameMaxFrameSize is enforced only if > 0 (wsutil/reader.go:189); default 0.
PoC (end-to-end)
Attachment: gist https://gist.github.com/afldl/cb3eb1d0d8c0ea7f77d9ff9c1c4a9c4a
| File | Purpose |
|---|---|
main.go |
Reproducer: declared length 2^34 through make([]byte, len) |
output.txt |
Real run output |
Reproduction:
go run main.goSuggested fix
Default MaxFrameSize to a sane value (e.g. 16 MiB) instead of 0 (unlimited),
and/or cap in ws.ReadFrame itself.
Credit
Reported by afldl, 2026-07.
Source: gobwas/ws