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.
- Inspect the WebSocket handshake and authentication
- Bypass the origin or role check
- Read the authenticated inbox
- Capture the flag
Browser page origin to WebSocket handshake
Where to look before you type a payload
The browser sends GET /ws with Upgrade: websocket, a key, cookies and an Origin header.
The server authenticates the cookie or ticket and decides whether the origin may open a socket.
The server selects a subprotocol and returns 101 with Sec-WebSocket-Accept and the chosen protocol.
Client and server exchange frames; the server must authorize every action, not just the connection.
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 handshake has no origin check. Open ws://lab.localhost:3000/ws from the attacker page with the victim cookie and send history.
Hint 4 · near the answer
For the subprotocol flaw, request the admin protocol in the WebSocket constructor and send history.
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.
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 — The Inbox With No Origin Check - Family: WebSocket Hijacking - Lab ID: web-websocket-no-origin - Date: 2026-12-05 ## Workflow ### Observe - [ ] Open "The Inbox With No Origin Check" 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 WebSocket handshake authenticates with the cookie but never checks Origin. A page on the attacker origin can open the same socket and read the inbox. - [ ] 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.
The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.
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
- 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.
WebSocket Hijacking تستغل غياب التحقق من Origin أو الثقة في بروتوكول يختاره العميل. المتصفح يرسل الكوكي مع مصافحة WebSocket، فإذا اكتفى الخادم بالكوكي تستطيع صفحة المهاجم فتح القناة وقراءة رسائل الضحية. الحل: تحقق من Origin بقائمة تامة، ارفض null، واربط القناة بالجلسة والصلاحية، وأعد التحقق من كل رسالة، ولا تحوّل subprotocol أو حقول العميل إلى أدوار.