Join our Newsletter — 33% off our NHI Course
Home› Guides› Amazon Cognito Security Guide: User Pools, Identity Pools,…
Guide Cloud Security

Amazon Cognito Security Guide: User Pools, Identity Pools, Guest Access and Token Handling

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 13 min read
On this page

Amazon Cognito sits on the public internet and issues both application tokens and real AWS credentials, so a writable attribute, a generous guest role or a token that is never revoked can give anonymous users access to your AWS account. This guide covers the two halves of Cognito: user pools, which authenticate customers and issue JWTs, and identity pools, which exchange those tokens (or nothing at all, for guests) for temporary AWS credentials. It sets out the configuration choices that matter for security, how to verify and revoke tokens, how to log and detect abuse, and the misconfigurations that recur in assessments. It is for application security engineers, cloud architects and teams building customer sign-in on AWS. For customer identity strategy in general, see the Customer IAM (CIAM) Guide; feature behaviour here was checked against the Amazon Cognito Developer Guide on 27 October 2026.

Key takeaways

  • Identity pools hand out AWS credentials: an unauthenticated role is AWS access for anyone who knows the identity pool ID, which is usually embedded in the client app.
  • Trust policies must check aud and amr: IAM now requires the identity pool ID condition, but older roles and missing amr checks remain common.
  • App clients can write every attribute by default: any attribute used for authorisation must be removed from WriteAttributes on every app client.
  • Verify tokens properly: check signature, iss, token_use, aud or client_id and exp, and remember that offline verification cannot see revocation.
  • Turn on the defences that are off by default: refresh token rotation, threat protection in audit mode first, identity pool data event logging and user existence error suppression on API-created clients.

How identity and access work in Amazon Cognito

ComponentWhat it doesWhat it issuesMain security decision
User poolUser directory and OIDC provider: sign-up, sign-in, MFA, federation to social, SAML and OIDC IdPs, managed login pagesID token, access token, refresh tokenApp client settings, attribute permissions, token lifetimes, threat protection
App clientAn application's configuration within the user pool, public or with a client secretTokens for that clientAllowed flows, read and write attributes, revocation, rotation
Resource serverDefines custom OAuth scopes for your APIsScopes in access tokensScope design for APIs and machine-to-machine clients
Identity poolExchanges a user pool or other IdP token, or no token for guests, for AWS credentialsTemporary AWS credentials via AssumeRoleWithWebIdentityGuest access, role selection rules, IAM role permissions, basic or enhanced flow

Tokens

The ID token carries user attributes and has an aud equal to the app client ID. The access token carries scopes, cognito:groups and client_id. The refresh token is encrypted and opaque. ID and access tokens default to one hour and can be set between 5 minutes and 1 day; refresh tokens default to 30 days and can be set from 60 minutes to 10 years. Tokens can contain personal data and details of your authorisation model, so protect them in transit and at rest. For general token hygiene see the Token and Session Security Guide.

Verifying user pool JWTs

  1. Confirm the token is a three-part JWT and that alg is RS256.
  2. Match kid against the keys at https://cognito-idp.<Region>.amazonaws.com/<userPoolId>/.well-known/jwks.json, cached by kid and refreshed when an unknown kid arrives with the correct issuer.
  3. Check exp locally.
  4. Check aud (ID token) or client_id (access token) equals your app client ID.
  5. Check iss equals https://cognito-idp.<Region>.amazonaws.com/<userPoolId>.
  6. Check token_use is access for APIs that accept access tokens only, or id where you deliberately accept ID tokens.

AWS recommends the aws-jwt-verify library for Node.js, or any reputable OpenID Foundation listed library elsewhere. APIs should authorise on access tokens and scopes rather than ID tokens. See the JWT Security Guide.

Identity pools: authenticated and guest identities

Every identity pool identity is authenticated or unauthenticated, and each type maps to an IAM role. Guest access gives users who never signed in a unique identity ID and AWS credentials. The identity pool ID needed to request them ships inside the web or mobile app, so treat the unauthenticated role as public. The trust policy for both roles uses "Federated": "cognito-identity.amazonaws.com" and sts:AssumeRoleWithWebIdentity, with conditions on cognito-identity.amazonaws.com:aud (the identity pool ID) and cognito-identity.amazonaws.com:amr (authenticated or unauthenticated). For how these sessions behave, see the AWS STS and AssumeRole Guide.

FlowHow credentials are obtainedGuardrailsUse when
Enhanced (simplified) flowCognito selects the role and calls STS on the app's behalfGuest sessions get a scope-down inline session policy plus the managed policy AmazonCognitoUnAuthedIdentitiesSessionPolicy, limiting services and actionsDefault choice
Basic (classic) flowThe app calls AssumeRoleWithWebIdentity itself and can name any roleNo automatic scope-down; app can bypass role selection rulesOnly when a required service is outside the enhanced flow list

