[PR #2954] [CLOSED] Fix account enumeration vulnerabilities #4571

Closed
opened 2026-03-13 11:51:21 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2954
Author: @DePasqualeOrg
Created: 6/9/2025
Status: Closed

Base: mainHead: fix-account-enumeration-vulnerabilities


📝 Commits (3)

  • 1b1681b Prevent timing attack from revealing valid phone numbers
  • a811cc9 Prevent email and username enumeration
  • c36c336 Fix linter error

📊 Changes

12 files changed (+103 additions, -49 deletions)

View changed files

📝 docs/components/builder/index.tsx (+0 -1)
📝 packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.mysql.test.ts (+1 -1)
📝 packages/better-auth/src/adapters/kysely-adapter/test/normal/adapter.kysely.test.ts (+1 -1)
📝 packages/better-auth/src/api/routes/email-verification.ts (+0 -1)
📝 packages/better-auth/src/api/routes/sign-up.ts (+17 -3)
📝 packages/better-auth/src/plugins/email-otp/index.ts (+26 -6)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/team.test.ts (+1 -1)
📝 packages/better-auth/src/plugins/phone-number/index.ts (+4 -0)
📝 packages/better-auth/src/plugins/username/index.ts (+6 -3)
📝 packages/better-auth/src/plugins/username/username.test.ts (+4 -2)
📝 packages/stripe/src/stripe.test.ts (+41 -28)

📄 Description

This PR addresses multiple account enumeration vulnerabilities that could allow attackers to discover registered email addresses, usernames, and phone numbers through different API responses and timing attacks.

Please check these changes carefully, since I'm not yet deeply familiar with the internals of better-auth. In the interest of transparency, I generated these changes with Claude 4 Sonnet in Cursor after noticing an account enumeration vulnerability while testing my fix to the currently broken SvelteKit example.

Changes

  • Email Sign-up: Return success response instead of "User already exists" error

  • Email Verification: Return success response instead of "User not found" error

  • Username Plugin: Prevent username enumeration during sign-up by returning success for existing usernames

  • Phone Number Plugin: Add timing attack protection by hashing passwords for non-existent phone numbers

  • Email OTP Plugin: Fix enumeration in password reset, verification, and sign-in flows

  • Tests: Update username enumeration test to validate new secure behavior

  • API Schema: Make user field nullable in sign-up responses for enumeration protection

Security Impact

  • Before: Attackers could enumerate registered users through distinct error messages and timing differences

  • After: All endpoints return consistent success responses, preventing information disclosure

Breaking Changes

  • Sign-up endpoints now return { user: null, token: null } for existing emails/usernames instead of throwing errors

  • Applications should handle the null user response appropriately in their UI


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/2954 **Author:** [@DePasqualeOrg](https://github.com/DePasqualeOrg) **Created:** 6/9/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-account-enumeration-vulnerabilities` --- ### 📝 Commits (3) - [`1b1681b`](https://github.com/better-auth/better-auth/commit/1b1681bf815ceb090b88fd237e6a7856a965bbad) Prevent timing attack from revealing valid phone numbers - [`a811cc9`](https://github.com/better-auth/better-auth/commit/a811cc949566df4a1de3d31d6037242107c80906) Prevent email and username enumeration - [`c36c336`](https://github.com/better-auth/better-auth/commit/c36c336c49277bb887689b68dc670b439e0a4302) Fix linter error ### 📊 Changes **12 files changed** (+103 additions, -49 deletions) <details> <summary>View changed files</summary> 📝 `docs/components/builder/index.tsx` (+0 -1) 📝 `packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.mysql.test.ts` (+1 -1) 📝 `packages/better-auth/src/adapters/kysely-adapter/test/normal/adapter.kysely.test.ts` (+1 -1) 📝 `packages/better-auth/src/api/routes/email-verification.ts` (+0 -1) 📝 `packages/better-auth/src/api/routes/sign-up.ts` (+17 -3) 📝 `packages/better-auth/src/plugins/email-otp/index.ts` (+26 -6) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/team.test.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/phone-number/index.ts` (+4 -0) 📝 `packages/better-auth/src/plugins/username/index.ts` (+6 -3) 📝 `packages/better-auth/src/plugins/username/username.test.ts` (+4 -2) 📝 `packages/stripe/src/stripe.test.ts` (+41 -28) </details> ### 📄 Description This PR addresses multiple account enumeration vulnerabilities that could allow attackers to discover registered email addresses, usernames, and phone numbers through different API responses and timing attacks. Please check these changes carefully, since I'm not yet deeply familiar with the internals of better-auth. In the interest of transparency, I generated these changes with Claude 4 Sonnet in Cursor after noticing an account enumeration vulnerability while testing [my fix to the currently broken SvelteKit example](https://github.com/better-auth/better-auth/pull/2404). ### Changes - Email Sign-up: Return success response instead of "User already exists" error - Email Verification: Return success response instead of "User not found" error - Username Plugin: Prevent username enumeration during sign-up by returning success for existing usernames - Phone Number Plugin: Add timing attack protection by hashing passwords for non-existent phone numbers - Email OTP Plugin: Fix enumeration in password reset, verification, and sign-in flows - Tests: Update username enumeration test to validate new secure behavior - API Schema: Make user field nullable in sign-up responses for enumeration protection ### Security Impact - Before: Attackers could enumerate registered users through distinct error messages and timing differences - After: All endpoints return consistent success responses, preventing information disclosure ### Breaking Changes - Sign-up endpoints now return { user: null, token: null } for existing emails/usernames instead of throwing errors - Applications should handle the null user response appropriately in their UI --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 11:51:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#4571