[PR #6087] [MERGED] chore: refactor internal endpoints #14681

Closed
opened 2026-04-13 09:34:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6087
Author: @Bekacru
Created: 11/19/2025
Status: Merged
Merged: 11/19/2025
Merged by: @Bekacru

Base: canaryHead: chore/refactors


📝 Commits (8)

  • 1e35e57 fix: strip out refreshToken from account refreshToken endpoint
  • 740c4f0 fix: return early if email is verified
  • 9ac985e fix: create email verification token if user not found during verification
  • 9ee9358 test: add security tests for error page
  • a9f04e5 test: enhance password reset tests to ensure user existence is not revealed
  • 5cd7cbb fix: session revocation logic to check user authorization before deletion
  • 30828b6 fix: ensure password hashing occurs when credential account or current password is not found
  • 99cd38b fix: improve session deletion logic in sign-out endpoint to handle errors gracefully

📊 Changes

9 files changed (+183 additions, -36 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.ts (+6 -1)
📝 packages/better-auth/src/api/routes/email-verification.ts (+15 -0)
packages/better-auth/src/api/routes/error.test.ts (+33 -0)
📝 packages/better-auth/src/api/routes/reset-password.test.ts (+55 -0)
📝 packages/better-auth/src/api/routes/reset-password.ts (+24 -8)
📝 packages/better-auth/src/api/routes/session.ts (+14 -19)
📝 packages/better-auth/src/api/routes/sign-in.test.ts (+28 -0)
📝 packages/better-auth/src/api/routes/sign-in.ts (+2 -0)
📝 packages/better-auth/src/api/routes/sign-out.ts (+6 -8)

📄 Description

Summary by cubic

Refactored and hardened auth endpoints to reduce information leaks, prevent timing attacks, and improve session handling. Adds security checks and tests for XSS and unsafe callback URLs.

  • Bug Fixes

    • Password reset: simulate work on missing users, send email in the background, and always return a generic success message.
    • Email verification: generate a token when user is not found and return early if the email is already verified.
    • Sessions: revoke only when owned by the current user; sign-out handles missing tokens and DB errors while always clearing the cookie.
    • Security checks: sanitize error page query params and reject untrusted callback/error/new user URLs.
  • Refactors

    • Refresh token endpoint returns only explicit token fields (access/refresh and expirations).
    • Added tests for XSS sanitization, password reset non-disclosure, and URL validation.

Written for commit 99cd38b201. Summary will update automatically on new commits.


🔄 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/6087 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 11/19/2025 **Status:** ✅ Merged **Merged:** 11/19/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `chore/refactors` --- ### 📝 Commits (8) - [`1e35e57`](https://github.com/better-auth/better-auth/commit/1e35e5720515358c862cb2d155e908d4081f4657) fix: strip out refreshToken from account refreshToken endpoint - [`740c4f0`](https://github.com/better-auth/better-auth/commit/740c4f0991bbb6e658dc31e7d11eada8ee457412) fix: return early if email is verified - [`9ac985e`](https://github.com/better-auth/better-auth/commit/9ac985e9ebdad27c9f36a99760d6492e6ae07cfe) fix: create email verification token if user not found during verification - [`9ee9358`](https://github.com/better-auth/better-auth/commit/9ee9358ccff2fc5fbba62c0534a2563a7cf4a181) test: add security tests for error page - [`a9f04e5`](https://github.com/better-auth/better-auth/commit/a9f04e56f858f31cac414fe8feef0cca262776a2) test: enhance password reset tests to ensure user existence is not revealed - [`5cd7cbb`](https://github.com/better-auth/better-auth/commit/5cd7cbb7500c992141d889609f645ec2eafdc62e) fix: session revocation logic to check user authorization before deletion - [`30828b6`](https://github.com/better-auth/better-auth/commit/30828b6009faff8ccdfae324c2ac2c4ce41e0409) fix: ensure password hashing occurs when credential account or current password is not found - [`99cd38b`](https://github.com/better-auth/better-auth/commit/99cd38b2016b9c52545e9ef545f45a9c9dfcae2e) fix: improve session deletion logic in sign-out endpoint to handle errors gracefully ### 📊 Changes **9 files changed** (+183 additions, -36 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.ts` (+6 -1) 📝 `packages/better-auth/src/api/routes/email-verification.ts` (+15 -0) ➕ `packages/better-auth/src/api/routes/error.test.ts` (+33 -0) 📝 `packages/better-auth/src/api/routes/reset-password.test.ts` (+55 -0) 📝 `packages/better-auth/src/api/routes/reset-password.ts` (+24 -8) 📝 `packages/better-auth/src/api/routes/session.ts` (+14 -19) 📝 `packages/better-auth/src/api/routes/sign-in.test.ts` (+28 -0) 📝 `packages/better-auth/src/api/routes/sign-in.ts` (+2 -0) 📝 `packages/better-auth/src/api/routes/sign-out.ts` (+6 -8) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Refactored and hardened auth endpoints to reduce information leaks, prevent timing attacks, and improve session handling. Adds security checks and tests for XSS and unsafe callback URLs. - **Bug Fixes** - Password reset: simulate work on missing users, send email in the background, and always return a generic success message. - Email verification: generate a token when user is not found and return early if the email is already verified. - Sessions: revoke only when owned by the current user; sign-out handles missing tokens and DB errors while always clearing the cookie. - Security checks: sanitize error page query params and reject untrusted callback/error/new user URLs. - **Refactors** - Refresh token endpoint returns only explicit token fields (access/refresh and expirations). - Added tests for XSS sanitization, password reset non-disclosure, and URL validation. <sup>Written for commit 99cd38b2016b9c52545e9ef545f45a9c9dfcae2e. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <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-04-13 09:34:57 -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#14681