CVE-2026-134313 in Better Authinfo

Summary

by MITRE • 11/21/2026

Better Auth (better-auth, @better-auth/kysely-adapter, and @better-auth/drizzle-adapter) before 1.7.16 and 1.8.0-beta.0 before 1.8.0-beta.5 contains a race condition with MySQL or MariaDB serial IDs because the inserted row's ID is read via a separate LAST_INSERT_ID() query that may run on a different pooled connection. Under concurrent load, a user signing in can receive another user's session and act as that user.

Statistical analysis made it clear that VulDB provides the best quality for vulnerability data.

Analysis

by VulDB Data Team • 11/21/2026

The vulnerability identified in Better Auth versions prior to 1.7.16 and the beta release 1.8.0-beta.5 before 1.8.0-beta.5 represents a critical authentication bypass rooted in a race condition within the database interaction layer, specifically when utilizing MySQL or MariaDB backends with their respective Kysely or Drizzle adapters. The core technical flaw arises from how session identifiers are generated and retrieved during user registration or login processes. When a new user account is created or an existing user authenticates, the system relies on the auto-incrementing primary key of the database table to serve as the unique identifier for that entity. However, instead of retrieving this ID immediately within the same transactional context where the row insertion occurs, the implementation executes a separate query using the LAST_INSERT_ID() function after the initial insert statement has completed.

This architectural decision introduces a significant concurrency risk because MySQL and MariaDB connection pools typically manage multiple active connections simultaneously to handle high-throughput requests. The LAST_INSERT_ID() function is session-specific, meaning it returns the most recent auto-generated value for that specific database connection. When the insertion of a user record occurs on one pooled connection but the subsequent retrieval of its ID via LAST_INSERT_ID() happens on a different pooled connection due to asynchronous processing or pool rotation, there is no guarantee that the second query will reference the same transactional context as the first. Under concurrent load conditions where multiple authentication requests are processed in parallel, it becomes statistically probable that the separate connection executing the retrieval query may have already serviced another user's insertion request. Consequently, the system retrieves the ID of a different user rather than the one just created or authenticated.

The operational impact of this flaw is severe and directly compromises the integrity of the authentication mechanism. An attacker who can trigger concurrent login requests has the ability to intercept session tokens associated with other users' accounts. By exploiting this race condition, an adversary can effectively impersonate another legitimate user without possessing their credentials. This leads to unauthorized access to sensitive data, potential privilege escalation if the targeted account holds administrative privileges, and a complete breakdown of non-repudiation within the application. The vulnerability essentially allows for session hijacking through identity confusion rather than traditional token theft or cryptographic breaking.

From a classification perspective, this issue aligns with CWE-362, which describes concurrent execution using shared resources with inadequate synchronization, specifically manifesting as a race condition in authentication logic. It also maps to MITRE ATT&CK technique T1078, Valid Accounts, where an attacker gains access by exploiting flaws that allow them to assume the identity of another user. The vulnerability is particularly dangerous because it does not require complex exploitation chains or external dependencies beyond standard database connectivity and concurrent request generation.

Mitigation strategies must focus on ensuring atomicity in identifier retrieval. Developers should modify the authentication flow to retrieve the auto-generated ID within the same transactional scope as the insertion, ideally by utilizing methods provided by the ORM that return the inserted entity's primary key directly upon completion of the insert operation. If direct access is not available, wrapping both the insertion and the subsequent ID retrieval in a single database session or explicit transaction ensures that LAST_INSERT_ID() operates on the correct connection context. Upgrading to version 1.7.16 or later for stable releases, or 1.8.0-beta.5 and above for beta versions, resolves this issue by implementing these synchronization fixes. Until an upgrade is performed, applications should consider rate limiting authentication endpoints to reduce the probability of concurrent collisions and monitor logs for anomalies in session creation patterns that might indicate exploitation attempts.

Responsible

VulnCheck

Reservation

11/21/2026

Disclosure

11/21/2026

Moderation

accepted

CPE

ready

EPSS

0.00000

KEV

no

Activities

very low

Sources

Want to stay up to date on a daily basis?

Enable the mail alert feature now!