/

CVE-2026-39976

Severity:

HIGH RISK

(7.1)

Authentication Bypass in Laravel Passport OAuth2 Guard

CVE-2026-39976

Analyzed

Vulnerability type

Category:

Authentication Bypass

CWE:

CWE-287

Impact:

Improper User Authentication / Privilege Confusion

Severity:

HIGH RISK

(7.1)

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

Laravel Passport versions 13.0.0 through 13.7.0 contain an authentication bypass where machine-to-machine client_credentials tokens can be treated as if they belong to a real user.

Because the JWT sub claim is set to the OAuth client identifier and then passed directly into retrieveById() without validation, these tokens may inadvertently resolve to and authenticate as an unrelated application user.

Affected context

This vulnerability occurs in Laravel applications that:

  • Use Laravel Passport as an OAuth2 server
  • Rely on the token guard for authentication
  • Issue client_credentials tokens for machine-to-machine communication
  • Use retrieveById() in a way that can resolve identifiers from multiple domains (e.g., user IDs and client IDs sharing the same backing store or identifier space)

In such contexts, a client identifier embedded as the JWT sub claim may collide with existing user identifiers and be treated as a legitimate user account.

Exploit preconditions

  • Attack surface: API endpoints, controllers, or routes that:
  • Are protected by Laravel Passport's token guard, and
  • Expect only end-user tokens but also accept or are reachable via client_credentials tokens.
  • Required access: Ability to obtain or mint a valid client_credentials access token for some OAuth client within the Passport installation.
  • Trigger point: Using a client_credentials token in a context where the guard:
  1. Parses the JWT,
  2. Reads the sub claim as an identifier, and
  3. Passes it directly to retrieveById() to look up a user.
  • Why exploitation is possible: The JWT sub claim semantics are overloaded. Instead of clearly distinguishing between "user subject" and "client subject," the guard assumes sub is always a user ID and does not validate the token grant type or subject type before resolving it to an application user.

Why this happens

The core issue is an authentication decision made on an ambiguous identifier without validating its type or provenance.

In the league/oauth2-server library, client_credentials tokens correctly use the OAuth client identifier as the JWT sub claim, since there is no end user. Laravel Passport's token guard, however, assumes sub corresponds to a user identifier and passes it directly to retrieveById() to load an authenticated user model.

When the application's identifier space for clients and users is not strictly separated, or when retrieveById() can interpret the client ID as a valid user ID, the guard can authenticate a machine token as an application user. This maps to CWE-287: Improper Authentication, where the system fails to verify that the subject being authenticated actually represents the expected entity type.

Potential impact

  • Machine-to-machine tokens could authenticate as unintended real users.
  • API endpoints intended only for human users could be accessed using client_credentials tokens.
  • Business logic tied to user identity (e.g., billing, quotas, or role-based access) could be executed under the wrong account.
  • Audit trails and logs may incorrectly attribute actions to legitimate users rather than to OAuth clients.
  • Lateral movement within the application may be possible if a client token maps to a privileged user.

General mitigation guidance

Effective mitigation focuses on strictly separating client and user identity semantics and ensuring authentication logic respects that distinction.

Pattern-based defensive measures include:

  • Distinct subject handling: Treat OAuth client identifiers and user identifiers as different subject types. Do not assume the JWT sub claim always references a user; gate user resolution on grant type or a dedicated claim.
  • Grant-type-aware guards: Implement or configure the token guard to:
  • Reject client_credentials tokens for routes that require a user context, or
  • Only resolve a user when the grant type is user-centric (e.g., password, authorization code, refresh token).
  • Identifier namespace separation: Use clearly separated identifier spaces or backing stores for clients and users so that collisions between client IDs and user IDs are structurally impossible.
  • Principle of least privilege: Design routes and controllers so that:
  • Machine tokens are limited to endpoints that do not require user identity, and
  • Sensitive operations always assert the existence of a valid, expected user identity type.
  • Defense-in-depth checks: Within business logic, assert that the authenticated principal matches the expected category (user vs. client) before performing privileged actions.

How teams detect issues like this

Detection centers on reviewing identity resolution and token parsing logic for ambiguous subject handling:

  • Static analysis patterns:
  • Identify code paths where JWT claims (especially sub) are directly passed to retrieveById() or similar user lookup methods.
  • Flag guard implementations that do not differentiate behavior based on grant type or subject type.
  • Code review signals:
  • Authentication logic that assumes all access tokens correspond to users.
  • Mixed handling of users and clients in the same model or table without explicit type checks.
  • Absence of validation around claim semantics (e.g., no checks on client vs. user subject).
  • Runtime and policy-based monitoring:
  • Log and analyze grant types and subjects used to access user-only endpoints.
  • Create rules or alerts when client_credentials tokens are used on routes that are expected to be user-authenticated.
  • Automated tooling:
  • Use application security scanners or custom linters to detect direct use of JWT sub claims as user identifiers without verifying token context or grant type.

Sources

SourceLink
github.comgithub.com/laravel/passport/issues/1900
github.comgithub.com/laravel/passport/pull/1901
github.comgithub.com/laravel/passport/pull/1902
github.comgithub.com/laravel/passport/security/advisories/GHSA-349c-2h2f-mxf6
github.comgithub.com/thephpleague/oauth2-server/issues/1456#issuecomment-2734989996

Frequently asked

questions

Yes. Any party that can obtain a valid client_credentials token against the affected Laravel Passport deployment and reach protected endpoints over the network can potentially trigger this issue, depending on how identifiers are stored and resolved.

No direct user credentials are required. The key requirement is the ability to authenticate as an OAuth client and obtain a client_credentials token; from there, the ambiguity in subject handling may allow the token to be treated as a user.

Enforce strict separation between client and user identities in your authentication layer. Ensure the token guard does not treat client_credentials tokens as user tokens, and only resolve users from tokens whose grant type and claims unambiguously represent an end user.

Adopt a clear identity model distinguishing machine principals from human users, validate token context (grant type, audience, subject type) before user resolution, keep identifier namespaces separate, and incorporate these rules into code review, static analysis, and security design guidelines for authentication and authorization flows.

Find out what's already
exploitable in your codebase.