Bypassing Laravel's TokenGuard on MySQL with {"api_token": [0]}

Sending an integer array [0] instead of a string to Laravel's TokenGuard triggered MySQL type coercion and authenticated an unauthenticated request as an existing user.

With a standard Laravel token API guard on MySQL or MariaDB, sending {"api_token": [0]} instead of a string was enough to authenticate an unauthenticated request as an existing user, without knowing any API token.

The application didn't need any custom query code. Just protecting a route with auth:api and the stock token guard was enough.

Normal request vs. bypass

With a standard config/auth.php token guard ('driver' => 'token', 'hash' => false), a request with a wrong token gets rejected with 401 as expected:

GET /protected
Content-Type: application/json
Accept: application/json

{"api_token": "wrong_token"}

Response:

{"message": "Unauthenticated."}

Changing api_token from a string to a single-element integer array bypassed authentication completely:

GET /protected
Content-Type: application/json
Accept: application/json

{"api_token": [0]}

Response (HTTP 200):

{"authenticated_user_id": 1}

Why [0] matched a real token

Three separate behaviors lined up to make this work:

  1. TokenGuard::user() read api_token from the request and only checked ! empty($token) before passing it to the user provider. [0] is a non-empty array, so it passed straight through.
  2. Both EloquentUserProvider and DatabaseUserProvider treat array credential values as whereIn clauses.
  3. Laravel bound the integer 0 as PDO::PARAM_INT, producing WHERE api_token IN (0).

In MySQL and MariaDB, comparing a VARCHAR column (api_token) against an integer (0) coerces the string to a number. Any non-numeric token like "alpha-random-token" evaluates to 0, matches 0, and returns the first matching user row, even with strict mode enabled.

The fix

Taylor patched this in src/Illuminate/Auth/TokenGuard.php by rejecting non-string tokens in both user() and validate() before they ever reach the user provider:

// src/Illuminate/Auth/TokenGuard.php
$token = $this->getTokenForRequest();

if (is_string($token) && ! empty($token)) {
    $user = $this->provider->retrieveByCredentials([
        $this->storageKey => $this->hash ? hash('sha256', $token) : $token,
    ]);
}
public function validate(#[SensitiveParameter] array $credentials = [])
{
    if (! is_string($credentials[$this->inputKey] ?? null) || empty($credentials[$this->inputKey])) {
        return false;
    }

    // ...
}

Affected versions

Published as GHSA-f9x3-7vq9-cph6 (CVE-2026-114509, Critical severity). Patched in Laravel 12.68.0 and Laravel 13.29.0. If you use the token guard on MySQL or MariaDB, make sure you've upgraded.

Hristijan Manasijev · Member of Technical Staff at Native Teams & Laravel framework contributor.

Need a Laravel security or performance audit, or looking to build AI automations? Get in touch →