Skip to content
CORS Write-up Intermediate

How I Got $5,000 for Out-of-Scope XSS

A CORS misconfiguration on an API endpoint allowed any origin to read user PII with credentials, but the SameSite cookie flag normally blocked the attack. The author chained it with a self-XSS on a user-controlled subdomain to bypass the cookie restriction and steal PII.

Mahmoud Hamed Follow

Published on 7odamoo.medium.com

Bounty$5,000 View original

Mahmoud Hamed

Mahmoud Hamed, on 7odamoo.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. 6 min read.

Context

The target was a private bug bounty program on HackerOne. The program's business is, in the author's words, "an online content management system and website builder". When a user creates an account, they receive a unique subdomain of the form <YOUR-SUB>.target.com, and that subdomain can be customised.

Because of this structure, XSS on <YOUR-SUB>.target.com is effectively self-XSS: the only person who can be made to run script on a given subdomain is the owner of that subdomain. The program's policy therefore excludes XSS on <YOUR-SUB>.target.com from scope, and XSS in general is listed as out of scope. The author had already reported other issues to the program, including broken access control and leaking other users' authorisation tokens.

This write-up covers one of several XSS chains the author found. It is the only one that had been resolved at the time of writing; the others were still open and were to be written up separately once resolved.

Setup

The only tool described is the CORS Burp Extension* from the PortSwigger BApp Store. The workflow is to tick the "Activate CORS*" checkbox and then browse the target normally, letting the extension attempt different CORS bypass techniques on every request that passes through the Burp proxy. The researcher then reviews the results the extension reports.

Preconditions for the chain:

  1. An account on the target, which gives the researcher a subdomain <MY-SUB>.target.com they control and can inject script into.
  2. A CORS misconfiguration on an endpoint that returns sensitive data.
  3. A victim who is logged in to www.target.com and who visits the attacker's subdomain.

Finding it

Finding the self-XSS took little time, and the author treats it as the easy half of the chain. On its own it is out of scope, so the goal became to find a second bug that the self-XSS could be chained with to demonstrate real impact.

With that in mind, the researcher tested the site specifically looking for bugs to chain. One of the classes tested was CORS misconfiguration, using the Burp extension described above. After activating the extension and browsing, it flagged a possible CORS misconfiguration on:

Text
www.target.com/api/me

That API request is responsible for fetching user PII: first name, last name, email and account ID.

The evidence was a request carrying an attacker-controlled origin:

HTTP
Origin: 7odamoo-target.com

and a response that reflected it while also allowing credentials:

Text
Access-Control-Allow-Credentials: trueAccess-Control-Allow-Origin: 7odamoo-target.com

(The two headers are shown run together in the report; they are the Access-Control-Allow-Credentials: true and Access-Control-Allow-Origin: 7odamoo-target.com response headers.)

Reflecting an arbitrary origin together with Access-Control-Allow-Credentials: true would let any site read the authenticated response from /api/me in a victim's browser, but the SameSite cookie flag prevented that from an arbitrary domain. The normal next step would be to register 7odamoo-target.com, host a CORS proof of concept on it and show the exploit to the team.

That step turned out not to be necessary. When the researcher checked the cookie flags, the obstacle was the SameSite cookie flag: the browser would not include the cookie in the cross-site request unless the origin was allowed. So a plain external domain hosting the PoC would not receive the victim's authenticated data.

Exploitation

The insight is that the SameSite restriction is about the origin of the page making the request. A page served from <MY-SUB>.target.com is same-site with www.target.com, so the cookie is attached. The out-of-scope self-XSS gives the attacker script execution on exactly such an origin.

Step 1: inject the script on the attacker's own subdomain

The researcher injected the following script on their own subdomain <MY-SUB>.target.com:

JavaScript
function cors() {  var xhttp = new XMLHttpRequest();  xhttp.onreadystatechange = function() {    if (this.readyState == 4 && this.status == 200) {      document.getElementById("demo").innerHTML = alert(this.responseText);    }  };  xhttp.onload = cors;  xhttp.open("GET", "https://www.target.com/api/me", true);  xhttp.withCredentials = true;  xhttp.send();}cors();

