Headline
GHSA-99h5-pjcv-gr6v: Better Auth: Unauthenticated API key creation through api-key plugin
Summary
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.
Details
The vulnerability exists in the authentication logic at when checking for user authentication then derives the user as 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.
PoC
curl -X POST http://localhost:3000/api/auth/api-key/create \
-H 'Content-Type: application/json' \
-d '{
"userId": "victim-user-id",
"name": "zeropath"
}'
Response contains the new API key whose userId matches the victim, confirming the bypass.
Impact
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.
This issue was found by ZeroPath.
Summary
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.
Details
The vulnerability exists in the authentication logic at when checking for user authentication then derives the user as 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.
PoC
curl -X POST http://localhost:3000/api/auth/api-key/create \ -H ‘Content-Type: application/json’ \ -d ‘{ "userId": "victim-user-id", "name": “zeropath” }’
Response contains the new API key whose userId matches the victim, confirming the bypass.
Impact
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.
This issue was found by ZeroPath.
References
- GHSA-99h5-pjcv-gr6v
- better-auth/better-auth@5560850