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:

You could also take a look at my Slim 4 CSRF package:

Update: Maybe you don’t need CSRF protection anymore:

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

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