Fall account takeover via Amazon Cognito misconfiguration
The Amazon Cognito custom authentication flow did not verify that the IdToken presented in the RespondToAuthChallenge call belonged to the same user as the session and username. An attacker could obtain a valid session for a victim's account and combine it with their own IdToken to receive the victim's tokens, leading to account takeover.
Published on medium.com
Hello reader, I hope you are doing well. Today I want to talk about one of my findings.
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 public bug bounty program that the author refers to as redirect.com; the real name is withheld because the bug was not fixed at the time of writing. The program uses Amazon Cognito for authentication and authorisation, and offers two ways to register: email and password, and OAuth through Google as an identity provider (IdP).
Cognito has two main components. User pools are user directories that provide sign-up and sign-in, either directly with a username and password or federated through a third-party IdP such as Facebook, Amazon, Google or Apple. Identity pools let the developer grant users access to other AWS services. They can be used separately or together. After a successful user pool sign-in the app receives user pool tokens, which the developer can use to retrieve AWS credentials, to control access to server-side resources, or to control access to Amazon API Gateway. The developer can also create user pool groups to manage permissions and to represent different types of users.

Two authentication flows matter here.
Client-side authentication flow:
- The user enters their user name and password into the app.
- The app calls
InitiateAuthwith the user name and Secure Remote Password (SRP) details. The operation returns the authentication parameters. - The app calls
RespondToAuthChallenge. If it succeeds, Cognito returns the user's tokens and the flow is complete. If another challenge is required, no tokens are returned; instead the call returns a session. - If
RespondToAuthChallengereturns a session, the app callsRespondToAuthChallengeagain with the session and the challenge response (for example an MFA code).

Custom authentication flow: user pools allow custom flows that build a challenge/response model using AWS Lambda triggers. The flow starts with InitiateAuth, indicating the type of authentication and any initial parameters. Cognito answers with one of three things: a challenge for the user along with a session and parameters; an error if the user fails to authenticate; or ID, access and refresh tokens if the supplied parameters are sufficient to sign the user in (typically the user or app must first answer a challenge, but the custom code determines this). If a challenge comes back, the app gathers more input and calls RespondToAuthChallenge with the challenge responses and the session. Cognito responds the same way as to InitiateAuth: tokens if signed in, otherwise another challenge or an error. The sequence repeats until the user signs in or an error is returned.
An app starts a custom flow by calling InitiateAuth with CUSTOM_AUTH as the Authflow. Three Lambda triggers control challenges and verification:
DefineAuthChallengetakes a session array of previous challenges and responses, and generates the next challenge name plus Booleans indicating whether the user is authenticated and can be granted tokens. It is a state machine controlling the user's path through the challenges.CreateAuthChallengetakes a challenge name and generates the challenge and parameters used to evaluate the response. WhenDefineAuthChallengereturnsCUSTOM_CHALLENGEas the next challenge, the flow callsCreateAuthChallenge, which passes the next type of challenge in the challenge metadata parameter.VerifyAuthChallengeResponseevaluates the response and returns a Boolean indicating whether it was valid.
A custom flow can combine built-in challenges, such as SRP password verification and SMS MFA, with custom challenges such as CAPTCHA or secret questions.

Tokens. The IdToken is a JSON web token (JWT) containing claims about the authenticated user, such as name, email and phone_number. It can be used inside the application and to authenticate users to resource servers or server applications, and outside the application with web API operations, in which case its signature must be verified before any claims inside it are trusted. Its expiration can be set between 5 minutes and 1 day. The AccessToken contains claims about the authenticated user, a list of the user's groups and a list of scopes; its purpose is to authorise API operations in the context of the user, for example to add, change or delete user attributes. Its expiration can also be set between 5 minutes and 1 day. The RefreshToken retrieves new ID and access tokens; by default it expires 30 days after sign-in, and the application's refresh token expiration can be set between 60 minutes and 10 years.
Setup
The author worked as a normal user of the program, with BurpSuite to capture and replay requests. The scope was limited to authentication and authorisation: sign-up, sign-in and OAuth where available. Two accounts are involved in the attack: the attacker's own account, used to obtain a valid IdToken, and a victim account whose username and email are known to the attacker. No special tooling beyond BurpSuite Repeater is shown.
Finding it
The recon was done in three stages: use the program as a normal user, analyse requests and responses to understand what each feature does, then build an attack scenario from that analysis.
Registering with email and password revealed nothing unfamiliar. Registering through OAuth revealed two things:
- During registration, after authenticating with the third party and granting access to the application, there were delays in accessing the account that did not stem from the internet connection.
- After registration there was no option to change the email or to unlink the Google account from the program account.
That prompted a closer look at the OAuth registration requests, which were highlighted in BurpSuite so they could be analysed individually.
The OAuth registration process works as follows.
- Clicking the Google icon transfers the user to Google for authentication, then to the consent step granting access to the client (the target app).