What the important parts do:

  • xhttp.open("GET", "https://www.target.com/api/me", true) targets the vulnerable API endpoint from the attacker's subdomain.
  • xhttp.withCredentials = true makes the browser send cookies with the cross-origin request and expose the response to the script, which is only possible because the server returns Access-Control-Allow-Credentials: true and reflects the requesting origin.
  • alert(this.responseText) displays the returned PII in a popup as the proof of concept.

Step 2: the victim visits the subdomain

When anyone visits the attacker's subdomain, the injected script runs in the context of <MY-SUB>.target.com. Because that origin is same-site with www.target.com, the browser includes the victim's cookie in the request to www.target.com/api/me. The CORS misconfiguration then lets the script read the response, and the victim's PII is shown in the alert popup.

This chained the CORS misconfiguration with the out-of-scope XSS to bypass the origin check enforced by the SameSite cookie flag.

Root cause

The server-side mistake is the CORS configuration on www.target.com/api/me: it reflects an arbitrary Origin value into Access-Control-Allow-Origin while sending Access-Control-Allow-Credentials: true. That combination authorises any origin to make credentialed reads of the endpoint.

The reason this was not already exploitable from an arbitrary domain is the SameSite cookie flag, which stops the browser from attaching the cookie to a cross-site request. The program treats XSS on <YOUR-SUB>.target.com as self-XSS and excludes it from scope. Both defences fail once the two issues are combined: the subdomain is same-site with www.target.com, so the cookie is sent, and the permissive CORS policy lets the response be read.

Impact

An attacker who can place script on a subdomain of the target can read the PII of any logged-in user who visits that subdomain: first name, last name, email and account ID, as returned by /api/me. The attack requires the victim to visit the attacker's subdomain while authenticated on www.target.com. The author demonstrated the read with an alert popup rather than exfiltrating the data to a server.

Fix

The team fixed the CORS misconfiguration. After the fix they no longer allow *.target.com to read the response from www.target.com. The report does not describe the exact allow-list logic that replaced the reflected origin.

Variants to test

  1. Reflected origin with credentials on other API endpoints. Send requests with a foreign Origin header to endpoints that return account data and look for Access-Control-Allow-Origin echoing the value together with Access-Control-Allow-Credentials: true. A positive result is a response whose body contains the victim's data and whose CORS headers permit a credentialed read from your origin.
  2. Subdomain-based same-site bypass. Where a program excludes XSS on user-controlled subdomains, check whether those subdomains are same-site with the main application and whether any sensitive endpoint has a permissive CORS policy. A positive result is a script on the subdomain reading an authenticated response from the main domain.
  3. Cookie flag review. Before building an external PoC domain, inspect the session cookie's SameSite attribute. If it is not None, look for an execution context on a same-site origin instead of an external one.
  4. Automated CORS probing. Run the CORS* Burp Extension with "Activate CORS*" ticked while browsing authenticated areas, then review the flagged requests. A positive result is a flagged request where the reflected origin is one you control and credentials are allowed.
  5. Chain inventory. Enumerate low-severity or out-of-scope issues (self-XSS, open redirects, subdomain takeover) and test each against the sensitive endpoints for a combination that restores impact. A positive result is any pair where the first issue supplies the origin or execution context and the second supplies the data read.

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

What happened, in plain words

A security researcher was invited to a private bug bounty program on HackerOne. A bug bounty program is a deal between a company and independent testers: the company says which parts of its systems may be tested, and pays for real security problems that are reported. The company in this story runs, in the researcher's words, "an online content management system and website builder". That means people sign up and use it to build websites and manage content, a bit like a hosted tool for making pages without writing code.

When someone creates an account on this product, they get their own small piece of the company's website, at an address of the form <YOUR-SUB>.target.com. Think of target.com as a large building and <YOUR-SUB> as a room inside it that the customer is allowed to decorate. The customer can customise that room.

Because every customer has their own room, a script injection attack (XSS, explained below) on <YOUR-SUB>.target.com can only ever affect the person who owns that subdomain. The program's policy therefore treats XSS on those subdomains as out of scope, and XSS in general is listed as out of scope. Out of scope means the company is not inviting reports about that kind of issue and will not pay for it on its own.

