WebSocket Vulnerabilities Explained: The Bug Hunters Overlook
Open a live chat app, a stock trading dashboard, or an online game, and behind the scenes there is probably a WebSocket: a persistent two-way connection between your browser and the server. Unlike normal HTTP, where the browser asks and the server answers, a WebSocket stays open and both sides can send messages at any time. That persistence is exactly why attackers love it — and why most security testing ignores it. If you hunt bugs, WebSockets are one of the least crowded places to look.
How WebSockets Work
A WebSocket starts life as an ordinary HTTP request with an Upgrade: websocket header. If the server agrees, the connection switches protocols and stays open. After that, messages flow in frames — small packets that can carry text or binary data — in both directions, with no new handshake per message. The browser's same-origin policy does not block WebSocket connections the way it blocks some other requests, which is where the first vulnerability comes from.
Vulnerability 1: Cross-Site WebSocket Hijacking (CSWSH)
This is the WebSocket version of CSRF, and it is the classic finding. The browser will happily open a WebSocket to any site, and if the server authenticates the connection using only cookies — with no Origin check and no per-connection token — then a malicious page can open a WebSocket to the victim's app as the victim. The attacker's page receives the victim's live data and can send messages as them.
The defense is simple and the test is simple too. On the defense side: validate the Origin header on the handshake and require a CSRF-style token in the connection setup. On the testing side (your own app or an in-scope target only): try connecting from a different origin and see if the server accepts it. If it does, you have found a real bug.
Vulnerability 2: Missing Authentication on Messages
Many apps check authentication once, during the handshake, and then trust every message that arrives on the open socket. That is a broken access control bug hiding inside a live connection. A classic test: connect as a low-privilege user and send a message that only an admin should be able to send — a delete command, a role change, a transfer. If the server executes it without re-checking your role, the WebSocket is the hole. The fix is to authorize every sensitive action, not just the connection.
Vulnerability 3: Unvalidated Input, Same as Everywhere Else
A WebSocket message is just data, and servers that trust it are vulnerable to the same injection bugs as any other input. JSON fields in WebSocket messages have carried SQL injection, NoSQL injection, and even server-side template injection in real bug bounty reports. The payloads are the same ones you already know — the only difference is the delivery channel. When you test, intercept the WebSocket traffic with Burp Suite's WebSockets history tab and fuzz the message fields exactly as you would fuzz a form.
Vulnerability 4: No Rate Limiting or Message Size Limits
A WebSocket that accepts unlimited messages of unlimited size is a denial-of-service bug waiting to happen. One client flooding the socket can exhaust the server's memory or CPU, and because the connection is persistent, the flood never needs a new handshake. Defenders should cap message size and messages per second per connection. Testers can note the absence of limits — but only test rate limits gently on in-scope targets, and never flood a production system.
How to Start Testing WebSockets
- Find them. In Burp Suite, WebSocket traffic appears in the WebSockets history tab. In the browser, the Network tab filters to
WS. - Read the messages. Watch a normal session first. Understand the message format before you touch anything.
- Replay and modify. Copy a message, change a field — a user ID, a room ID, a command — and see what the server does.
- Check the origin. Try the handshake from another origin and watch whether the server cares.
Remember the rules that keep this legal: only test systems you own or have written permission to test — your own lab app, a CTF challenge, or a bug bounty target whose scope explicitly includes the WebSocket endpoints. Everything else is off-limits.
WebSockets are everywhere and almost nobody tests them properly. That gap is your opportunity — learn the protocol, test it methodically, and the findings will follow.



Comments
Post a Comment