Skip to content

Chapter 3

Twelve bug families

The same HTTP bugs, carried in frames the route middleware does not see.

10 min readWebSocket

Every bug family below is a classic HTTP flaw hiding inside a WebSocket frame where route middleware and WAFs stop watching. CSWSH covers cross-site hijacking. Everything else treats the open socket as an undocumented API. Keep Alice as your attacker account, Bob as your victim account, and send the same tests you would send over REST.

No authentication. Sometimes the server answers 101 with no cookie and no token, then happily executes private commands. It sounds too simple to be real, yet wss://target.com/admin still answers unauthenticated on live programs.

  1. Send the admin path with no Cookie header.
  2. Record it if a private action still answers.

Authentication once. The server accepted the handshake as a guest, or as a low role. The server then runs later frames as an administrator.

  1. Find the admin paths in chapter 1.
  2. Open a handshake as the lowest role.
  3. Send the admin frames.
  4. Record every frame that gets a real answer.

Token in the query string. The URL looks like wss://target.com/ws?token=eyJhbGc.... A URL is not a secret. The token is then stored in server logs, in proxy logs, and in browser history. It also leaks in a Referer header when that URL is reused on a navigation or an error page. Prefer to report the leak locations you actually observed. Report the placement on its own, then test what the token still opens.

The token is never checked again. The server reads the token at the handshake and never reads it again. The socket has no built-in second check, so it outlives the token. Test this on every target. Sockets that survive logout are common. Sockets that survive a password reset, or a demotion, are common too.

  1. Log in.
  2. Open the socket and keep it open.
  3. Log out on HTTP, or let the token reach its expiry.
  4. Send one frame on the old socket.
  5. If the frame still runs, record a socket that outlived the session.
  6. Reset the password.
  7. Send one frame on the old socket.
  8. Lower the role.
  9. Send one privileged frame on the old socket.

A revoked session that still drives a live socket is a real finding. Logout and password change are the two events that should drop the socket.

Socket.IO can hide the token in the connect packet instead of the handshake. That packet is the 40 plus JSON form from chapter 1.

  1. Open the socket.
  2. Do not send the connect token.
  3. Send a later event.
  4. If the server answers, record that the connect packet was optional.

Some servers accept the handshake and wait for a login frame. If you never send that frame, and other actions still run, the wait is optional. If the login frame accepts an expired token, the check is a signature check with no expiry.

The session layer manual in the Broken Access Control guide covers stale sessions in depth. It also covers other token flaws.

{"action": "subscribe", "channel": "user_1042"}
{"action": "get_order", "orderId": 88413}
{"action": "read_document", "docId": "7f3a9c1e-d29b-4b8a"}

This is the same bug as an id in a URL. The transport is a frame. Channel names and object ids inside subscribe frames are the usual place. Test them as frames, not only as REST calls. The middleware that protects GET /api/orders/88413 never sees the frame. The same object can be safe on REST and open on subscribe for order 88413. Developers rarely test the twin.

GraphQL subscriptions are another copy of this bug. A subscription document is a frame. Swap the id inside it the same way.

The identifier formats, the base64 and hashid cases, and the four-identity diff are in the IDOR guide.

Let Account B own the object. Send the frames from Account A. Stop when one foreign object comes back.

{"action": "search", "query": "\" OR 1=1--"}
{"action": "send", "to": "<script>alert(1)</script>"}
{"action": "set_name", "name": "admin<script>alert(1)</script>"}

SQL injection fits in a frame the same way it fits in a query string. Cross-site scripting fits in any string the client later inserts into the page. Live views often trust the server and insert the text as HTML. The WAF on the HTTP API never saw the string, because the string was inside a frame.

NoSQL and JSON injection use operators instead of quotes.

{"action": "query", "filters": {"$ne": ""}}
{"userId": {"$gt": ""}}

Also change the JSON type of a field. Send the same id as a string, a number, an array, and an object. A parser that only expected a string can take the other shapes. If the server copies your JSON onto one of its objects, add a role field the client should not own. That is mass assignment, delivered as a frame.

On an XSS check, render the result in an account you own. A marker such as a unique string is enough to prove the data path. Use the script string when you need to prove HTML execution in that same account.

One HTTP route is capped per request. Sending a flood of HTTP calls costs headers, connections, and the limiter. One socket can send frames as fast as the client can write them. Nothing in the protocol parses a new request between those frames. The client can also open many sockets.

An enumeration that REST would throttle can run here. The hole is large enough for 10000 get_order frames, each with a new id, on one socket. Report that size. Send only the small test below.

  1. Send about 30 frames on one socket you already have open.
  2. If every frame is accepted, record that no per-frame limit fired.
  3. Do not raise the volume, and do not try to exhaust the host.

Programs reject outage reports. You are paid for showing the missing limit, not for taking the service down. A huge single frame, or a very large socket count, is the same class of risk. Name it only after a small test has already shown that no limit exists.

A socket makes a race easy to send. Send many frames close together on one socket. Or open many sockets. The handshake is cheap.

The actions are the ones you already race on HTTP. Redeem one coupon on parallel sockets. Submit one transfer on parallel sockets. Subscribe the same limited object on parallel sockets. Use accounts you own, and stay inside the program rules.

