Summary
Portainer's WebSocket attach and exec endpoints may allow Standard users to access containers belonging to other users in a shared environment. If a user can obtain another session's container or exec ID, they may hijack that session and gain interactive access, potentially including a root shell.
Affected context
The issue concerns Portainer's WebSocket attach and exec endpoints in shared environments. It may arise when the application accepts a container or exec identifier without adequately verifying that the requesting user is authorized to access the associated resource. The described affected releases are Portainer 2.39.0 before 2.39.9, 2.40.0 before 2.45.4, and 3.0.0 before 3.1.0.
Exploit preconditions
- Attack surface: Portainer WebSocket endpoints at
/api/websocket/attachand/api/websocket/exec - Required access: A Standard user account with access to a shared environment
- Trigger point: A WebSocket attach or exec request referencing another user's container or exec session
- Why exploitation is possible: Authorization may not be correctly checked against the requested resource and the user's permissions; access to a relevant ID can enable session hijacking
Why this happens
The vulnerability is an object-level authorization failure associated with CWE-639: Authorization Bypass Through User-Controlled Key. The insecure pattern is allowing a client-supplied identifier to select a container or exec session without verifying, for each request, that the authenticated user is permitted to access that specific resource. Identifier secrecy alone is not an authorization control.
Potential impact
- A Standard user may access containers assigned to other users
- An attacker could hijack an attach or exec session
- Unauthorized interactive command execution may occur within a container
- If the container runs with elevated privileges, compromise could have broader effects on the host or environment
General mitigation guidance
Defensive patterns focus on enforcing resource-level authorization at every attach and exec operation.
- Derive the user's permitted resources from trusted server-side identity and policy data
- Check ownership and environment permissions for each requested container or exec session
- Avoid treating possession or unpredictability of an identifier as proof of authorization
- Apply least privilege to users, containers, and service accounts
- Limit WebSocket access to the operations and resources each role requires
How teams detect issues like this
- Review WebSocket handlers for authorization checks tied to the specific requested container and exec session
- Use static analysis or code review rules to flag client-controlled identifiers used in resource lookups without permission checks
- Audit access logs for users attaching to or executing in resources outside their expected scope
- Enforce policy tests covering cross-user and cross-environment access attempts
- Consider automated security review tools as an aid for identifying missing object-level authorization

