Skip to content
CSRF Write-up Intermediate

Account Takeover Using Cross-Site WebSocket Hijacking (CSWH)

The application's WebSocket endpoint accepted connections from any origin without checking the Origin header, so a malicious page could open a WebSocket in the victim's authenticated session. By chaining this with a password reset request, the attacker could read the victim's forgot-password token and reset their password.

Sharan Panegav Follow

Published on medium.com

{{media:0}}

Sharan Panegav, 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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 3 min read.

Context

While hunting on a private program, the researcher found that the application established its connection over WebSocket. The WebSocket URL was checked and found to be vulnerable to Cross-Site WebSocket Hijacking (CSWH). The write-up points readers to Christian Schneider's explanation of CSWH for background: https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html.

The feature that made the attack possible is the forgot password flow. The application exposes a forgotPasswordId value over the WebSocket connection, and after a password reset request is submitted, the same connection carries the forgot password token. Chaining the hijacked WebSocket with the password reset request leads to account takeover.

Setup

The report describes a private program and does not name the target. The report does not spell out preconditions; the attack as described relies on a victim with a valid session and an attacker who can host a page and receive requests on a listener. The tools used were a browser, Burp proxy to capture WebSocket frames, and the public echo page at http://websocket.org/echo.html to open a cross-origin WebSocket connection. No versions are given.

Finding it

The researcher noticed the application was using a WebSocket connection and checked the WebSocket URL. To verify whether it was vulnerable to CSWH, the following steps were used, assuming an application establishing a connection on wss://website.com:

  1. Open the web application in the browser and log in.
  2. Visit http://websocket.org/echo.html in a new tab, enter the WebSocket URL and click 'Connect'.
  3. Once the connection is established, frames can be sent to the server from this page. Capture the WebSocket frames using Burp proxy from a valid session and send them to see how the server responds. If the server responds in the same way as it did for the valid session, it is most likely vulnerable to Cross-Site WebSocket Hijacking.
Image for post
Image for post From the original on medium.com

By following these steps the researcher determined that the application was vulnerable to Cross-Site WebSocket Hijacking. The key observation is that the server responded to frames sent over the cross-origin connection in the same way as it did for the valid session.

Exploitation

Step 1: Read the WebSocket response

Once the WebSocket connection was established on the new tab, the researcher received the following WebSocket response.

Image for post
Image for post From the original on medium.com

In that response there is a parameter forgotPasswordId and its value is null.

Step 2: Obtain a real forgot password token

To complete the attack, the value of _forgotPasswordId had to be determined. The researcher checked the forgot password page and submitted a password reset request.

Image for post
Image for post From the original on medium.com

The WebSocket connection was checked again, and this time the response contained the forgot password token.

Step 3: Chain CSWH with the password reset request

To prepare the account takeover exploit, the CSWH and the password reset request are chained. The researcher prepared a payload, CSWH.html, to send the WebSocket response to the attacker site using XHR. The steps are:

  1. Send the password reset link to the victim (using the forgot password page).
  2. Host CSWH.html and send the URL to the victim (similar to CSRF attacks).
  3. Once the victim clicks on the URL, the WebSocket response arrives on the attacker's listener, as shown below.
Image for post
Response on Webhook Listener of attacker From the original on medium.com

Response on Webhook Listener of attacker

Once the forgot password token is in hand, the victim's password can be reset.

Root cause

The server responded to a WebSocket connection opened from another origin in the same way as to the valid session, so a page on the attacker's site could receive the same responses. The report does not describe the server-side origin checks or session handling in more detail; The report does not analyse why the cross-site connection succeeded.

Impact

An attacker who can get a logged-in victim to visit a hosted page receives the victim's WebSocket responses, including the forgot password token, on a listener they control. With that token the attacker can reset the victim's password and take over the account. As described, the attack involves a victim with a valid session who clicks the attacker's URL.

Fix

The report does not state what was changed.

Variants to test

  • Open the application's WebSocket URL from http://websocket.org/echo.html while logged in. A positive result is a response identical to the one the application itself receives.
  • Capture frames from a valid session with Burp and replay them over the cross-origin connection. A positive result is the same server response as for the valid session.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

A security researcher was testing a private bug bounty program, meaning a company had invited selected researchers to look for security problems in its systems in exchange for a reward. While exploring the application, the researcher noticed that it kept a live, two-way connection open with the browser. This kind of connection is called a WebSocket. The researcher checked the address of that connection and found that the server responded to a connection opened from a different website in the same way as to the logged-in user's session. That weakness is called Cross-Site WebSocket Hijacking, or CSWH for short.

The researcher then found a way to turn that weakness into a full account takeover. After a password reset request was submitted, the WebSocket response contained the forgot password token. By combining the hijacked connection with a password reset request, the researcher could obtain that token and use it to reset the victim's password.

This article walks through the same steps the researcher took, explaining each concept from scratch. You only need a browser and a computer to follow along.

