Files
floci/docs
Mark a827daebfc fix(cognito): accept the sign-in alias in challenge responses (#8229)
In a pool with UsernameAttributes the challenge sessions keep the user's own
username (the sub), while the user signs in with, and answers with, the email.
NEW_PASSWORD_REQUIRED, MFA_SETUP, SOFTWARE_TOKEN_MFA and the SMS and email MFA
codes compared USERNAME with that stored sub, so a response that carried the
email was rejected with "Invalid session for the user." or "Session does not
match user".

The AWS Developer Guide ("Working with user attributes") says that with
username attributes the email address or phone number can be used in place of
the username in all APIs except ListUsers. Only the SRP password verifier is
documented to need USER_ID_FOR_SRP (AdminInitiateAuth ChallengeParameters), so
the SRP paths stay as they are.

isSessionUser first compares the sign-in keys, so a pool without aliases and
its case sensitivity behave as before. Only when they differ is the supplied
value resolved to its user and compared with the user of the session, which is
what the custom-auth challenges already do. The alias of another user is still
rejected.

Tests: CognitoAliasMfaIntegrationTest covers TOTP (MFA_SETUP and
SOFTWARE_TOKEN_MFA), SMS MFA and NEW_PASSWORD_REQUIRED in an alias pool, each
with a response for another user that must be rejected. docs/services/cognito.md
lists the behaviour next to the custom-auth rule.

applyNewPasswordAttributes read the user back with the USERNAME of the
response. That value can now be the email the user signed in with, so a
userAttributes.email in the same response made it stop naming the user once
the attribute was applied. The password had been changed and the session
consumed by then, and the response failed with UserNotFoundException without
a way to retry. It now takes the username of the user from the session. The
custom-auth challenge, which already accepted the alias, gets the same.

isSessionUser also looked up the username of the session. Every session holds
the username of its user already, and adminGetUser scans the pool, so that
lookup was a second scan for nothing. The supplied value is resolved once and
compared with the username of the session.

The new test answers NEW_PASSWORD_REQUIRED with the email and a new email,
then signs in with the new one.

validateCustomUsername and the CUSTOM_CHALLENGE check now use isSessionUser,
so a single check decides whether a USERNAME names the session's user.
Move latestSms into CognitoRestAssuredUtils and share it between the
alias and message MFA tests.

Closes #8228
2026-11-13 16:58:05 -04:00
..
2026-03-15 17:43:56 -05:00