Summary
Nezha contains an insecure direct object reference in WebSocket terminal and file-manager sessions. An authenticated member who obtains another user's live stream identifier may attach to that session, read or modify files, and execute shell commands on the target server.
Affected context
The issue occurs in Nezha deployments where stream identifiers created for terminal or file-manager sessions are not associated with their creating user. The affected WebSocket endpoints validate that a supplied UUID exists but may not verify that the requesting authenticated user owns the corresponding stream. Exploitation depends on obtaining a valid, active identifier through exposed logs, browser history, referer data, telemetry, or another information-leak path.
Exploit preconditions
- Attack surface: Authenticated WebSocket endpoints for terminal and file-manager sessions
- Required access: A valid authenticated account with member-level privileges
- Required information: A live stream UUID belonging to another user's session
- Trigger point: Supplying the obtained identifier to the terminal or file WebSocket endpoint
- Why exploitation is possible: Authorization checks confirm identifier existence without binding the stream to its creating user or enforcing equivalent ownership controls
Why this happens
The underlying flaw is a missing object-level authorization check. Stream identifiers are created as session references, but the application does not retain or enforce a reliable relationship between each stream and its authorized user when the stream is later accessed. This maps primarily to CWE-639: Authorization Bypass Through User-Controlled Key, with CWE-862: Missing Authorization also applicable. Treating possession of a valid identifier as sufficient authorization allows one authenticated user to reach another user's live session.
Potential impact
- An attacker could attach to another user's terminal session
- An attacker could execute shell commands on the associated server
- An attacker could read, create, modify, or delete files through the file manager
- An attacker could alter monitored systems or disrupt operational workloads
- Sensitive credentials, configuration data, or application secrets could be exposed
- Compromised servers could be used for lateral movement or persistence
General mitigation guidance
Mitigation typically focuses on making authorization server-side, object-specific, and independent of identifier secrecy.
Common defensive patterns include:
- Bind every stream identifier to its creating user, tenant, role scope, and target resource
- Enforce ownership or explicit permission checks before establishing WebSocket connections
- Treat stream UUIDs as references rather than bearer credentials
- Use short-lived, single-purpose session tokens with revocation and rotation controls
- Minimize exposure of identifiers in logs, browser history, referer headers, and telemetry
- Apply least privilege to member roles and monitored-server accounts
- Separate terminal execution permissions from read-only monitoring and file access
- Invalidate streams promptly when sessions end, users log out, or authorization changes
How teams detect issues like this
Organizations commonly detect this class of issue through:
- Static analysis and code review rules requiring ownership checks for identifier-based resource access
- Review of WebSocket handshake handlers for existence-only validation
- Tests that attempt cross-user access using valid identifiers from separate accounts
- Authorization policy checks confirming user, tenant, role, and target-resource binding
- Audit monitoring for terminal or file sessions accessed by users who did not create them
- Logging of denied and successful stream attachment attempts without recording sensitive tokens
- Automated security testing that models authenticated object-level authorization failures

