Skip to content

fix(bb-auth-cognito): enable PreventUserExistenceErrors (close username enumeration oracle) - #293

Open
osama-rizk wants to merge 2 commits into
mainfrom
fix/cognito-prevent-user-enumeration
Open

fix(bb-auth-cognito): enable PreventUserExistenceErrors (close username enumeration oracle)#293
osama-rizk wants to merge 2 commits into
mainfrom
fix/cognito-prevent-user-enumeration

Conversation

@osama-rizk

Copy link
Copy Markdown
Contributor

What

Enable preventUserExistenceErrors: true on the Cognito UserPoolClient in packages/bb-auth-cognito/src/index.cdk.ts.

 this.userPoolClient = new cognito.UserPoolClient(this, 'client', {
   userPool: this.userPool,
   generateSecret: false,
+  // Return a uniform error for "user doesn't exist" and "wrong password"
+  // so sign-in / forgot-password responses can't enumerate registered
+  // usernames. Amazon's recommended posture is ENABLED.
+  preventUserExistenceErrors: true,
   disableOAuth: true,
   ...

Why

Board bug-bash card (P1 / Security): bb-auth-cognito: user enumeration via PreventUserExistenceErrors unsethttps://github.com/orgs/aws-amplify/projects/141/views/15?pane=issue&itemId=195532810

Cognito's default client returns a distinct UserNotFoundException for unknown usernames vs. a wrong-password error for known ones — a classic account-enumeration oracle on sign-in and forgot-password (reported 3× across bench rounds R6/R8). PreventUserExistenceErrors: ENABLED is Amazon's recommended setting.

Mock parity

No mock change needed. The mock's public sign-in path already returns a uniform NotAuthorized ("Incorrect username or password") for both missing-user and wrong-password (index.ts), matching ENABLED behavior. The only user-existence-revealing throw (UserNotFound) is in the privileged admin surface (buildAdminSurface), which is inside the trust boundary by design — so local↔AWS behavior stays aligned.

Testing

  • CDK regression test added asserting the synthesized AWS::Cognito::UserPoolClient has PreventUserExistenceErrors: ENABLED. Verified red on the prior code (Missing key 'PreventUserExistenceErrors'), green with the fix.
  • npm run build (full monorepo) — passes
  • npm test in packages/bb-auth-cognito — 231 tests, 0 failures
  • biome lint --changed --since=origin/main — clean
  • README Security Model note added; no public API change (internal CDK prop).

Changeset

Included (@aws-blocks/bb-auth-cognito patch).

…ool client

Cognito's default user pool client returns a distinct UserNotFoundException for
unknown usernames vs. a wrong-password error for known ones, which is an account-
enumeration oracle on sign-in and forgot-password. Setting
preventUserExistenceErrors: true makes Cognito return a uniform error regardless
of whether the username exists.

The mock's public sign-in path already returns a uniform NotAuthorized error, so
local↔AWS parity holds; the only user-existence-revealing throw is in the
privileged admin surface, which is inside the trust boundary by design.

Adds a CDK assertion that the synthesized UserPoolClient has
PreventUserExistenceErrors: ENABLED (verified red on the prior code).
@osama-rizk
osama-rizk requested a review from a team as a code owner August 3, 2026 10:26
@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f7b5ec4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-blocks/bb-auth-cognito Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants