GHSA-7242-982F-83P9
File manager WebSocket missing read limit allows single-message memory exhaustion
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-7242-982F-83P9 divulgada · CVSS 6.5 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Maintainer resolution
Fixed in v2.3.15 https://github.com/nezhahq/nezha/releases/tag/v2.3.15 by commit 36b742a7 https://github.com/nezhahq/nezha/commit/36b742a7e9a81ed782363dd19efd77b7030fbd0f. Affected versions: `>= 1.0.0, < 2.3.15`. Patched versions: `>= 2.3.15`.
Summary
The Nezha dashboard's file manager WebSocket endpoint `GET /api/v1/ws/file/:id` performs a WebSocket upgrade in `fmStream` (cmd/dashboard/controller/fm.go) without calling `SetReadLimit` on the connection. gorilla/websocket v1.5.3 defaults its per-connection read limit to zero, which the library treats as no limit, so a single inbound WebSocket message from an authenticated file manager user is read into a heap allocation proportional to the attacker's payload size. One oversized message is sufficient to exhaust dashboard memory and OOM the process, severing all agent monitoring. The sibling terminal endpoint has the guard; the file manager path does not.
Root Cause
Every server-side WebSocket connection that reads attacker-controlled frames must cap the maximum in-memory message size at a value bounded by the intended protocol. In gorilla/websocket, that cap is set explicitly via `(*websocket.Conn).SetReadLimit(limit)`. Without an explicit call, the default `readLimit` is 0, and the internal check `if c.readLimit > 0 && c.readLength > c.readLimit` is a no-op, so `ReadMessage()` accumulates the entire frame or continuation sequence in memory before returning any bytes. `fmStream` upgrades the connection and immediately wraps it as a `websocketx.Conn` without applying any size cap, while the parallel `terminalStream` handler applies a strict cap.
// cmd/dashboard/controller/fm.go (fmStream, WebSocket upgrade path)
wsConn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
return nil, newWsError("%v", err)
}
// no SetReadLimit call here
conn := websocketx.NewConn(wsConn)// cmd/dashboard/controller/terminal.go (terminalStream, guarded sibling)
wsConn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
return nil, newWsError("%v", err)
}
wsConn.SetReadLimit(terminalWebSocketInputLimit) // 512*1024 + 64 bytes`websocketx.Conn.Read` (service/rpc/websocketx/safe_conn.go) forwards to `(*websocket.Conn).ReadMessage`, which itself calls `io.ReadAll` on the message reader with no size cap when `readLimit == 0`. Overflow bytes beyond the caller-supplied buffer are retained in `dataBuf` until drained, so the full allocation stays live for the duration of the read/relay.
Impact
An authenticated dashboard user with the file manager scopes (`server:read`, `server:write`, `server:delete`) can create one file manager session via `POST /api/v1/file?id=<serverID>` and then connect to the WebSocket at `GET /api/v1/ws/file/<sessionID>`. Sending a single binary WebSocket message with an attacker-chosen payload size drives a server-side heap allocation of that size. A payload in the low-GB range on a typically provisioned dashboard is sufficient to trigger an OOM kill and drop every agent gRPC stream, disabling monitoring and alerting until the process restarts. The stream-count quota introduced by GHSA-jg62-j5h6-8mpq (per-user 20, per-server 40) constrains the number of concurrent streams but not the per-message allocation, so exactly one stream and one message are needed for the attack. Non-admin team members with a legitimate reason to hold file manager scopes can trigger the outage.
Proof of Concept
Prerequisites:
- Any dashboard user token (JWT cookie from a member login, or a PAT) with the
server:read, server:write, and server:delete scopes on at least one online server.
- A monitored server with agent connected (server_id=1 in the example).
- Network reachability to the dashboard's HTTP(S) endpoint.Reproduction steps:
- Create a file manager session and capture the returned `session_id`:
SESSION_ID=$(curl -sk -X POST "https://dashboard.example.com/api/v1/file?id=1" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["data"]["session_id"])')- Connect to the file manager WebSocket and send one large binary message. A 512 MB payload is used here; the sibling terminal endpoint rejects anything past ~512 KB.
# fm_readlimit_poc.py
import os, ssl, sys
import websocket
url = f"wss://dashboard.example.com/api/v1/ws/file/{os.environ['SESSION_ID']}"
ws = websocket.create_connection(
url,
header=[f"Authorization: Bearer {os.environ['TOKEN']}"],
sslopt={"cert_reqs": ssl.CERT_NONE},
)
payload = b"A" * (512 * 1024 * 1024) # 512 MiB
ws.send_binary(payload)Observed server behavior:
# dashboard process RSS climbs by ~payload size within a few seconds
# on a 1 GiB VM: OOM killer terminates the dashboard, all agent gRPC streams drop,
# and monitoring stops until systemd restarts the serviceThe terminal sibling rejects the equivalent request; sending a single 1 MB message to `GET /api/v1/ws/terminal/<sessionID>` fails at the read-limit check because `terminalWebSocketInputLimit = 512*1024 + 64`.
Attack Chain
- Exposure: The route `GET /api/v1/ws/file/:id` is registered in the authenticated route group (cmd/dashboard/controller/controller.go) in every default deployment; it ships enabled and does not require an operator flag.
- Control: The attacker fully controls the size and content of any WebSocket message sent after the upgrade. WebSocket framing bypasses `http.MaxBytesReader` and Gin body limits because those apply only to pre-upgrade HTTP.
- Path: `fmStream` (fm.go) checks stream ownership via `streamAttachAllowedForRequest`, calls `upgrader.Upgrade`, wraps the connection with `websocketx.NewConn`, registers it via `rpc.NezhaHandlerSingleton.UserConnected`, and enters `StartStream`, which relays through `io.CopyBuffer(agentIo, userIo, bp.buf)` where `bp.buf` is a 1 MB pool buffer for output framing only.
- Guard: No `SetReadLimit` is applied to the FM connection. `grep -rn "SetReadLimit"` across the tree finds only the terminal handler and an unrelated agent-compat client. No `SetReadDeadline` is set either, so a slow oversized message is not truncated by a read timeout.
- Primitive: `(*websocket.Conn).ReadMessage` reads the full message via `io.ReadAll` and returns the complete byte slice, so the server holds the entire payload live in the heap. The 1 MB pool buffer for `io.CopyBuffer` only controls output chunking; unread bytes remain in `dataBuf` and keep the allocation live.
- Result: A single oversized inbound WebSocket message consumes memory proportional to its size, up to the process or OS limit, causing GC pressure, service degradation, and OOM termination of the dashboard.
Bypass Evidence
The relevant protection is a per-connection read limit on the file manager WebSocket. It is missing. Direct inspection of gorilla/websocket v1.5.3 (conn.go around line 924) confirms that when `readLimit == 0` the length check short-circuits and `ReadMessage` calls `io.ReadAll` without a cap. `SetReadLimit` is called only in `terminalStream` (terminal.go). No HTTP-layer body limit applies after the WebSocket protocol switch, and the WebSocket upgrader's `ReadBufferSize: 32768` is an I/O read-syscall buffer, not a message size cap, since gorilla/websocket assembles messages frame by frame across many reads. Compression is disabled on the upgrader, so decompression cannot be blamed for or mitigate the allocation. GHSA-jg62-j5h6-8mpq (CVE-2026-53522) addresses stream count (`ioStreams` map growth) and does not touch per-message read limits; its per-user stream cap of 20 permits the single stream this attack uses.
Affected Versions
- Ecosystem: `go`
- Package: `github.com/nezhahq/nezha`
- Confirmed affected range: `>= 2.0.13, <= 2.3.14`
- Latest release checked: `v2.3.14` (GitHub release
https://github.com/nezhahq/nezha/releases/tag/v2.3.14) - Fix status: not fixed
The v2.x lineage of the dashboard has never called `SetReadLimit` on the file manager WebSocket. Commit `c3c165c` (first released in v2.3.4) added `SetReadLimit` to the sibling terminal handler only; the diff does not touch fm.go. The current release `v2.3.14` (commit `c726930`) remains vulnerable. Note that the Go module path published as `github.com/nezhahq/nezha` predates the project's v2 tag lineage; user-facing deployments consume tagged GitHub releases rather than the go-proxy module.
Suggested Fix
Apply a per-message read limit in `fmStream` immediately after `upgrader.Upgrade` and before `websocketx.NewConn`, mirroring `terminalStream`. The cap should be sized for realistic file manager control frames rather than bulk file bytes; large transfers already flow through the agent's gRPC IOStream, not the user WebSocket. A value in the hundreds of kilobytes, matching or slightly exceeding the terminal cap, is appropriate. Consider also setting a bounded `SetReadDeadline` per message so a slow attacker cannot hold a growing allocation open indefinitely, and audit any other WebSocket upgrade sites in the codebase for the same missing guard.
As an interim mitigation, operators can front the dashboard with a reverse proxy that caps WebSocket frame size (for example, NGINX `proxy_max_temp_file_size` and `client_max_body_size` combined with a WebSocket-aware size limit), but this is a partial defense that depends on the proxy's WebSocket message inspection behavior and does not remove the underlying dashboard-side allocation risk.
---
Reported by zx (GitHub: @manus-pi).
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
gogithub.com/nezhahq/nezha |
Sin parche | — | — | v1.14.14 afectada |
2.3.15Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/nezhahq/nezha/security/advisories/GHSA-7242-982f-83p9Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
