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/denyendpoints - 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_codevalues (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 /devicePOST /device/approvePOST /device/deny- Required access:
- The attacker must have an authenticated session in the target application.
- The attacker must obtain a valid
user_codecorresponding to a pending device authorization. - Trigger point:
- When the attacker submits
POST /device/approveorPOST /device/denywith the stolenuser_code, the system incorrectly associates or denies the device authorization using the attacker's session context. - Why exploitation is possible:
GET /devicedoes not claim or bind the pending device code row to the original initiating user.POST /device/approveandPOST /device/denyshort-circuit whenuserIdis unset, effectively treating any authenticated caller with a validuser_codeas 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
userIdunset or unclaimed when a device code is created or retrieved. - Short-circuits approval and denial handlers when
userIdis 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
userIdstored on the corresponding device record before performing any state change. - Treat the
user_codeonly 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/denyfor missing checks that user identity matches the storeduserIdon device records. - Look for conditions that short-circuit authorization logic when
userIdis unset, or where actions are allowed solely based on auser_codeor 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.