- The user pool receives the code from the third-party provider, exchanges it for tokens, and sends them to the program. Decoding the JWT showed that the email had not yet been verified.

- The client generates an API call to an endpoint responsible for linking the Google account username with the program account. That endpoint takes 2 parameters and the IdToken as part of the request headers.

- The target app does an extra step, fetching the IdToken and AccessToken after the email has been confirmed, using two requests. First it connects to an
InitiateAuthendpoint that takes a set of parameters in JSON. This endpoint fetches a valid session belonging to the user account, the challenge name created by the website developers through the AWS Lambda trigger, and the username and email address of the user account.

Second, the app connects to the RespondToAuthChallenge endpoint with the session, the ChallengeName and the username from the previous step, plus additional parameters. If the session, username and the additional parameter Answer (the IdToken) are validated, user-specific tokens are returned in the HTTP response. The session is associated with the username of the user and the IdToken.

The question that drove the attack: what happens if a valid session of another user is used instead of my own session, together with the IdToken of my account and the username of the other user account? Manipulating the parameters of the RespondToAuthChallenge request answered it.
Exploitation
Step 1: obtain the attacker's IdToken
The attacker logs in to their own account to get a valid IdToken belonging to that account.
Step 2: obtain the victim's session with InitiateAuth
The attacker sends a POST request to the AWS InitiateAuth endpoint to retrieve a valid session belonging to the victim account. In BurpSuite Repeater, a new window is opened with this request:
POST / HTTP/2Host: cognito-idp.us-east-1.amazonaws.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0Accept: */*Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: https://redirect.com/Content-Type: application/x-amz-json-1.1X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuthX-Amz-User-Agent: aws-amplify/5.0.4 jsContent-Length: 155Origin: https://redirect.comSec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: cross-siteTe: trailers{"AuthFlow":"CUSTOM_AUTH","ClientId":"targetAppClientId","AuthParameters":{"USERNAME":"XXXXXXXXXXXXXXXXXXX"},"ClientMetadata":{}}
The X-Amz-Target header selects the AWSCognitoIdentityProviderService.InitiateAuth operation, the body sets AuthFlow to CUSTOM_AUTH and identifies the app with ClientId. The victim's email is put as the value of the USERNAME parameter. The response body is:
{"ChallengeName":"CUSTOM_CHALLENGE","ChallengeParameters":{"USERNAME":"VICTIM_USERNAME","email":"Victim's email"},"Session":"Victim's session"}
So the call returns a CUSTOM_CHALLENGE, the victim's username and email in the challenge parameters, and a session belonging to the victim.
Step 3: exchange the victim's session for the victim's tokens
The attacker sends a POST request to the AWS RespondToAuthChallenge endpoint to retrieve valid tokens belonging to the victim account, while using an IdToken for the attacker's account. In BurpSuite Repeater, another window is opened with this request:
POST / HTTP/2Host: cognito-idp.us-east-1.amazonaws.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0Accept: */*Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: https://redirect.com/Content-Type: application/x-amz-json-1.1X-Amz-Target: AWSCognitoIdentityProviderService.RespondToAuthChallengeX-Amz-User-Agent: aws-amplify/5.0.4 jsContent-Length: 2385Origin: https://redirect.comSec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: cross-siteTe: trailers{"ChallengeName":"CUSTOM_CHALLENGE","ChallengeResponses":{"USERNAME":"VICTIM-USERNAME","ANSWER":"ATTACKER_IdToken"},"ClientId":"targetAppClientId","Session":"VICTIM'S_SESSION"}
The three values that matter are set as follows:
- The victim's username as the value of the
USERNAMEparameter. - The attacker's IdToken as the value of the
ANSWERparameter. The attacker's IdToken must be valid. - The victim's session obtained from the previous request as the value of the
SESSIONparameter.
The response body is:
{"AuthenticationResult":{"AccessToken":"VICTIM'S-AccessToken","ExpiresIn":3600,"IdToken":"VICTIM'S_IdToken","RefreshToken":"VICTIM'S_RefreshToken","TokenType":"Bearer"},"ChallengeParameters":{}}
The attacker now holds the victim's access token, ID token and refresh token, with an ExpiresIn of 3600 seconds.


