On October 20, 2026, Taylor Otwell pushed a commit to laravel/framework with the message “limit bytes” (commit 1b8b12d). It added twenty-five lines to a middleware base class, shipped the same day in v13.38.0, and appeared nowhere in the release changelog. There is no CVE, no GitHub Security Advisory, and no pull request attached to it.
The commit closed an unauthenticated denial of service reported by Hristijan Manasijev, a Skopje-based developer who goes by KIKOmanasijev on GitHub. A single JSON request of roughly 590 kilobytes kept a PHP worker busy for a measured 30.1 seconds. In that time it built approximately 43 gigabytes of short-lived strings inside Laravel’s input-normalization middleware, before the framework had resolved a route, checked a session, or touched a controller. A few such requests in parallel are enough to occupy every worker in a typical PHP-FPM pool.
What stands out is where the flaw lived. It sat in code whose entire job is to trim whitespace off form fields, and it had been there in one form or another since 2018.
How the TrimStrings middleware runs before routing, auth, and rate limiting
Applications built on the modern Laravel skeleton configure middleware in bootstrap/app.php, but the framework still maintains a default global stack that runs on every request. The list comes from Illuminate\Foundation\Configuration\Middleware::getGlobalMiddleware(). In order, it contains path-encoding validation, deferred-callback invocation, optional host trusting, proxy trusting, CORS handling, maintenance-mode checks, POST size validation, TrimStrings, and ConvertEmptyStringsToNull.
Routing happens after this pipeline. Authentication guards, the throttle middleware, and every other route-level concern live downstream of it. A request to a path that does not exist, sent without credentials, still passes through both string-normalizing middleware before Laravel decides there is nothing to dispatch to.
TrimStrings extends TransformsRequest, a small base class that walks the request’s parameter bags and applies a transformation to each leaf value. Its clean() method processes the query-string bag, then the JSON bag if the request carries a JSON content type, or the form bag otherwise. ConvertEmptyStringsToNull, the next middleware in the stack, extends the same base class and does the same traversal with a different leaf operation. Every default Laravel installation therefore walks the entire input tree twice per request, and any cost embedded in that walk is paid twice.
For a login form with three fields, the walk is invisible. Manasijev’s finding shows what happens when an attacker chooses the shape of the tree.
The cleanArray bug: eight years of rebuilding key paths
The relevant code is short enough to quote in full. This is cleanArray and cleanValue as they appear at the v13.37.0 tag, the last release before the fix:
php
protected function cleanArray(array $data, $keyPrefix = ''){ foreach ($data as $key => $value) { $data[$key] = $this->cleanValue($keyPrefix.$key, $value); } return $data;}protected function cleanValue($key, $value){ if (is_array($value)) { return $this->cleanArray($value, $key.'.'); } return $this->transform($key, $value);}
The $keyPrefix parameter exists so that transform() receives the full dotted path of each value instead of just its leaf name. That design dates to November 2018, when Marcin Nabiałek’s commit “Pass full array key when transforming request value” taught the middleware to concatenate $keyPrefix.$key for every element. Exclusion lists could then address nested fields such as user.password.
📬 Stay Ahead of Cyber Threats
Get the latest cybersecurity news, critical vulnerabilities, threat intelligence, tutorials, and exclusive giveaways delivered straight to your inbox. No spam. Unsubscribe anytime.
The feature is reasonable. Current TrimStrings releases match their $except entries (by default current_password, password, and password_confirmation) against the full path using Str::is(), which supports wildcard patterns. The concatenation is the price of that feature, and for eight years nobody metered it. A 2022 refactor, PR #42074, replaced the original collect($data)->map(...) with the plain foreach above. That removed Collection overhead and left the string building untouched.
Now read the loop the way an attacker would. When a top-level key maps to an array, cleanValue recurses with $key.'.' as the new prefix, and the child loop evaluates $keyPrefix.$key once per element. PHP strings are immutable byte buffers, so the . operator always allocates a fresh zend_string and copies both operands into it. There is no rope structure, no shared-prefix optimization, and no caching of the prefix between iterations.
If the parent key is 295 kilobytes long and the array holds 147,000 elements, the loop builds 147,000 separate strings of roughly 295 kilobytes each, copying the parent key in full every time. Its only purpose is to hand transform() a path that gets compared against three short password field names and thrown away.
How a 590 KB JSON payload turns into 43 GB of string copying
The payload in Manasijev’s disclosure is a single JSON object with one enormous key and one large array of zeros. This line of PHP reconstructs a body consistent with the published figures:
php
$body = json_encode( [str_repeat('é', 147500) => array_fill(0, 147000, 0)], JSON_UNESCAPED_UTF8);
The character é occupies two bytes in UTF-8, so 147,500 repetitions produce a key of about 295,000 bytes. Each zero in the array costs two bytes on the wire (0,), adding roughly 294,000 bytes, and the whole body lands near 590 kilobytes. Nothing about it is malformed. It is valid UTF-8 and valid JSON, only two levels deep, and json_decode parses it in linear time.
The damage starts afterward, when TrimStrings begins its walk. Each of the 147,000 elements triggers the concatenation described above, and 295,000 bytes multiplied by 147,000 iterations comes to about 43.4 gigabytes of string data allocated and copied over the life of the request, from a body of 590 kilobytes. That is an amplification factor on the order of 70,000 to one. The attacker controls both the key length and the element count, so the cost grows roughly with the square of the permitted body size.
Early descriptions of the bug mixed up two different resources, so precision matters here. The 43 gigabytes are cumulative allocations, not resident memory. Each path string is freed when its iteration ends, so at any instant the process holds only the current path plus the shared prefix, and the resident set barely moves. PHP’s memory_limit, commonly 128 MB, never trips, and the Linux OOM killer never fires.
What the request consumes is CPU time and allocator bandwidth: allocate a large buffer, copy 295 kilobytes into it, run a pattern match against it, free it, repeat. Dividing the reported 43.4 GB by the reported 30.1 seconds gives an effective throughput of about 1.4 GB/s for that allocate-copy-match-free cycle. That is plausible for large zend_mm allocations interleaved with per-element PHP overhead.
Before the follow-up hardening described below, each integer element also paid for an array_merge of the exclusion lists and a Str::is call inside transform(), even though trim() has nothing to do with integers. The zeros in the payload are deliberate. The leaf transformation is a no-op, so all the work lives in key handling.
The measured 30.1 seconds fits a worker that spends its whole execution budget inside the loop and gets killed at the ceiling. PHP’s max_execution_time defaults to 30 seconds, and on non-Windows builds using the default ITIMER_PROF tracking it measures CPU time rather than wall-clock time, so the copying counts against it directly. Whether the worker dies at the PHP limit or at FPM’s request_terminate_timeout, the operational result is the same: one small request pins one worker for half a minute. Pools sized with pm.max_children in the single or double digits cover a great many production deployments, and a handful of concurrent connections can saturate them. Every other visitor then queues behind requests that will never reach application code.
Why nginx, PHP limits, WAFs, and rate limiting all missed it
The attacker chose the payload size well. Nginx’s client_max_body_size defaults to 1 MB, so 590 KB passes untouched. PHP’s post_max_size defaults to 8 MB. Laravel’s own ValidatePostSize middleware runs immediately before TrimStrings and only compares the Content-Length header against that value. Its source shows there is nothing else to it.
The limits that would catch a 147,000-element input are max_input_vars, which defaults to 1000, and max_input_nesting_level, which defaults to 64. Both apply only to PHP’s parsing of $_GET, $_POST, and $_COOKIE. The PHP manual says max_input_vars exists to mitigate hash-collision denial-of-service attacks, a lineage that runs back to the algorithmic-complexity research in Crosby and Wallach’s 2003 USENIX Security paper and the hash-flooding attacks demonstrated against PHP in 2011.
JSON bodies bypass that defensive layer entirely. PHP does not parse them into superglobals. Laravel reads php://input and calls json_decode itself, and the resulting array can have arbitrarily many elements with arbitrarily long string keys. The framework inherited the parser’s freedom without inheriting its limits.
Edge defenses do no better. A CDN or WAF inspecting the request sees a well-formed JSON document with no injection signatures, no anomalous headers, and a body smaller than a typical profile photo. Rate limiting and authentication cannot help even in principle, because both are route middleware and the expensive work happens in the global stack before route resolution. A POST to /nonexistent costs exactly as much as a POST to a real endpoint.
Exclusion lists do not help either, since shouldSkip runs inside transform(), after the path has already been built. Only removing or skipping the middleware avoids the traversal, and the default configuration does neither.
Lowering the edge body cap raises the attacker’s cost without changing its shape. With cost quadratic in body size, even a 64 KB cap leaves room for hundreds of megabytes of churn per request, and that parallelizes cheaply. The problem needed a structural fix.
The fix in Laravel 13.38.0: a key-byte budget
Commit 1b8b12d does not try to recognize bad input. It meters the work. Two properties appear on TransformsRequest: $maxKeyBytes, defaulting to 20 * 1024 * 1024, and a running $keyBytes counter that handle() resets to zero on every request. The rewritten loop, as it ships in v13.38.0, looks like this:
php
protected function cleanArray(array $data, $keyPrefix = ''){ $prefixLength = strlen($keyPrefix); foreach ($data as $key => $value) { $this->keyBytes += $prefixLength + strlen((string) $key); if ($this->keyBytes > $this->maxKeyBytes) { throw new PostTooLargeException('The cumulative size of the input keys is too large.'); } $data[$key] = $this->cleanValue($keyPrefix.$key, $value); } return $data;}
The counter tracks exactly the quantity that was unbounded: the total length of every full key path the traversal would construct. The check runs before the concatenation, so the oversized string is never allocated, and the worst-case volume of key copying per request is capped at 20 MiB per middleware instance. At the throughput implied by the disclosure measurements, that ceiling means milliseconds of work instead of half a minute. It holds for any payload shape, including nested trees and dotted keys that no signature-based filter would catch.
The exception is PostTooLargeException, the same class ValidatePostSize already uses for post_max_size violations. It extends Symfony’s HttpException with status 413, so the rejection renders as HTTP 413 (named “Content Too Large” in RFC 9110) through the framework’s existing exception handling, with no new wiring.
The regression tests pin down the semantics and read well as a specification:
- The budget counts full dotted paths, so
fooplusfoo.barconsumes ten bytes, separators included. - It is shared across parameter bags, so an attacker cannot split a payload between the query string and the body to double the allowance.
- It resets on each
handle()call, which matters under Octane, where middleware instances are long-lived and reused across requests. testRejectsAmplifiedJsonKeysbuilds a key ofstr_repeat('è', 197499), roughly 395 KB, with only 100 elements. It asserts a 413 and that the next middleware is never reached, acrossTransformsRequest,TrimStrings, andConvertEmptyStringsToNull, and across integer, string, empty-string, and array values.
The guard lives on the shared base class, so one change protects both default normalizers.
Follow-up hardening in Laravel 13.39.0
A week later, on October 27, v13.39.0 carried the second commit, “adjust parsing” (31dbc2b). It removed two residual per-element costs.
The loop now writes a value back only when $cleaned !== $value. PHP’s copy-on-write arrays separate when written to, even if the written value is identical. The new test shows that 20,000 unchanged nested arrays used to cost several MiB of duplicated array storage and now cost under one. Separately, TrimStrings::transform() returns non-string values before merging the exclusion lists or calling Str::is. A test asserts that shouldSkip is never invoked for integers, booleans, nulls, floats, or empty arrays.
For the attack payload these changes are secondary, since the budget already rejects it. For large legitimate payloads of numbers and nested structures, they remove overhead that had built up quietly over years. Neither commit references a public pull request, and neither release’s changelog mentions them. The published notes for 13.38.0 and 13.39.0 cover database replica reads and queue fixes.
Which Laravel versions are vulnerable, and how to patch
At the time of writing, the guard exists only on the 13.x line. The current 12.x branch still contains the unguarded foreach, and the researcher’s disclosure graphic marks everything below 13.38.0 as affected and tells users to upgrade.
The straightforward remediation is to move to Laravel 13.38.0 or later, preferably 13.39.0 or later to pick up the parsing refinements.
Applications that cannot make the major-version jump yet can backport the budget, since it touches only the shared base class. Subclass the framework’s TrimStrings with the same two properties, the same reset in handle(), and the same metered cleanArray, and it reproduces upstream behavior. Do the same for ConvertEmptyStringsToNull, then register both replacements in bootstrap/app.php:
php
$middleware->replace( \Illuminate\Foundation\Http\Middleware\TrimStrings::class, \App\Http\Middleware\BudgetedTrimStrings::class,);
Removing the middleware outright also eliminates the traversal, but it changes input semantics your application may rely on, and you would have to remove both normalizers to close the path. The backport is the safer interim measure.
Tightening client_max_body_size on JSON-only locations is worth doing as defense in depth, keeping the quadratic caveat above in mind.
For detection, PHP-FPM’s slowlog (request_slowlog_timeout) points directly at TransformsRequest::cleanArray while an attack is in flight. The access-log signature is distinctive once you know to look for it: multi-second requests with small bodies against arbitrary paths, including paths that return 404, together with CPU saturation and no matching memory growth.
No CVE, no advisory: why composer audit won’t flag this Laravel bug
A search of the GitHub Advisory Database for “TrimStrings” returns zero results, and the repository’s own advisory list has no entry for this fix. That has practical consequences. composer audit, Dependabot alerts, and commercial SCA scanners key off CVEs and GitHub advisories. An application running a vulnerable release will pass every automated dependency check while remaining easy for an unauthenticated stranger to exhaust. The only public artifacts of the fix are the commits, their tests, and the researcher’s summary graphic, so teams that patch by feed will not see it.
Compare Laravel’s other recent input-layer work. On November 18, 2026, the project published a batch of advisories that included GHSA-h84h-g58v-xg2h, a quadratic regex-backtracking DoS in the decimal validation rule, and a DoS in email validation via oversized Unicode domains. These belong to the same family of bug: small inputs that make normalization or validation code do disproportionate work. Those two are visible in advisory feeds, and this one is not.
The pattern is older than Laravel. PHP itself grew max_input_vars because attackers learned to weaponize the cost of parsing instead of the content of what was parsed, and the research literature has treated algorithmic complexity as an attack surface since the early 2000s. This incident adds a reminder that dangerous code is not limited to parsers and validators. It also lives in the convenience layers a framework runs on every request, where a feature as modest as dotted-path exclusions carried an unbounded cost for eight years.
The 13.38.0 fix is a good model for this class of problem. It does not guess which inputs are malicious. It bounds the work any input can cause and fails closed with a status code the stack already understands. If you run a Laravel application on any release before 13.38.0, treat the upgrade as a security patch. No scanner will tell you to.