Background concepts

Before diving in, let's define a few terms that will come up repeatedly.

WebSocket: Normally, when your browser talks to a website, it sends a request and waits for a response, then sends another request, and so on. Think of it like sending letters back and forth. A WebSocket is different: it is a persistent, two-way connection that stays open. Think of it like a phone call that remains connected, where both sides can talk at any time without hanging up and redialling. Applications use WebSockets for live features such as chat, notifications, or real-time updates.

Origin: The origin of a web page is the combination of its protocol (http or https), its hostname, and its port. For example, https://example.com and https://other.com are different origins. Browsers use the origin to decide whether one page is allowed to read data from another. This is a core security boundary on the web.

Cross-Site WebSocket Hijacking (CSWH): This is a vulnerability where a WebSocket server accepts connections from any origin, not just its own. Because the browser automatically attaches the user's cookies (including session cookies) to the WebSocket handshake, a malicious page on a different origin can open a connection to the vulnerable server and read the responses as if it were the legitimate application. Think of it like a hotel that lets anyone walk in and ask for your room key just because you are standing nearby.

Session cookie: When you log in to a website, the server gives your browser a small piece of data called a session cookie. Your browser sends this cookie with every subsequent request to that site, so the server knows who you are without asking you to log in again. It is like a wristband you get at an event: as long as you wear it, staff know you are allowed in.

Token: A token is a piece of data that proves something, usually that you have permission to do a specific action. In this case, the forgot password token is a secret value that proves you are allowed to reset a particular account's password. It is like a temporary key that opens one specific door.

XHR (XMLHttpRequest): This is a browser feature that lets JavaScript code send HTTP requests to a server without reloading the page. It is commonly used to fetch data in the background. Think of it as a messenger that runs errands for the page quietly.

Burp proxy: Burp Suite is a tool used by security researchers to intercept and inspect the traffic between a browser and a server. A proxy sits in the middle, like a postman who opens every letter, reads it, and then delivers it. The researcher used Burp to capture WebSocket frames.

Webhook listener: A listener is a service or server that waits for incoming requests. In this context, the attacker sets up a listener to receive the stolen data. Think of it as a mailbox that the attacker controls, where the victim's browser will drop off the stolen token.

CSRF (Cross-Site Request Forgery): This is an attack where a malicious website tricks a logged-in user's browser into sending a request to another site where the user is authenticated. The browser automatically includes the user's cookies, so the request appears legitimate. The researcher compares the delivery step to a CSRF attack because the victim is tricked into visiting a URL.

The setup

The report describes a private program and does not name the target. The report does not spell out preconditions; the attack as described relies on a victim with a valid session and an attacker who can host a page and receive requests on a listener. The tools used were a browser, Burp proxy to capture WebSocket frames, and the public echo page at http://websocket.org/echo.html to open a cross-origin WebSocket connection. No versions are given.

Finding the vulnerability

The researcher noticed the application was using a WebSocket connection and checked the WebSocket URL. To verify whether it was vulnerable to CSWH, the following steps were used, assuming an application establishing a connection on wss://website.com:

  1. Open the web application in the browser and log in.
  2. Visit http://websocket.org/echo.html in a new tab, enter the WebSocket URL and click 'Connect'.
  3. Once the connection is established, frames can be sent to the server from this page. Capture the WebSocket frames using Burp proxy from a valid session and send them to see how the server responds. If the server responds in the same way as it did for the valid session, it is most likely vulnerable to Cross-Site WebSocket Hijacking.
Image for post
Image for post From the original on medium.com

Let's break down each step and explain why it was taken.

Step 1: Log in to the application. This is necessary because the vulnerability only matters if the victim is authenticated. The session cookie is what the server uses to identify the user. Without logging in, there is no session to hijack.

Step 2: Visit the echo page and connect. The echo page at http://websocket.org/echo.html is a simple public tool that lets you open a WebSocket connection to any URL and send messages. The key point is that this page is on a different origin (websocket.org) from the target application. By opening a connection from this page to the application's WebSocket URL, the researcher is simulating what a malicious website would do. If the server accepts the connection and responds as if it were the logged-in user, that is the first sign of CSWH.

Step 3: Capture and replay frames. WebSocket communication happens in frames, which are individual messages sent over the connection. The researcher used Burp proxy to capture the frames that the legitimate application sends during a valid session. Then, from the echo page, the researcher sent those same frames to the server. If the server responds in the same way as it did for the valid session, it means the server is treating the cross-origin connection as the legitimate user's session. That is the confirmation of CSWH.

By following these steps, the researcher determined that the application was vulnerable to Cross-Site WebSocket Hijacking. The key observation is that the server responded to frames sent over the cross-origin connection in the same way as it did for the valid session.

Exploitation

Step 1: Read the WebSocket response

Once the WebSocket connection was established on the new tab, the researcher received the following WebSocket response.

Image for post
Image for post From the original on medium.com

