Chapter 2
Cross-site WebSocket hijacking
The browser can attach the session cookie. The server has to notice the Origin.
Cross-site WebSocket hijacking, tracked as CWE-1385 and first named by Christian Schneider in 2013, should be the very first test you run on any socket. It shows up far more often than teams expect, and its impact matches whatever that socket can do. Worse, a hijacked socket acts as the victim the moment they visit your page, with zero clicks on the target app.
Here is how it works. Any page on another domain can open a WebSocket to the target, and the browser happily attaches the victim’s session cookies to the upgrade request. If the server skips checking the Origin header, it upgrades the connection as the logged-in user. Your page can then read incoming frames and send commands for as long as the tab stays open.
Verify this safely with two accounts you own. Host the test page as Alice, log in as Bob in the same browser, and stop once one read or write proves the flaw.
Why CSWSH hits harder than classic CSRF
Section titled “Why CSWSH hits harder than classic CSRF”Classic cross-site request forgery is blind and one-way. You fire a single forged request, and the browser blocks your script from reading the response. CSWSH gives you a live, two-way channel. Your script reads private data coming off the server and sends follow-up actions in real time until the victim closes the tab.
Why CORS will not save the target
Section titled “Why CORS will not save the target”Browsers attach an Origin header to every page-initiated WebSocket handshake, but they do not enforce CORS on the WebSocket API. A missing Access-Control-Allow-Origin header stops nothing. As long as the server replies with 101 Switching Protocols, the browser hands the live socket straight to the calling script.
Never assume a strict CORS policy on the main REST API protects the socket. Socket handlers often live in a separate service written at a different time, so always send the handshake and check.
The test page
Section titled “The test page”Serve this from an origin you control. Log Account B into the target in that same browser first.
const ws = new WebSocket("wss://target.com/chat");ws.onopen = () => { ws.send(JSON.stringify({action: "get_history"}));};ws.onmessage = (event) => { console.log(event.data);};If Origin is not checked, get_history runs as Account B.
Any other action that socket accepts can be sent the same way.
onmessage is how you see the read, not only the write.
The handshake that shows the hole
Section titled “The handshake that shows the hole”GET /chat HTTP/1.1Host: target.comCookie: session=ACCOUNT_B_SESSIONOrigin: https://evil.comThe browser adds the Cookie line. Your script does not. Script on the other origin cannot read an HttpOnly cookie. It does not need to read it. The browser attaches the cookie.
- Copy the real handshake from Burp.
- Change Origin to a host you control.
- Send it with the Account B cookie.
- If the status is still 101, record CSWSH.
- Remove Origin and send the handshake again.
- Set Origin to the value null and send it again.
A strict server refuses the odd Origin and closes. A careless server returns 101 for any Origin. There are many careless servers.
Severity follows the actions
Section titled “Severity follows the actions”A chat or notification socket can show live personal data. The same socket can often send messages as that user. A price feed or an order feed discloses data on each update. An action socket can place trades, send messages, or read files as the user.
If the socket can send orders, say that in the first line of the report. Call it a cross-site action on a live account, with a live read. That report is high or critical when the actions are real. A notification socket is medium or high, based on the personal data in the frames. These are starting points. The program scale still wins.
SameSite is a measurement
Section titled “SameSite is a measurement”Older notes say a SameSite=Lax cookie still rides this handshake.
Do not file that sentence as a current fact. Test it.
Include Security published a browser test in April 2025.
In Chrome, this handshake is not a top-level navigation.
Chrome did not attach a Lax cookie to a cross-site socket.
Their result was that cross-site CSWSH needed SameSite=None.
Firefox Total Cookie Protection blocked the cross-site cookie even then.
Browser rules change. Repeat the test on the version in front of you.
Same-site is a different bucket.
https://evil.target.com and https://app.target.com share a site.
A Lax cookie is still sent to a same-site host.
Praetorian’s notes on CVE-2024-26135 show the split.
Lax stopped a fully cross-site page on that product.
An origin under the same registrable domain was not the same story.
If you can run script on a subdomain, run the CSWSH test again.
Record the cookie attributes beside the result.
| Cookie attribute | What to observe on a cross-site handshake |
|---|---|
| SameSite=None, Secure | The browser sends it, unless partitioning blocks third-party cookies |
| SameSite=Lax | Do not assume. Chrome withheld it in the April 2025 test |
| SameSite=Strict | The browser usually withholds it cross-site |
| HttpOnly | Does not remove it from the handshake. Script still cannot read it |
What stops the browser test
Section titled “What stops the browser test”An allow-list of exact Origin values stops it. The list has to reject null, prefixes, and suffixes. Chapter 3 has those probes. A secret the other origin cannot read also stops it.
The constructor cannot set arbitrary headers.
It can set Sec-WebSocket-Protocol.
It can put fields in the query string.
A CSRF token that exists only in a header the constructor cannot set is out of reach.
A CSRF token stored in a cookie the browser will attach is not a second secret.
A token in the first frame stops the test only when the other origin cannot obtain it.
A token in localStorage of the target origin is not readable by the test page.
Prove that. Do not assume the first frame is protected.
Public cases
Section titled “Public cases”These are existence proofs, not procedures. A CVE is a public vulnerability id.
CVE-2020-25095. A security information and event management console did not check Origin. CWE-1385 cites it. CVE-2018-6651. The Origin check used a substring, so a lookalike host matched. CVE-2018-14730. A socket on localhost did not check Origin. CVE-2024-26135. MeshCentral. Read it for the SameSite and same-site split, not for steps.
Next, Chapter 3 covers the other socket bug families.
Open local graph around this page
Linked from here
Links out to
No outgoing internal links on this page.
WebSocketFor authorized testing only.