Skip to content

Commit 297c72d

Browse files
authored
Merge pull request #5555 from kenjis/replace_deprecated_filter
fix: replace deprecated FILTER_SANITIZE_STRING
2 parents 27235a1 + b4b24e0 commit 297c72d

File tree

7 files changed

+95
-5
lines changed

7 files changed

+95
-5
lines changed

system/Helpers/cookie_helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function get_cookie($index, bool $xssClean = false)
6565
{
6666
$prefix = isset($_COOKIE[$index]) ? '' : config(App::class)->cookiePrefix;
6767
$request = Services::request();
68-
$filter = $xssClean ? FILTER_SANITIZE_STRING : FILTER_DEFAULT;
68+
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_DEFAULT;
6969

7070
return $request->getCookie($prefix . $index, $filter);
7171
}

user_guide_src/source/changelogs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See all the changes.
1212
.. toctree::
1313
:titlesonly:
1414

15+
v4.1.7
1516
v4.1.6
1617
v4.1.5
1718
v4.1.4
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Version 4.1.7
2+
#############
3+
4+
Release Date: Not Released
5+
6+
**4.1.7 release of CodeIgniter4**
7+
8+
.. contents::
9+
:local:
10+
:depth: 2
11+
12+
BREAKING
13+
********
14+
15+
- Because ``FILTER_SANITIZE_STRING`` is deprecated since PHP 8.1, ``get_cookie()`` that uses it when ``$xssClean`` is true changed the output. Now it uses ``FILTER_SANITIZE_FULL_SPECIAL_CHARS``. Note that using XSS filtering is a bad practice. It does not prevent XSS attacks perfectly. Using ``esc()`` with the correct ``$context`` in the views is recommended.
16+
17+
Enhancements
18+
************
19+
20+
none.
21+
22+
Changes
23+
*******
24+
25+
none.
26+
27+
Deprecations
28+
************
29+
30+
none.
31+
32+
Bugs Fixed
33+
**********
34+
35+
See the repo's `CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_ for a complete list of bugs fixed.

user_guide_src/source/helpers/cookie_helper.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The following functions are available:
5353
the ``$cookiePrefix`` that you might've set in your
5454
**app/Config/App.php** file.
5555

56+
.. warning:: Using XSS filtering is a bad practice. It does not prevent XSS attacks perfectly. Using ``esc()`` with the correct ``$context`` in the views is recommended.
57+
5658
.. php:function:: delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]])
5759
5860
:param string $name: Cookie name

user_guide_src/source/incoming/incomingrequest.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,15 @@ The methods provided by the parent classes that are available are:
399399
The second optional parameter lets you run the data through the PHP's
400400
filters. Pass in the desired filter type as the second parameter::
401401

402-
$request->getVar('some_data', FILTER_SANITIZE_STRING);
402+
$request->getVar('some_data', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
403403

404404
To return an array of all POST items call without any parameters.
405405

406406
To return all POST items and pass them through the filter, set the
407407
first parameter to null while setting the second parameter to the filter
408408
you want to use::
409409

410-
$request->getVar(null, FILTER_SANITIZE_STRING);
410+
$request->getVar(null, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
411411
// returns all POST items with string sanitation
412412

413413
To return an array of multiple POST parameters, pass all the required keys as an array::
@@ -417,7 +417,7 @@ The methods provided by the parent classes that are available are:
417417
Same rule applied here, to retrieve the parameters with filtering, set the second parameter to
418418
the filter type to apply::
419419

420-
$request->getVar(['field1', 'field2'], FILTER_SANITIZE_STRING);
420+
$request->getVar(['field1', 'field2'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
421421

422422
.. php:method:: getGet([$index = null[, $filter = null[, $flags = null]]])
423423
@@ -489,7 +489,7 @@ The methods provided by the parent classes that are available are:
489489
This method is identical to ``getPost()`` and ``getGet()``, only it fetches cookie data::
490490

491491
$request->getCookie('some_cookie');
492-
$request->getCookie('some_cookie', FILTER_SANITIZE_STRING); // with filter
492+
$request->getCookie('some_cookie', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // with filter
493493

494494
To return an array of multiple cookie values, pass all the required keys as an array::
495495

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#############################
2+
Upgrading from 4.1.6 to 4.1.7
3+
#############################
4+
5+
Please refer to the upgrade instructions corresponding to your installation method.
6+
7+
- :ref:`Composer Installation App Starter Upgrading <app-starter-upgrading>`
8+
- :ref:`Composer Installation Adding CodeIgniter4 to an Existing Project Upgrading <adding-codeigniter4-upgrading>`
9+
- :ref:`Manual Installation Upgrading <installing-manual-upgrading>`
10+
11+
.. contents::
12+
:local:
13+
:depth: 2
14+
15+
Breaking Changes
16+
****************
17+
18+
- ``get_cookie()`` when ``$xssClean`` is true changed the output. Now it uses ``FILTER_SANITIZE_FULL_SPECIAL_CHARS``, not ``FILTER_SANITIZE_STRING``. Make sure the change is acceptable or not. Note that using XSS filtering is a bad practice. It does not prevent XSS attacks perfectly. Using ``esc()`` with the correct ``$context`` in the views is recommended.
19+
20+
Breaking Enhancements
21+
*********************
22+
23+
none.
24+
25+
Project Files
26+
*************
27+
28+
Numerous files in the **project space** (root, app, public, writable) received updates. Due to
29+
these files being outside of the **system** scope they will not be changed without your intervention.
30+
There are some third-party CodeIgniter modules available to assist with merging changes to
31+
the project space: `Explore on Packagist <https://packagist.org/explore/?query=codeigniter4%20updates>`_.
32+
33+
.. note:: Except in very rare cases for bug fixes, no changes made to files for the project space
34+
will break your application. All changes noted here are optional until the next major version,
35+
and any mandatory changes will be covered in the sections above.
36+
37+
Content Changes
38+
===============
39+
40+
The following files received significant changes (including deprecations or visual adjustments)
41+
and it is recommended that you merge the updated versions with your application:
42+
43+
*
44+
45+
All Changes
46+
===========
47+
48+
This is a list of all files in the **project space** that received changes;
49+
many will be simple comments or formatting that have no effect on the runtime:
50+
51+
*

user_guide_src/source/installation/upgrading.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ upgrading from.
88
.. toctree::
99
:titlesonly:
1010

11+
Upgrading from 4.1.6 to 4.1.7 <upgrade_417>
1112
Upgrading from 4.1.5 to 4.1.6 <upgrade_416>
1213
Upgrading from 4.1.4 to 4.1.5 <upgrade_415>
1314
Upgrading from 4.1.3 to 4.1.4 <upgrade_414>

0 commit comments

Comments
 (0)