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_credentialstokens 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_credentialstokens. - Required access: Ability to obtain or mint a valid
client_credentialsaccess token for some OAuth client within the Passport installation. - Trigger point: Using a
client_credentialstoken in a context where the guard:
- Parses the JWT,
- Reads the
subclaim as an identifier, and - Passes it directly to
retrieveById()to look up a user.
- Why exploitation is possible: The JWT
subclaim semantics are overloaded. Instead of clearly distinguishing between "user subject" and "client subject," the guard assumessubis 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_credentialstokens. - 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
subclaim 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_credentialstokens 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 toretrieveById()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_credentialstokens 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
subclaims as user identifiers without verifying token context or grant type.