In that response there is a parameter forgotPasswordId and its value is null.

Let's explain what this means. The WebSocket response contains data sent by the server. Among that data is a parameter named forgotPasswordId. A parameter is simply a named value, like a field in a form. The value of forgotPasswordId is null, which means it is empty or not set. This is expected because the researcher had not yet requested a password reset. The parameter is present with a null value, which is what the researcher observed before requesting a reset. If the researcher can trigger a password reset and then read the WebSocket response, the value might change from null to a real token.

Step 2: Obtain a real forgot password token

To complete the attack, the value of _forgotPasswordId had to be determined. The researcher checked the forgot password page and submitted a password reset request.

Image for post
Image for post From the original on medium.com

The WebSocket connection was checked again, and this time the response contained the forgot password token.

Why did the researcher do this? The goal is to make the server generate a real password reset token for the victim's account. After submitting a password reset request through the forgot password page, the researcher checked the WebSocket connection again and the response contained the forgot password token. The researcher then checked the WebSocket response again and saw that the forgotPasswordId parameter now had a real value, the forgot password token. This token is the key to resetting the victim's password.

Step 3: Chain CSWH with the password reset request

To prepare the account takeover exploit, the CSWH and the password reset request are chained. The researcher prepared a payload, CSWH.html, to send the WebSocket response to the attacker site using XHR. The steps are:

  1. Send the password reset link to the victim (using the forgot password page).
  2. Host CSWH.html and send the URL to the victim (similar to CSRF attacks).
  3. Once the victim clicks on the URL, the WebSocket response arrives on the attacker's listener, as shown below.
Image for post
Response on Webhook Listener of attacker From the original on medium.com

Response on Webhook Listener of attacker

Let's walk through this chain step by step.

Step 1: Send the password reset link to the victim. The attacker first triggers a password reset for the victim's account using the forgot password page. After the reset request, the WebSocket response contained the forgot password token. However, the attacker cannot read the victim's WebSocket connection directly. So the attacker needs the victim to open a WebSocket connection from the attacker's page.

Step 2: Host CSWH.html and send the URL to the victim. The attacker creates an HTML page (CSWH.html) that sends the WebSocket response to the attacker's site using XHR. The attacker hosts this page and sends the URL to the victim. This is similar to a CSRF attack, where the victim is tricked into visiting a malicious page.

Step 3: The victim clicks the URL. When the victim clicks the link, their browser loads the attacker's page. The JavaScript on that page opens a WebSocket connection to the vulnerable application. The victim's browser opens the connection, and the WebSocket response containing the forgot password token arrives on the attacker's listener. The JavaScript then takes that data and sends it to the attacker's listener using XHR. The attacker receives the token on their listener, as shown in the image.

Once the forgot password token is in hand, the victim's password can be reset.

Root cause

The server responded to a WebSocket connection opened from another origin in the same way as to the valid session, so a page on the attacker's site could receive the same responses. The report does not describe the server-side origin checks or session handling in more detail; The report does not analyse why the cross-site connection succeeded.

Impact

An attacker who can get a logged-in victim to visit a hosted page receives the victim's WebSocket responses, including the forgot password token, on a listener they control. With that token the attacker can reset the victim's password and take over the account. As described, the attack involves a victim with a valid session who clicks the attacker's URL.

Fix

The report does not state what was changed.

Variants to test

  • Open the application's WebSocket URL from http://websocket.org/echo.html while logged in. A positive result is a response identical to the one the application itself receives.
  • Capture frames from a valid session with Burp and replay them over the cross-origin connection. A positive result is the same server response as for the valid session.

Glossary

  • WebSocket: A persistent, two-way connection between a browser and a server that stays open, allowing both sides to send messages at any time.
  • Origin: The combination of protocol, hostname, and port that identifies where a web page came from; browsers use it to enforce security boundaries.
  • Cross-Site WebSocket Hijacking (CSWH): A vulnerability where a WebSocket server accepts connections from any origin, allowing a malicious site to read the victim's WebSocket data using the victim's session.
  • Session cookie: A small piece of data stored by the browser and sent with requests to a site, used by the server to identify the logged-in user.
  • Token: A piece of data that proves permission or identity, often used for one-time actions like password resets.
  • XHR (XMLHttpRequest): A browser API that lets JavaScript send HTTP requests to a server without reloading the page.
  • Burp proxy: A tool that intercepts and inspects traffic between a browser and a server, used by security researchers.
  • Webhook listener: A server or service that waits for incoming requests, used by an attacker to receive stolen data.
  • CSRF (Cross-Site Request Forgery): An attack where a malicious site tricks a logged-in user's browser into sending a request to another site where the user is authenticated.
  • Frame: A single message sent over a WebSocket connection.
  • Parameter: A named value in a request or response, like a field in a form.
  • Origin header: An HTTP header sent by the browser that indicates the origin of the request; servers can use it to decide whether to allow the request.

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.