Unauthenticated remote crash via unbounded length-prefix in protobuf stream decoder (centrifugal/protocol dependency)
Description
Vulnerability Details
Note on scope: this vulnerability lives in github.com/centrifugal/protocol (a third, separate repository from both centrifugo and centrifuge), which has private vulnerability reporting disabled and no SECURITY.md/security contact of its own. Both centrifugo and centrifugal/centrifuge depend on the exact vulnerable version (v0.19.2, confirmed via go.sum hash match), and every primary client transport in centrifuge (WebSocket, SSE, HTTP-stream, emulation/WebTransport) calls straight into the vulnerable decode path with no mitigating configuration — so this is submitted through centrifugo's working advisory channel, same as GHSA-hvvj-x7m8-3vr9 earlier this session.
File: decode_stream.go (in centrifugal/protocol), lines 128-141, (*ProtobufStreamCommandDecoder).Decode Also: bpool.go lines 52-70, getByteBuffer — where the panic actually fires CWE: CWE-129 — Improper Validation of Array Index (primary, zero-bandwidth crash path); CWE-770 — Allocation of Resources Without Limits or Throttling (secondary, bandwidth-bound path) Severity: Critical CVSS: 8.6 — CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Root Cause
// decode_stream.go:128-141
func (d *ProtobufStreamCommandDecoder) Decode() (*Command, int, error) {
msgLength, err := binary.ReadUvarint(d.reader)
if err != nil {
return nil, 0, err
}
if d.messageSizeLimit > 0 && msgLength > uint64(d.messageSizeLimit) {
return nil, 0, ErrMessageTooLarge
}
bb := getByteBuffer(int(msgLength)) // msgLength fully attacker-controlled;
defer putByteBuffer(bb) // no upper bound when messageSizeLimit == 0
...// bpool.go:52-70
func getByteBuffer(length int) *ByteBuffer {
if length == 0 { return &ByteBuffer{B: nil} }
if length > maxBufferLength { // maxBufferLength = 262144
return &ByteBuffer{B: make([]byte, 0, length)}
}
idx := nextLogBase2(uint32(length)) // length cast to uint32, no range check
if v := pools[idx].Get(); v != nil { // pools is [19]sync.Pool — idx can exceed 18
return v.(*ByteBuffer)
}
return &ByteBuffer{B: make([]byte, 0, 1<<idx)}
}The critical call site, used by every primary transport, requests the unlimited variant:
// decode_stream.go:18-19
func GetStreamCommandDecoder(protoType Type, reader io.Reader) StreamCommandDecoder {
return GetStreamCommandDecoderLimited(protoType, reader, 0) // 0 = "no limit"
}// centrifuge/handler_websocket.go:318-320 (identically reached from
// handler_http_stream.go, handler_sse.go, and emulation.go via the shared
// HandleReadFrame helper)
func HandleReadFrame(c *Client, r io.Reader) bool {
protoType := c.Transport().Protocol().toProto()
decoder := protocol.GetStreamCommandDecoder(protoType, r)A sibling call site in centrifugo itself (internal/wt/handler.go:85, the WebTransport handler) correctly passes a real, configured limit via GetStreamCommandDecoderLimited — showing the safe pattern exists in the codebase, but it is not used by the far more heavily used WS/SSE/HTTP-stream/emulation call sites.
Why It's Vulnerable
binary.ReadUvarint reads a fully attacker-controlled uint64 length prefix (up to 10 bytes on the wire) with no upper bound when messageSizeLimit == 0. That value is converted to int and passed to getByteBuffer. On a 64-bit platform, sending the varint encoding of math.MaxUint64 converts to int(-1) (two's-complement narrowing), which is not > 262144 (the large-buffer branch), so execution falls into: idx := nextLogBase2(uint32(-1)) → uint32(-1) = 4294967295 → bits.Len32(4294967294) = 32. pools is a fixed 19-element [19]sync.Pool array, so pools[32] panics immediately with "index out of range".
Dynamic Confirmation (2026-08-16)
Reproduced independently, twice, via direct in-process invocation against the checked-out source (v0.19.2, matching the exact version pinned in both centrifugo's and centrifuge's go.sum):
func TestVuln101(t *testing.T) {
var buf bytes.Buffer
lenBuf := make([]byte, binary.MaxVarintLen64)
n := binary.PutUvarint(lenBuf, ^uint64(0)) // math.MaxUint64
buf.Write(lenBuf[:n])
decoder := NewProtobufStreamCommandDecoder(&buf, 0) // messageSizeLimit=0, matches
// GetStreamCommandDecoder's default
_, _, _ = decoder.Decode()
}Result — a single 10-byte input, no command body needed:
panic: runtime error: index out of range [32] with length 19
github.com/centrifugal/protocol.getByteBuffer(...) bpool.go:64
github.com/centrifugal/protocol.(*ProtobufStreamCommandDecoder).Decode(...) decode_stream.go:140Process-wide blast radius confirmed by code inspection: for WebSocket connections negotiated over HTTP/1.1 (the common case), centrifuge's handler_websocket.go:308 spawns go handleConn() — a bare goroutine that reads frames via this exact decode path — outside the scope of Go's net/http server's automatic per-request panic recovery (which only guards the original request-handling goroutine, not goroutines spawned by application code). emulation.go:166 has the identical pattern (go func() { ... HandleReadFrame(...) ... }()). An unrecovered panic in either of these goroutines is fatal to the entire process — disconnecting every client on that node, not just the attacker's connection. (For the synchronous SSE/HTTP-stream paths, which call HandleReadFrame directly inside ServeHTTP without a spawned goroutine, Go's built-in per-connection panic recovery would likely limit the blast radius to that one connection — but the WS and emulation paths are process-wide.)
A secondary, non-overflow path also exists: any legitimate large msgLength (e.g. exactly 4GB, no integer overflow) hits make([]byte, 0, length) with no cap — bandwidth-bound (requires the attacker to actually send proportional data) rather than a free crash, but still an uncapped-allocation gap given messageSizeLimit == 0 is the default posture for every primary transport.
Attack Scenario
- Attacker opens a WebSocket (or SSE/HTTP-stream/emulation) connection to any Centrifugo/centrifuge deployment using the binary protobuf protocol — no authentication or completed Connect handshake required, since this decoder parses the very first client message
- Attacker sends a single ~10-byte message: just the varint-encoding of
math.MaxUint64, no command body needed getByteBufferpanics on the out-of-range pool index- On HTTP/1.1 WebSocket or emulation transport, the unrecovered goroutine panic crashes the entire Centrifugo node process, disconnecting every currently-connected client
Impact
- Who is affected: any Centrifugo/centrifuge deployment accepting protobuf-framed WebSocket, SSE, HTTP-stream, or emulation connections — the default/recommended protocol for production use
- What attacker achieves: unauthenticated, pre-connect, single ~10-byte-message trigger for a process-wide crash (WS/emulation) or at minimum a per-connection crash
- Conditions required: network reachability to the endpoint; no authentication, no non-default configuration needed
Recommended Fix
- Hard cap in
getByteBufferitself regardless of caller-supplied limits (defense in depth): ``go func getByteBuffer(length int) *ByteBuffer { if length < 0 || length > someHardMaximum { return &ByteBuffer{B: make([]byte, 0, 0)} // or propagate an error instead } ... }`` - Bounds-check
idxagainstlen(pools)before indexing, regardless of the above. - Root-cause fix: every call to
GetStreamCommandDecoderfromcentrifuge's transport handlers should pass a real, non-zeromessageSizeLimit(mirroringcentrifugo's owninternal/wt/handler.go), andDecodeshould reject oversized lengths before callinggetByteBufferwhenever a limit is configured (which it already does correctly when a limit is passed — the gap is that0is treated as "unlimited" and that's what the heavily-used call sites pass).
Verification
Dynamically confirmed via direct in-process invocation of the vulnerable decoder against the exact centrifugal/protocol v0.19.2 checkout that both centrifugo and centrifugal/centrifuge pin in their go.sum — a single ~10-byte crafted message reliably panics the decoder.
---
IMPORTANT CORRECTION (2026-08-16, same day as initial report)
After submitting this report, I did a follow-up check of centrifugal/protocol's git history and found this exact bug was already fixed upstream, 12 days before this report:
- Commit
1fc2374("fix overflow in stream decode, more fuzzing, docs, ci"), 2026-08-04, tagged as release v0.20.0. - The fix adds a
maxMessageLength = math.MaxInt32hard ceiling check inProtobufStreamCommandDecoder.Decode(decode_stream.go) applied unconditionally, even whenmessageSizeLimit == 0— closing exactly the gap described in this report. - The same commit also fixed the sibling
getByteBuffernegative-length case inbpool.go, and added new fuzz tests (FuzzProtobufStreamDecode, with the code comment "Huge declared length" directly on a seed corpus entry) — strongly suggesting the maintainer found this independently via the repo's own continuous fuzzing (per.github/workflows/fuzz.yml, also added in the same commit) rather than via this report. I want to be transparent about this rather than imply I was first to find it. - I independently confirmed (via
git log -S) this fix does not touch any exported function signatures indecode_stream.go— so upgrading thecentrifugal/protocoldependency to>= v0.20.0in bothcentrifugoandcentrifugal/centrifuge(both currently pinned to the vulnerablev0.19.2) should be a safe, drop-in version bump with no consumer-side code changes required.
Net effect on this report: the underlying vulnerability described above is still real and still live in every current centrifugo/centrifuge deployment (both pin v0.19.2, pre-dating the fix), so the report and dynamic confirmation stand — but the actionable remediation is simply bumping the pinned centrifugal/protocol dependency version, not writing a new fix. Apologies for not checking this before initial submission; wanted to correct it same-day rather than let it stand.