← WebSocket Hijacking lesson
Web InfrastructureWebSocket HijackingAdvanced50 min+150 XP

Sandboxed Origin, Real Session

The Lumen Support Inbox delivers support messages over a WebSocket at /ws. Hijack the victim's socket from the attacker origin or abuse the subprotocol role mapping, read the support secret and report it.

“The victim opened the support inbox. My page opened the same socket and read the administrator's messages.”

RFC 6455: The WebSocket ProtocolRFC 9110: HTTP SemanticsOWASP Web Security Testing Guide: Testing WebSocketsOWASP ASVS v4.0.3, chapter 14: configurationHTML Living Standard: origin and sandboxed iframe semantics
The story
A WebSocket is an HTTP upgrade followed by a long-lived bidirectional channel. The handshake still carries cookies and an Origin header, and the server must authorize both. If the server trusts the cookie but not the origin, or maps a client-supplied subprotocol to a role, any page can speak to the socket.

Browsers send cookies with cross-origin WebSocket handshakes according to cookie policy, and they always send an Origin header. A server that authenticates only by cookie allows cross-site WebSocket hijacking: attacker JavaScript opens a socket to the victim host, rides the victim's session and reads or sends messages. A server that accepts Origin: null trusts sandboxed iframes. A server that treats a requested subprotocol as a role lets the client choose its own privilege.

Your objective
  • Inspect the WebSocket handshake and authentication
  • Bypass the origin or role check
  • Read the authenticated inbox
  • Capture the flag
Boundary under test

Browser page origin to WebSocket handshake

Field guide · request anatomy

Where to look before you type a payload

01Upgrade

The browser sends GET /ws with Upgrade: websocket, a key, cookies and an Origin header.

02Authorize

The server authenticates the cookie or ticket and decides whether the origin may open a socket.

03Negotiate

The server selects a subprotocol and returns 101 with Sec-WebSocket-Accept and the chosen protocol.

04Message

Client and server exchange frames; the server must authorize every action, not just the connection.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Inspect the WebSocket handshake and the server's origin policy; the lab mode tells you which trust decision is wrong.

Hint 2

For a normal origin bypass, open the socket from the attacker page with the victim cookie.

Hint 3

The server accepts Origin: null. Open the socket from a sandboxed iframe with allow-scripts but no allow-same-origin.

Hint 4 · near the answer

For the subprotocol flaw, request the admin protocol in the WebSocket constructor and send history.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — Sandboxed Origin, Real Session

- Family: WebSocket Hijacking
- Lab ID: web-websocket-origin-null
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "Sandboxed Origin, Real Session" and record the entry point, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects the entry point, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: The server accepts Origin: null as trustworthy. A sandboxed iframe has an opaque origin and sends null, while the cookie still rides along.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: the WebSocket handshake Origin and subprotocol.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • The server returns 101 but closes the socket before any authenticated message is exchanged.
  • The handshake requires a token that the attacker page cannot obtain; a stolen cookie alone is not enough.
  • The socket only broadcasts public data and accepts no user-specific action.

Regression tests to name

  • Foreign origin is rejected: The handshake is rejected before any message is accepted
  • Null origin is rejected: The connection is closed with a policy error
  • Subprotocol is not a role: The requested protocol does not change the user's server-side role
The defender's move
  • Validate the Origin header against an exact allowlist during the handshake and reject missing or null origins.
  • Authenticate the handshake with a session token, bind the socket to that user and re-check authorization for every message.
  • Never map a client-supplied subprotocol, query parameter or message field directly to a role.
  • Use SameSite cookies, CSRF tokens where appropriate, short-lived socket tickets and server-side channel authorization.
See the secure-code pattern and all 4 regression tests →
الخلاصة

WebSocket Hijacking تستغل غياب التحقق من Origin أو الثقة في بروتوكول يختاره العميل. المتصفح يرسل الكوكي مع مصافحة WebSocket، فإذا اكتفى الخادم بالكوكي تستطيع صفحة المهاجم فتح القناة وقراءة رسائل الضحية. الحل: تحقق من Origin بقائمة تامة، ارفض null، واربط القناة بالجلسة والصلاحية، وأعد التحقق من كل رسالة، ولا تحوّل subprotocol أو حقول العميل إلى أدوار.