Skip to content

Notify users when resetting password for an unregistered account (#1251) - #1264

Open
IshanA2007 wants to merge 2 commits into
devfrom
1251-notify-unregistered-password-reset
Open

Notify users when resetting password for an unregistered account (#1251)#1264
IshanA2007 wants to merge 2 commits into
devfrom
1251-notify-unregistered-password-reset

Conversation

@IshanA2007

Copy link
Copy Markdown
Collaborator

Closes #1251

⚠️ Draft for maintainer discussion — security tradeoff

Explicitly telling a user "no account exists" partially defeats Cognito's prevent_user_existence_errors = "ENABLED" (iac/cognito.tf:66) anti-enumeration protection — it lets an attacker probe which emails have accounts. The issue explicitly requests this behavior, and a prior attempt (PR #1254) was closed over exactly this tension. Opening as draft so maintainers can decide whether the UX win is worth the enumeration exposure.

Problem

Auth is fully Cognito-hosted. When someone requests a password reset (or email OTP) for an email with no account, Cognito silently no-ops — no email, no message — leaving the user confused.

Fix

New custom /forgot-password/ Django flow:

  1. User enters email; the view looks it up in the local auth-user table case-insensitively (email__iexact).
  2. No match → "No account is associated with that email address. Sign in with your UVA email to create an account."
  3. Match → calls Cognito forgot_password via boto3 (computes SECRET_HASH when the app client has a secret) to send the reset email; redirects to login with a generic confirmation.
  4. UserNotFoundException → same no-account message; other Cognito errors → generic retry (no existence leak) + logged.

Adds a "Forgot your password?" link to the login modal.

Leakage limiting: the success copy is deliberately generic ("If an account exists…") and Cognito-side errors never reveal existence — the only disclosure is the local-DB pre-check the issue asks for.

Verification (actually run — throwaway Postgres)

  • manage.py check — no issues.
  • New tcf_website/tests/test_auth.py8/8 pass (GET render, empty/unknown/known email, case-insensitivity, secret-hash on/off, UserNotFoundException, generic error).
  • Existing test_redirects (33 incl. auth) — pass. ruff check — clean.

Follow-up

Rate-limit /forgot-password/ (per-IP + per-email) — it's unauthenticated and triggers Cognito calls/emails.


🤖 Implemented with Claude Code.

Cognito's hosted UI has prevent_user_existence_errors enabled, so a
password reset for an unknown email silently no-ops and the user is left
with no feedback. Add a custom /forgot-password/ page that checks the
local account table first:

- No matching account (case-insensitive email lookup): tell the user to
  sign in with their UVA email to create one.
- Matching account: call Cognito's forgot_password via boto3 to send the
  reset code, computing SECRET_HASH when the app client has a secret.
  UserNotFoundException maps to the same "no account" message; other
  Cognito errors surface a generic retry message.

Also add a "Forgot your password?" link to the login modal and unit
tests covering GET render, empty/unknown/known email, the no-secret
path, UserNotFoundException, and generic Cognito errors (boto3 mocked).

Fixes #1251
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@IshanA2007, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c81ecbf5-b193-4215-aef9-af8aa25af26a

📥 Commits

Reviewing files that changed from the base of the PR and between ed955fb and 7e51024.

📒 Files selected for processing (6)
  • tcf_website/templates/site/auth/forgot_password.html
  • tcf_website/templates/site/common/modals/_login.html
  • tcf_website/tests/test_auth.py
  • tcf_website/urls.py
  • tcf_website/views/__init__.py
  • tcf_website/views/auth/__init__.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 1251-notify-unregistered-password-reset

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@IshanA2007
IshanA2007 marked this pull request as ready for review July 8, 2026 18:53
@IshanA2007 IshanA2007 self-assigned this Jul 8, 2026
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.

Bug: User not notified if resetting password with unregistered account

1 participant