You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -41,6 +44,49 @@ You can set to use the Session based CSRF protection by editing the following co
41
44
42
45
public $csrfProtection = 'session';
43
46
47
+
Token Randomization
48
+
-------------------
49
+
50
+
To mitigate compression side-channel attacks like `BREACH`_, and prevent an attacker from guessing the CSRF tokens, you can configure token randomization (off by default).
51
+
52
+
If you enable it, a random mask is added to the token and used to scramble it.
You can enable it by editing the following config parameter value in
57
+
**app/Config/Security.php**::
58
+
59
+
public $tokenRandomize = true;
60
+
61
+
Token Regeneration
62
+
------------------
63
+
64
+
Tokens may be either regenerated on every submission (default) or
65
+
kept the same throughout the life of the CSRF cookie. The default
66
+
regeneration of tokens provides stricter security, but may result
67
+
in usability concerns as other tokens become invalid (back/forward
68
+
navigation, multiple tabs/windows, asynchronous actions, etc). You
69
+
may alter this behavior by editing the following config parameter value in
70
+
**app/Config/Security.php**::
71
+
72
+
public $regenerate = true;
73
+
74
+
Redirection on Failure
75
+
----------------------
76
+
77
+
When a request fails the CSRF validation check, it will redirect to the previous page by default,
78
+
setting an ``error`` flash message that you can display to the end user with the following code in your view::
79
+
80
+
<?= session()->getFlashdata('error') ?>
81
+
82
+
This provides a nicer experience
83
+
than simply crashing. This can be turned off by editing the following config parameter value in
84
+
**app/Config/Security.php**::
85
+
86
+
public $redirect = false;
87
+
88
+
Even when the redirect value is ``true``, AJAX calls will not redirect, but will throw an error.
89
+
44
90
Enable CSRF Protection
45
91
======================
46
92
@@ -79,20 +125,6 @@ It is also possible to enable the CSRF filter only for specific methods::
79
125
'post' => ['csrf'],
80
126
];
81
127
82
-
Token Randomization
83
-
===================
84
-
85
-
To mitigate compression side-channel attacks like `BREACH`_, and prevent an attacker from guessing the CSRF tokens, you can configure token randomization (default off).
86
-
87
-
If you enable it, a random mask is added to the token and used to scramble it.
0 commit comments