Slim 3 uses the optional standalone slimphp/Slim-Csrf PHP component to protect your application from CSRF (cross-site request forgery). This component generates a unique token per request that validates subsequent POST requests from client-side HTML forms.
Execute this bash command from your project’s root directory:
slimphp/Slim-Csrf component contains an application middleware. Add it
to your application like this:
The latest CSRF token’s name and value are available as attributes on the PSR7 request object. The CSRF token name and value are unique for each request. You can fetch the current CSRF token name and value like this.
You should pass the CSRF token name and value to the template so they may be submitted with HTML form POST requests. They are often stored as a hidden field with HTML forms.
For more use cases and documentation please check slimphp/Slim-Csrf’s page.