Ehsan Bagherzadegan
Back to articles
4 min read

Critical Laravel Token Guard Auth Bypass: What You Need to Know (GHSA-f9x3-7vq9-cph6)

A critical authentication bypass in Laravel's token guard (CVSS 9.2) lets attackers log in as any user on MySQL/MariaDB. Fixed in 13.29.0 and 12.68.0 — upgrade now if you use the token driver.

Laravel's built-in token guard — the token driver in config/auth.php — had a critical authentication bypass vulnerability that was disclosed on October 19, 2026 (GHSA-f9x3-7vq9-cph6, CVSS 9.2). If your application uses the token guard on MySQL or MariaDB, an unauthenticated attacker could log in as any existing user without knowing their API token.

The fix landed in Laravel 13.29.0 and 12.68.0 (both released August 25, 2026), but the advisory was only published this week. If you haven't upgraded yet, do it now.

What the vulnerability allows

The token guard is Laravel's simplest API authentication mechanism. You enable it like this:

// config/auth.php
'guards' => [
    'api' => [
        'driver' => 'token',
        'provider' => 'users',
    ],
],

When a request arrives, the guard extracts a token from the query string, request body, Authorization: Bearer header, or HTTP basic auth password. It then passes that token to the user provider to find a matching user.

The bug: the guard only checked that the token was "not empty" before using it. It never verified that the token was actually a string.

On MySQL and MariaDB, this type laxity is exploitable. If an attacker sends a non-string value — an array, an integer, a boolean — PHP's loose comparison and MySQL's type juggling can cause the query to match the wrong row. In the worst case, the attacker authenticates as the first user in the table (often an admin) without providing a valid token.

Sanctum and Passport are not affected. They use their own guard drivers with proper type handling.

The root cause in code

Here's the vulnerable logic from TokenGuard::user() (simplified):

public function user()
{
    $token = $this->getTokenForRequest();

    if (! empty($token)) {  // Only checks "not empty"
        return $this->provider->retrieveByToken($this->tokenColumn, $token);
    }
}

getTokenForRequest() pulls the token from multiple sources. If the request sends ?api_token[]=foo (an array) or api_token=123 (an integer), empty() returns false for both. The raw value gets passed to the database query.

MySQL's loose comparison then kicks in. For example, WHERE api_token = 123 matches a string token "123". An array can produce even stranger matches depending on how the query builder handles it.

The fix

The patch adds an explicit is_string() check in two places — user() and validate():

public function user()
{
    $token = $this->getTokenForRequest();

    if (is_string($token) && ! empty($token)) {
        return $this->provider->retrieveByToken($this->tokenColumn, $token);
    }
}

public function validate(array $credentials = [])
{
    $token = $credentials['token'] ?? $this->getTokenForRequest();

    if (is_string($token) && ! empty($token)) {
        return $this->provider->retrieveByToken($this->tokenColumn, $token);
    }
}

Now non-string values are rejected early, before they ever reach the database.

A second issue in the same release

The same patch versions (12.68.0 / 13.29.0) also fixed a medium-severity issue: GHSA-5wcm-3v2w-8362 (CVSS 6.5). JSON:API resources could allow a read-only request to trigger destructive database operations on related tables. If you use API resources with relationship loading, upgrade for this reason too.

What you should do today

  1. Upgrade immediately
    Run composer update laravel/framework to get ≥12.68.0 or ≥13.29.0.

  2. Check your auth config
    Look for any guard using 'driver' => 'token'. These are the only ones affected.

  3. Run composer audit
    It will flag this advisory and any others that apply to your dependencies.

  4. If you can't upgrade right now
    Add a middleware that rejects non-string api_token values before they hit the guard:

    // app/Http/Middleware/EnsureTokenIsString.php
    public function handle($request, Closure $next)
    {
        $token = $request->input('api_token')
            ?? $request->query('api_token')
            ?? $request->bearerToken()
            ?? $request->getPassword();
    
        if ($token !== null && ! is_string($token)) {
            abort(401, 'Invalid token format');
        }
    
        return $next($request);
    }
    

    Register it globally or on the affected routes.

Why this matters for Laravel teams

The token guard is often used for simple internal APIs, webhook endpoints, or legacy integrations. It's not the default anymore (Sanctum is), but it's still there, still documented, and still in production apps.

This vulnerability is a reminder that type validation at trust boundaries is not optional. The guard assumed the input was a string because "that's what the docs say." Attackers don't read the docs.

If you maintain a Laravel 12 or 13 application, check your composer.lock today. The fix has been available for two months — the only reason this is news now is the delayed advisory publication.

Sources