/

CVE-2026-45337

Severity:

HIGH RISK

(7.6)

Authorization Bypass (CWE-285) in Better Auth Device Flow

CVE-2026-45337

Analyzed

Vulnerability type

Category:

Authorization Bypass

CWE:

CWE-285, CWE-345

Impact:

Account and session takeover within device authorization flows

Severity:

HIGH RISK

(7.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A logic flaw in Better Auth's deviceAuthorization plugin causes any authenticated session to be treated as the owner of pending device codes, regardless of which account initiated the flow.

If an attacker learns a valid user_code while logged in, they can hijack or deny another user's device authorization flow, binding the device to their own account or blocking the legitimate user.

Affected context

The vulnerability arises in applications using Better Auth's deviceAuthorization plugin for OAuth-style device login flows between versions 1.6.0 and 1.6.10.

It manifests when the server:

  • Exposes /device, /device/approve, and /device/deny endpoints
  • Treats any authenticated session as eligible to complete a device authorization, without binding the pending device code to a specific account
  • Allows attacker-controlled or guessable access to valid user_code values (e.g., via shoulder surfing, interception, or weak entropy)

In such deployments, any authenticated user who obtains a valid user_code can interfere with another user's device login process.

Exploit preconditions

  • Attack surface: HTTP endpoints implementing the device authorization flow:
  • GET /device
  • POST /device/approve
  • POST /device/deny
  • Required access:
  • The attacker must have an authenticated session in the target application.
  • The attacker must obtain a valid user_code corresponding to a pending device authorization.
  • Trigger point:
  • When the attacker submits POST /device/approve or POST /device/deny with the stolen user_code, the system incorrectly associates or denies the device authorization using the attacker's session context.
  • Why exploitation is possible:
  • GET /device does not claim or bind the pending device code row to the original initiating user.
  • POST /device/approve and POST /device/deny short-circuit when userId is unset, effectively treating any authenticated caller with a valid user_code as the owner.
  • There is no strong verification step ensuring the user performing approval/denial is the same principal that initiated the device flow, creating an authorization gap.

Why this happens

The core issue is an authorization logic error that fails to enforce proper ownership and identity binding on device authorization records.

Instead of associating each pending device code with a specific userId and requiring a matching authenticated principal to approve or deny it, the implementation:

  • Leaves the userId unset or unclaimed when a device code is created or retrieved.
  • Short-circuits approval and denial handlers when userId is unset, implicitly trusting the currently authenticated caller.

This maps to CWE-285: Improper Authorization, where access is granted without sufficient checks, and to CWE-345: Insufficient Verification of Data Authenticity, because possession of user_code is incorrectly treated as proof of legitimate ownership.

Conceptually, the bug class is a missing binding between "what is being approved" (device code) and "who is allowed to approve it" (originating account), turning a cross-user authorization step into a simple knowledge-of-code check.

Potential impact

  • An attacker may bind a victim's device login flow to the attacker's own account, leading to account confusion and misuse.
  • An attacker could deny a legitimate user's device authorization flow, resulting in denial of service for device-based login.
  • An attacker can potentially gain control over sessions on devices that the victim intended to link to their own account.
  • Logs and audit trails may misattribute device authorizations, complicating incident response and user support.

General mitigation guidance

Effective mitigation centers on enforcing strict ownership and identity checks around device authorization records:

  • Bind each device authorization record to a specific userId (or equivalent principal identifier) at creation time or at first interaction, and persist this association.
  • Ensure that approval and denial endpoints validate that the currently authenticated user matches the userId stored on the corresponding device record before performing any state change.
  • Treat the user_code only as a correlation or lookup key, not as proof of identity or authorization; always combine it with an authenticated user context.
  • Consider implementing explicit state transitions for device codes (e.g., pending, claimed, approved, denied) with checks that forbid cross-user modifications.
  • Apply the principle of least privilege to device flows, minimizing what actions can be taken based solely on possession of a short-lived code.

How teams detect issues like this

Detection approaches typically focus on reviewing authorization logic and monitoring for anomalous device flow behavior:

  • Static analysis and code review:
  • Inspect handlers for /device, /device/approve, and /device/deny for missing checks that user identity matches the stored userId on device records.
  • Look for conditions that short-circuit authorization logic when userId is unset, or where actions are allowed solely based on a user_code or similar token.
  • Flag patterns where ownership of a resource is implied by knowledge of a non-cryptographic identifier rather than explicit user-resource binding.
  • Runtime monitoring and logging:
  • Log user identifiers, device codes, and actions for device flows and alert on cases where multiple distinct users interact with the same device code.
  • Track anomalous denial rates or frequent cross-account approvals for device authorizations.
  • Automated review tools:
  • Use application security scanners or policy-as-code tools configured to detect endpoints that change security-sensitive state without verifying resource ownership.

Sources

SourceLink
github.comgithub.com/better-auth/better-auth/commit/99a254a79b59d5a3f5ca2123260118cddb5beed7
github.comgithub.com/better-auth/better-auth/pull/9573
github.comgithub.com/better-auth/better-auth/releases/tag/v1.6.11
github.comgithub.com/better-auth/better-auth/security/advisories/GHSA-cq3f-vc6p-68fh

Frequently asked

questions

Yes, it is remotely exploitable via the application's HTTP API, provided the attacker has a valid authenticated session and can obtain a legitimate user_code value from another user's device flow.

The attacker must be a logged-in user of the affected application and must learn a valid user_code associated with a pending device authorization. They do not need elevated privileges beyond a standard authenticated account.

The most robust fix is to explicitly bind every device authorization record to a specific user identity and require that any approval or denial operation verifies the caller's identity against this binding before updating state. In addition, avoid treating possession of short-lived codes as sufficient proof of ownership.

When designing flows that rely on secondary codes or tokens, define clear ownership semantics and enforce them consistently at every state change. Incorporate security reviews that focus on authorization boundaries, require explicit identity checks for modifying shared or cross-user resources, and add automated tests that simulate cross-account interactions to ensure they are rejected.

Find out what's already
exploitable in your codebase.