Do not use aws:SourceIp conditions in roles assumed through the enhanced flow, because Cognito makes the STS request, so the source IP never matches the user.

Admin roles and privileged access

Cognito administration is privileged access to your customers' accounts. The administrative APIs can create users, set passwords, mark email addresses as verified and sign users out.

  • Separate administration from the app: the application's runtime role should not hold cognito-idp:Admin* actions unless it genuinely needs them, and never cognito-idp:AdminSetUserPassword, AdminUpdateUserAttributes or UpdateUserPoolClient on the production pool from a public-facing service.
  • Treat email_verified as sensitive: an administrator can set it to true with AdminUpdateUserAttributes. Verified email and phone aliases transfer between accounts: if a user verifies an address that is already a verified alias on another account, Cognito moves the alias and marks it unverified on the original account. Test account recovery and linking flows against this behaviour.
  • Protect pool configuration: changes to app client flows, callback URLs, identity providers, Lambda triggers and identity pool roles should go through infrastructure as code with review. A changed callback URL or added IdP is an account takeover path.
  • Guard Lambda triggers: pre sign-up, pre token generation and migration triggers run with their own roles and can alter claims. Whoever can edit trigger code controls the tokens.
  • Scope the identity pool roles: the authenticated role is effectively granted to every customer. Use ${cognito-identity.amazonaws.com:sub} policy variables or principal tags so each user can only reach their own S3 prefix or DynamoDB items.

Integrations, API tokens and service accounts

Attribute permissions

A new app client can read and write all standard and custom attributes. If WriteAttributes is not set, users can change any attribute for themselves with UpdateUserAttributes. Because attributes are shared across every app client in the pool, a value written through one client appears in tokens issued by all of them. AWS's guidance is direct: if your application or identity pool makes authorisation decisions on an attribute (for example custom:role or custom:tenant_id), remove it from the WriteAttributes of every app client. Custom attributes cannot be deleted or changed after creation, so plan the schema before production. The legacy dev: developer attributes have been replaced by app client permissions.

Role selection and principal tags

Identity pools can choose a role per provider with up to 25 rules on token claims, or honour a preferred_role from user pool group membership. If no rule matches, role resolution either denies credentials or falls back to the authenticated role; choose deny. Attributes for access control map claims to principal tags (by default sub and aud) that IAM policies can test. Rules and tags are only as trustworthy as the claims behind them, which is why attribute write permissions matter.

Machine-to-machine clients

App clients with a client secret can use the OAuth client credentials grant against custom scopes defined on a resource server. These are non-human identities: store the client secret in a secrets manager, give each calling service its own app client, keep scopes narrow and rotate the secret on a schedule. Threat protection does not apply to client credentials requests, so monitor them separately. See the OAuth 2.0 Security Best Current Practice Guide.

Federation to external IdPs

User pools can federate to SAML and OIDC providers. Map IdP attributes carefully: a mapping into an attribute used for authorisation hands that decision to the IdP's administrators. Threat protection cannot be used with federated sign-in, so rely on the IdP's own controls. See the Customer IAM (CIAM) Guide.

Logging and detection

SourceWhat it recordsWhat to watch
CloudTrail management events, cognito-idp.amazonaws.comUser pool API calls (AwsApiCall) and managed login or hosted UI requests (AwsServiceEvent, for example Login_GET, Token_POST, signup_POST); the user's sub, not usernameSpikes of NotAuthorizedException by source IP, bursts of ForgotPassword, admin calls from unexpected principals, client and IdP configuration changes
CloudTrail data events for identity poolsGetId, GetCredentialsForIdentity, GetOpenIdToken and others; not logged by default and charged separatelyGuest identity creation rates, credentials issued to unauthenticated identities, use from unusual networks
CloudTrail for the identity pool rolesWhat guest and authenticated credentials actually doCalls outside the expected API set; enumeration such as ListBuckets or GetCallerIdentity
Threat protection logs (Plus plan)Authentication details, risk assessments and session metadata, exportable to S3, CloudWatch Logs or Amazon Data FirehoseHigh-risk sign-ins, compromised credential detections, blocked IPs

Cognito masks passwords and tokens in CloudTrail as HIDDEN_DUE_TO_SECURITY_REASONS but does not mask personal data placed in other request fields. Relevant ATT&CK techniques are T1110.004 Brute Force: Credential Stuffing, T1078.004 Valid Accounts: Cloud Accounts for misuse of issued credentials, and T1580 Cloud Infrastructure Discovery for guests probing the account.

Metrics

  • Guest role permissions: number of actions allowed to the unauthenticated role; target zero if guests are not needed.
  • Authorisation attributes writable by any app client: target zero.
  • App clients with refresh token rotation and revocation enabled: target 100 percent.
  • Credential stuffing signal: failed sign-ins per hour and per source IP against a baseline.
  • Threat protection coverage: share of password-based sign-ins assessed in full function mode.

Hardening baseline

