Skip to content
Account takeover Write-up Intermediate

From staging to 0 click account takeover

The staging dashboard and production dashboard shared the same JWT signing secret, and the OAuth endpoint trusted a referer parameter to decide which app to log into. An attacker could create a staging account with a victim's email and then use the staging session with the referer set to dashboard to log into the victim's forms account without a password.

mohamad mahmoudi Follow

Published on med-mahmoudi26.medium.com

Often, as bug bounty hunters or pentesters, while doing our recon on a specific target, we come accross their staging or pre-production environments. And if we look at these from the right angle, hidden gems could be waiting for us.

mohamad mahmoudi, on med-mahmoudi26.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. 5 min read.

Context

This is a write-up about a private bug bounty program with a wild scope, which the author refers to as *.akme.com for obvious reasons. The target is a set of web applications: a dashboard, a staging version of that dashboard, a forms application, and an API. The feature at the centre of the report is the OAuth-style login flow that lets a user who has signed up on the dashboard reach the forms application without a separate registration.

During subdomain enumeration, four hosts caught the author's attention:

  1. dashboard.akme.com
  2. dashboard-staging.akme.com
  3. forms.akme.com
  4. api.akme.com

After a few hours of clicking around, the author took the following notes:

  1. dashboard-staging.akme.com is the staging version of dashboard.akme.com.
  2. You can create an account on both of them, most importantly with the same email, which will come in handy.
  3. An account gets created for you automatically on forms.akme.com when you sign up on the dashboard app, and you can log in to it by hitting this endpoint with your JWT session: api.akme.com/oauth.
  4. You do not need to confirm your email on dashboard.acme.com to log in to forms.akme.com through OAuth.

Setup

The author needed two accounts, one on the production dashboard and one on the staging dashboard, both created with the same email address. The production account is referred to as account A and the staging account as account B. In the exploit, account A is the victim and account B is the attacker. The tooling mentioned is Burp, used to intercept and inspect the OAuth traffic.

The preconditions that make the attack possible are the ones from the notes above: the same email can be registered on both dashboards, the forms account is created automatically from the dashboard signup, and email confirmation is not required to log in to forms through OAuth.

Finding it

Looking at the notes, the author thought about the following scenario:

  1. Create an account A in dashboard.
  2. Create an account B in staging-dashboard.
  3. Log in to forms with account A, by hitting the OAuth endpoint with my user session.
  4. Log in to forms with account B (same process as step 3).

The desired outcome was making account B log in to account A's forms account without knowing its password. It did not work on the first try. Instead, the flow took the author to forms-staging, which is the staging version of the forms app. A failure.

From the original on med-mahmoudi26.medium.com

Exploitation

Step 1: Inspect the OAuth request in Burp history

Looking at the Burp history, the author found that a parameter is added to the OAuth request each time. When logging in from the dashboard, the request becomes:

HTTP
api.akme.com/oauth?referer=dashboard

When logging in from the staging dashboard, it becomes:

HTTP
api.akme.com/oauth?referer=staging-dashboard

The referer parameter is added to the OAuth request each time, with a different value depending on which dashboard the login comes from.

Step 2: Intercept and change the referer

The author intercepted the traffic while repeating the same steps, with account A as the victim and account B as the attacker, but changed the value of ?referer to dashboard while using the staging JWT session (user B). The result was a redirect to the victim's account.

In other words, the request was sent with the staging session but with the production referer value, and the author was redirected to the victim's account.

Root cause

The author gives two reasons why the exploit was possible:

  • The developers used the same JWT secret to decode the session of the users. This allowed the author to access the account of anyone on forms.akme.com by knowing their email.
  • You do not need email confirmation to log in with OAuth. Otherwise, if you were not able to prove that the victim's email belongs to you, you would not be able to fully sign up on dashboard-staging, which is the main vector of the attack.

Because email confirmation is not required to log in with OAuth, an attacker can fully sign up on dashboard-staging with a victim's email address.

Impact

An attacker who knows a victim's email address can take over that victim's account on forms.akme.com. The attack requires the ability to sign up on the staging dashboard with the victim's email, which is possible because email confirmation is not required to log in with OAuth, and it requires the shared JWT secret that lets the staging token be accepted by the production OAuth endpoint.