Twenty or thirty sockets is the picture of the bug, not a quota. If the program forbids load, stop at two sockets and describe the rest as capability. The race theory does not change. The delivery is cheaper than HTTP. The race condition chapter in Bug Hunting for Beginners has the single-packet procedure.

CSWSH is the total miss. These are the partial checks that still fail.

Origin: null
Origin: https://evil.target.com
Origin: https://target.com.evil.com
  1. Set Origin to the value null.
  2. Set Origin to a subdomain that contains the real host.
  3. Set Origin to the real host followed by an attacker domain.
  4. Remove Origin and send the handshake from curl or wscat.

Some sandboxed pages send Origin null. A weak allow-list treats null as safe. Try null every time. A suffix or prefix compare is the same mistake as a weak SSRF allow-list. Some servers allow a missing Origin for industrial clients that are not browsers. A browser page does send Origin. If a missing Origin still returns 101, say which clients can connect that way. curl and wscat can omit the header. A page cannot.

Sec-Fetch-Site is set by the browser on modern Chromium. A real cross-site page sends cross-site. Your curl client can send anything, so a curl result does not prove a browser bug. Use curl to see whether the server trusts that header. Use a real browser page to prove CSWSH.

Socket.IO-style rooms often split the permission check from the later fan-out. Joining a room and receiving the room are different events. Test the gap between them.

  1. Join a room as a user who is allowed to join.
  2. See whether the server remembers that this socket may hear the room.
  3. Log out, or rotate the credential, and see if the socket leaves the room.
  4. Move the user to another tenant or team, and see if room access is computed again.
  5. Subscribe to users.* and compare the delivered rooms with the UI.

Step 5 is the wildcard. Record it if the server expands the pattern further than the UI shows. A room string is an authorization decision. Do not treat it as a harmless label.

A stored payload can ride the broadcast. Save it through the normal profile or chat field. Watch the admin dashboard that keeps a socket open. If that client inserts the text as HTML, every listening admin renders it. You have a stored XSS bug with live delivery.

Run this against an admin account you own. The marker should be unmistakable in the frame, and harmless to anyone else. The HTTP save and the socket delivery can sit behind different filters. A filter on the save does not prove the dashboard escapes the frame.

3.9 Cleartext ws on a page that looks locked

Section titled “3.9 Cleartext ws on a page that looks locked”

Search HTTPS pages for the scheme ws://. A hit is a lead. It is not automatically a live cleartext channel.

A current browser blocks ws:// from an HTTPS page as mixed content. Chrome throws SecurityError and does not open the socket. The lock on the address bar is about the page. It does not cover a socket that the browser refused. It also does not cover a socket that some other client opened in cleartext.

Record a cleartext finding when a client actually connects with ws://.

  • The page itself is served over HTTP.
  • A mobile app, a desktop app, or another non-browser client uses ws://.
  • A fallback runs only when the page was loaded over HTTP.
  • The site has no HSTS, so a network attacker can strip TLS and then load the HTTP page.

On a socket that really is cleartext, a network attacker can read the frames. Chat, tokens, and trade actions are then visible on the path. The same attacker can insert frames. A fake chat line or a fake trade confirmation is the impact to describe. Every confirmed cleartext client deserves a sentence in the report. An unused string in an HTTPS-only bundle is a note, until a client connects.

The server often routes on an action name it invented. That router has its own input checks, and they are often weak. That router has its own authorization, and it is often missing. Actions to look for include rename_channel, kick_user, names that start with admin, and impersonate.

Map the names the way you map REST routes.

Terminal window
grep -rEo '"action"\s*:\s*"[a-z_]+"' js-bundle/*.js | sort -u
  1. Copy every action name the command prints.
  2. Send each action as the lowest role.
  3. Record which actions answer, and what data they return.

The UI hides some of these names. The bundle still contains the strings. Nobody on the HTTP test pass sent them. That list is the part of the product the route review did not cover.

Also repeat the list while logged out, and again after logout on an old socket. An action that only checks the handshake will answer all three times. The function-level chapter in the Broken Access Control guide covers the same hidden-action bugs on HTTP.

Some sockets negotiate permessage compression on the handshake. Compression mixes your input with a secret in the same stream. The compressed size then leaks something about the secret. This is the same class as the CRIME and BREACH attacks on HTTPS.

The bug is rare and slow to prove. Note the permessage-deflate extension on the handshake. Chase it only when one frame mixes attacker text with a secret the server echoes.

The same questions fit transports that are not raw WebSocket.

Socket.IO and SignalR wrap frames in their own envelope. Read the envelope, then test the inner action the same way.

Server-sent events push one way over plain HTTP. Check that each stream is scoped to the caller, not shared by channel name.

Message buses such as MQTT appear on device dashboards and IoT backends. A topic is an object name. Subscribe to a topic you should not own and watch for other tenant data.

Next, Chapter 4 covers the tools that send these frames.

Connections2 backlinks · 4 outgoing · 6 cross-guideFull graph →
Open local graph around this page
Open full graph →
Click a node to open · Drag to reposition · Scroll to zoom

WebSocketFor authorized testing only.