Summary
A cross-site request forgery vulnerability in djust's Server-Sent Events (SSE) endpoints allows a cross-origin webpage to interact with a victim's cookie-authenticated LiveView session. If the victim is authenticated and the SSE transport is enabled, an attacker may cause state-changing event handlers to run with the victim's privileges.
Affected context
The issue occurs in djust deployments using the SSE transport when client-to-server POST endpoints accept cross-origin requests without CSRF protection and the stream endpoint does not verify the request Origin. A client-selected session identifier is checked only for UUID formatting, so it does not provide proof that the request originated from the legitimate application.
Exploit preconditions
- Attack surface: SSE stream and client-to-server message endpoints exposed by the djust application
- Required access: A victim must have an active, cookie-authenticated session; the attacker generally needs only to control or publish a cross-origin webpage
- Trigger point: The victim's browser is induced to open the SSE stream and submit a message request to the associated endpoint
- Why exploitation is possible: Missing Origin validation and CSRF protection allow cross-origin requests, while a JSON body sent with a simple-request content type can avoid a browser preflight
Why this happens
The vulnerability results from treating browser cookies as sufficient authorization for SSE session actions without validating the request's origin or requiring an effective CSRF token. The stream endpoint creates and mounts a LiveView session based on a client-supplied identifier, while the POST endpoints accept cross-origin state-changing requests. This maps to CWE-352: Cross-Site Request Forgery, because an attacker-controlled origin can cause an authenticated browser to submit actions to the application.
Potential impact
- Unauthorized state changes in LiveView event handlers
- Actions performed with the victim's application privileges
- Modification or deletion of application-managed data, depending on exposed handlers
- Abuse of authenticated workflows or business operations
- Potential data integrity or account-impacting consequences
General mitigation guidance
Mitigation typically focuses on enforcing origin and request-integrity checks across every SSE endpoint.
Common defensive patterns include:
- Validate the
Originheader against an explicit, trusted allowlist for both stream and message requests - Require an appropriate JSON content type for state-changing POST requests
- Use framework-supported CSRF protections or unpredictable, server-validated CSRF tokens
- Avoid treating client-chosen session identifiers as authentication or request-integrity credentials
- Disable the SSE transport when its security controls cannot be consistently enforced
- Apply least privilege to authenticated sessions and sensitive event handlers
- Enforce equivalent origin policy at a trusted reverse proxy where appropriate
How teams detect issues like this
Organizations can identify this class of issue through:
- Static analysis rules flagging CSRF exemptions on state-changing endpoints
- Code review checks for missing Origin or Referer validation on cookie-authenticated SSE and WebSocket-like interfaces
- Tests that submit cross-origin requests with simple-request content types and verify rejection
- Policy checks requiring CSRF tokens or explicit origin allowlists for browser-accessible state-changing routes
- Runtime monitoring for rejected and accepted cross-origin requests, unusual SSE session creation, and unexpected event activity
- Automated security review tools that model browser credential behavior and CORS preflight conditions