Root cause
By manipulating the parameter values of the RespondToAuthChallenge request, the author found that:
- The session is validated and linked to the username.
- The validity of the IdToken is verified.
- It is not checked whether the IdToken is associated with this session and this username.
The checks are performed piece by piece: the session belongs to the victim, the IdToken is a genuine, valid token, and the username matches the session.: the session belongs to the victim, the IdToken is a genuine, valid token, and the username matches the session. Nothing ties the IdToken to the session or to the username it is presented with, so any valid IdToken from any account satisfies the challenge for any session.
Impact
An attacker who knows a victim's username or email can obtain that victim's access token, ID token and refresh token. The author notes the bug was not fixed at the time of writing and does not describe the program or its bounty.
Fix
The report does not describe a fix. : the identity in the verified token has to match the identity the session was issued for, and the request must be rejected otherwise.
Variants to test
- Other custom challenge answers. On any Cognito-backed app using
CUSTOM_AUTH, replayRespondToAuthChallengewith a session from one account and a valid IdToken from another. A positive result is anAuthenticationResultcontaining tokens for the session's account. - A positive result is a successful link that should have been rejected.
What happened, in plain words
A security researcher was looking at a website that lets people sign in either with an email address and password, or with their Google account. The website used a service from Amazon, called Amazon Cognito, to handle all of that signing in and checking of permissions. The researcher found a flaw in the way that service was wired up: it was possible to take a valid login session that belonged to one person and pair it with a login token that belonged to a completely different person, and the service would happily hand back the first person's login tokens. With those tokens, an attacker holds the victim's access token, ID token and refresh token.
The researcher calls the target redirect.com because the bug was still unfixed when the write-up was published, so the real name is withheld. Everything below is about how the researcher got there, step by step, in a way you can follow even if you have never done security testing before.
Background: what Amazon Cognito is
Before the attack makes sense, you need to know what the website was using under the bonnet.
Amazon Cognito is a service that Amazon Web Services (AWS) sells. It does the boring but critical job of letting users sign up, sign in, and get permission to do things. Instead of every website building its own login system from scratch, the website hands that job to Cognito. Cognito has two main parts:
- User pools: a directory of users. It handles sign-up and sign-in, either with a username and password, or through a third party such as Facebook, Amazon, Google or Apple. When someone signs in successfully, the app receives tokens from the user pool.
- Identity pools: these let the developer give users access to other AWS services. They can be used on their own or together with user pools.
After a successful sign-in, the app gets user pool tokens. The developer can use those tokens to fetch AWS credentials, to control access to server-side resources, or to control access to Amazon API Gateway. The developer can also create user pool groups to manage permissions and to represent different types of users.

A quick everyday comparison: think of a user pool as the reception desk of an office building. You show your ID, the receptionist checks it, and gives you a visitor badge. The badge is a token. Other doors in the building trust the badge, not you personally. If someone else gets hold of your badge, they can walk through the same doors you can.
The two sign-in flows that matter
Cognito supports several ways of signing a user in. Two of them are relevant here.
Client-side authentication flow
This is the ordinary flow most people experience without noticing:
- The user enters their user name and password into the app.
- The app calls
InitiateAuthwith the user name and Secure Remote Password (SRP) details. This operation returns the authentication parameters. - The app calls
RespondToAuthChallenge. If it succeeds, Cognito returns the user's tokens and the flow is complete. If another challenge is required, no tokens are returned; instead the call returns a session. - If
RespondToAuthChallengereturns a session, the app callsRespondToAuthChallengeagain with the session and the challenge response (for example an MFA code).

