Skip to content
Account takeover Write-up Intermediate

A tale of critical account take over

A registration API endpoint issued a JWT for any email address supplied in the request body, without verifying that the caller owned that email. An attacker could request a token for a victim's email and then use it to change the victim's password, taking over the account.

Shivam Pandey Follow

Published on medium.com

{{media:0}}

shivam Pandey, on 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 write-up covers a finding on a private bug bounty program. The product offered a "login with Google" and "login with Facebook" feature, and the backend used JWT authentication: after a successful social login, the server generated a JWT for the given email address. The researcher's interest was in how that JWT was produced, and whether the endpoint that produced it could be abused.

The author is Shivam Pandey (@shivam31200), and the write-up was published on 10 July 2020.

shivam Pandey
shivam Pandey From the original on medium.com

Setup

The researcher used a test account, [redacted], alongside a victim account. The victim's details appear in the responses below as they were shown in the report, with personal data redacted here. The main tool was Burp Suite, used to intercept every request made during the Google login flow and to review the proxy history afterwards.

The precondition for the attack is that the target exposes an endpoint which mints a JWT for an arbitrary email address, and that the password change flow does not require the current password.

Finding it

The starting point was the social login feature. The researcher logged in with Google and intercepted the requests one by one. In the Burp history, one API endpoint stood out: it generated a JWT for a user by taking the email address as a parameter.

HTTP
POST /register?src=aweb HTTP/1.1
Host: userapi.target.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://www.target.com
cp-origin: 11
Content-Type: application/json
X-Auth-Token: xxxxx
X-JWT-Token:
Origin: https://www.target.com
Content-Length: 1354
Connection: close

{"name":"Shivam Pandey","email":"[redacted]","providerUserId":"103151677586368643333","providerToken":" [redacted]","providerName":"g"}

The body carries the user's name, email, a providerUserId, a providerToken and providerName (g for Google). The researcher's observation was that this endpoint generates a JWT for a user by taking the email address as a parameter. The X-Auth-Token value is shown as xxxxx in the report, and the X-JWT-Token header is empty.

Exploitation

Step 1: request a JWT for a different email

The researcher changed the email field from his own address to his test account, [redacted], and sent the request. The server returned a JWT for that account.

HTTP
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Content-Length: 476
Connection: close
Date: Wed, 08 Jul 2020 15:42:16 GMT
Server: nginx/1.16.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: DENY
Access-Control-Allow-Origin: https://www.target.com
Vary: Origin
Access-Control-Allow-Credentials: true
X-Application-Context: application:prod
X-Cache: Miss from cloudfront

{"userInfo":{"id":8023402,"name":"Test account Reddy","email":"[redacted]","status":2,"phone":"xxxxxxxxxx","phoneVerified":true,"socialUserId":"8023402","wasUserExists":true,"coins":1209.00},"jwtToken":"[redacted]"}

The response contains a userInfo object for the requested account and, crucially, a jwtToken for it. The researcher notes that he changed the JWT in the write-up for security purposes.

Image for post
Image for post From the original on medium.com

Step 2: look for a way to use the token

With a valid JWT for another account in hand, the next question was what to do with it. An email change request was an obvious candidate, but the target did not allow it. The researcher then looked at the account settings page and found a smaller, low-hanging fruit: the change password form did not require the current password.

Image for post
Image for post From the original on medium.com

Step 3: intercept the password change request

He intercepted the request that sets a new password.

Image for post
Image for post From the original on medium.com

Step 4: swap the email and the JWT

Changing the email parameter to his test account's address on its own returned 401. He then replaced the JWT with the one he had obtained in step 1, keeping the changed email parameter, and the victim's password was changed successfully. The victim's window showed the confirmation.

Image for post
Image for post From the original on medium.com
Image for post
Image for post

Root cause

