sarathiscookie's avatar

How to check CSRF token in Lumen 5.2?

How to add CSRF Protection in Lumen 5.2?

0 likes
5 replies
olympus999's avatar

Also trying to figure it out. Can anyone point in a correct direction?

olympus999's avatar

willvincent, are you sure this works in lumen 5.2?

I get the following error:

[2016-06-28 16:30:27] lumen.ERROR: exception 'ReflectionException' with message 'Class Laravel\Lumen\Http\Middleware\VerifyCsrfToken does not exist' in /var/www/api/vendor/illuminate/container/Container.php:734 Stack trace: #0 /var/www/api/vendor/illuminate/container/Container.php(734): ReflectionClass->__construct('Laravel\Lumen\H...') #1 /var/www/api/vendor/illuminate/container/Container.php(629): Illuminate\Container\Container->build('Laravel\Lumen\H...', Array) #2 /var/www/api/vendor/laravel/lumen-framework/src/Application.php(205): Illuminate\Container\Container->make('Laravel\Lumen\H...', Array) #3 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(126): Laravel\Lumen\Application->make('Laravel\Lumen\H...') #4 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request)) #5 /var/www/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(32): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #6 [internal function]: Laravel\Lumen\Routing\Pipeline->Laravel\Lumen\Routing{closure}(Object(Illuminate\Http\Request)) #7 /var/www/api/vendor/illuminate/pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request)) #8 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(633): Illuminate\Pipeline\Pipeline->then(Object(Closure)) #9 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(482): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure)) #10 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(383): Laravel\Lumen\Application->handleFoundRoute(Array) #11 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(636): Laravel\Lumen\Application->Laravel\Lumen\Concerns{closure}() #12 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(389): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure)) #13 /var/www/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(334): Laravel\Lumen\Application->dispatch(NULL) #14 /var/www/api/public/index.php(28): Laravel\Lumen\Application->run() #15 {main}

willvincent's avatar

willvincent, are you sure this works in lumen 5.2?

No.. I don't use lumen. A quick look around the codebase, and docs though, it looks like the csrf token middleware was removed in 5.2... but it is in 5.1: https://lumen.laravel.com/docs/5.1/routing#csrf-x-csrf-token

So, if you need it, you'll probably need to manually implement it in 5.2.

There's probably good reason for it having been removed as lumen is intended for microservices which almost certainly should be stateless, but csrf tokens depend on sessions.

Please or to participate in this conversation.