Skip to content
OAuth / SSO Write-up Intermediate

Open Redirect to Account Takeover

An open redirect in the OAuth login flow allowed an attacker to redirect the victim's access token to an attacker-controlled URL. The attacker could then use the token to make API calls on behalf of the victim.

z3r0tru5t.medium.com

Published on z3r0tru5t.medium.com

Bug Bounty

z3r0tru5t, on z3r0tru5t.medium.com

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

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

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

Context

This is a write-up from the group z3r0tru5t, published on Medium on 3 June 2021. It describes an open redirect in an OAuth login flow that led to account takeover. The target is referred to only as target.com; the report does not name the product or the program.

The feature involved is the login page of the target, which is an OAuth authorisation endpoint. When a user navigates to the login page, the application builds a URL containing a state value, the protocol=oauth2 marker, a response_type of token id_token, and a redirect_uri pointing back at the target itself. After a successful login, the OAuth flow returns the user's token to the address given in redirect_uri.

Setup

No accounts, roles, tools or versions are described. The only precondition shown is that the attacker needs the victim to open a crafted login URL and complete a successful login, which the author frames as a phishing step.

Finding it

The researcher identified a target containing an open redirect URL parameter:

Text
redirect_uri=https://target.com

Changing target.com to an attacker-controlled URL did not work. The researcher then stepped back and looked at the full URL produced when navigating to the login page:

Text
https://target.com/login?state=XXXXX&protocol=oauth2&response_type=token%20id_token&redirect_uri=https%3A%2F%2Ftarget.com%2F

This is a standard OAuth authorisation request: state carries the anti-CSRF value, protocol=oauth2 selects the OAuth flow, response_type=token%20id_token asks for an access token and an ID token, and redirect_uri is the callback. Because the callback is validated, tampering with redirect_uri alone was rejected.

Exploitation

Step 1: add a second redirect parameter

While redirect_uri did not work, appending &redirect_to did. The proof of concept is:

The URL keeps the legitimate redirect_uri value and adds a redirect_to parameter pointing at the attacker's host. Appending redirect_to pointing at the attacker's host worked, and the token was forwarded there.

Step 2: the token is forwarded to the attacker

After a successful login, the victim's access token is forwarded to the server hosting the redirect_to URI, appearing in the URL bar as:

Text
https://attacker.com/#<ACCESS_TOKEN>

The token appears in the URL bar at the attacker's host as a fragment value. With the access token, the researcher states it is possible to make API calls on behalf of the resource owner.

Step 3: the phishing requirement

The attack requires the attacker to first launch a successful phishing attack. The author notes this would not be difficult, since most common users do not check the full URL, for example the redirect parameters.

Picture for attention? From the original on z3r0tru5t.medium.com

The image is captioned "Picture for attention?" and sits after the phishing discussion; the report gives no further detail about it.

Root cause

The OAuth flow validates redirect_uri against the registered callback, which is why replacing it with an attacker URL failed. The application also honoured a redirect_to parameter, which the report does not say was validated. After login the access token was forwarded to the host named in redirect_to.

Impact

An attacker who convinces a victim to open the crafted login URL and log in receives the victim's access token at an attacker-controlled origin. With that token, the attacker can make API calls on behalf of the resource owner.

Fix

Variants to test

  1. Add a second redirect parameter alongside a valid redirect_uri (redirect_to, return_to, next, continue, callback) and see whether the post-login navigation follows it. A positive result is a redirect to your host after login.
  2. Check whether the token or code lands in the fragment or query of your host. A positive result is https://attacker.com/#<token> or a code= parameter you can exchange.
  3. A positive result is the same off-site redirect with a valid callback.
  4. A positive result is a redirect that the validator did not intend to allow.

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

What happened, in plain words

A group of security researchers who call themselves z3r0tru5t published this write-up on Medium on 3 June 2021. It describes a bug in a website's login system that let an attacker steal a user's login token and then act as that user. The report calls the website only target.com; it does not name the company or the bug bounty programme.

The bug is an open redirect in the login flow that led to account takeover. If the site does not check that address, an attacker can make the site send people to a page the attacker controls. The second problem is that the login system hands out a token (a short string that proves who you are) and that token ends up being carried to the attacker's page.

To understand the rest, you need three ideas:

  • OAuth: a way for one website to let you log in using another service, without sharing your password. When you click "Log in with X", the site sends your browser to X, X confirms who you are, and then your browser is sent back to the original site with proof of your identity. That proof is the token.
  • Token: think of it like a cloakroom ticket. You show it and you get your coat. Anyone holding the ticket can collect the coat, so a stolen token means a stolen identity, at least until it expires.
  • API: the behind-the-scenes doorway a website uses to fetch and change data. If you have someone's token, you can walk through that doorway as them.

The attack needs one human step: the victim has to click a crafted login link and actually log in. The author calls this phishing, and notes that most people do not read the full address bar, especially the parts with words like redirect in them.

The setup

The report does not describe any tools, accounts, versions or special access. The only precondition is that the attacker can get a victim to open a prepared login URL and complete a successful login. That is the phishing step.

Finding the open redirect

The researcher started from a login URL that contained a parameter called redirect_uri:

Text
redirect_uri=https://target.com

A parameter is a named value in a URL, the part after a ? or &, written as name=value. Here the name is redirect_uri and the value is the site's own address. The name means "where to send the user after login".