A session here is a short-lived handle that Cognito gives the app so that the next step can be tied back to the same sign-in attempt. Think of it as a numbered ticket you get at a deli counter: you order, you get a ticket, and when your number is called you come back to collect your food. The ticket on its own is not the food, but it lets the counter know which order is yours.
MFA stands for multi-factor authentication: a second proof of identity, such as a code sent by SMS, on top of the password.
Custom authentication flow
User pools also allow custom flows, which build a challenge/response model using AWS Lambda triggers. A Lambda trigger is a small piece of code that AWS runs automatically at a particular moment, like a hook. The flow starts with InitiateAuth, indicating the type of authentication and any initial parameters. Cognito answers with one of three things:
- A challenge for the user, along with a session and parameters.
- An error if the user fails to authenticate.
- ID, access and refresh tokens if the supplied parameters are sufficient to sign the user in. Typically the user or app must first answer a challenge, but the custom code determines this.
If a challenge comes back, the app gathers more input and calls RespondToAuthChallenge with the challenge responses and the session. Cognito responds the same way as to InitiateAuth: tokens if signed in, otherwise another challenge or an error. The sequence repeats until the user signs in or an error is returned.
An app starts a custom flow by calling InitiateAuth with CUSTOM_AUTH as the Authflow. Three Lambda triggers control challenges and verification:
DefineAuthChallengetakes a session array of previous challenges and responses, and generates the next challenge name plus Booleans indicating whether the user is authenticated and can be granted tokens. It is a state machine controlling the user's path through the challenges.CreateAuthChallengetakes a challenge name and generates the challenge and parameters used to evaluate the response. WhenDefineAuthChallengereturnsCUSTOM_CHALLENGEas the next challenge, the flow callsCreateAuthChallenge, which passes the next type of challenge in the challenge metadata parameter.VerifyAuthChallengeResponseevaluates the response and returns a Boolean indicating whether it was valid.
A custom flow can combine built-in challenges, such as SRP password verification and SMS MFA, with custom challenges such as CAPTCHA or secret questions.

A state machine is just a set of rules about what can happen next: from state A you can go to B, from B to C, and so on. A vending machine is a state machine: insert coin, choose item, receive item.
Tokens: what they are and why they matter
A token is a string of characters that a server gives to a client as proof that something has already happened, usually a successful login. The client sends the token back on later requests instead of sending the password again. It is like a coat-check ticket: you hand over your coat once, get a ticket, and later the ticket gets your coat back. Whoever holds the ticket gets the coat.
Cognito issues three kinds of token.
IdToken. A JSON web token (JWT) containing claims about the authenticated user, such as name, email and phone_number. It can be used inside the application and to authenticate users to resource servers or server applications, and outside the application with web API operations, in which case its signature must be verified before any claims inside it are trusted. Its expiration can be set between 5 minutes and 1 day.
A JWT (JSON Web Token) is a token with a standard structure: three chunks of text separated by dots. The middle chunk is a JSON object with fields called claims, which are simply statements like "this user's email is X". The third chunk is a cryptographic signature, so the server can check the token was really issued by Cognito and not forged.
AccessToken. Contains claims about the authenticated user, a list of the user's groups and a list of scopes. Its purpose is to authorise API operations in the context of the user, for example to add, change or delete user attributes. Its expiration can also be set between 5 minutes and 1 day.
RefreshToken. Used to retrieve new ID and access tokens. By default it expires 30 days after sign-in, and the application's refresh token expiration can be set between 60 minutes and 10 years.
An API (Application Programming Interface) is the set of URLs and rules a program uses to talk to another program. When your browser loads a page, it is making API calls behind the scenes. An API endpoint is one specific URL in that set, like one counter in a post office: each counter does one job.
Setting up
The researcher worked as a normal user of the program, with a tool called BurpSuite to capture and replay requests. BurpSuite is a program that sits between your browser and the website and lets you see, pause, edit and resend every request. Think of it as a transparent proxy: the browser talks to Burp, Burp talks to the website, and you can read and change everything in the middle.
The scope was limited to authentication and authorisation: sign-up, sign-in and OAuth where available. OAuth is the system that lets you click "Sign in with Google" and have Google vouch for you, without the website ever seeing your Google password.
Two accounts are involved in the attack: the attacker's own account, used to obtain a valid IdToken, and a victim account whose username and email are known to the attacker. No special tooling beyond BurpSuite Repeater is shown. Repeater is the part of BurpSuite that lets you take one captured request, change a value, and send it again to see what comes back.
Finding it
The recon was done in three stages: use the program as a normal user, analyse requests and responses to understand what each feature does, then build an attack scenario from that analysis. Recon (reconnaissance) just means looking around before attacking.
Registering with email and password revealed nothing unfamiliar. Registering through OAuth revealed two things:
- During registration, after authenticating with the third party and granting access to the application, there were delays in accessing the account that did not stem from the internet connection.
- After registration there was no option to change the email or to unlink the Google account from the program account.
After noticing these, the researcher moved on to analysing the OAuth registration requests, which were highlighted in BurpSuite so they could be analysed individually. That prompted a closer look at the OAuth registration requests, which were highlighted in BurpSuite so they could be analysed individually.
The OAuth registration process works as follows.
- Clicking the Google icon transfers the user to Google for authentication, then to the consent step granting access to the client (the target app).

