Miggo Logo

CVE-2025-61928: Better Auth: Unauthenticated API key creation through api-key plugin

N/A

CVSS Score

Basic Information

EPSS Score
0.29115%
Published
10/9/2025
Updated
10/13/2025
KEV Status
No
Technology
TechnologyJavaScript

Technical Details

CVSS Vector
-
Package NameEcosystemVulnerable VersionsFirst Patched Version
better-authnpm< 1.3.261.3.26

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability allows an unauthenticated attacker to create API keys for any user by exploiting a flaw in the authentication logic. The analysis of the provided commit 556085067609c508f8c546ceef9003ee8c607d39 confirms this.

The patch modifies the createApiKey function in packages/better-auth/src/plugins/api-key/routes/create-api-key.ts. The original code made authentication optional if a userId was present in the request body, which is the root cause of the vulnerability. An attacker could simply include a victim's userId in the POST request to /api/auth/api-key/create to generate an API key for that user.

The vulnerable function identified is createApiKey. The patch replaces the flawed logic with a stricter check that ensures a session exists for the request and that the userId in the body matches the session's user ID if provided. Although the vulnerability description mentions a similar flaw in an 'update endpoint', the provided commit only contains changes for the creation endpoint. Therefore, the analysis is focused on the explicitly patched createApiKey function.

Vulnerable functions

createApiKey
packages/better-auth/src/plugins/api-key/routes/create-api-key.ts
The function `createApiKey` was vulnerable to an authentication bypass. The logic incorrectly determined if authentication was required. Specifically, if a `userId` was present in the request body, `authRequired` was set to `false`. This allowed the code to proceed without a valid session, creating a user object with the `userId` supplied by the attacker: `{ id: ctx.body.userId }`. Consequently, an unauthenticated attacker could forge a request to create an API key for any user, gaining unauthorized access.

WAF Protection Rules

WAF Rule

### Summ*ry Un*ut**nti**t** *tt**k*rs **n *r**t* or mo*i*y *PI k*ys *or *ny us*r *y p*ssin* t**t us*r's i* in t** r*qu*st *o*y to t** `*pi/*ut*/*pi-k*y/*r**t*` rout*. ### **t*ils T** vuln*r**ility *xists in t** *ut**nti**tion lo*i* *t w**n ****kin*

Reasoning

T** vuln*r**ility *llows *n un*ut**nti**t** *tt**k*r to *r**t* *PI k*ys *or *ny us*r *y *xploitin* * *l*w in t** *ut**nti**tion lo*i*. T** *n*lysis o* t** provi*** *ommit `****************************************` *on*irms t*is. T** p*t** mo*i*i*s t