pkj / minibase-plugin-csrfprotection
Plugin that enabled CSRF Protection by default for Minibase framework apps.
Installs: 24
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/pkj/minibase-plugin-csrfprotection
Requires
- php: >=5.4.0
- minibase/minibase: dev-master
This package is auto-updated.
Last update: 2025-09-29 01:29:05 UTC
README
CSRF Protection Plugin
CSRF Protection plugin for Minibase applications.
Handle evil CSRF attacks for all your routes except GET.
Install
{ "require":{ "pkj/minibase-plugin-csrfprotection": "dev-master" } }
Usage
Add the plugin to your app.
$mb->initPlugins(array('Pkj\Minibase\Plugin\Csrf\CsrfPlugin' => null));
Echo $csrfTokenInput
in the forms that does post requests. Note, also $csrfToken
is available, it contains only the token.
<form> <?php echo $csrfTokenInput ?> </form>
You are now safe for CSRF protection.
Configuration array:
- store:
cookie
orsession
. Note SESSION must be started if session is used. I recommend usingcookie
. - token_name: the name of the token. Default is "csrfToken".
Events
You may customize the error exception if a token is invalid by adding event handler.
$mb->events->on("csrf:invalid", function ($request) { return function () { return $this->respond("html")->view("csrfinvalid.html.php"); }; });
Annotations
First, use the class . use Pkj\Minibase\Plugin\Csrf\Annotation\IgnoreCsrfProtection
.
@IgnoreCsrfProtection
Can be applied to controllers or a controller method. Useful for RESTful API's. (JSON API). In such where we do not need to check for CSRF protection.