- The user pool receives the code from the third-party provider, exchanges it for tokens, and sends them to the program. Decoding the JWT showed that the email had not yet been verified.

- The client generates an API call to an endpoint responsible for linking the Google account username with the program account. That endpoint takes 2 parameters and the IdToken as part of the request headers.

- The target app does an extra step, fetching the IdToken and AccessToken after the email has been confirmed, using two requests. First it connects to an
InitiateAuthendpoint that takes a set of parameters in JSON. This endpoint fetches a valid session belonging to the user account, the challenge name created by the website developers through the AWS Lambda trigger, and the username and email address of the user account.

Second, the app connects to the RespondToAuthChallenge endpoint with the session, the ChallengeName and the username from the previous step, plus additional parameters. If the session, username and the additional parameter Answer (the IdToken) are validated, user-specific tokens are returned in the HTTP response. The session is associated with the username of the user and the IdToken.

A header is a small piece of metadata attached to a request, like the label on a parcel. The body is the contents. JSON is a text format for structured data, using curly braces and quotes, that both humans and programs can read.
The question that drove the attack: what happens if a valid session of another user is used instead of my own session, together with the IdToken of my account and the username of the other user account? Manipulating the parameters of the RespondToAuthChallenge request answered it.
Exploitation
Step 1: obtain the attacker's IdToken
The attacker logs in to their own account to get a valid IdToken belonging to that account.
Step 2: obtain the victim's session with InitiateAuth
The attacker sends a POST request to the AWS InitiateAuth endpoint to retrieve a valid session belonging to the victim account. In BurpSuite Repeater, a new window is opened with this request:
POST / HTTP/2Host: cognito-idp.us-east-1.amazonaws.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0Accept: */*Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: https://redirect.com/Content-Type: application/x-amz-json-1.1X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuthX-Amz-User-Agent: aws-amplify/5.0.4 jsContent-Length: 155Origin: https://redirect.comSec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: cross-siteTe: trailers{"AuthFlow":"CUSTOM_AUTH","ClientId":"targetAppClientId","AuthParameters":{"USERNAME":"XXXXXXXXXXXXXXXXXXX"},"ClientMetadata":{}}
Line by line, in plain words:
POST / HTTP/2says this is a POST request (a request that sends data) to the root path, over HTTP version 2.Host: cognito-idp.us-east-1.amazonaws.comsays which server the request is going to: Amazon's Cognito service in the us-east-1 region.User-Agent,Accept,Accept-Language,Accept-Encodingare standard headers that describe the browser and what it will accept back. They are copied from a real browser so the request looks normal.Referer: https://redirect.com/tells the server which page the request came from.Content-Type: application/x-amz-json-1.1says the body is JSON in Amazon's particular flavour.X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuthis the important one: it tells Cognito which operation to run. Here it isInitiateAuth, the operation that starts a sign-in.X-Amz-User-Agent: aws-amplify/5.0.4 jsidentifies the client library the app uses.Content-Length: 155is the size of the body in bytes.Origin: https://redirect.comsays which site the request is being made on behalf of.Sec-Fetch-*andTeare browser security and transport headers.- The body is JSON:
AuthFlowis set toCUSTOM_AUTH, which selects the custom authentication flow;ClientIdidentifies the app;AuthParameterscontains theUSERNAME;ClientMetadatais an empty object.
The X-Amz-Target header selects the AWSCognitoIdentityProviderService.InitiateAuth operation, the body sets AuthFlow to CUSTOM_AUTH and identifies the app with ClientId. The victim's email is put as the value of the USERNAME parameter. The response body is:
{"ChallengeName":"CUSTOM_CHALLENGE","ChallengeParameters":{"USERNAME":"VICTIM_USERNAME","email":"Victim's email"},"Session":"Victim's session"}
So the call returns a CUSTOM_CHALLENGE, the victim's username and email in the challenge parameters, and a session belonging to the victim. In other words, just by naming the victim's email, the attacker gets a ticket that the system considers to belong to the victim. The response echoes back the victim's username and email in the challenge parameters.
Step 3: exchange the victim's session for the victim's tokens
The attacker sends a POST request to the AWS RespondToAuthChallenge endpoint to retrieve valid tokens belonging to the victim account, while using an IdToken for the attacker's account. In BurpSuite Repeater, another window is opened with this request:
POST / HTTP/2Host: cognito-idp.us-east-1.amazonaws.comUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0Accept: */*Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateReferer: https://redirect.com/Content-Type: application/x-amz-json-1.1X-Amz-Target: AWSCognitoIdentityProviderService.RespondToAuthChallengeX-Amz-User-Agent: aws-amplify/5.0.4 jsContent-Length: 2385Origin: https://redirect.comSec-Fetch-Dest: emptySec-Fetch-Mode: corsSec-Fetch-Site: cross-siteTe: trailers{"ChallengeName":"CUSTOM_CHALLENGE","ChallengeResponses":{"USERNAME":"VICTIM-USERNAME","ANSWER":"ATTACKER_IdToken"},"ClientId":"targetAppClientId","Session":"VICTIM'S_SESSION"}
Line by line:
- The headers are the same as before, except
X-Amz-Targetnow saysAWSCognitoIdentityProviderService.RespondToAuthChallenge, which is the operation that answers a challenge. Content-Length: 2385is larger because the body now contains a full IdToken, which is a long string.- In the body,
ChallengeNameisCUSTOM_CHALLENGE, matching what the previous response said. ChallengeResponsesholds the answer:USERNAMEis the victim's username, andANSWERis the attacker's IdToken.ClientIdis the same app identifier as before.Sessionis the victim's session from the previous response.
The three values that matter are set as follows:
- The victim's username as the value of the
USERNAMEparameter. - The attacker's IdToken as the value of the
ANSWERparameter. The attacker's IdToken must be valid. - The victim's session obtained from the previous request as the value of the
SESSIONparameter.
The response body is:
{"AuthenticationResult":{"AccessToken":"VICTIM'S-AccessToken","ExpiresIn":3600,"IdToken":"VICTIM'S_IdToken","RefreshToken":"VICTIM'S_RefreshToken","TokenType":"Bearer"},"ChallengeParameters":{}}
The attacker now holds the victim's access token, ID token and refresh token, with an ExpiresIn of 3600 seconds. ExpiresIn is how long, in seconds, the access token stays valid: 3600 seconds is one hour. TokenType: Bearer means "whoever bears (carries) this token is treated as the user", which is exactly why stealing it is so damaging.