The author also mentions finding another way to mass leak emails of other users, described as not an SQL injection, and leaves it for another article.

Fix

The report does not describe any fix that was applied. Based on the root cause, the changes that would address it are: use separate JWT secrets per environment so a staging token cannot be accepted by production, and enforce email confirmation before an account can be used for OAuth login, so a staging signup with someone else's email cannot produce a usable session.

Variants to test

  • Look for staging or pre-production hosts during subdomain enumeration and compare their authentication flows with production. A positive result is a staging token that is accepted by a production endpoint.
  • Check whether the same email can be registered on both a staging and a production environment. A positive result is two accounts with the same email, one of which can be used to reach the other's data.
  • Inspect OAuth requests for parameters that select an environment or tenant, such as a referer value. A positive result is a change to that parameter redirecting you into another environment's account.
  • Test whether email confirmation is enforced before OAuth login. A positive result is a fully usable session on an account whose email was never confirmed.
  • Compare JWT signing secrets across environments by taking a token from one and presenting it to another. A positive result is the second environment accepting the token.

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.

What happened, in plain words

A security researcher was taking part in a private bug bounty programme. A bug bounty programme is a scheme where a company invites independent researchers to look for security problems in its systems and pays them for reporting what they find. The programme covered a wide range of addresses (a "wild scope"), and the researcher refers to the company as *.akme.com so the real name stays private. The * is a wildcard: it means "any subdomain of akme.com".

A subdomain is a name that sits in front of a main domain, like mail.example.com next to example.com. Companies often run several of them: one for the main website, one for an internal tool, one for an API, and so on. Some of these are not meant for the public at all, such as test copies of a website. Those test copies are called staging or pre-production environments. They are where developers try out changes before releasing them to real users, and they are often less carefully protected than the live site.

The researcher found four such hosts and noticed how they fit together. One of them, the forms application, lets people fill in and submit forms. You do not register on it directly: an account is created for you automatically when you sign up on the dashboard application, and you get into forms through a login hand-off. That hand-off is the feature at the centre of this story, and it had a flaw that let one person log in as another. That is called account takeover: someone else ends up inside your account, without your password.

The four hosts and what they are

During subdomain enumeration (the process of discovering which subdomains exist under a domain, usually with wordlists and DNS lookups), four hosts caught the researcher's attention:

  1. dashboard.akme.com
  2. dashboard-staging.akme.com
  3. forms.akme.com
  4. api.akme.com

Here is what each one is, in everyday terms:

  • The dashboard is the main web application where a user signs up and manages their account. Think of it as the front desk of a building.
  • The staging dashboard is a test copy of that same front desk, used by developers before changes go live. It looks the same but is not the real one.
  • The forms application is a separate product where users fill in forms. It has its own login, but you do not create an account there yourself.
  • The API is the behind-the-scenes service the applications talk to. An API (Application Programming Interface) is a set of addresses a program can call to ask for something or to make something happen, without a human clicking buttons. A useful comparison: a website is a waiter taking your order at the table, and the API is the kitchen door the waiter walks through. You never see the kitchen, but the food comes from there.

Notes after a few hours of clicking around

After exploring the applications for a few hours, the researcher wrote down four observations:

  1. dashboard-staging.akme.com is the staging version of dashboard.akme.com. This needed little thinking: the name says it.
  2. You can create an account on both of them, and most importantly with the same email address. This will come in handy later.
  3. An account gets created for you automatically on forms.akme.com when you sign up on the dashboard app, and you can log in to it by hitting this endpoint with your JWT session: api.akme.com/oauth.
  4. You do not need to confirm your email on dashboard.acme.com to log in to forms.akme.com through OAuth.

Two terms in those notes need explaining.

A JWT (JSON Web Token) is a small piece of text that a server gives you after you log in, and that your browser sends back with later requests to prove who you are. It is like a wristband at an event: the staff at the door check it, and once you are inside it lets you move around without showing your ID again. The token is signed by the server, meaning the server can check that it really issued it and that nobody altered it. The signing uses a secret key, which only the server is supposed to know.