SettingDefaultBaseline
Guest access on identity poolsOff until activatedOff unless a guest use case is documented; if on, near-zero permissions and per-identity resource scoping
Basic (classic) flowOffOff
Role trust conditionsaud enforced for new and edited policiesaud plus amr on every role; edit legacy roles to add them
Role resolution when no rule matchesConfigurableDeny
App client WriteAttributesAll attributesExplicit minimal list excluding authorisation attributes
PreventUserExistenceErrorsEnabled in console, LEGACY via APIENABLED on every client
Token revocationEnabled on new clientsEnabled on all clients, including older ones
Refresh token rotationOffEnabled with a short RetryGracePeriodSeconds
Token lifetimes1 hour ID and access, 30 days refreshShortest access token your offline verifiers can tolerate; refresh lifetime matched to risk
MFAConfigurableRequired or adaptive; prefer passkeys or authenticator apps over SMS
Threat protectionRequires Plus planAudit only for two weeks or more, then full function
Rate limitingNot provided by threat protectionAWS WAF web ACL on the user pool

Rollout

  1. Inventory user pools, app clients, identity pools and their roles; export each client's attribute permissions, flows and token settings.
  2. Close public AWS access first: review unauthenticated roles, switch any basic flow pools to enhanced flow where possible, add amr conditions, and set role resolution to deny.
  3. Lock attributes: set explicit WriteAttributes on every client in a test pool, run the app's sign-up and profile flows, then promote.
  4. Tokens: enable revocation on older clients, then rotation; move integrations from REFRESH_TOKEN_AUTH to GetTokensFromRefreshToken, which rotation requires.
  5. Threat protection: enable audit only, review risk decisions for at least two weeks, then switch to full function per app client. Rollback is returning the client to audit only.
  6. Logging: enable identity pool data events on the organisation trail and build the failed sign-in and ForgotPassword queries into alerts.

Small versus large deployments: a single app can run one user pool with a few clients and no identity pool. Multi-tenant platforms should decide early whether tenants share a pool (tenant attribute, read-only, enforced in every API) or get separate pools, because attributes are shared across all clients in a pool and custom attributes cannot be changed later.

Common misconfigurations

  • Guest roles with real permissions: an unauthenticated role allowed to read a bucket or invoke a function is open to anyone with the pool ID from the app bundle. In basic flow there is not even a scope-down policy.
  • Self-writable authorisation attributes: users call UpdateUserAttributes to set custom:role to admin, and the next ID token carries it to every API that trusts it.
  • Trusting ID tokens or skipping token_use: an ID token minted for one app client is accepted as an API access token by another.
  • Assuming sign-out kills tokens everywhere: revoked tokens still pass offline JWT checks until exp, and managed login cookies survive GlobalSignOut unless users are sent to the Logout endpoint.
  • Username enumeration through API-created clients left on LEGACY, feeding credential stuffing of the kind that reached about 18,000 accounts and data on roughly 7 million people in the 23andMe breach.
  • Relying on threat protection for volume attacks: it applies no rate limits; put AWS WAF in front of the user pool.

Framework mapping

FrameworkReferenceCognito control
NIST CSF 2.0PR.AA-01, PR.AA-03, PR.AA-05Customer and guest identity management, MFA and threat protection, least privilege identity pool roles
NIST SP 800-53 Rev. 5IA-2, IA-5, AC-6, AC-3, AU-2Authentication, token and secret management, scoped roles, attribute-based enforcement, CloudTrail events
OWASP ASVS 5.0V9 Self-contained Tokens, V10 OAuth and OIDCJWT validation and OAuth client configuration
CIS Controls v8.16 Access Control Management, 8 Audit Log Management, 16 Application Software SecurityMFA and access policy, Cognito logging, secure app integration
ISO/IEC 27001:2022 Annex A5.17, 8.5, 8.15Authentication information, secure authentication, logging
MITRE ATT&CK v20T1110.004, T1078.004, T1580Credential stuffing, misuse of issued AWS credentials, guest discovery

Practitioner checklist

  • Disable guest access unless documented; scope any unauthenticated role to the minimum.
  • Confirm every identity pool role trust policy checks aud and amr.
  • Keep identity pools on the enhanced flow and set role resolution to deny.
  • Set explicit WriteAttributes on every app client and exclude authorisation attributes.
  • Verify JWTs fully, including token_use and client_id, and authorise APIs on access tokens.
  • Enable token revocation and refresh token rotation on every client.
  • Set PreventUserExistenceErrors to ENABLED on every client.
  • Run threat protection in audit only, then full function, and add AWS WAF rate limits.
  • Log identity pool data events and alert on failed sign-in and password reset bursts.

Standards and references

Related NHI Mgmt Group resources: Customer IAM (CIAM) Guide · AWS STS and AssumeRole Guide · Token and Session Security Guide · Account Takeover Prevention Guide · AWS Security Guide

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org