The obvious test was to swap target.com for a website the attacker controls. That did not work. The site refused to send the user anywhere else. This is normal and good: the site keeps a list of allowed return addresses and checks the value against it.

So the researcher took a step back and looked at the whole login URL that the site itself produces when you visit the login page:

Text
https://target.com/login?state=XXXXX&protocol=oauth2&response_type=token%20id_token&redirect_uri=https%3A%2F%2Ftarget.com%2F

Line by line, this URL says:

  • https://target.com/login is the login page.
  • ? starts the list of parameters.
  • state=XXXXX is a random value the site generates to tie the login response to this particular browser session. It is an anti-forgery measure, so that someone cannot trick your browser into completing a login you did not start. XXXXX stands in for the real value.
  • protocol=oauth2 tells the site to use the OAuth login flow.
  • response_type=token%20id_token asks for two things back: an access token and an ID token. %20 is how a space is written inside a URL, so this is token id_token.
  • redirect_uri=https%3A%2F%2Ftarget.com%2F is the return address. %3A is :, %2F is /, so the decoded value is https://target.com/. The site checks this value against its allow-list.

Because the return address is checked, changing it alone was rejected. The researcher needed another way to move the user after login.

Exploitation

Step 1: add a second redirect parameter

While redirect_uri was rejected, adding a second parameter called redirect_to worked. The proof of concept is:

Line by line:

  • The start is the same legitimate login URL.
  • redirect_uri=https%3A%2F%2Ftarget.com%2F is still the site's own address, so the OAuth check passes.
  • redirect_to=https://attacker.com is a new parameter, pointing at the attacker's server.
  • Notice there is no & between the two: the text runs ...target.com%2Fredirect_to=.... The report shows it exactly this way. The researcher's point is that the site accepted this extra parameter and used it for the redirect after login.

The site rejected a changed redirect_uri, but appending redirect_to pointing at the attacker's host worked. So the login itself was legitimate, and the redirect afterwards was not.

Step 2: the token is forwarded to the attacker

After a successful login, the victim's access token was sent to the server named in redirect_to. It appeared in the address bar like this:

Text
https://attacker.com/#<ACCESS_TOKEN>

Line by line:

  • https://attacker.com/ is the attacker's website.
  • # starts the fragment, the part of a URL after the hash. Browsers do not send the fragment to the server in the request; it stays in the browser. But any script running on that page can read it.
  • <ACCESS_TOKEN> stands for the victim's real token.

The token appeared in the address bar on the attacker's page. With that token, the researcher says it is possible to make API calls on behalf of the resource owner, meaning the attacker can act as the victim through the site's API.

Step 3: the phishing requirement

The attack needs the victim to click a prepared link and log in. The author notes this would not be difficult, because most users do not check the full URL, for example the redirect parameters.

Picture for attention? From the original on z3r0tru5t.medium.com

The image is captioned "Picture for attention?" and appears after the phishing discussion. The report gives no further detail about it.

Why it worked

The OAuth flow checks redirect_uri against the registered return address, which is why replacing it with an attacker address failed. The token is issued to the legitimate return address and then carried along to whatever host redirect_to names.

Impact

An attacker who convinces a victim to open the crafted login URL and log in receives the victim's access token at an attacker-controlled origin. With that token, the attacker can make API calls on behalf of the resource owner. The attack depends on the phishing step succeeding.

Fix

Variants to test

  1. Add a second redirect parameter alongside a valid redirect_uri (redirect_to, return_to, next, continue, callback) and see whether the post-login navigation follows it. A positive result is a redirect to your host after login.
  2. Check whether the token or code lands in the fragment or query of your host. A positive result is https://attacker.com/#<token> or a code= parameter you can exchange.
  3. A positive result is the same off-site redirect with a valid callback.
  4. A positive result is a redirect that the validator did not intend to allow.

Glossary

  • OAuth: a login method where one site asks another service to confirm who you are, then receives a token as proof.
  • Open redirect: a feature that sends the visitor to an address taken from the URL without checking it, so an attacker can send people to their own site.
  • Account takeover: gaining control of someone else's account, here by stealing their token.
  • Token: a short string that proves your identity to a site, like a cloakroom ticket.
  • Access token: the token used to make API calls as a user.
  • ID token: a token that carries information about who the user is.
  • API: the behind-the-scenes doorway a site uses to read and change data.
  • Parameter: a named value in a URL, written as name=value after ? or &.
  • redirect_uri: the OAuth parameter that says where to send the user after login; it is checked against an allow-list.
  • redirect_to: the extra parameter the researcher added, which the site used for a second redirect after login without the same check.
  • state: a random value the site puts in the login URL to tie the response to your browser session and prevent forgery.
  • protocol=oauth2: a marker telling the site to use the OAuth login flow.
  • response_type: the parameter that says what the site wants back, here token id_token.
  • Fragment: the part of a URL after #; it is not sent to the server but can be read by scripts on the page.
  • URL encoding: writing special characters as % codes, such as %20 for a space, %3A for :, %2F for /.
  • Allow-list: a list of values a site will accept, here the trusted return addresses.
  • Phishing: tricking someone into clicking a link or entering details by making the request look legitimate.
  • Proof of concept (PoC): a concrete example that demonstrates the bug works.
  • Resource owner: the user whose data and permissions the token represents.
  • CSRF: cross-site request forgery, an attack where another site makes your browser perform an action you did not intend; the state value helps prevent it.

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.