OAuth here means a login hand-off between two applications: you are already logged in to one (the dashboard), and it vouches for you so that a second application (forms) can log you in without a separate password. A comparison: a hotel guest asking the front desk to call the restaurant next door and confirm they are a guest, so the restaurant lets them in on the hotel's word.

An endpoint is simply a specific address on a server that does a specific job, like a particular counter in a large office. api.akme.com/oauth is the counter that handles the hand-off.

Point 4 matters a great deal. Normally, when you sign up with an email address, the site sends you a message with a link, and you have to click it to prove the address is really yours. That is email confirmation. Email confirmation was not required to log in to forms through OAuth, so an account created with any email address could be used to log in.

Setting up the test

The researcher needed two accounts, both created with the same email address: one on the production dashboard and one on the staging dashboard. The production account is called account A and the staging account is called account B. In the exploit, account A is the victim and account B is the attacker.

The tool used is Burp, short for Burp Suite, a program that sits between your browser and the website and lets you look at, pause and edit the requests going back and forth. Think of it as a transparent mail room: every letter your browser sends passes through it, and you can open a letter, change a word and send it on.

The conditions that make the attack possible are exactly the notes above: the same email can be registered on both dashboards, the forms account is created automatically from the dashboard signup, and email confirmation is not required to log in to forms through OAuth.

Finding it

Looking at the notes, the researcher thought about the following scenario:

  1. Create an account A in dashboard.
  2. Create an account B in staging-dashboard.
  3. Log in to forms with account A, by hitting the OAuth endpoint with my user session.
  4. Log in to forms with account B (same process as step 3).

The desired outcome was making account B log in to account A's forms account without knowing its password. In plain terms: the attacker's staging account would be used to walk into the victim's forms account.

It did not work on the first try. Instead, the flow took the researcher to forms-staging, which is the staging version of the forms app. A failure.

From the original on med-mahmoudi26.medium.com

The image shows the result of that first attempt: the login from the staging account landed on the staging copy of forms rather than on the real one. That is actually sensible behaviour on the surface, since a staging login should lead to a staging product. The interesting question is what decides which copy you land in.

Exploitation

Step 1: Inspect the OAuth request in Burp history

Looking at the Burp history (the log of every request that passed through the tool), the researcher found that a parameter is added to the OAuth request each time. A parameter is a named value attached to an address, after a question mark, that tells the server something extra. In ?colour=blue, the parameter is colour and its value is blue.

When logging in from the dashboard, the request becomes:

HTTP
api.akme.com/oauth?referer=dashboard

When logging in from the staging dashboard, it becomes:

HTTP
api.akme.com/oauth?referer=staging-dashboard

Line by line, in plain words:

  • api.akme.com/oauth is the address of the hand-off endpoint on the API server.
  • ? marks the start of the parameters.
  • referer=dashboard says "this login is coming from the production dashboard".
  • referer=staging-dashboard says "this login is coming from the staging dashboard".

The referer parameter is added to the OAuth request each time, with a different value depending on which dashboard the login comes from.

Step 2: Intercept and change the referer

The researcher intercepted the traffic while repeating the same steps, with account A as the victim and account B as the attacker, but changed the value of ?referer to dashboard while using the staging JWT session (user B). The result was a redirect to the victim's account.

In other words, the request was sent with the staging session but with the production referer value, and the author was redirected to the victim's account.

Unpacking that: the attacker's wristband (the staging token) was presented at the production door, with a note saying "I came from the production front desk". The door checked the wristband, found it valid, and let the attacker in. Because the email inside the staging token was the victim's email, the account the attacker landed in was the victim's forms account. No password was ever needed.

Root cause

The researcher gives two reasons why the exploit was possible:

  • The developers used the same JWT secret to decode the session of the users. This allowed the researcher to access the account of anyone on forms.akme.com by knowing their email.
  • You do not need email confirmation to log in with OAuth. Otherwise, if you were not able to prove that the victim's email belongs to you, you would not be able to fully sign up on dashboard-staging, which is the main vector of the attack.

The first reason is about the shared secret. A JWT is signed with a secret key, and the server uses that key to check the token is genuine. If staging and production use the same key, then a token issued by staging is accepted by production as genuine. The two environments are supposed to be separate worlds, but they share the same lock and key. A comparison: two offices in the same building use identical keys, so a key from the test office opens the real office too.

