Skip to content
CSRF Write-up Intermediate

How Cross-Site WebSocket Hijacking (CSWSH) Leads to Unauthenticated State Modification

The WebSocket endpoint authenticated upgrade requests using only the session cookie and did not validate the Origin header, so any website could open an authenticated socket for a logged-in user. The cross-origin script could then read pushed messages and send commands such as changing the account email.

T4nv1 Follow

Published on medium.com

While HTTP APIs rely heavily on headers like Authorization or custom headers (X-Requested-With) to protect against Cross-Site Request Forgery (CSRF), WebSocket upgrades depend on standard HTTP requests during the initial handshake.

T4nv1, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The server validated the session cookie on the WebSocket upgrade but did not check the Origin header or require a one-time handshake token.

Impact

An attacker could read real-time data pushed to the victim and perform state changes such as changing the account email, though the text does not show a full account takeover.

What the attacker needed

Victim logged in to the target; victim visits an attacker-controlled page; session cookie sent cross-site

The fix

The server should validate the Origin header against an allowlist, require a short-lived one-time token during the handshake, and set session cookies to SameSite=Strict or Lax.

How it was found

  1. From a different origin, open a WebSocket to the target's stream endpoint.
  2. Observe that the browser attaches the session cookie and the handshake succeeds despite the foreign Origin.
  3. Send a JSON frame instructing the server to change the account email.
  4. Read incoming messages through the onmessage handler.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A WebSocket is a two-way connection a web page keeps open with a server. Browsers attach a user's login cookie to the opening request even when another website starts it, so the server must check which site is asking. Here it did not, letting a malicious page act as the logged-in user.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

More by T4nv1

View all

113 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.