Slim 4 CSRF Protection?

Hello, How works CSRF protection in Slim v4?

Take a look a the “official” Slim-CSRF package. Unfortunately it doesn’t support Slim 4 yet: https://github.com/slimphp/Slim-Csrf/pull/104

You could also take a look at my Slim 4 CSRF package: https://github.com/odan/csrf

Update: Maybe you don’t need CSRF protection anymore: https://scotthelme.co.uk/csrf-is-really-dead/

Solution: use it without Middleware

Instead of using a separate middleware for CSRF Attack Protection, we should use it directly in our bootstrapper file like this

Now you can use these csrf fields in you template files like this
image

Ps: update this block as per your requirements or you can move these all to different file as well

Adding Twig v3 Globals for csrf fields will give you this error in Slim 4
Unable to add global “csrf” as the runtime or the extensions have already been initialized.
To fix these I implemented this answer.

Thanks & Regards
shindea890@gmail.com