9.3critical
Better Auth: Unauthenticated API key creation through api-key plugin
- Severity
- 9.3critical CVSS:4.0 by GitHub_M
- Exploit likelihood
- 17.8% (higher than 97% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-99h5-pjcv-gr6v
Description
Better Auth is an authentication and authorization library for TypeScript. In versions prior to 1.3.26, unauthenticated attackers can create or modify API keys for any user by passing that user's id in the request body to the `api/auth/api-key/create` route. `session?.user ?? (authRequired ? null : { id: ctx.body.userId })`. When no session exists but `userId` is present in the request body, `authRequired` becomes false and the user object is set to the attacker-controlled ID. Server-only field validation only executes when `authRequired` is true (lines 280-295), allowing attackers to set privileged fields. No additional authentication occurs before the database operation, so the malicious payload is accepted. The same pattern exists in the update endpoint. This is a critical authentication bypass enabling full an unauthenticated attacker can generate an API key for any user and immediately gain complete authenticated access. This allows the attacker to perform any action as the victim user using the api key, potentially compromise the user data and the application depending on the victim's privileges. Version 1.3.26 contains a patch for the issue.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| better-auth better-auth | < 1.3.26 | CVE List |
| better-auth (npm) | before 1.3.26 | GitHub Advisory Database |
All scores
| GitHub_M | 9.3critical CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N |
| GitHub | 8.6high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:L |
Classification
What each source says
CVE List
Better Auth is an authentication and authorization library for TypeScript. In versions prior to 1.3.26, unauthenticated attackers can create or modify API keys for any user by passing that user's id in the request body to the `api/auth/api-key/create` route. `session?.user ?? (authRequired ? null : { id: ctx.body.userId })`. When no session exists but `userId` is present in the request body, `authRequired` becomes false and the user object is set to the attacker-controlled ID. Server-only field validation only executes when `authRequired` is true (lines 280-295), allowing attackers to set privileged fields. No additional authentication occurs before the database operation, so the malicious payload is accepted. The same pattern exists in the update endpoint. This is a critical authentication bypass enabling full an unauthenticated attacker can generate an API key for any user and immediately gain complete authenticated access. This allows the attacker to perform any action as the victim user using the api key, potentially compromise the user data and the application depending on the victim's privileges. Version 1.3.26 contains a patch for the issue.
GitHub Advisory Database
Summary
A critical authentication bypass was identified in the API key creation and update endpoints. An attacker could create or modify API keys for arbitrary users by supplying a victim’s user ID in the request body. Due to a flaw in how the authenticated user was derived, the endpoints could treat attacker-controlled input as an authenticated user object under certain conditions.
Details
The vulnerability originated from fallback logic used when determining the current user. When no session was present, the handler incorrectly allowed request-body data to populate the user context used for authorization decisions. Because server-side validation only executed when authentication was required, privileged fields were not properly protected. As a result, the API accepted unauthenticated requests that targeted other users.
This same pattern affected both the API key creation and update routes.
Impact
Unauthenticated attackers could generate or modify API keys belonging to any user. This granted full authenticated access as the targeted user and, depending on the user’s privileges, could lead to account compromise, access to sensitive data, or broader application takeover.
NVD (es)
Better Auth es una biblioteca de autenticación y autorización para TypeScript. En versiones anteriores a la 1.3.26, atacantes no autenticados pueden crear o modificar claves API para cualquier usuario pasando el ID de ese usuario en el cuerpo de la solicitud a la ruta 'api/auth/api-key/create'. 'session?.user ?? (authRequired ? null : { id: ctx.body.userId })'. Cuando no existe ninguna sesión pero 'userId' está presente en el cuerpo de la solicitud, 'authRequired' se vuelve falso y el objeto de usuario se establece en el ID controlado por el atacante. La validación de campos solo del servidor solo se ejecuta cuando 'authRequired' es verdadero (líneas 280-295), permitiendo a los atacantes establecer campos privilegiados. No se produce ninguna autenticación adicional antes de la operación de la base de datos, por lo que la carga útil maliciosa es aceptada. El mismo patrón existe en el endpoint de actualización. Esto es una omisión de autenticación crítica que permite que un atacante no autenticado pueda generar una clave API para cualquier usuario y obtener inmediatamente acceso autenticado completo. Esto permite al atacante realizar cualquier acción como el usuario víctima utilizando la clave API, potencialmente comprometer los datos del usuario y la aplicación dependiendo de los privilegios de la víctima. La versión 1.3.26 contiene un parche para el problema.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2025-61928 changed 2025-10-10 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-99h5-pjcv-gr6v changed 2025-12-09 | CC-BY-4.0 |
| NVD | CVE-2025-61928 changed 2026-10-19 | Public domain |