The flaw is that the registration endpoint mints a JWT for whatever email address is supplied in the request. Anyone who can reach the endpoint can therefore obtain a valid session token for any account whose email address they know.

The second flaw is in the password change flow: it does not ask for the current password. Combined, the two flaws turn a token-minting endpoint into a full account takeover. The report does not describe any server-side check that would have stopped either step.

Impact

An attacker who knows a victim's email address can obtain a JWT for that account and use it to change the victim's password, taking over the account. The report shows this working against a test account. The author notes that the email change path was not available on this target, so the password change was the route used.

Fix

The report does not state what the program changed. Based on the flaws described, the registration endpoint should derive the account identity from the verified provider token rather than from the client-supplied email, and the password change flow should require the current password or another proof of identity beyond a bearer token.

Variants to test

  1. Social login endpoints that accept an email parameter. Intercept the login-with-Google or login-with-Facebook flow and look for a request that carries an email alongside a provider token. Change the email to another account you control. A positive result is a response containing a JWT or session for the other account.
  2. Password change without the current password. Intercept the change password request on any target. If the current password is not required, try replaying the request with a token belonging to a different account. A positive result is a successful password change on the second account.
  3. Burp history review after social login. Walk through every request made during the social login flow and look for endpoints that mint tokens, especially ones whose parameters include an email or user identifier. A positive result is an endpoint that returns a token for an identifier you supplied.
  4. Token reuse across flows. Take a JWT obtained from one flow and present it to another authenticated endpoint, such as email change or profile update. A positive result is the endpoint accepting the token and acting on the account it belongs to.

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

What happened, in plain words

A security researcher was testing a website that let people sign in with their Google or Facebook account instead of creating a separate password. While watching the traffic between his browser and the site during a Google login, he found a hidden web address (an API endpoint) that handed out a login token for any email address you typed into it. A login token is the digital equivalent of a wristband at a festival: show it at the door and you are let in as that person, no password needed. Because the site's password change form did not ask for the old password, the researcher could take a token for someone else's email, use it on the password change form, and set a new password on that person's account. That is a full account takeover. He reported it, and the report was marked as a duplicate of something already known, but he still learned from it.

The author is Shivam Pandey (@shivam31200), and the write-up was published on 10 July 2020.

shivam Pandey
shivam Pandey From the original on medium.com

The pieces you need to know before we start

Before walking through the steps, here are the ideas the whole story rests on, explained from scratch.

  • A request and a response. When you click something in a browser, the browser sends a request to a server (a computer somewhere that runs the website) and the server sends back a response. Most of the time you only see the result, the page that appears. Tools let you see the raw text of both.
  • An API endpoint. A website is often built from several smaller services. The page you see is one part; behind it, the browser talks to other addresses that return data rather than pretty pages. Those addresses are API endpoints. Think of a restaurant: the menu and the dining room are the website, the kitchen door where orders go in and plates come out is the API. You normally never see the kitchen, but it is where the real work happens.
  • Intercepting. A proxy tool sits between your browser and the server, like a post office that opens every letter, copies it, and then sends it on. The researcher used Burp Suite, a common tool for this. It lets you pause each request, read it, change it, and forward it. It also keeps a history of everything that passed through, which is how he later spotted the interesting endpoint.
  • A token (JWT). After you log in, most sites do not want to ask for your password on every single click. Instead the server gives your browser a token, a long string of characters, and the browser shows it on each later request to prove who you are. A JWT (JSON Web Token) is one common format for such a token. It has three parts separated by dots: a header saying which signing method was used, a payload with claims about the user (such as an id, a name, an issue time and an issuer), and a signature. The signature is what makes it trustworthy: the server can check that it really produced the token and that nobody edited the payload. If you change even one character of the payload, the signature no longer matches and the server should reject it. So a JWT is like a stamped, tamper-evident pass: you can read it, but you cannot forge a new one without the server's secret stamp.
  • Social login. "Login with Google" means the site asks Google to confirm who you are, and Google sends back a confirmation (a provider token) that the site can check. The site then creates its own session for you. The whole point is that the site should trust Google's confirmation, not whatever your browser claims about itself.
  • Account takeover. This is the name for any bug that lets one person get into another person's account. It is one of the most serious kinds of web vulnerability because the attacker becomes the victim: they can read private data, change settings, or lock the real owner out.
  • HTTP status codes. Servers answer with a number. 200 means success. 401 means "you are not authorised", in other words the server did not accept your proof of identity. Seeing a 401 and then a 200 after one change is a strong hint about which part of the request the server actually cares about.

