Miggo Logo

GHSA-99h5-pjcv-gr6v: Better Auth: Unauthenticated API key creation through api-key plugin

N/A

CVSS Score

Basic Information

CVE ID
-
EPSS Score
-
Published
10/9/2025
Updated
10/9/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 analysis of the provided security patch (commit 556085067609c508f8c546ceef9003ee8c607d39) for the vulnerability in 'better-auth' clearly points to the createApiKey function as the source of the vulnerability. The diff in packages/better-auth/src/plugins/api-key/routes/create-api-key.ts shows the exact lines of code that were changed to fix the authentication bypass. The vulnerability description corroborates this, explaining how the logic in the createApiKey route could be exploited. The PoC provided also targets the api/auth/api-key/create endpoint, which is handled by the createApiKey function. Although the vulnerability description mentions that a similar pattern exists in an 'update endpoint', the provided commit only contains the fix for the creation endpoint. Therefore, with high confidence, createApiKey is identified as a vulnerable function. An attacker exploiting this vulnerability would have this function appear in the runtime profile.

Vulnerable functions

createApiKey
packages/better-auth/src/plugins/api-key/routes/create-api-key.ts
The vulnerability is in the `createApiKey` function. The logic for determining if authentication is required was flawed. When an unauthenticated request was made with a `userId` in the request body, `authRequired` was set to `false`. This resulted in the `user` object being set to `{ id: ctx.body.userId }`, effectively allowing the attacker to impersonate any user and create an API key for them. The fix ensures that authentication is always required for this endpoint and that the `userId` from the session matches the one in the request body, if provided.

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** *n*lysis o* t** provi*** s**urity p*t** (*ommit ****************************************) *or t** vuln*r**ility in '**tt*r-*ut*' *l**rly points to t** `*r**t**piK*y` *un*tion *s t** sour** o* t** vuln*r**ility. T** *i** in `p**k***s/**tt*r-*ut*/s