The researcher had already reported other issues to the program, including broken access control (users being able to do things they should not be allowed to do) and leaking other users' authorisation tokens (explained in the glossary). This write-up is about one of several XSS chains the researcher found. A chain means combining two or more small issues so that together they do something serious. This was the only chain that had been resolved at the time of writing; the others were still open and were to be written up separately once resolved.

The story is a good lesson for beginners: a bug that looks harmless on its own can become serious when it is combined with a second bug. The researcher's whole approach was to find the harmless half first, then hunt for a partner for it.

The setup

The only tool described in the report is the CORS Burp Extension* from the PortSwigger BApp Store. Burp is a program that sits between your browser and a website and lets you look at, and change, every request and response. An extension is an add-on for Burp. This particular add-on watches the traffic and tries different tricks against the website's CORS settings (explained below) automatically.

The workflow is simple: tick the "Activate CORS*" checkbox, then browse the target normally. The extension attempts different CORS bypass techniques on every request that passes through the Burp proxy, and the researcher reviews the results it reports. You do not have to craft anything by hand; you just use the site and read what the add-on flags.

For the chain to work, three things had to be true at the same time:

  1. The researcher had an account on the target, which gave them a subdomain <MY-SUB>.target.com they controlled and could inject script into.
  2. There was a CORS misconfiguration on an endpoint that returns sensitive data.
  3. A victim was logged in to www.target.com and visited the attacker's subdomain.

Each of those is explained as it comes up below.

Finding it

Finding the self-XSS took little time, and the author treats it as the easy half of the chain. Self-XSS means the only person who can be made to run the malicious script is you, on your own account. On its own it is out of scope, so the goal became to find a second bug that the self-XSS could be chained with to demonstrate real impact.

With that in mind, the researcher tested the site specifically looking for bugs to chain. One of the classes tested was CORS misconfiguration, using the Burp extension described above. CORS is a browser rule about which websites are allowed to read responses from other websites; a misconfiguration is when a site sets that rule too loosely. After activating the extension and browsing, it flagged a possible CORS misconfiguration on:

Text
www.target.com/api/me

An API is a way for one piece of software to ask another for data, usually over the web, without a human clicking anything. The path /api/me is the address of one such request. That API request is responsible for fetching user PII: first name, last name, email and account ID. PII stands for personally identifiable information, data that identifies a real person.

The evidence was a request carrying an attacker-controlled origin:

HTTP
Origin: 7odamoo-target.com

The Origin header is a label the browser attaches to a request saying which website the request came from. Here the researcher made the request claim to come from 7odamoo-target.com, a domain they chose, not from the target's own site. The response reflected it while also allowing credentials:

Text
Access-Control-Allow-Credentials: trueAccess-Control-Allow-Origin: 7odamoo-target.com

These are two response headers shown run together in the report. Access-Control-Allow-Origin is the server's answer to the browser saying "this origin is allowed to read my response". Access-Control-Allow-Credentials: true says "and it may do so while carrying the user's login cookies". Cookies are small pieces of data the browser stores for a site and sends back with each request; the login cookie is what tells the server who you are.

Reflecting an arbitrary origin together with Access-Control-Allow-Credentials: true would let any site read the authenticated response from /api/me in a victim's browser, but the SameSite cookie flag stopped that from an arbitrary domain. In everyday terms: the server is a receptionist who will hand over your personal file to anyone who says a name, as long as the visitor is wearing your badge.

The normal next step would be to register 7odamoo-target.com, host a CORS proof of concept on it and show the exploit to the team. A proof of concept is a small demonstration that the problem is real, not theoretical.

That step turned out not to be necessary. When the researcher checked the cookie flags, the obstacle was the SameSite cookie flag: the browser would not include the cookie in the cross-site request unless the origin was allowed. SameSite is a setting on a cookie that tells the browser when to send it: a cookie marked SameSite will not be attached to requests going to a different site. So a plain external domain hosting the PoC would not receive the victim's authenticated data. The receptionist would still hand over the file, but the visitor would not be wearing the badge, because the browser refuses to lend it across sites.

Exploitation