Setting up

The researcher used a test account of his own, [redacted], alongside a victim account. The victim's details appear in the responses below as they were shown in the report, with personal data redacted here. The main tool was Burp Suite, used to intercept every request made during the Google login flow and to review the proxy history afterwards.

The precondition for the attack is that the target exposes an endpoint which mints a JWT for an arbitrary email address, and that the password change flow does not require the current password.

Finding it

The starting point was the social login feature. The researcher logged in with Google and intercepted the requests one by one. In the Burp history, one API endpoint stood out: it generated a JWT for a user by taking the email address as a parameter.

Why start here? Because social login is a place where a site has to create an identity for you out of thin air, and that creation step is easy to get wrong. If the site builds your identity from something your browser sends (like an email address) rather than from something Google signed, then anyone can ask for someone else's identity.

HTTP
POST /register?src=aweb HTTP/1.1
Host: userapi.target.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://www.target.com
cp-origin: 11
Content-Type: application/json
X-Auth-Token: xxxxx
X-JWT-Token:
Origin: https://www.target.com
Content-Length: 1354
Connection: close

{"name":"Shivam Pandey","email":"[redacted]","providerUserId":"103151677586368643333","providerToken":" [redacted]","providerName":"g"}

Line by line, in plain words:

  • POST /register?src=aweb HTTP/1.1 is the first line of the request. POST means "I am sending data to the server", as opposed to GET, which just asks for a page. /register is the path on the server, and ?src=aweb is a small extra piece of information attached to the address (a query parameter) saying where the request came from. HTTP/1.1 is the version of the language being spoken.
  • Host: userapi.target.com tells the server which site name the request is for. Notice it is a different subdomain from the main website, which is typical for an API.
  • User-Agent, Accept, Accept-Language, Accept-Encoding are headers, the metadata lines of a request. They describe the browser and what kind of content it can handle. They are normal and not the interesting part.
  • Referer: https://www.target.com says which page the request was made from.
  • cp-origin: 11 is a custom header. Custom headers are often added by the site's own code, and they can be a sign of an internal endpoint.
  • Content-Type: application/json says the body of the request is in JSON, a text format for structured data that looks like {"key":"value"}.
  • X-Auth-Token: xxxxx is a header carrying some kind of authentication value. In the report it is shown as xxxxx, so we do not know what it really was.
  • X-JWT-Token: is present but empty. An empty header is a small clue: the client is prepared to send a JWT here, but on this request it has none yet.
  • Origin: https://www.target.com says which site the browser believes it is talking on behalf of. Servers use it for cross-origin checks.
  • Content-Length: 1354 is the size of the body in bytes, and Connection: close asks the server to close the connection after answering.
  • The blank line separates headers from the body. Everything after it is the data being sent.
  • The body is a JSON object with five fields. name is the display name. email is the address the account should belong to. providerUserId is Google's internal id for the user. providerToken is the confirmation Google gave the site. providerName is g, short for Google.

The researcher's observation was that this endpoint generates a JWT for a user by taking the email address as a parameter. In other words, the server looked at the email field to decide whose token to make. That is the bug in one sentence: the server trusted the browser's claim about who the user is.

Exploitation

Step 1: request a JWT for a different email

The researcher changed the email field from his own address to his test account, [redacted], and sent the request. The server returned a JWT for that account.

