Skip to content

Commit 0bab68b

Browse files
authored
Merge pull request #8673 from kenjis/config-Security-redirect
feat: environment-specific Config\Security::$redirect
2 parents 3574196 + 00896cf commit 0bab68b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

app/Config/Security.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ class Security extends BaseConfig
7979
* --------------------------------------------------------------------------
8080
*
8181
* Redirect to previous page with error on failure.
82+
*
83+
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
8284
*/
83-
public bool $redirect = false;
85+
public bool $redirect = (ENVIRONMENT === 'production');
8486

8587
/**
8688
* --------------------------------------------------------------------------

user_guide_src/source/changelogs/v4.5.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ Others
199199
if the HTTP method is different.
200200
- **Bootstrap:** The ``CodeIgniter\Boot`` class has been introduced, replacing
201201
**system/bootstrap.php**.
202+
- **Security:** ``Config\Security::$redirect`` is now, by default, environment-specific.
203+
For production environment, changed to ``true`` but is still ``false`` for other
204+
environments.
202205

203206
********
204207
BREAKING

user_guide_src/source/installation/upgrade_450.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ Others
327327
- app/Config/Kint.php
328328
- It no longer extends ``BaseConfig`` because enabling
329329
:ref:`factories-config-caching` could cause errors.
330+
- app/Config/Security.php
331+
- The property ``$redirect`` has been changed to ``true`` in ``production``
332+
environment.
330333

331334
All Changes
332335
===========

user_guide_src/source/libraries/security.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,17 @@ may alter this behavior by editing the following config parameter value in
130130
Redirection on Failure
131131
----------------------
132132

133-
Since v4.3.0, when a request fails the CSRF validation check,
134-
it will throw a SecurityException by default,
133+
Starting with v4.5.0, when a request fails the CSRF validation check, by default,
134+
the user is redirected to the previous page in production environment, or a
135+
SecurityException is thrown in other environments.
135136

136137
.. note:: In production environment, when you use HTML forms, it is recommended
137138
to enable this redirection for a better user experience.
138139

139-
If you want to make it redirect to the previous page,
140-
change the following config parameter value in
141-
**app/Config/Security.php**:
140+
Upgrade users should check their configuration files.
141+
142+
If you want to make it redirect to the previous page, set the following config
143+
parameter value to ``true`` in **app/Config/Security.php**:
142144

143145
.. literalinclude:: security/005.php
144146

0 commit comments

Comments
 (0)