WebSocket Security Testing Severity: High | CWE: CWE-345, CWE-20, CWE-79 OWASP: A03:2021 – Injection | A07:2021 – Identification and Authentication Failures
What Are WebSocket Attacks? WebSockets provide full-duplex, persistent connections. Unlike HTTP, WebSocket frames lack built-in CSRF protection, don’t require Content-Type negotiation, and are often less scrutinized for injection. Attack surface: Cross-Site WebSocket Hijacking (CSWSH), injection via WebSocket messages, and authentication bypass.
Upgrade handshake: GET /chat HTTP/1.1 Host: target.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Origin: https://target.com → After upgrade: bidirectional message frames → No per-message CSRF protection → No per-message authentication header requirement Discovery Checklist Find WebSocket endpoints: browser DevTools → Network → WS filter Check Upgrade handshake — does server validate Origin header? Test CSWSH: connect from attacker.com — does it use victim’s session cookie? Replay captured WebSocket messages with modified data (Burp WS Repeater) Test injection in WebSocket message payloads: XSS, SQLi, CMDi, SSTI Check authentication: is auth checked at handshake only or per-message? Test for IDOR in message IDs/room IDs Test for privilege escalation via message type manipulation Check if WebSocket messages are reflected (stored XSS via WS) Test token-based auth: JWT in WS URL or first message — test bypass Test reconnection — does reconnect revalidate auth? Test wss:// downgrade to ws:// (cleartext) Payload Library Attack 1 — Cross-Site WebSocket Hijacking (CSWSH) If the server doesn’t validate the Origin header during the WebSocket handshake, an attacker’s page can initiate a WebSocket connection that carries the victim’s session cookie.
...