Why this step? To check whether the server actually verifies that the email matches the Google account behind the provider token. If it does, changing the email should fail. If it does not, the server will happily mint a token for whatever address is typed in.

HTTP
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Content-Length: 476
Connection: close
Date: Wed, 08 Jul 2020 15:42:16 GMT
Server: nginx/1.16.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: DENY
Access-Control-Allow-Origin: https://www.target.com
Vary: Origin
Access-Control-Allow-Credentials: true
X-Application-Context: application:prod
X-Cache: Miss from cloudfront

{"userInfo":{"id":8023402,"name":"Test account Reddy","email":"[redacted]","status":2,"phone":"xxxxxxxxxx","phoneVerified":true,"socialUserId":"8023402","wasUserExists":true,"coins":1209.00},"jwtToken":"[redacted]"}

Line by line:

  • HTTP/1.1 200 is the status line. 200 means the server accepted the request and did what was asked.
  • Content-Type: application/json;charset=UTF-8 says the answer is JSON text.
  • Content-Length: 476 is the size of the answer.
  • Date, Server: nginx/1.16.1 tell you when the answer was produced and which web server software produced it. Version banners like this are useful to an attacker for other reasons, but they are not the bug here.
  • X-Content-Type-Options: nosniff, X-XSS-Protection, Cache-Control, Pragma, Expires, Strict-Transport-Security, X-Frame-Options are security-related response headers. They tell the browser things like "do not guess content types", "do not cache this", "only use HTTPS", "do not put this page in a frame". They are good practice, but they do not stop the attack.
  • Access-Control-Allow-Origin: https://www.target.com, Vary: Origin, Access-Control-Allow-Credentials: true are CORS headers. CORS is the rule set that decides which websites are allowed to read responses from this server in a browser. Here the server allows the main site to read the answer and to send credentials.
  • X-Application-Context: application:prod is a custom header saying this is the production environment, and X-Cache: Miss from cloudfront says the answer was not served from a cache.
  • The body is the important part. userInfo describes the account: an id, a name, the email, a status, a phone (redacted), whether the phone is verified, a socialUserId, whether the user already existed (wasUserExists), and a coins balance.
  • jwtToken is the prize: a signed token for that account. The researcher notes that he changed the JWT in the write-up for security purposes, so the string shown is not the real one.
Image for post
Image for post From the original on medium.com

Step 2: look for a way to use the token

With a valid JWT for another account in hand, the next question was what to do with it. An email change request was an obvious candidate, but the target did not allow it. The researcher then looked at the account settings page and found a smaller, low-hanging fruit: the change password form did not require the current password.

Why does that matter? Normally, changing a password asks for the old one. That is a deliberate check: even if someone has borrowed your session, they still cannot lock you out without knowing your password. If the form skips that check, then whoever holds a valid token can set a new password, and the token becomes the only key needed.

Image for post
Image for post From the original on medium.com

Step 3: intercept the password change request

He intercepted the request that sets a new password.

Why intercept it? To see exactly which fields the server reads. If the request contains both an email and a token, you can test which of the two the server actually trusts by changing one at a time.

Image for post
Image for post From the original on medium.com

Step 4: swap the email and the JWT

Changing the email parameter to his test account's address on its own returned 401. He then replaced the JWT with the one he had obtained in step 1, keeping the changed email parameter, and the victim's password was changed successfully. The victim's window showed the confirmation.

The 401 is the key observation. It means the server did check something and rejected the request when only the email was changed. But when the matching token was supplied, the request went through. So when the matching token was supplied alongside the changed email, the request went through. The token from step 1 was minted for the test account, so pairing it with the test account's email satisfied both checks at once.

Image for post
Image for post From the original on medium.com
Image for post
Image for post

Root cause

The flaw is that the registration endpoint mints a JWT for whatever email address is supplied in the request. Anyone who can reach the endpoint can therefore obtain a valid session token for any account whose email address they know.

