File tree Expand file tree Collapse file tree 7 files changed +22
-13
lines changed Expand file tree Collapse file tree 7 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -369,7 +369,7 @@ class App extends BaseConfig
369
369
*
370
370
* @deprecated Use `Config\Security` $redirect property instead of using this property.
371
371
*/
372
- public bool $ CSRFRedirect = true ;
372
+ public bool $ CSRFRedirect = false ;
373
373
374
374
/**
375
375
* --------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ class Security extends BaseConfig
80
80
*
81
81
* Redirect to previous page with error on failure.
82
82
*/
83
- public bool $ redirect = true ;
83
+ public bool $ redirect = false ;
84
84
85
85
/**
86
86
* --------------------------------------------------------------------------
Original file line number Diff line number Diff line change 124
124
# security.cookieName = 'csrf_cookie_name'
125
125
# security.expires = 7200
126
126
# security.regenerate = true
127
- # security.redirect = true
127
+ # security.redirect = false
128
128
# security.samesite = 'Lax'
129
129
130
130
#--------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ class Security implements SecurityInterface
123
123
*
124
124
* @var bool
125
125
*/
126
- protected $ redirect = true ;
126
+ protected $ redirect = false ;
127
127
128
128
/**
129
129
* CSRF SameSite
Original file line number Diff line number Diff line change @@ -85,7 +85,9 @@ Changes
85
85
- The ``CodeIgniter\CLI\CommandRunner `` class has been removed due to a change in Spark commands processing.
86
86
- The system route configuration file ``system/Config/Routes.php `` has been removed.
87
87
- The route configuration file ``app/Config/Routes.php `` has been changed. Removed include of system routes configuration file.
88
- - All atomic type properties in ``Config `` classes have been typed.
88
+ - Config
89
+ - All atomic type properties in ``Config `` classes have been typed.
90
+ - Changed the default setting to not redirect when a CSRF check fails so that it is easy to see that it is a CSRF error.
89
91
90
92
Deprecations
91
93
************
Original file line number Diff line number Diff line change @@ -112,18 +112,22 @@ may alter this behavior by editing the following config parameter value in
112
112
Redirection on Failure
113
113
----------------------
114
114
115
- When a request fails the CSRF validation check, it will redirect to the previous page by default ,
116
- setting an `` error `` flash message that you can display to the end user with the following code in your view::
115
+ Since v4.3.0, when a request fails the CSRF validation check,
116
+ it will throw a SecurityException by default,
117
117
118
- <?= session()->getFlashdata('error') ?>
119
-
120
- This provides a nicer experience
121
- than simply crashing. This can be turned off by editing the following config parameter value in
118
+ If you want to make it redirect to the previous page,
119
+ change the following config parameter value in
122
120
**app/Config/Security.php **:
123
121
124
122
.. literalinclude :: security/005.php
125
123
126
- Even when the redirect value is ``true ``, AJAX calls will not redirect, but will throw an error.
124
+ When redirected, an ``error `` flash message is set and can be displayed to the end user with the following code in your view::
125
+
126
+ <?= session()->getFlashdata('error') ?>
127
+
128
+ This provides a nicer experience than simply crashing.
129
+
130
+ Even when the redirect value is ``true ``, AJAX calls will not redirect, but will throw a SecurityException.
127
131
128
132
Enable CSRF Protection
129
133
======================
Original file line number Diff line number Diff line change 6
6
7
7
class Security extends BaseConfig
8
8
{
9
- public $ redirect = false ;
9
+ // ...
10
+
11
+ public bool $ redirect = true ;
12
+
10
13
// ...
11
14
}
You can’t perform that action at this time.
0 commit comments