The second reason is about proving ownership of an email address. Because staging did not require email confirmation, the attacker could sign up there using the victim's email address and get a valid token containing that address. Without that, the attacker could not have created a staging account with someone else's email, and the whole chain would not start.

Impact

An attacker who knows a victim's email address can take over that victim's account on forms.akme.com. The attack requires the ability to sign up on the staging dashboard with the victim's email, which is possible because email confirmation is not required to log in with OAuth, and it requires the shared JWT secret that lets the staging token be accepted by the production OAuth endpoint.

In everyday terms: if someone knows your email address, they can end up inside your forms account without ever knowing your password. That is a serious outcome, because an account is normally the one thing that proves "this is you".

The researcher also mentions finding another way to mass leak emails of other users, described as not an SQL injection, and leaves it for another article. An SQL injection is a classic attack where specially crafted input is slipped into a database query; the researcher is saying this other finding was something different.

Fix

The report does not describe any fix that was applied. Based on the root cause, the changes that would address it are: use separate JWT secrets per environment so a staging token cannot be accepted by production, and enforce email confirmation before an account can be used for OAuth login, so a staging signup with someone else's email cannot produce a usable session.

In plain words: give each environment its own key, so a test-office key cannot open the real office, and make people prove they own an email address before that address can be used to log in anywhere.

Variants to test

These are the same ideas applied more widely, useful if you want to look for similar problems yourself:

  • Look for staging or pre-production hosts during subdomain enumeration and compare their authentication flows with production. A positive result is a staging token that is accepted by a production endpoint.
  • Check whether the same email can be registered on both a staging and a production environment. A positive result is two accounts with the same email, one of which can be used to reach the other's data.
  • Inspect OAuth requests for parameters that select an environment or tenant, such as a referer value. A positive result is a change to that parameter redirecting you into another environment's account.
  • Test whether email confirmation is enforced before OAuth login. A positive result is a fully usable session on an account whose email was never confirmed.
  • Compare JWT signing secrets across environments by taking a token from one and presenting it to another. A positive result is the second environment accepting the token.

Glossary

  • Account takeover: a security problem where one person gains access to another person's account without knowing their password.
  • API (Application Programming Interface): a set of addresses a program can call to ask for data or trigger actions, without a human clicking through a website.
  • Bug bounty programme: a scheme where a company invites independent researchers to look for security problems and pays them for valid reports.
  • Burp (Burp Suite): a tool that sits between your browser and a website so you can view, pause and edit the requests and responses.
  • Dashboard: here, the main web application where users sign up and manage their account.
  • Email confirmation: the step where a site sends a link to your email address and you must click it to prove the address belongs to you.
  • Endpoint: a specific address on a server that performs a specific job.
  • Environment: one running copy of an application, such as production (the real one used by customers) or staging (a test copy).
  • Forms application: here, a separate product where users fill in and submit forms, with accounts created automatically from the dashboard signup.
  • JWT (JSON Web Token): a signed piece of text a server gives you after login, which your browser sends back to prove who you are; the signature lets the server check it was not altered.
  • JWT secret: the secret key a server uses to sign and verify JWTs; if two environments share it, a token from one is accepted by the other.
  • OAuth: a login hand-off where one application vouches for you so a second application can log you in without a separate password.
  • Parameter: a named value attached to an address after a question mark, telling the server something extra, as in ?referer=dashboard.
  • Production: the live version of an application that real users use.
  • Referer parameter: here, a value in the OAuth request that says which dashboard the login came from and therefore which forms environment to send the user to.
  • Session: the state of being logged in, represented by a token or cookie your browser sends with each request.
  • SQL injection: an attack where crafted input is inserted into a database query to change what the database does.
  • Staging (pre-production): a test copy of an application used by developers before changes reach real users.
  • Subdomain: a name in front of a main domain, such as forms in forms.akme.com.
  • Subdomain enumeration: the process of discovering which subdomains exist under a domain.
  • Wild scope: a bug bounty scope that covers a broad range of addresses, often any subdomain of a domain.
  • Wildcard: the * symbol, meaning "anything in this position", as in *.akme.com.

More by mohamad mahmoudi

View all

2 more disclosed reports, best first.

More from Pinterest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.