#223·ws

[Security] ReadFrame/ReadMessage allocate peer-declared frame length, MaxFrameSize defaults 0 -> OOM DoS (read.go:116)

Author: afldlCreated Aug 1, 2026Updated Aug 1, 2026

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:

go
f.Payload = make([]byte, int(f.Header.Length))   // peer-declared, no cap

wsutil/helper.go:48:

go
p = make([]byte, h.Length)                        // same

MaxFrameSize 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:

bash
go run main.go

Suggested 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.