Summary
Chainlit contains a session hijacking flaw where WebSocket session restoration accepts any valid sessionId without verifying that the requester owns that session.
An unauthenticated attacker who can obtain or guess a victim's session identifier may inherit the victim's authenticated context, gaining access to restricted tools, data, and permissions during that restored session.
Affected context
This vulnerability affects Chainlit deployments that expose WebSocket-based session restoration mechanisms to clients.
It becomes relevant when the restore_existing_session path is used and session identifiers can be reused without strict ownership checks or binding to a specific client.
Environments where session IDs are long-lived, predictable, or observable in logs, URLs, or client storage are more susceptible, as attackers may more easily obtain a valid identifier.
Exploit preconditions
- Attack surface: Public or internal Chainlit WebSocket endpoint that supports
restore_existing_session. - Required access: Network access to the application, along with knowledge or successful guessing of a valid sessionId belonging to a victim.
- Trigger point: Initiating a WebSocket connection and invoking the session restore flow while presenting a victim's sessionId.
- Why exploitation is possible: The server does not enforce authorization or ownership verification for the provided sessionId, allowing a new client to attach to an existing authenticated session and inherit its roles and permissions.
Why this happens
The underlying issue stems from missing authorization checks when restoring sessions over WebSockets.
The implementation accepts a sessionId as sufficient proof of identity, failing to confirm that the caller is the legitimate owner or that the session is bound to a stable authentication context.
This maps to CWE-862: Missing Authorization, where sensitive operations—in this case, session restoration and permission inheritance—are performed without validating that the requester is authorized to assume the session's identity and privileges.
Potential impact
- Attackers may hijack active user sessions and act as the victim.
- Unauthorized invocation of privileged tools or actions restricted to the authenticated user.
- Access to conversation history, outputs, and data that the victim can see but others should not.
- Escalation of privileges if the victim holds elevated roles or administrative capabilities.
- Abuse of integrated systems (APIs, databases, external tools) via the victim's authenticated context.
General mitigation guidance
Effective mitigation focuses on enforcing strong authorization and context binding around session restoration actions.
Common secure patterns include:
- Treating session restore as a privileged operation that requires a fresh authentication check or a proven, bound identity (e.g., token linked to a user account).
- Binding sessions to client-specific attributes (such as authenticated user ID, device or token fingerprint) rather than accepting bare sessionIds.
- Designing session tokens to be opaque, unguessable, and short-lived, and never using them as the sole proof of identity during restoration flows.
- Minimizing the scope of what a restored session can access, using least-privilege defaults and separate, more constrained contexts for tool invocations.
- Applying defense-in-depth controls such as secondary checks before executing high-impact tools or accessing sensitive data, even from an apparently valid session.
How teams detect issues like this
Detection often relies on identifying insecure authorization patterns and anomalous session behavior.
Useful strategies include:
- Static and manual code review focused on WebSocket handlers and session management logic, verifying that restore endpoints perform ownership checks tied to an authenticated principal.
- Policy-based linting or automated analysis to flag flows where session identifiers are trusted without additional identity verification.
- Runtime logging and monitoring of session restoration events, including user IDs, IP addresses, device identifiers, and timestamps, to detect unusual cross-user reuse of sessionIds.
- Behavioral anomaly detection that looks for multiple distinct clients attaching to the same sessionId or rapid switching of user contexts within a single connection.
- Incorporating automated security review tools in CI pipelines to highlight missing authorization checks on endpoints that modify or reattach to sessions.