The second flaw is in the password change flow: it does not ask for the current password. Combined, the two flaws turn a token-minting endpoint into a full account takeover. The report does not describe any server-side check that would have stopped either step.

Impact

An attacker who knows a victim's email address can obtain a JWT for that account and use it to change the victim's password, taking over the account. The report shows this working against a test account. The author notes that the email change path was not available on this target, so the password change was the route used.

Fix

The report does not state what the program changed. Based on the flaws described, the registration endpoint should derive the account identity from the verified provider token rather than from the client-supplied email, and the password change flow should require the current password or another proof of identity beyond a bearer token.

Variants to test

  1. Social login endpoints that accept an email parameter. Intercept the login-with-Google or login-with-Facebook flow and look for a request that carries an email alongside a provider token. Change the email to another account you control. A positive result is a response containing a JWT or session for the other account.
  2. Password change without the current password. Intercept the change password request on any target. If the current password is not required, try replaying the request with a token belonging to a different account. A positive result is a successful password change on the second account.
  3. Burp history review after social login. Walk through every request made during the social login flow and look for endpoints that mint tokens, especially ones whose parameters include an email or user identifier. A positive result is an endpoint that returns a token for an identifier you supplied.
  4. Token reuse across flows. Take a JWT obtained from one flow and present it to another authenticated endpoint, such as email change or profile update. A positive result is the endpoint accepting the token and acting on the account it belongs to.

Glossary

  • API: the set of addresses a website's own pages talk to in order to fetch and change data, separate from the pages you see.
  • API endpoint: one specific address in that set, for example /register on a particular host.
  • Account takeover: a bug that lets one person access and control another person's account.
  • Authentication: proving who you are, usually with a password or a token.
  • Authorisation: deciding what an already identified user is allowed to do.
  • Bearer token: a token that grants access to whoever holds it, with no further check of who that is.
  • Body: the data part of a request or response, after the headers.
  • Burp Suite: a tool that sits between a browser and a server so you can read, pause and change requests.
  • CORS: browser rules that decide which websites may read responses from a given server.
  • Cross-origin: a request from one site to a different site or subdomain.
  • Header: a metadata line in a request or response, such as Content-Type or Origin.
  • HTTP: the language browsers and servers use to exchange requests and responses.
  • HTTP status code: the number a server returns to say how the request went, such as 200 for success or 401 for not authorised.
  • Intercept: to pause a request in a proxy tool so you can inspect or edit it before it reaches the server.
  • JSON: a text format for structured data, written as {"key":"value"} pairs.
  • JWT (JSON Web Token): a signed token with a header, a payload of claims and a signature, used to prove identity on later requests.
  • Low-hanging fruit: a bug that is easy to find and exploit.
  • Parameter: a named value sent with a request, either in the address (query parameter) or in the body.
  • POST: an HTTP method used to send data to the server, as opposed to GET, which asks for a resource.
  • Private program: a bug bounty program that only invited researchers can see and report to.
  • Provider token: the confirmation a social login provider such as Google gives to the site, which the site is supposed to verify.
  • Proxy: a tool or service that sits between two parties and forwards traffic, optionally letting you inspect it.
  • Query parameter: a value attached to the address after a ?, such as src=aweb.
  • Request: the message a browser sends to a server.
  • Response: the message a server sends back.
  • Root cause: the underlying design mistake that makes a bug possible.
  • Session: the state of being logged in, usually represented by a token or cookie.
  • Social login: signing in to a site using an account from another provider, such as Google or Facebook.
  • Subdomain: a named part of a domain, such as userapi in userapi.target.com.
  • Token: a string of characters that stands in for your identity on later requests.
  • Vulnerability: a weakness in software that an attacker can use to do something the owner did not intend.
  • Write-up: a public description of a bug and how it was found.

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.