Timing out PHP with a 220 KB request via Laravel's distinct rule

Validating large wildcard arrays with distinct fell into quadratic O(n²) CPU time on booleans, null, empty arrays, or non-strings with ignore_case.

Another Laravel security advisory was published today (GHSA-jrc9-gpx2-4p3r): on any endpoint that validates a wildcard array with the distinct rule, a ~220 KB request was enough to push PHP past its default execution time limit and tie up application workers.

Unlike the TrimStrings DoS bugs I wrote about earlier, this one only affects endpoints that actually use distinct on user-submitted arrays. Still, distinct is common in bulk APIs, tag inputs, and form arrays, and no authentication is required if the endpoint is public.

Where the quadratic slowdown came from

Take a standard wildcard validation rule:

$request->validate([
    'items' => ['required', 'array'],
    'items.*' => ['distinct'],
]);

Before the fix, ValidatesAttributes::validateDistinct() checked every item in items.* by scanning the rest of the array with in_array() (or preg_grep() when ignore_case was enabled):

// src/Illuminate/Validation/Concerns/ValidatesAttributes.php (before PR #62666)
public function validateDistinct($attribute, $value, $parameters)
{
    $ignoreCase = in_array('ignore_case', $parameters) && is_string($value) && mb_check_encoding($value, 'UTF-8');

    $data = Arr::except($this->getDistinctValuesToCompare($attribute, $value, $ignoreCase), $attribute);

    if ($ignoreCase) {
        return empty(preg_grep('/^'.preg_quote($value, '/').'$/iu', $data));
    }

    return ! in_array($value, array_values($data), in_array('strict', $parameters));
}

For strings and numbers, Laravel had some grouping to avoid scanning everything, but values like booleans, null, empty arrays ([]), and non-strings under ignore_case fell back into a full linear scan for every single element.

Validating N items meant up to O(n²) comparisons. With a ~220 KB JSON array of those values, a single request burned enough CPU to hit PHP's max_execution_time and stall the worker.

The fix

The Laravel team fixed this across 12.x and 13.x (PR #62666, PR #62667, PR #62668) by grouping values up front according to how PHP compares them (strict, ignore_case, or loose) and caching at most two representatives per group.

Instead of rescanning the full array on every element, validateDistinct() now iterates over getDistinctValueCandidates() and only checks the small bucket of values that could actually match:

// src/Illuminate/Validation/Concerns/ValidatesAttributes.php (after PR #62666)
foreach ($this->getDistinctValueCandidates($attribute, $value, $ignoreCase, $strict) as $key => $other) {
    if ((string) $key === (string) $attribute) {
        continue;
    }

    $equal = match (true) {
        $ignoreCase => preg_match($pattern, (string) $other) === 1,
        $strict => $other === $value,
        default => $other == $value,
    };

    if ($equal) {
        return false;
    }
}

Each item only gets compared against a tiny number of candidates instead of the entire array.

Affected versions

Published as GHSA-jrc9-gpx2-4p3r (Medium severity, CVSS 5.3). Patched in Laravel 12.75.0 and Laravel 13.45.0 (released December 1, 2026). If you validate user-submitted arrays with distinct, bump laravel/framework and redeploy.

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 →