Lion Cipher Lab

Exploit and fix Cross-Site WebSocket Hijacking (CSWSH) in your own lab

Why it matters

Cross-Site WebSocket Hijacking (CSWSH) is CSRF's overlooked, more dangerous cousin. A WebSocket does not begin life as a WebSocket: it begins as a plain HTTP GET carrying an Upgrade header, and because that request is bound for the target site, the browser attaches the target's cookies to it automatically. The trap is that the Same-Origin Policy, which stops a random page from READING your webmail, does NOT stop that page from OPENING a WebSocket to your server -- there is no CORS gate on the handshake. So if a server authenticates each socket purely from the ambient session cookie and never…

What you'll learn

Steps in this lab

  1. What CSWSH is -- the handshake, the cookie, and the missing gate
  2. Set up: confirm Node, make a folder, install ws and express
  3. Build the VULNERABLE app (the socket trusts the cookie, checks no Origin)
  4. Run it and confirm the legit dashboard works
  5. Exploit: hijack the socket from a different origin and exfiltrate
  6. Why the naive origin check is worthless -- and what the root cause really is
  7. Fix it: exact-match Origin allowlist on the handshake + a session-bound token
  8. Re-test: confirm the hijack is dead and the real feed still works
  9. The judgment: SameSite, WSS, and the pro pattern to keep

Open the full interactive lab →