The Slim CSRF bypass needs no exploit chain and no payload, just one hidden form field. A form on someone else’s site posts _METHOD=GET, and the CSRF middleware waves the request through as if it were a harmless read. The Slim team described the problem in a security advisory published on December 4, 2026 and fixed two bugs at once, one in the framework and one in the Slim-Csrf add-on. The official rating is “Low”. If your Slim app uses method overrides, check it today anyway: all an attacker needs is a single crafted web page.
CSRF stands for cross-site request forgery. A third-party page gets a logged-in user’s browser to send a request to your application, and the browser attaches the session cookie on its own. CSRF middleware stops this by checking a secret token that only your own forms know. In the affected versions, that check could be skipped.
How the Slim CSRF bypass works
HTML forms only speak GET and POST. So that REST routes can still receive PUT, PATCH or DELETE, Slim offers method overriding: a POST carries a _METHOD field in its body, and MethodOverrideMiddleware rewrites the request method. Slim 3 has the same logic baked into Request::getMethod().
What was missing was a limit on the target. Slim accepted any method, including GET, HEAD, OPTIONS, TRACE, CONNECT and, on Slim 4, QUERY. CSRF middleware only checks methods that change state. If it runs after the override, it sees a GET and lets it pass. The router then dispatches the request to any route that accepts GET, such as one registered with $app->any() or $app->map(['GET', 'POST'], ...), and the handler receives the full POST body.
The second bug sits in Slim-Csrf. According to GHSA-p7vx-gggp-8hm7, the Guard only validated the token for POST, PUT, DELETE and PATCH, and the comparison was case-sensitive. A form posting _METHOD=PURGE or any other custom method reached a matching route without a token, and so did a lower-case method such as post.
Which apps are actually exposed
The advisory is refreshingly specific here. An app is only vulnerable when every one of these conditions holds:
- It uses
_METHODoverrides, viaMethodOverrideMiddlewareon Slim 4 and always on Slim 3. - The CSRF middleware runs after the override. On Slim 4 that means route-level and group-level guards, plus an app-level guard registered before
MethodOverrideMiddleware. - A state-changing handler accepts GET, HEAD, OPTIONS or QUERY and reads the body, or it is mapped to a custom method.
- The session cookies set neither
SameSite=LaxnorSameSite=Strict.
Handlers that only change data on POST, PUT, PATCH or DELETE are safe from the framework bug. The CVSS 3.1 vector is AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:L/A:N: reachable over the network, but with high complexity and only if the victim visits a page. Affected are Slim 4.0.0 through 4.16.0, Slim 3.0.0 through 3.13.1, Slim-Csrf 1.0.0 through 1.5.1 and every 0.x release up to 0.8.3. There is no CVE number yet; the issues are tracked as GHSA-w62v-rcw8-mxvw and GHSA-p7vx-gggp-8hm7.
Middleware order in Slim 4 trips up a lot of people. Whatever you register last with add() runs first. Add the guard first and the override second, and you have built exactly the vulnerable setup.
We tested Slim 4.16.0 against 4.16.1
We rebuilt the bug in a small test app, running PHP 8.4’s built-in development server on an isolated machine. The first round used the vulnerable slim/slim 4.16.0 with slim/csrf 1.5.1, the second used 4.16.1 with 1.5.2. Here is the core of the app:
$app = AppFactory::create();
$guard = new Guard($app->getResponseFactory(), 'csrf', $storage);
$app->add($guard); // registered first, so it runs later
$app->add(new MethodOverrideMiddleware()); // registered last, so it runs first
// Form route that accepts GET and POST and reads the body
$app->map(['GET', 'POST'], '/account/email', function ($req, $res) {
$new = $req->getParsedBody()['email'] ?? null; // changes the email address
$res->getBody()->write($req->getMethod() . ' email=' . ($new ?? '-'));
return $res;
});
// Custom method, e.g. for flushing a cache
$app->map(['PURGE'], '/cache', fn ($req, $res) => $res);
Then we sent form POSTs without a token, the way a third-party form would. The plain POST fails as expected. With the override field, it gets through:
# Plain POST without a token: the Guard blocks it
curl -s -X POST -d 'email=attacker@example.org' http://127.0.0.1:8099/account/email
# Failed CSRF check!
# Same POST with _METHOD=GET: no token needed, the handler still gets the body
curl -s -X POST -d '_METHOD=GET&email=attacker@example.org' http://127.0.0.1:8099/account/email
# GET email=attacker@example.org
# Custom method: Slim-Csrf 1.5.1 only checked POST, PUT, DELETE and PATCH
curl -s -X POST -d '_METHOD=PURGE' http://127.0.0.1:8099/cache
# PURGE cache cleared
The control runs show which fix does the job. In the table below, 200 means “got through without a token” and 400 means “rejected by the Guard”:
Setup _METHOD=GET _METHOD=HEAD _METHOD=PURGE
Slim 4.16.0 + Csrf 1.5.1, Guard after override 200 200 200
Slim 4.16.1 + Csrf 1.5.2, Guard after override 400 400 400
Slim 4.16.0 + Csrf 1.5.1, Guard before override 400 400 400
Slim 4.16.0 + Csrf 1.5.1, own allowlist 400 400 400
After the upgrade the Guard rejects all three variants, with no change to the app code. Without upgrading, moving the Guard so it runs after the override middleware also worked, because the Guard then sees the original POST. One side note: lower-case variants such as _METHOD=get found no route in our test on the old version, since the router compares methods exactly. The case-sensitivity bug in the Guard mostly bites with custom methods.
What the patch changes
The diff in Slim 4.16.1 is small. MethodOverrideMiddleware now ignores a _METHOD value of GET, HEAD, OPTIONS, QUERY, TRACE or CONNECT, checked after upper-casing. The request stays a POST and gets validated. PUT, PATCH, DELETE and custom methods can still be set. The X-Http-Method-Override header is untouched, because a cross-site page cannot send custom headers without a CORS preflight.
Slim-Csrf flips its logic around. Version 1.5.2 validates the token for every method except GET, HEAD, OPTIONS, QUERY and TRACE; version 0.8.4 for everything except GET, HEAD, OPTIONS and TRACE. Both compare case-insensitively. That is the safer default, since a new method no longer slips through by accident. The Slim team names the trade-off itself: non-browser API clients that call custom-method routes behind the Guard now need a valid token, or those routes have to be excluded.
Other frameworks have had this limit for a while. In Symfony 8.2, or more precisely in the current symfony/http-foundation 8.2.0, Request::getMethod() ignores an override to GET, HEAD, CONNECT and TRACE. Request::setAllowedHttpMethodOverride() narrows the list further and refuses to allow GET or HEAD at all. If you also run Laravel next to Slim, install the recent Laravel security release with 22 CVEs too, which among other things closes several validation bypasses.
Fixing it in your app
The clean fix is upgrading both packages. Upgrading only one leaves you half protected, and the Slim team says so explicitly:
# Upgrade both packages together (Slim 4)
composer require slim/slim:^4.16.1 slim/csrf:^1.5.2
composer show slim/slim slim/csrf | grep versions
# Slim 3: slim/slim 3.13.2 and slim/csrf 0.8.4
composer require slim/slim:^3.13.2 slim/csrf:^0.8.4
If you can’t upgrade right away, the advisory lists three stopgaps: on Slim 4, register the Guard after MethodOverrideMiddleware; set session cookies with SameSite=Lax or Strict; and never change state in routes that accept GET. We would add a fourth and restrict the override to the methods you actually use. In our test, this held up even on the old versions:
// Replacement for MethodOverrideMiddleware: only PUT, PATCH and DELETE allowed
$app->add($guard);
$app->add(function (ServerRequestInterface $req, RequestHandlerInterface $handler) {
$wanted = strtoupper((string) (($req->getParsedBody() ?? [])['_METHOD'] ?? ''));
if ($req->getMethod() === 'POST' && in_array($wanted, ['PUT', 'PATCH', 'DELETE'], true)) {
$req = $req->withMethod($wanted);
}
return $handler->handle($req);
});
// Send the session cookie with SameSite=Lax as well
session_set_cookie_params(['samesite' => 'Lax', 'secure' => true, 'httponly' => true]);
session_start();
The SameSite attribute belongs in every PHP setup regardless. On our test machine session.cookie_samesite was empty, which is PHP’s default. Whether a given browser then assumes Lax on its own is not something to leave to chance. The OWASP CSRF cheat sheet covers the remaining building blocks, and our piece on the legacy ASP.NET library Idunno.AntiCsrf showed how quickly a protection module can turn into the problem itself.
Our take
“Low” is fair across the install base, because the attack needs an unlucky mix of routes, middleware order and cookie settings. In a single app, though, it can mean a changed email address and from there an account takeover via password reset. Start with composer show slim/slim slim/csrf to see what you run, then grep your code for map( and any( calls that include GET. Any handler there that writes data should move to POST or PUT, patch or no patch. The upgrade takes minutes; cleaning up those routes pays off for much longer.