The insight is that the SameSite restriction is about the origin of the page making the request. A page served from <MY-SUB>.target.com is same-site with www.target.com, so the cookie is attached. Same-site means the two addresses belong to the same registered domain, like two rooms in the same building. The out-of-scope self-XSS gives the attacker script execution on exactly such an origin.

Step 1: inject the script on the attacker's own subdomain

The researcher injected the following script on their own subdomain <MY-SUB>.target.com:

JavaScript
function cors() {  var xhttp = new XMLHttpRequest();  xhttp.onreadystatechange = function() {    if (this.readyState == 4 && this.status == 200) {      document.getElementById("demo").innerHTML = alert(this.responseText);    }  };  xhttp.onload = cors;  xhttp.open("GET", "https://www.target.com/api/me", true);  xhttp.withCredentials = true;  xhttp.send();}cors();

Line by line, in plain words:

  • function cors() { starts the definition of a function, a named block of instructions that can be run later. The name cors is just a label.
  • var xhttp = new XMLHttpRequest(); creates an object that a web page can use to send a request to a server in the background, without reloading the page. Think of it as a messenger the page can send out.
  • xhttp.onreadystatechange = function() { says: whenever the state of that request changes, run the following instructions. The state changes as the request is prepared, sent, and answered.
  • if (this.readyState == 4 && this.status == 200) { checks two things: readyState == 4 means the request has finished, and status == 200 means the server answered successfully. Only then does the next line run.
  • document.getElementById("demo").innerHTML = alert(this.responseText); takes the text the server sent back (this.responseText, which is the PII) and shows it in a popup box on screen using alert. The document.getElementById("demo").innerHTML = part assigns the result of the popup to an element on the page; the visible effect for the proof of concept is the popup showing the data.
  • }; closes the function that runs when the state changes.
  • xhttp.onload = cors; sets the function cors to run again when the request finishes loading. In this snippet it is part of the original code as written.
  • xhttp.open("GET", "https://www.target.com/api/me", true); prepares the request: GET means "fetch this", the URL is the vulnerable API endpoint, and true means do it in the background without freezing the page. This is the line that targets the endpoint from the attacker's subdomain.
  • xhttp.withCredentials = true; tells the browser to include the user's cookies with this request and to let the script read the answer. This only works because the server returns Access-Control-Allow-Credentials: true and reflects the requesting origin.
  • xhttp.send(); actually sends the request.
  • }cors(); closes the function definition and then calls cors() straight away, so the request goes out as soon as the page loads.

Step 2: the victim visits the subdomain

When anyone visits the attacker's subdomain, the injected script runs in the context of <MY-SUB>.target.com. Because that origin is same-site with www.target.com, the browser includes the victim's cookie in the request to www.target.com/api/me. The CORS misconfiguration then lets the script read the response, and the victim's PII is shown in the alert popup.

This chained the CORS misconfiguration with the out-of-scope XSS to bypass the origin check enforced by the SameSite cookie flag. In plain terms: the SameSite rule was doing its job, but the attacker found a page that the browser considers part of the same building, and put the script there.

Root cause

The server-side mistake is the CORS configuration on www.target.com/api/me: it reflects an arbitrary Origin value into Access-Control-Allow-Origin while sending Access-Control-Allow-Credentials: true. That combination authorises any origin to make credentialed reads of the endpoint.

The reason this was not already exploitable from an arbitrary domain is the SameSite cookie flag, which stops the browser from attaching the cookie to a cross-site request. The program treats XSS on <YOUR-SUB>.target.com as self-XSS and excludes it from scope. Both defences fail once the two issues are combined: the subdomain is same-site with www.target.com, so the cookie is sent, and the permissive CORS policy lets the response be read.

Impact

An attacker who can place script on a subdomain of the target can read the PII of any logged-in user who visits that subdomain: first name, last name, email and account ID, as returned by /api/me. The attack requires the victim to visit the attacker's subdomain while authenticated on www.target.com. The author demonstrated the read with an alert popup rather than exfiltrating the data to a server. Exfiltrating means quietly sending the stolen data somewhere the attacker can collect it; the popup was enough to prove the data could be read.

Fix

The team fixed the CORS misconfiguration. After the fix they no longer allow *.target.com to read the response from www.target.com. The report does not describe the exact allow-list logic that replaced the reflected origin.

Variants to test

These are the same ideas generalised, so a beginner can try them on a target they are authorised to test:

  1. Reflected origin with credentials on other API endpoints. Send requests with a foreign Origin header to endpoints that return account data and look for Access-Control-Allow-Origin echoing the value together with Access-Control-Allow-Credentials: true. A positive result is a response whose body contains the victim's data and whose CORS headers permit a credentialed read from your origin.
  2. Subdomain-based same-site bypass. Where a program excludes XSS on user-controlled subdomains, check whether those subdomains are same-site with the main application and whether any sensitive endpoint has a permissive CORS policy. A positive result is a script on the subdomain reading an authenticated response from the main domain.
  3. Cookie flag review. Before building an external PoC domain, inspect the session cookie's SameSite attribute. If it is not None, look for an execution context on a same-site origin instead of an external one.
  4. Automated CORS probing. Run the CORS* Burp Extension with "Activate CORS*" ticked while browsing authenticated areas, then review the flagged requests. A positive result is a flagged request where the reflected origin is one you control and credentials are allowed.
  5. Chain inventory. Enumerate low-severity or out-of-scope issues (self-XSS, open redirects, subdomain takeover) and test each against the sensitive endpoints for a combination that restores impact. A positive result is any pair where the first issue supplies the origin or execution context and the second supplies the data read.

Glossary

  • API: a way for one piece of software to ask another for data over the web, usually without a human clicking anything.
  • Authorisation token: a piece of data, often a long string, that proves a request is allowed to act on behalf of a user.
  • Broken access control (BAC): a flaw where users can do things they should not be permitted to do, such as reading another user's data.
  • Bug bounty program: an arrangement where a company invites independent testers to look for security problems and pays for valid reports.
  • Chain: two or more small issues combined so that together they cause more harm than either alone.
  • Cookie: a small piece of data a browser stores for a website and sends back with later requests; the login cookie identifies the user.
  • CORS: a browser rule that decides which websites are allowed to read responses from other websites.
  • CORS misconfiguration: a CORS setup that is too permissive, for example allowing any origin to read a response.
  • CORS Burp Extension*: an add-on for Burp that automatically tries CORS bypass techniques on traffic passing through the proxy.
  • Credentials: in this context, the cookies that identify a logged-in user.
  • Cross-site request: a request sent from a page on one site to a different site.
  • Endpoint: a specific address on a server that performs a particular action, such as /api/me.
  • Exfiltration: quietly sending stolen data to a place the attacker can collect it.
  • Header: a labelled piece of information attached to a request or response, such as Origin or Access-Control-Allow-Origin.
  • HackerOne: a platform where bug bounty programs are run and reports are submitted.
  • Origin: the combination of scheme, host and port that identifies where a page came from, for example https://www.target.com.
  • Out of scope: a part of a system, or a class of issue, that the program does not invite reports about and will not pay for on its own.
  • PII (personally identifiable information): data that identifies a real person, such as a name, email address or account ID.
  • Proof of concept (PoC): a small demonstration that a problem is real.
  • Proxy: a program that sits between your browser and a website and lets you inspect and change the traffic.
  • SameSite: a cookie setting that tells the browser when to send the cookie, in particular whether to send it on cross-site requests.
  • Same-site: two addresses that belong to the same registered domain, such as <MY-SUB>.target.com and www.target.com.
  • Self-XSS: a script injection that can only affect the person who runs it, on their own account.
  • Subdomain: a smaller address inside a larger domain, such as <YOUR-SUB>.target.com inside target.com.
  • XSS (cross-site scripting): a flaw that lets an attacker get their own script to run inside another person's browser on a website.
  • Access-Control-Allow-Credentials: a response header that says whether a cross-origin request may carry the user's cookies.
  • Access-Control-Allow-Origin: a response header that says which origin is allowed to read the response.
  • Origin: a request header that tells the server which website the request came from.
  • withCredentials: a setting on a browser request that tells it to include cookies and to let the script read the answer.

More by Mahmoud Hamed

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

CORS misconfiguration

The lesson behind this report.

A permissive cross-origin policy lets another site read responses with the user's credentials.