Root cause
By manipulating the parameter values of the RespondToAuthChallenge request, the author found that:
- The session is validated and linked to the username.
- The validity of the IdToken is verified.
- It is not checked whether the IdToken is associated with this session and this username.
The checks are performed piece by piece: the session belongs to the victim, the IdToken is a genuine, valid token, and the username matches the session.: the session belongs to the victim, the IdToken is a genuine, valid token, and the username matches the session. Nothing ties the IdToken to the session or to the username it is presented with, so any valid IdToken from any account satisfies the challenge for any session.
A comparison: imagine a nightclub where the bouncer checks that your ticket is genuine, and checks that the name on the guest list matches the name you gave, but never checks that the ticket has your name on it. Anyone with any genuine ticket gets in under any name on the list.
Impact
An attacker who knows a victim's username or email can obtain that victim's access token, ID token and refresh token. The author notes the bug was not fixed at the time of writing and does not describe the program or its bounty.
Fix
The report does not describe a fix. : the identity in the verified token has to match the identity the session was issued for, and the request must be rejected otherwise.
Variants to test
- Other custom challenge answers. On any Cognito-backed app using
CUSTOM_AUTH, replayRespondToAuthChallengewith a session from one account and a valid IdToken from another. A positive result is anAuthenticationResultcontaining tokens for the session's account. - A positive result is a successful link that should have been rejected.
Glossary
- Account takeover: an attack in which someone else gains control of a victim's account, usually by stealing their login credentials or tokens.
- API (Application Programming Interface): the set of URLs and rules one program uses to talk to another.
- API endpoint: one specific URL in an API, each doing one job.
- AccessToken: a Cognito token that authorises API operations in the context of a user, for example changing user attributes.
- Amazon Cognito: an AWS service that handles sign-up, sign-in and permissions for web and mobile apps.
- AWS (Amazon Web Services): Amazon's cloud platform, which hosts many services including Cognito.
- AWS Lambda trigger: a small piece of code that AWS runs automatically at a particular moment in a flow.
- Boolean: a value that is either true or false.
- BurpSuite: a tool that sits between a browser and a website so requests can be seen, paused, edited and resent.
- Claim: a statement inside a token, such as the user's email address.
- Client: the program (browser or app) that talks to a server.
- ClientId: an identifier that tells Cognito which application is making the request.
- Content-Type: a header that says what format the body of a request is in.
- Cookie: a small piece of data a website stores in your browser and that your browser sends back on later requests.
- CUSTOM_AUTH: the value of
AuthFlowthat selects Cognito's custom authentication flow. - CUSTOM_CHALLENGE: the challenge name returned when the custom flow wants the app to answer a challenge.
- DefineAuthChallenge: the Lambda trigger that decides what the next challenge should be.
- CreateAuthChallenge: the Lambda trigger that builds the challenge and its parameters.
- VerifyAuthChallengeResponse: the Lambda trigger that checks whether the answer to a challenge is valid.
- Header: metadata attached to a request or response, like a label on a parcel.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- HTTP/2: a newer version of HTTP.
- IdP (Identity Provider): a service that vouches for a user's identity, such as Google or Facebook.
- IdToken: a Cognito token containing claims about the authenticated user, such as name, email and phone number.
- Identity pool: the Cognito component that grants users access to other AWS services.
- IDOR (Insecure Direct Object Reference): a bug where the server accepts an identifier from the client and acts on it without checking the client is allowed to use it.
- InitiateAuth: the Cognito operation that starts a sign-in and may return a challenge and a session.
- JSON: a text format for structured data using curly braces, quotes and colons.
- JWT (JSON Web Token): a token with three dot-separated parts, the middle one holding claims and the last one a signature.
- Lambda: see AWS Lambda trigger.
- MFA (Multi-Factor Authentication): a second proof of identity on top of a password, such as an SMS code.
- OAuth: the system that lets a site sign you in via another provider such as Google, without seeing your password there.
- Origin: a header that says which site a request is being made on behalf of.
- POST: an HTTP request method used to send data to a server.
- Recon (reconnaissance): looking around a target before attacking, to understand how it works.
- Repeater: the part of BurpSuite that lets you edit and resend a single request.
- RefreshToken: a Cognito token used to obtain new ID and access tokens.
- RespondToAuthChallenge: the Cognito operation that answers a challenge and, if accepted, returns tokens.
- Scope: a permission listed inside an access token.
- Session: a short-lived handle Cognito gives the app so the next step of a sign-in can be tied back to the same attempt.
- SRP (Secure Remote Password): a way of proving a password without sending it over the network.
- State machine: a set of rules about which state can follow which.
- Token: a string a server gives a client as proof that something, usually a login, has already happened.
- User pool: the Cognito component that stores users and handles sign-up and sign-in.
- X-Amz-Target: the header that tells Cognito which operation to run.
- Referer: a header that says which page a request came from.
- User-Agent: a header that describes the browser or client making the request.