From e3810cb84d3fa341e3808d6aa9c3e18f8bda3305 Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Wed, 10 Mar 2021 22:11:52 +0200 Subject: Merge pull request #6028 from vibbow/patch-1 Update Session.php --- system/libraries/Session/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 06b953ab2..ec57ee548 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -723,7 +723,7 @@ class CI_Session { * * Legacy CI_Session compatibility method * - * @returns array + * @return array */ public function &get_userdata() { -- cgit v1.2.3-24-g4f1b From 0286ab3513ade8681a7172c78440a81059435e22 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Mar 2021 13:26:50 +0200 Subject: [ci skip] Add SameSite=Strict to CSRF cookie --- system/core/Security.php | 38 ++++++++++++++++++++++++++++--------- user_guide_src/source/changelog.rst | 1 + 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/system/core/Security.php b/system/core/Security.php index e1dc2a92f..f6b0407f8 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -272,15 +272,35 @@ class CI_Security { return FALSE; } - setcookie( - $this->_csrf_cookie_name, - $this->_csrf_hash, - $expire, - config_item('cookie_path'), - config_item('cookie_domain'), - $secure_cookie, - config_item('cookie_httponly') - ); + if (is_php('7.3')) + { + setcookie( + $this->_csrf_cookie_name, + $this->_csrf_hash, + array( + 'expires' => $expire, + 'path' => config_item('cookie_path'), + 'domain' => config_item('cookie_domain'), + 'secure' => $secure_cookie, + 'httponly' => config_item('cookie_httponly'), + 'samesite' => 'Strict' + ) + ); + } + else + { + $domain = trim(config_item('cookie_domain')); + header('Set-Cookie: '.$this->_csrf_cookie_name.'='.$this->_csrf_hash + .'; Expires='.gmdate('D, d-M-Y H:i:s T', $expire) + .'; Max-Age='.$this->_csrf_expire + .'; Path='.rawurlencode(config_item('cookie_path')) + .($domain === '' ? '' : '; Domain='.$domain) + .($secure_cookie ? '; Secure' : '') + .(config_item('cookie_httponly') ? '; HttpOnly' : '') + .'; SameSite=Strict' + ); + } + log_message('info', 'CSRF cookie sent'); return $this; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 4c081ad84..812016050 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -15,6 +15,7 @@ Release Date: Not Released - Added support for detecting WebP image type to :doc:`File Uploading Library `. - Added method :doc:`Database Library ` method ``trans_active()`` to expose transaction state. - Updated :doc:`Database Library ` 'pdo' driver to attempt to free resources in order to allow connections to be closed. + - Added ``SameSite=Strict`` attribute to the CSRF cookie sent by the :doc:`Security Class `. Bug fixes for 3.1.12 ==================== -- cgit v1.2.3-24-g4f1b From 063aee9e0f6f560b479958e4fae9f5b77048c8fa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Sep 2021 13:23:24 +0300 Subject: [ci skip] Merge pull request #6054 from gphg/attributes export-ignore user_guide_src/ --- .gitattributes | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index a4296d591..b4f0b6cbb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18,8 +18,6 @@ readme.rst tests/codeigniter/ export-ignore tests/travis/ export-ignore -# User Guide Source Files -user_guide_src - -# User Guide Compiled Files +# User Guide source files and compiled files +user_guide_src export-ignore user_guide export-ignore -- cgit v1.2.3-24-g4f1b From 87928371de8a316c9880a451fae04d9785c32840 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 14 Sep 2021 13:47:31 +0300 Subject: Merge pull request #6045 from gxgpet/develop_fixtravis Fixes Travis pipeline. Adding PHPUnit 8. --- .travis.yml | 17 ++++++++++------- composer.json | 4 ++-- tests/Bootstrap.php | 7 +++++++ tests/codeigniter/Setup_test.php | 2 +- tests/codeigniter/core/Input_test.php | 10 +++++++++- .../codeigniter/database/query_builder/select_test.php | 2 +- tests/codeigniter/helpers/file_helper_test.php | 5 +---- tests/codeigniter/helpers/text_helper_test.php | 7 +------ tests/mocks/ci_testcase.php | 18 ++++++++++++++++-- tests/phpunit.xml | 3 ++- 10 files changed, 50 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 990a962cd..ee717ab9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,15 @@ php: - nightly env: - - DB=mysqli - - DB=pgsql - - DB=sqlite - - DB=pdo/mysql - - DB=pdo/pgsql - - DB=pdo/sqlite + global: + - XDEBUG_MODE=coverage + jobs: + - DB=mysqli + - DB=pgsql + - DB=sqlite + - DB=pdo/mysql + - DB=pdo/pgsql + - DB=pdo/sqlite services: - mysql @@ -33,7 +36,7 @@ before_script: - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi" - sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'mysqli' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi" -script: php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.func_overload=7 -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml +script: test $(php -r 'echo PHP_VERSION_ID;') -lt 70300 && php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.func_overload=7 -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml || php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml jobs: allow_failures: diff --git a/composer.json b/composer.json index 4a1b33313..6b802d493 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "paragonie/random_compat": "Provides better randomness in PHP 5.x" }, "require-dev": { - "mikey179/vfsstream": "1.1.*", - "phpunit/phpunit": "4.* || 5.*" + "mikey179/vfsstream": "1.6.*", + "phpunit/phpunit": "4.* || 5.* || 8.*" } } diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index b4e56bdae..ada6a5998 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -65,6 +65,13 @@ else is_php('5.6') && ini_set('php.internal_encoding', 'UTF-8'); +if (is_php('7.0')) +{ + $test_case_code = file_get_contents(PROJECT_BASE.'vendor/phpunit/phpunit/src/Framework/TestCase.php'); + $test_case_code = preg_replace('/^\s+((?:protected|public)(?: static)? function \w+\(\)): void/m', '$1', $test_case_code); + file_put_contents(PROJECT_BASE.'vendor/phpunit/phpunit/src/Framework/TestCase.php', $test_case_code); +} + include_once SYSTEM_PATH.'core/compat/mbstring.php'; include_once SYSTEM_PATH.'core/compat/hash.php'; include_once SYSTEM_PATH.'core/compat/password.php'; diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index 5317c56c7..43545822a 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -1,6 +1,6 @@ assertSame(array(), $this->input->get()); @@ -136,7 +144,7 @@ class Input_test extends CI_TestCase { $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); $_SERVER['REQUEST_METHOD'] = 'POST'; - $_POST['foo']['bar'] = 'baz'; + $_POST['foo'] = array('bar' => 'baz'); $barArray = array('bar' => 'baz'); $this->assertEquals('baz', $this->input->post('foo[bar]')); diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index 93b5c3d46..facda791f 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -74,7 +74,7 @@ class Select_test extends CI_TestCase { ->row(); // Average should be 2.5 - $this->assertEquals('2.5', $job_avg->id); + $this->assertEquals(2.5, (float) $job_avg->id); } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index ad56beb28..0d7ae96ee 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -6,10 +6,7 @@ class File_helper_Test extends CI_TestCase { { $this->helper('file'); - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); - - $this->_test_dir = vfsStreamWrapper::getRoot(); + $this->_test_dir = vfsStream::setup(''); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index b6902c016..7a7dc0a12 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -64,12 +64,7 @@ class Text_helper_test extends CI_TestCase { public function test_convert_accented_characters() { - $path = 'application/config/foreign_chars.php'; - $this->ci_vfs_clone($path); - if (is_php('7.4')) - { - copy(PROJECT_BASE.$path, APPPATH.'../'.$path); - } + $this->ci_vfs_clone('application/config/foreign_chars.php'); $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); } diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index 8dc4682ef..de46f6df6 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -1,6 +1,6 @@ ci_vfs_root = vfsStream::setup(); + $this->ci_vfs_root = vfsStream::setup(''); $this->ci_app_root = vfsStream::newDirectory('application')->at($this->ci_vfs_root); $this->ci_base_root = vfsStream::newDirectory('system')->at($this->ci_vfs_root); $this->ci_view_root = vfsStream::newDirectory('views')->at($this->ci_app_root); @@ -381,4 +381,18 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { return parent::__call($method, $args); } + public function setExpectedException($exception_class, $exception_message = '', $exception_code = null) + { + $use_expect_exception = method_exists($this, 'expectException'); + + if ($use_expect_exception) + { + $this->expectException($exception_class); + $exception_message !== '' && $this->expectExceptionMessage($exception_message); + } + else + { + parent::setExpectedException($exception_class, $exception_message, $exception_code); + } + } } diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 875198c4e..a1626ce91 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> ./codeigniter/core -- cgit v1.2.3-24-g4f1b From d9218efec1d89e9d633b73f367bcc7b676400621 Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Tue, 16 Nov 2021 02:18:40 +0200 Subject: [ci skip] Merge pull request #6071 from ddonatek/patch-1 Added another SVG mimetype --- application/config/mimes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/mimes.php b/application/config/mimes.php index f5407ff89..b2e989fea 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -162,7 +162,7 @@ return array( 'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'), 'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'), 'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'), - 'svg' => array('image/svg+xml', 'application/xml', 'text/xml'), + 'svg' => array('image/svg+xml', 'image/svg', 'application/xml', 'text/xml'), 'vcf' => 'text/x-vcard', 'srt' => array('text/srt', 'text/plain'), 'vtt' => array('text/vtt', 'text/plain'), -- cgit v1.2.3-24-g4f1b From 74384ca7f88913b87e982696bb5cb3eb5593c451 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Dec 2021 15:47:39 +0200 Subject: Merge pull request #6074 from philsturgeon/ci3-php8 CodeIgniter 3.0 on PHP 8 --- composer.json | 8 ++++- system/core/Output.php | 10 ++++-- system/database/DB_driver.php | 2 +- system/database/drivers/pdo/pdo_driver.php | 8 +++++ .../drivers/pdo/subdrivers/pdo_pgsql_forge.php | 7 ++++ tests/codeigniter/core/Loader_test.php | 39 ++++++++++++++-------- tests/codeigniter/core/Security_test.php | 2 +- tests/codeigniter/core/compat/mbstring_test.php | 4 +-- tests/codeigniter/helpers/array_helper_test.php | 4 +-- tests/codeigniter/helpers/string_helper_test.php | 2 +- tests/codeigniter/libraries/Driver_test.php | 16 +++++---- tests/codeigniter/libraries/Encryption_test.php | 4 +-- tests/codeigniter/libraries/Table_test.php | 12 +++---- tests/mocks/database/config/mysql.php | 10 +++--- tests/mocks/database/config/mysqli.php | 10 +++--- tests/mocks/database/config/pdo/mysql.php | 14 ++++---- tests/mocks/database/config/pdo/pgsql.php | 4 +-- tests/mocks/database/config/pgsql.php | 4 +-- tests/mocks/database/schema/skeleton.php | 10 +++--- tests/travis/mysql.phpunit.xml | 3 +- tests/travis/mysqli.phpunit.xml | 3 +- tests/travis/pdo/mysql.phpunit.xml | 3 +- tests/travis/pdo/pgsql.phpunit.xml | 3 +- tests/travis/pdo/sqlite.phpunit.xml | 3 +- tests/travis/pgsql.phpunit.xml | 3 +- tests/travis/sqlite.phpunit.xml | 36 ++++++++++---------- 26 files changed, 135 insertions(+), 89 deletions(-) diff --git a/composer.json b/composer.json index 6b802d493..cf9ac486c 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,14 @@ "suggest": { "paragonie/random_compat": "Provides better randomness in PHP 5.x" }, + "scripts": { + "test:coverage": [ + "@putenv XDEBUG_MODE=coverage", + "phpunit --color=always --coverage-text --configuration tests/travis/sqlite.phpunit.xml" + ] + }, "require-dev": { "mikey179/vfsstream": "1.6.*", - "phpunit/phpunit": "4.* || 5.* || 8.*" + "phpunit/phpunit": "4.* || 5.* || 9.*" } } diff --git a/system/core/Output.php b/system/core/Output.php index cef092600..93d85e798 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -299,10 +299,14 @@ class CI_Output { */ public function get_header($header) { - // Combine headers already sent with our batched headers + // We only need [x][0] from our multi-dimensional array + $header_lines = array_map(function ($headers) + { + return array_shift($headers); + }, $this->headers); + $headers = array_merge( - // We only need [x][0] from our multi-dimensional array - array_map('array_shift', $this->headers), + $header_lines, headers_list() ); diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index c7bca96d8..6e1d8d11e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -887,7 +887,7 @@ abstract class CI_DB_driver { { return $this->_trans_status; } - + // -------------------------------------------------------------------- /** diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index d0a2bf959..b2178b684 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -131,6 +131,14 @@ class CI_DB_pdo_driver extends CI_DB { $this->options[PDO::ATTR_PERSISTENT] = TRUE; } + // From PHP8.0, default PDO::ATTR_ERRMODE is changed + // from PDO::ERRMODE_SILENT to PDO::ERRMODE_EXCEPTION + // as https://wiki.php.net/rfc/pdo_default_errmode + if ( ! isset($this->options[PDO::ATTR_ERRMODE])) + { + $this->options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_SILENT; + } + try { return new PDO($this->dsn, $this->username, $this->password, $this->options); diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php index 187cb2d09..4c3a5aaea 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php @@ -53,6 +53,13 @@ class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge { */ protected $_drop_table_if = 'DROP TABLE IF EXISTS'; + /** + * CREATE TABLE IF statement + * + * @var string + */ + protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS'; + /** * UNSIGNED support * diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 8c5bb3021..6a7aa916a 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -36,7 +36,8 @@ class Loader_test extends CI_TestCase { // Test loading as an array. $this->assertInstanceOf('CI_Loader', $this->load->library(array($lib))); $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); + $this->assertObjectHasAttribute($lib, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$lib); // Create library in VFS $lib = array('unit_test_lib' => 'unit_test_lib'); @@ -87,14 +88,16 @@ class Loader_test extends CI_TestCase { $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); $this->assertTrue(class_exists($class), $class.' does not exist'); $this->assertTrue(class_exists($ext), $ext.' does not exist'); - $this->assertAttributeInstanceOf($class, $name, $this->ci_obj); - $this->assertAttributeInstanceOf($ext, $name, $this->ci_obj); + $this->assertObjectHasAttribute($name, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$name); + $this->assertInstanceOf($ext, $this->ci_obj->$name); // Test reloading with object name $obj = 'exttest'; $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj)); - $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); - $this->assertAttributeInstanceOf($ext, $obj, $this->ci_obj); + $this->assertObjectHasAttribute($obj, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$obj); + $this->assertInstanceOf($ext, $this->ci_obj->$obj); // Test reloading unset($this->ci_obj->$name); @@ -137,7 +140,8 @@ class Loader_test extends CI_TestCase { $obj = 'testy'; $this->assertInstanceOf('CI_Loader', $this->load->library($lib, NULL, $obj)); $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); + $this->assertObjectHasAttribute($obj, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$obj); $this->assertEquals($cfg, $this->ci_obj->$obj->config); // Test is_loaded @@ -168,7 +172,8 @@ class Loader_test extends CI_TestCase { // Was the model class instantiated. $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); + $this->assertObjectHasAttribute($lib, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$lib); } // -------------------------------------------------------------------- @@ -188,12 +193,14 @@ class Loader_test extends CI_TestCase { // Test loading as an array. $this->assertInstanceOf('CI_Loader', $this->load->driver(array($driver))); $this->assertTrue(class_exists($class), $class.' does not exist'); - $this->assertAttributeInstanceOf($class, $driver, $this->ci_obj); + $this->assertObjectHasAttribute($driver, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$driver); // Test loading as a library with a name $obj = 'testdrive'; $this->assertInstanceOf('CI_Loader', $this->load->library($driver, NULL, $obj)); - $this->assertAttributeInstanceOf($class, $obj, $this->ci_obj); + $this->assertObjectHasAttribute($obj, $this->ci_obj); + $this->assertInstanceOf($class, $this->ci_obj->$obj); // Test a string given to params $this->assertInstanceOf('CI_Loader', $this->load->driver($driver, ' ')); @@ -242,8 +249,9 @@ class Loader_test extends CI_TestCase { // Was the model class instantiated? $this->assertTrue(class_exists($model)); $this->assertObjectHasAttribute($name, $this->ci_obj); - $this->assertAttributeInstanceOf($base, $name, $this->ci_obj); - $this->assertAttributeInstanceOf($model, $name, $this->ci_obj); + $this->assertObjectHasAttribute($name, $this->ci_obj); + $this->assertInstanceOf($base, $this->ci_obj->$name); + $this->assertInstanceOf($model, $this->ci_obj->$name); // Test name conflict $obj = 'conflict'; @@ -567,15 +575,18 @@ class Loader_test extends CI_TestCase { // Verify library $this->assertTrue(class_exists($lib_class), $lib_class.' does not exist'); - $this->assertAttributeInstanceOf($lib_class, $lib, $this->ci_obj); + $this->assertObjectHasAttribute($lib, $this->ci_obj); + $this->assertInstanceOf($lib_class, $this->ci_obj->$lib); // Verify driver $this->assertTrue(class_exists($drv_class), $drv_class.' does not exist'); - $this->assertAttributeInstanceOf($drv_class, $drv, $this->ci_obj); + $this->assertObjectHasAttribute($drv, $this->ci_obj); + $this->assertInstanceOf($drv_class, $this->ci_obj->$drv); // Verify model $this->assertTrue(class_exists($model), $model.' does not exist'); - $this->assertAttributeInstanceOf($model, $model, $this->ci_obj); + $this->assertObjectHasAttribute($model, $this->ci_obj); + $this->assertInstanceOf($model, $this->ci_obj->$model); // Verify config calls $this->assertEquals($cfg['config'], $this->ci_obj->config->loaded); diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index c3113adba..5f94e1501 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -252,7 +252,7 @@ class Security_test extends CI_TestCase { // Perform hash $this->security->xss_hash(); - $this->assertRegExp('#^[0-9a-f]{32}$#iS', $this->security->xss_hash); + $this->assertMatchesRegularExpression('#^[0-9a-f]{32}$#iS', $this->security->xss_hash); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/compat/mbstring_test.php b/tests/codeigniter/core/compat/mbstring_test.php index 415222446..8b8629efc 100644 --- a/tests/codeigniter/core/compat/mbstring_test.php +++ b/tests/codeigniter/core/compat/mbstring_test.php @@ -27,7 +27,7 @@ class mbstring_test extends CI_TestCase { // ------------------------------------------------------------------------ /** - * @depends test_boostrap + * @depends test_bootstrap */ public function test_mb_strpos() { @@ -39,7 +39,7 @@ class mbstring_test extends CI_TestCase { // ------------------------------------------------------------------------ /** - * @depends test_boostrap + * @depends test_bootstrap */ public function test_mb_substr() { diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index b2409c330..f4e344673 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -38,8 +38,8 @@ class Array_helper_test extends CI_TestCase { public function test_elements() { - $this->assertInternalType('array', elements('test', $this->my_array)); - $this->assertInternalType('array', elements('foo', $this->my_array)); + $this->assertEquals('array', gettype(elements('test', $this->my_array))); + $this->assertEquals('array', gettype(elements('foo', $this->my_array))); } } diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 75701ec13..9bd1ea816 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -129,7 +129,7 @@ class String_helper_test extends CI_TestCase { { $this->assertEquals(16, strlen(random_string('alnum', 16))); $this->assertEquals(32, strlen(random_string('unique', 16))); - $this->assertInternalType('string', random_string('numeric', 16)); + $this->assertEquals('string', gettype(random_string('numeric', 16))); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php index e4401e688..ea5cfa235 100644 --- a/tests/codeigniter/libraries/Driver_test.php +++ b/tests/codeigniter/libraries/Driver_test.php @@ -5,6 +5,8 @@ */ class Driver_test extends CI_TestCase { + private $name; + /** * Set up test framework */ @@ -50,8 +52,8 @@ class Driver_test extends CI_TestCase { // Was driver loaded? $this->assertObjectHasAttribute($driver, $this->lib); - $this->assertAttributeInstanceOf($class, $driver, $this->lib); - $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib); + $this->assertInstanceOf($class, $this->lib->$driver); + $this->assertInstanceOf('CI_Driver', $this->lib->$driver); // Was decorate called? $this->assertObjectHasAttribute($prop, $this->lib->$driver); @@ -85,8 +87,8 @@ class Driver_test extends CI_TestCase { // Was driver loaded? $this->assertObjectHasAttribute($driver, $this->lib); - $this->assertAttributeInstanceOf($class, $driver, $this->lib); - $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib); + $this->assertInstanceOf($class, $this->lib->$driver); + $this->assertInstanceOf('CI_Driver', $this->lib->$driver); // Do we get an error for a non-existent driver? $this->setExpectedException('RuntimeException', 'CI Error: Unable to load the requested driver: CI_'. @@ -119,9 +121,9 @@ class Driver_test extends CI_TestCase { // Was driver loaded? $this->assertObjectHasAttribute($driver, $this->lib); - $this->assertAttributeInstanceOf($class, $driver, $this->lib); - $this->assertAttributeInstanceOf($baseclass, $driver, $this->lib); - $this->assertAttributeInstanceOf('CI_Driver', $driver, $this->lib); + $this->assertInstanceOf($class, $this->lib->$driver); + $this->assertInstanceOf($baseclass, $this->lib->$driver); + $this->assertInstanceOf('CI_Driver', $this->lib->$driver); // Create driver extension without base $driver = 'baseless'; diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php index 8e411d9fa..68bc3d804 100644 --- a/tests/codeigniter/libraries/Encryption_test.php +++ b/tests/codeigniter/libraries/Encryption_test.php @@ -151,7 +151,7 @@ class Encryption_test extends CI_TestCase { 'hmac_key' => str_repeat("\x0", 16) ); - $this->assertInternalType('array', $this->encryption->__get_params($params)); + $this->assertEquals('array', gettype($this->encryption->__get_params($params))); $params['base64'] = TRUE; $params['hmac_digest'] = 'sha512'; @@ -217,7 +217,7 @@ class Encryption_test extends CI_TestCase { /** * encrypt(), decrypt test with custom parameters * - * @depends test___get_params + * @depends test__get_params */ public function test_encrypt_decrypt_custom() { diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index f505a43fc..6efae5d18 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -270,14 +270,14 @@ class Table_test extends CI_TestCase { $table = $this->table->generate($data); // Test the table header - $this->assertContains('Name', $table); - $this->assertContains('Color', $table); - $this->assertContains('Size', $table); + $this->assertEquals(1, substr_count($table, 'Name')); + $this->assertEquals(1, substr_count($table, 'Color')); + $this->assertEquals(1, substr_count($table, 'Size')); // Test the first entry - $this->assertContains('Fred', $table); - $this->assertContains('Blue', $table); - $this->assertContains('Small', $table); + $this->assertEquals(1, substr_count($table, 'Fred')); + $this->assertEquals(1, substr_count($table, 'Blue')); + $this->assertEquals(1, substr_count($table, 'Small')); } } diff --git a/tests/mocks/database/config/mysql.php b/tests/mocks/database/config/mysql.php index a590b9f53..ca30cb9ca 100644 --- a/tests/mocks/database/config/mysql.php +++ b/tests/mocks/database/config/mysql.php @@ -5,9 +5,9 @@ return array( // Typical Database configuration 'mysql' => array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'travis', - 'password' => '', + 'password' => 'travis', 'database' => 'ci_test', 'dbdriver' => 'mysql' ), @@ -15,7 +15,7 @@ return array( // Database configuration with failover 'mysql_failover' => array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'not_travis', 'password' => 'wrong password', 'database' => 'not_ci_test', @@ -23,9 +23,9 @@ return array( 'failover' => array( array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'travis', - 'password' => '', + 'password' => 'travis', 'database' => 'ci_test', 'dbdriver' => 'mysql', ) diff --git a/tests/mocks/database/config/mysqli.php b/tests/mocks/database/config/mysqli.php index 5dd08abb2..fd8fec962 100644 --- a/tests/mocks/database/config/mysqli.php +++ b/tests/mocks/database/config/mysqli.php @@ -5,9 +5,9 @@ return array( // Typical Database configuration 'mysqli' => array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'travis', - 'password' => '', + 'password' => 'travis', 'database' => 'ci_test', 'dbdriver' => 'mysqli' ), @@ -15,7 +15,7 @@ return array( // Database configuration with failover 'mysqli_failover' => array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'not_travis', 'password' => 'wrong password', 'database' => 'not_ci_test', @@ -23,9 +23,9 @@ return array( 'failover' => array( array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'travis', - 'password' => '', + 'password' => 'travis', 'database' => 'ci_test', 'dbdriver' => 'mysqli', ) diff --git a/tests/mocks/database/config/pdo/mysql.php b/tests/mocks/database/config/pdo/mysql.php index 96608f787..89e9fb130 100644 --- a/tests/mocks/database/config/pdo/mysql.php +++ b/tests/mocks/database/config/pdo/mysql.php @@ -4,10 +4,10 @@ return array( // Typical Database configuration 'pdo/mysql' => array( - 'dsn' => 'mysql:host=localhost;dbname=ci_test', - 'hostname' => 'localhost', + 'dsn' => 'mysql:host=127.0.0.1;dbname=ci_test', + 'hostname' => '127.0.0.1', 'username' => 'travis', - 'password' => '', + 'password' => 'travis', 'database' => 'ci_test', 'dbdriver' => 'pdo', 'subdriver' => 'mysql' @@ -16,7 +16,7 @@ return array( // Database configuration with failover 'pdo/mysql_failover' => array( 'dsn' => '', - 'hostname' => 'localhost', + 'hostname' => '127.0.0.1', 'username' => 'not_travis', 'password' => 'wrong password', 'database' => 'not_ci_test', @@ -24,10 +24,10 @@ return array( 'subdriver' => 'mysql', 'failover' => array( array( - 'dsn' => 'mysql:host=localhost;dbname=ci_test', - 'hostname' => 'localhost', + 'dsn' => 'mysql:host=127.0.0.1;dbname=ci_test', + 'hostname' => '127.0.0.1', 'username' => 'travis', - 'password' => '', + 'password' => 'travis', 'database' => 'ci_test', 'dbdriver' => 'pdo', 'subdriver' => 'mysql' diff --git a/tests/mocks/database/config/pdo/pgsql.php b/tests/mocks/database/config/pdo/pgsql.php index e55e3ea77..846c70be9 100644 --- a/tests/mocks/database/config/pdo/pgsql.php +++ b/tests/mocks/database/config/pdo/pgsql.php @@ -7,7 +7,7 @@ return array( 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', 'hostname' => 'localhost', 'username' => 'postgres', - 'password' => '', + 'password' => 'postgres', 'database' => 'ci_test', 'dbdriver' => 'pdo', 'subdriver' => 'pgsql' @@ -27,7 +27,7 @@ return array( 'dsn' => 'pgsql:host=localhost;port=5432;dbname=ci_test;', 'hostname' => 'localhost', 'username' => 'postgres', - 'password' => '', + 'password' => 'postgres', 'database' => 'ci_test', 'dbdriver' => 'pdo', 'subdriver' => 'pgsql' diff --git a/tests/mocks/database/config/pgsql.php b/tests/mocks/database/config/pgsql.php index 1444b0066..ce4583728 100644 --- a/tests/mocks/database/config/pgsql.php +++ b/tests/mocks/database/config/pgsql.php @@ -7,7 +7,7 @@ return array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'postgres', - 'password' => '', + 'password' => 'postgres', 'database' => 'ci_test', 'dbdriver' => 'postgre' ), @@ -25,7 +25,7 @@ return array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'postgres', - 'password' => '', + 'password' => 'postgres', 'database' => 'ci_test', 'dbdriver' => 'postgre', ) diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index 888236ff3..e2b6e7d0e 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -76,7 +76,7 @@ class Mock_Database_Schema_Skeleton { ) )); self::$forge->add_key('id', TRUE); - self::$forge->create_table('user', TRUE); + self::$forge->create_table('user', TRUE) OR show_error('Unable to create the `user` table'); // Job Table self::$forge->add_field(array( @@ -93,7 +93,7 @@ class Mock_Database_Schema_Skeleton { ) )); self::$forge->add_key('id', TRUE); - self::$forge->create_table('job', TRUE); + self::$forge->create_table('job', TRUE) OR show_error('Unable to create the `job` table'); // Misc Table self::$forge->add_field(array( @@ -110,7 +110,7 @@ class Mock_Database_Schema_Skeleton { ) )); self::$forge->add_key('id', TRUE); - self::$forge->create_table('misc', TRUE); + self::$forge->create_table('misc', TRUE) OR show_error('Unable to create the `misc` table'); } /** @@ -143,11 +143,11 @@ class Mock_Database_Schema_Skeleton { foreach ($data as $table => $dummy_data) { - self::$db->truncate($table); + self::$db->truncate($table) OR show_error("Unable to truncate `{$table}` table"); foreach ($dummy_data as $single_dummy_data) { - self::$db->insert($table, $single_dummy_data); + self::$db->insert($table, $single_dummy_data) OR show_error("Unable to insert data into `{$table}` table"); } } } diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index 06d4a011b..15063fd5a 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> diff --git a/tests/travis/mysqli.phpunit.xml b/tests/travis/mysqli.phpunit.xml index 1364f8bfa..c77aaa303 100644 --- a/tests/travis/mysqli.phpunit.xml +++ b/tests/travis/mysqli.phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index 7121edc45..1a9030ddf 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index df3ff986e..22261ee7d 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index 7d867f6d1..4b0ca2fe7 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index bfddbf6b5..8d7979a0f 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -8,7 +8,8 @@ stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" - stopOnSkipped="false"> + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false"> diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 75c946aee..4eaafc19f 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -1,6 +1,5 @@ - - - - - - - - ../codeigniter - - - - - ../../system - - - \ No newline at end of file + stopOnSkipped="false" + beStrictAboutTestsThatDoNotTestAnything="false" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" +> + + + ../../system + + + + + + + + ../codeigniter + + + -- cgit v1.2.3-24-g4f1b From 52e2fe01d2819110162b154b2785df88149f3a3b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Dec 2021 16:21:22 +0200 Subject: finfo_open() returns an finfo object instead of resource in PHP 8.1 --- system/libraries/Upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index ae60f35af..e754205de 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -1227,7 +1227,7 @@ class CI_Upload { if (function_exists('finfo_file')) { $finfo = @finfo_open(FILEINFO_MIME); - if (is_resource($finfo)) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system + if ($finfo !== FALSE) // It is possible that a FALSE value is returned, if there is no magic MIME database file found on the system { $mime = @finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); -- cgit v1.2.3-24-g4f1b From bf867137771c18f263bfab54cce258c27b91d2e8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Dec 2021 16:25:35 +0200 Subject: ftp_connect() returns an FTP\Connection object instead of resource in PHP 8.1 --- system/libraries/Ftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 61fa80c0f..92644153a 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -202,7 +202,7 @@ class CI_FTP { */ protected function _is_conn() { - if ( ! is_resource($this->conn_id)) + if ($this->conn_id !== FALSE) { if ($this->debug === TRUE) { -- cgit v1.2.3-24-g4f1b From a003ba25a58b5ddeae04225195b0aab1a5c29062 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Dec 2021 16:30:33 +0200 Subject: PHP 8.1 update to postgre database driver --- system/database/drivers/postgre/postgre_driver.php | 4 ++-- system/database/drivers/postgre/postgre_result.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 84717d8b5..eb11a556a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -135,7 +135,7 @@ class CI_DB_postgre_driver extends CI_DB { * Database connection * * @param bool $persistent - * @return resource + * @return resource|object */ public function db_connect($persistent = FALSE) { @@ -226,7 +226,7 @@ class CI_DB_postgre_driver extends CI_DB { * Execute the query * * @param string $sql an SQL query - * @return resource + * @return resource|object */ protected function _execute($sql) { diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index a0a628f0a..d977a60e3 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -126,7 +126,7 @@ class CI_DB_postgre_result extends CI_DB_result { */ public function free_result() { - if (is_resource($this->result_id)) + if ($this->result_id !== FALSE) { pg_free_result($this->result_id); $this->result_id = FALSE; -- cgit v1.2.3-24-g4f1b From 4612cb74d037b705f3d987431354e87bb2551749 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Dec 2021 16:40:18 +0200 Subject: PHP 8.1 update to mysqli database driver --- system/database/drivers/mysqli/mysqli_driver.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index c16897632..3dea1dbc5 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -116,6 +116,13 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_connect($persistent = FALSE) { + // PHP 8.1 changes default error handling mode from silent to exceptions - reverse that + if (is_php('8.1')) + { + $mysqli_driver = new mysqli_driver(); + $mysqli_driver->report_mode = MYSQLI_REPORT_OFF; + } + // Do we have a socket path? if ($this->hostname[0] === '/') { -- cgit v1.2.3-24-g4f1b From 50df2e78ec0e2b9e66f5aab8aa5f6f4de0cc0d3b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Dec 2021 16:54:24 +0200 Subject: Remove usage of deprecated strftime(), gmstrftime() --- system/libraries/Xmlrpc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 32b236b43..d500bcf87 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1914,7 +1914,7 @@ class XML_RPC_Values extends CI_Xmlrpc */ public function iso8601_encode($time, $utc = FALSE) { - return ($utc) ? strftime('%Y%m%dT%H:%i:%s', $time) : gmstrftime('%Y%m%dT%H:%i:%s', $time); + return ($utc) ? date('Ymd\TH:i:s', $time) : gmdate('Ymd\TH:i:s', $time); } } // END XML_RPC_Values Class -- cgit v1.2.3-24-g4f1b From 9b7541e04c4976f3cd0366b1866a4c71f3e3bb5f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 12:54:45 +0200 Subject: PHP 8.1 compatibility for sessions (ref #6078) --- .../Session/CI_Session_driver_interface.php | 58 ++++++++++++++ system/libraries/Session/OldSessionWrapper.php | 88 +++++++++++++++++++++ system/libraries/Session/PHP8SessionWrapper.php | 90 ++++++++++++++++++++++ system/libraries/Session/Session.php | 42 +++++----- .../libraries/Session/SessionHandlerInterface.php | 3 +- system/libraries/Session/Session_driver.php | 5 +- .../Session/drivers/Session_database_driver.php | 5 +- .../Session/drivers/Session_files_driver.php | 5 +- .../Session/drivers/Session_memcached_driver.php | 5 +- .../Session/drivers/Session_redis_driver.php | 5 +- user_guide_src/source/changelog.rst | 1 + 11 files changed, 274 insertions(+), 33 deletions(-) create mode 100644 system/libraries/Session/CI_Session_driver_interface.php create mode 100644 system/libraries/Session/OldSessionWrapper.php create mode 100644 system/libraries/Session/PHP8SessionWrapper.php diff --git a/system/libraries/Session/CI_Session_driver_interface.php b/system/libraries/Session/CI_Session_driver_interface.php new file mode 100644 index 000000000..a854e92af --- /dev/null +++ b/system/libraries/Session/CI_Session_driver_interface.php @@ -0,0 +1,58 @@ +driver = $driver; + } + + public function open($save_path, $name) + { + return $this->driver->open($save_path, $name); + } + + public function close() + { + return $this->driver->close(); + } + + public function read($id) + { + return $this->driver->read($id); + } + + public function write($id, $data) + { + return $this->driver->write($id, $data); + } + + public function destroy($id) + { + return $this->driver->destroy($id); + } + + public function gc($maxlifetime) + { + return $this->driver->gc($maxlifetime); + } +} diff --git a/system/libraries/Session/PHP8SessionWrapper.php b/system/libraries/Session/PHP8SessionWrapper.php new file mode 100644 index 000000000..c6dfaf7e0 --- /dev/null +++ b/system/libraries/Session/PHP8SessionWrapper.php @@ -0,0 +1,90 @@ +driver = $driver; + } + + public function open(string $save_path, string $name): bool + { + return $this->driver->open($save_path, $name); + } + + public function close(): bool + { + return $this->driver->close(); + } + + #[\ReturnTypeWillChange] + public function read(string $id): mixed + { + return $this->driver->read($id); + } + + public function write(string $id, string $data): bool + { + return $this->driver->write($id, $data); + } + + public function destroy(string $id): bool + { + return $this->driver->destroy($id); + } + + #[\ReturnTypeWillChange] + public function gc(int $maxlifetime): mixed + { + return $this->driver->gc($maxlifetime); + } +} diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index ec57ee548..ed379146d 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 2.0.0 @@ -102,31 +103,24 @@ class CI_Session { $this->_configure($params); $this->_config['_sid_regexp'] = $this->_sid_regexp; - $class = new $class($this->_config); - if ($class instanceof SessionHandlerInterface) + $class = new $class($this->_config); + $wrapper = new CI_SessionWrapper($class); + if (is_php('5.4')) { - if (is_php('5.4')) - { - session_set_save_handler($class, TRUE); - } - else - { - session_set_save_handler( - array($class, 'open'), - array($class, 'close'), - array($class, 'read'), - array($class, 'write'), - array($class, 'destroy'), - array($class, 'gc') - ); - - register_shutdown_function('session_write_close'); - } + session_set_save_handler($class, TRUE); } else { - log_message('error', "Session: Driver '".$this->_driver."' doesn't implement SessionHandlerInterface. Aborting."); - return; + session_set_save_handler( + array($class, 'open'), + array($class, 'close'), + array($class, 'read'), + array($class, 'write'), + array($class, 'destroy'), + array($class, 'gc') + ); + + register_shutdown_function('session_write_close'); } // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers @@ -193,6 +187,10 @@ class CI_Session { // PHP 5.4 compatibility interface_exists('SessionHandlerInterface', FALSE) OR require_once(BASEPATH.'libraries/Session/SessionHandlerInterface.php'); + require_once(BASEPATH.'libraries/Session/CI_Session_driver_interface.php'); + $wrapper = is_php('8.0') ? 'PHP8SessionWrapper' : 'OldSessionWrapper'; + require_once(BASEPATH.'libraries/Session/'.$wrapper.'.php'); + $prefix = config_item('subclass_prefix'); if ( ! class_exists('CI_Session_driver', FALSE)) diff --git a/system/libraries/Session/SessionHandlerInterface.php b/system/libraries/Session/SessionHandlerInterface.php index 95d2488b4..914eae03f 100644 --- a/system/libraries/Session/SessionHandlerInterface.php +++ b/system/libraries/Session/SessionHandlerInterface.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (http://codeigniter.com/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 diff --git a/system/libraries/Session/Session_driver.php b/system/libraries/Session/Session_driver.php index 734b6e052..d78492b5e 100644 --- a/system/libraries/Session/Session_driver.php +++ b/system/libraries/Session/Session_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 @@ -46,7 +47,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @author Andrey Andreev * @link https://codeigniter.com/userguide3/libraries/sessions.html */ -abstract class CI_Session_driver implements SessionHandlerInterface { +abstract class CI_Session_driver { protected $_config; diff --git a/system/libraries/Session/drivers/Session_database_driver.php b/system/libraries/Session/drivers/Session_database_driver.php index a3055af5e..2f788a1a1 100644 --- a/system/libraries/Session/drivers/Session_database_driver.php +++ b/system/libraries/Session/drivers/Session_database_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 @@ -46,7 +47,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @author Andrey Andreev * @link https://codeigniter.com/userguide3/libraries/sessions.html */ -class CI_Session_database_driver extends CI_Session_driver implements SessionHandlerInterface { +class CI_Session_database_driver extends CI_Session_driver implements CI_Session_driver_interface { /** * DB object diff --git a/system/libraries/Session/drivers/Session_files_driver.php b/system/libraries/Session/drivers/Session_files_driver.php index 49bf5b781..5ed556759 100644 --- a/system/libraries/Session/drivers/Session_files_driver.php +++ b/system/libraries/Session/drivers/Session_files_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 @@ -46,7 +47,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @author Andrey Andreev * @link https://codeigniter.com/userguide3/libraries/sessions.html */ -class CI_Session_files_driver extends CI_Session_driver implements SessionHandlerInterface { +class CI_Session_files_driver extends CI_Session_driver implements CI_Session_driver_interface { /** * Save path diff --git a/system/libraries/Session/drivers/Session_memcached_driver.php b/system/libraries/Session/drivers/Session_memcached_driver.php index b4d3eb464..d84a9df1d 100644 --- a/system/libraries/Session/drivers/Session_memcached_driver.php +++ b/system/libraries/Session/drivers/Session_memcached_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 @@ -46,7 +47,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @author Andrey Andreev * @link https://codeigniter.com/userguide3/libraries/sessions.html */ -class CI_Session_memcached_driver extends CI_Session_driver implements SessionHandlerInterface { +class CI_Session_memcached_driver extends CI_Session_driver implements CI_Session_driver_interface { /** * Memcached instance diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php index d65c6ee14..b112a18c8 100644 --- a/system/libraries/Session/drivers/Session_redis_driver.php +++ b/system/libraries/Session/drivers/Session_redis_driver.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2019, British Columbia Institute of Technology + * Copyright (c) 2019 - 2022, CodeIgniter Foundation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -30,6 +30,7 @@ * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2019 - 2022, CodeIgniter Foundation (https://codeigniter.com/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 3.0.0 @@ -46,7 +47,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @author Andrey Andreev * @link https://codeigniter.com/userguide3/libraries/sessions.html */ -class CI_Session_redis_driver extends CI_Session_driver implements SessionHandlerInterface { +class CI_Session_redis_driver extends CI_Session_driver implements CI_Session_driver_interface { /** * phpRedis instance diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 812016050..d00a482a5 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -16,6 +16,7 @@ Release Date: Not Released - Added method :doc:`Database Library ` method ``trans_active()`` to expose transaction state. - Updated :doc:`Database Library ` 'pdo' driver to attempt to free resources in order to allow connections to be closed. - Added ``SameSite=Strict`` attribute to the CSRF cookie sent by the :doc:`Security Class `. + - Added a wrapper class around :doc:`Session ` drivers to deal with compatibility between PHP 8.1 and older versions. Bug fixes for 3.1.12 ==================== -- cgit v1.2.3-24-g4f1b From 9c5227c56f9c29729659951b2ac3df9e8a87d5b5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 13:41:49 +0200 Subject: [ci skip] Changelog maintenance --- user_guide_src/source/changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index d00a482a5..1fbb0116e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -17,6 +17,7 @@ Release Date: Not Released - Updated :doc:`Database Library ` 'pdo' driver to attempt to free resources in order to allow connections to be closed. - Added ``SameSite=Strict`` attribute to the CSRF cookie sent by the :doc:`Security Class `. - Added a wrapper class around :doc:`Session ` drivers to deal with compatibility between PHP 8.1 and older versions. + - Updated a lot of code for PHP 8.0 and 8.1 compatibility. Bug fixes for 3.1.12 ==================== @@ -30,7 +31,7 @@ Bug fixes for 3.1.12 - Fixed a bug (#5906) - :doc:`Database Library ` 'postgre' driver couldn't use the failover feature without a ``$config['dsn']``. - Fixed a bug (#5903) - :doc:`common function ` :php:func:`set_status_header()` didn't recognize 'HTTP/2.0' as a valid ``$_SERVER['SERVER_PROTOCOL']``. - Fixed a bug (#6013) - :doc:`Session ` flashdata didn't work on PHP 8. -- Fixed a bug (#6006) - ``is_callable()`` change in PHP 8 broke :doc:`Migrations `, a part of :doc:`XML-RPC ` and an edge case in 404 detection logic. +- Fixed a bug (#6006) - ``is_callable()`` change in PHP 8 broke :doc:`Migrations `, a part of :doc:`XML-RPC ` and an edge case in 404 detection logic. Version 3.1.11 ============== -- cgit v1.2.3-24-g4f1b From 318c485b7b83356543c9aa7ab65464893d7eb8fe Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 13:57:33 +0200 Subject: Close #6021: Suppress possible E_DEPRECATION notices about mbstring.func_overload --- system/core/Log.php | 2 +- system/core/Output.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Encryption.php | 2 +- system/libraries/Session/drivers/Session_files_driver.php | 2 +- system/libraries/Zip.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/system/core/Log.php b/system/core/Log.php index f66f1aa48..683c16bac 100644 --- a/system/core/Log.php +++ b/system/core/Log.php @@ -122,7 +122,7 @@ class CI_Log { { $config =& get_config(); - isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload')); $this->_log_path = ($config['log_path'] !== '') ? $config['log_path'] : APPPATH.'logs/'; $this->_file_ext = (isset($config['log_file_extension']) && $config['log_file_extension'] !== '') diff --git a/system/core/Output.php b/system/core/Output.php index 93d85e798..8e3245b79 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -145,7 +145,7 @@ class CI_Output { && extension_loaded('zlib') ); - isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload')); // Get mime types for later $this->mimes =& get_mimes(); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index dcc4ca0d3..6c453da3f 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -397,7 +397,7 @@ class CI_Email { $this->initialize($config); $this->_safe_mode = ( ! is_php('5.4') && ini_get('safe_mode')); - isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload')); log_message('info', 'Email Class Initialized'); } diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index cb8ad9de9..db6b30d46 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -161,7 +161,7 @@ class CI_Encryption { show_error('Encryption: Unable to find an available encryption driver.'); } - isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload')); $this->initialize($params); if ( ! isset($this->_key) && self::strlen($key = config_item('encryption_key')) > 0) diff --git a/system/libraries/Session/drivers/Session_files_driver.php b/system/libraries/Session/drivers/Session_files_driver.php index 5ed556759..4b7b9878b 100644 --- a/system/libraries/Session/drivers/Session_files_driver.php +++ b/system/libraries/Session/drivers/Session_files_driver.php @@ -116,7 +116,7 @@ class CI_Session_files_driver extends CI_Session_driver implements CI_Session_dr $this->_sid_regexp = $this->_config['_sid_regexp']; - isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload')); } // ------------------------------------------------------------------------ diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index e99873ae7..44586697a 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -119,7 +119,7 @@ class CI_Zip { */ public function __construct() { - isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload')); + isset(self::$func_overload) OR self::$func_overload = ( ! is_php('8.0') && extension_loaded('mbstring') && @ini_get('mbstring.func_overload')); $this->now = time(); log_message('info', 'Zip Compression Class Initialized'); -- cgit v1.2.3-24-g4f1b From 39da78b2588a60a2f43fb8f77448ab9604550978 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 16:25:49 +0200 Subject: Fix some minor PHP 8.1 deprecation warnings --- system/core/Common.php | 5 ++--- system/core/Input.php | 2 +- system/core/Security.php | 2 +- system/libraries/Encryption.php | 10 +++++----- system/libraries/Form_validation.php | 2 +- system/libraries/User_agent.php | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 9e23a4ea5..a9b8828e3 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -778,11 +778,9 @@ if ( ! function_exists('_stringify_attributes')) */ function _stringify_attributes($attributes, $js = FALSE) { - $atts = NULL; - if (empty($attributes)) { - return $atts; + return NULL; } if (is_string($attributes)) @@ -792,6 +790,7 @@ if ( ! function_exists('_stringify_attributes')) $attributes = (array) $attributes; + $atts = ''; foreach ($attributes as $key => $val) { $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"'; diff --git a/system/core/Input.php b/system/core/Input.php index 3fb4121eb..c3a0a9094 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -565,7 +565,7 @@ class CI_Input { $which = FILTER_FLAG_IPV6; break; default: - $which = NULL; + $which = 0; break; } diff --git a/system/core/Security.php b/system/core/Security.php index f6b0407f8..d1d4f8432 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -193,7 +193,7 @@ class CI_Security { $this->_csrf_set_hash(); } - $this->charset = strtoupper(config_item('charset')); + $this->charset = strtoupper((string) config_item('charset')); log_message('info', 'Security Class Initialized'); } diff --git a/system/libraries/Encryption.php b/system/libraries/Encryption.php index db6b30d46..933f6f232 100644 --- a/system/libraries/Encryption.php +++ b/system/libraries/Encryption.php @@ -476,7 +476,7 @@ class CI_Encryption { $iv = ($iv_size = openssl_cipher_iv_length($params['handle'])) ? $this->create_key($iv_size) - : NULL; + : ''; $data = openssl_encrypt( $data, @@ -585,7 +585,7 @@ class CI_Encryption { } else { - $iv = NULL; + $iv = ''; } if (mcrypt_generic_init($params['handle'], $params['key'], $iv) < 0) @@ -632,7 +632,7 @@ class CI_Encryption { } else { - $iv = NULL; + $iv = ''; } return empty($params['handle']) @@ -910,8 +910,8 @@ class CI_Encryption { protected static function strlen($str) { return (self::$func_overload) - ? mb_strlen($str, '8bit') - : strlen($str); + ? mb_strlen((string) $str, '8bit') + : strlen((string) $str); } // -------------------------------------------------------------------- diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 9d976984e..1b7bbb96c 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1056,7 +1056,7 @@ class CI_Form_validation { { return is_array($str) ? (empty($str) === FALSE) - : (trim($str) !== ''); + : (trim((string) $str) !== ''); } // -------------------------------------------------------------------- diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index a42975b35..c144db7a8 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -498,7 +498,7 @@ class CI_User_agent { else { $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); - $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); + $own_host = parse_url((string) config_item('base_url'), PHP_URL_HOST); $this->referer = ($referer_host && $referer_host !== $own_host); } -- cgit v1.2.3-24-g4f1b From 1d0315b6b3d7003bfb348ccaf7ee30d2533635de Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 17:16:53 +0200 Subject: Bye Travis, Hello GH Actions --- .github/workflows/test-phpunit.yml | 119 +++++++++++++++++++++ .travis.yml | 133 ------------------------ composer.json | 6 ++ tests/codeigniter/core/Security_test.php | 5 +- tests/codeigniter/core/Utf8_test.php | 2 +- tests/codeigniter/core/compat/mbstring_test.php | 10 +- tests/codeigniter/helpers/text_helper_test.php | 7 +- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes 8 files changed, 141 insertions(+), 141 deletions(-) create mode 100644 .github/workflows/test-phpunit.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test-phpunit.yml b/.github/workflows/test-phpunit.yml new file mode 100644 index 000000000..3468dfdfb --- /dev/null +++ b/.github/workflows/test-phpunit.yml @@ -0,0 +1,119 @@ +name: PHPUnit + +on: [push, pull_request] + +jobs: + tests: + runs-on: ubuntu-18.04 + if: "!contains(github.event.head_commit.message, '[ci skip]')" + env: + PHP_INI_VALUES: assert.exception=1, zend.assertions=1 + + strategy: + fail-fast: false + matrix: + php: [ '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0', '5.6', '5.5', '5.4' ] + DB: [ 'pdo/mysql', 'pdo/pgsql', 'pdo/sqlite', 'mysqli', 'pgsql', 'sqlite' ] + compiler: [ default ] + include: + - php: '8.1' + DB: 'pdo/mysql' + compiler: jit + - php: '8.1' + DB: 'pdo/pgsql' + compiler: jit + - php: '8.1' + DB: 'pdo/sqlite' + compiler: jit + - php: '8.1' + DB: 'mysqli' + compiler: jit + - php: '8.1' + DB: 'pgsql' + compiler: jit + - php: '8.1' + DB: 'sqlite' + compiler: jit + - php: '8.0' + DB: 'pdo/mysql' + compiler: jit + - php: '8.0' + DB: 'pdo/pgsql' + compiler: jit + - php: '8.0' + DB: 'pdo/sqlite' + compiler: jit + - php: '8.0' + DB: 'mysqli' + compiler: jit + - php: '8.0' + DB: 'pgsql' + compiler: jit + - php: '8.0' + DB: 'sqlite' + compiler: jit + - php: '5.6' + DB: 'mysql' + compiler: default + - php: '5.5' + DB: 'mysql' + compiler: default + - php: '5.4' + DB: 'mysql' + compiler: default + + services: + postgres: + image: postgres:12 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: ci_test + ports: + - 5432:5432 + options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3 + + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_USER: travis + MYSQL_PASSWORD: travis + MYSQL_DATABASE: ci_test + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Override PHP ini values for JIT compiler + if: matrix.compiler == 'jit' + run: echo "PHP_INI_VALUES::assert.exception=1, zend.assertions=1, opcache.enable=1, opcache.enable_cli=1, opcache.optimization_level=-1, opcache.jit=1255, opcache.jit_buffer_size=64M" >> $GITHUB_ENV + + - name: Install PHP${{ matrix.php }} - DB ${{ matrix.DB }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer, pecl + extensions: imagick, sqlite3, pgsql, mysqli, pdo, pdo_mysql, pdo_pgsql, pdo_sqlite, mbstring + ini-values: ${{ env.PHP_INI_VALUES }} + coverage: xdebug + + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache composer dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: PHPUnit Test + run: | + php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.func_overload=7 -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/${{ matrix.DB }}.phpunit.xml + env: + XDEBUG_MODE: coverage diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ee717ab9a..000000000 --- a/.travis.yml +++ /dev/null @@ -1,133 +0,0 @@ -language: php -os: linux -dist: xenial - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - nightly - -env: - global: - - XDEBUG_MODE=coverage - jobs: - - DB=mysqli - - DB=pgsql - - DB=sqlite - - DB=pdo/mysql - - DB=pdo/pgsql - - DB=pdo/sqlite - -services: - - mysql - - postgresql - -cache: - directories: - - $HOME/.composer/cache - -before_script: - - sh -c "composer install --no-progress" - - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS ci_test;' -U postgres; fi" - - sh -c "if [ '$DB' = 'pgsql' ] || [ '$DB' = 'pdo/pgsql' ]; then psql -c 'create database ci_test;' -U postgres; fi" - - sh -c "if [ '$DB' = 'mysql' ] || [ '$DB' = 'mysqli' ] || [ '$DB' = 'pdo/mysql' ]; then mysql -e 'create database IF NOT EXISTS ci_test;'; fi" - -script: test $(php -r 'echo PHP_VERSION_ID;') -lt 70300 && php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.func_overload=7 -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml || php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/$DB.phpunit.xml - -jobs: - allow_failures: - - php: nightly - - php: hhvm-3.30 - include: - - php: 5.3 - dist: precise - env: DB=mysql - - php: 5.3 - dist: precise - env: DB=mysqli - - php: 5.3 - dist: precise - env: DB=pgsql - - php: 5.3 - dist: precise - env: DB=sqlite - - php: 5.3 - dist: precise - env: DB=pdo/mysql - - php: 5.3 - dist: precise - env: DB=pdo/pgsql - - php: 5.3 - dist: precise - env: DB=pdo/sqlite - - php: 5.4 - dist: trusty - env: DB=mysql - - php: 5.4 - dist: trusty - env: DB=mysqli - - php: 5.4 - dist: trusty - env: DB=pgsql - - php: 5.4 - dist: trusty - env: DB=sqlite - - php: 5.4 - dist: trusty - env: DB=pdo/mysql - - php: 5.4 - dist: trusty - env: DB=pdo/pgsql - - php: 5.4 - dist: trusty - env: DB=pdo/sqlite - - php: 5.5 - dist: trusty - env: DB=mysql - - php: 5.5 - dist: trusty - env: DB=mysqli - - php: 5.5 - dist: trusty - env: DB=pgsql - - php: 5.5 - dist: trusty - env: DB=sqlite - - php: 5.5 - dist: trusty - env: DB=pdo/mysql - - php: 5.5 - dist: trusty - env: DB=pdo/pgsql - - php: 5.5 - dist: trusty - env: DB=pdo/sqlite - - php: 5.6 - dist: xenial - env: DB=mysql - - php: hhvm-3.30 - dist: trusty - env: DB=mysql - - php: hhvm-3.30 - dist: trusty - env: DB=mysqli - - php: hhvm-3.30 - dist: trusty - env: DB=sqlite - - php: hhvm-3.30 - dist: trusty - env: DB=pdo/mysql - - php: hhvm-3.30 - dist: trusty - env: DB=pdo/sqlite - -branches: - only: - - develop - - 3.0-stable - - 3.1-stable - - /^feature\/.+$/ diff --git a/composer.json b/composer.json index cf9ac486c..01e65f40f 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,12 @@ "test:coverage": [ "@putenv XDEBUG_MODE=coverage", "phpunit --color=always --coverage-text --configuration tests/travis/sqlite.phpunit.xml" + ], + "post-install-cmd": [ + "sed -i s/name{0}/name[0]/ vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php" + ], + "post-update-cmd": [ + "sed -i s/name{0}/name[0]/ vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStream.php" ] }, "require-dev": { diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 5f94e1501..c650315ce 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -252,7 +252,10 @@ class Security_test extends CI_TestCase { // Perform hash $this->security->xss_hash(); - $this->assertMatchesRegularExpression('#^[0-9a-f]{32}$#iS', $this->security->xss_hash); + $assertRegExp = class_exists('PHPUnit_Runner_Version') + ? 'assertRegExp' + : 'assertMatchesRegularExpression'; + $this->$assertRegExp('#^[0-9a-f]{32}$#iS', $this->security->xss_hash); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index a0327dbd7..c02c1dd87 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -61,7 +61,7 @@ class Utf8_test extends CI_TestCase { elseif (ICONV_ENABLED) { // This is a known issue, iconv doesn't always work with //IGNORE - $this->assertContains($utf8->clean_string($illegal_utf8), array('тест', '')); + $this->assertContains($this->utf8->clean_string($illegal_utf8), array('тест', '')); } else { diff --git a/tests/codeigniter/core/compat/mbstring_test.php b/tests/codeigniter/core/compat/mbstring_test.php index 8b8629efc..39f48ac10 100644 --- a/tests/codeigniter/core/compat/mbstring_test.php +++ b/tests/codeigniter/core/compat/mbstring_test.php @@ -31,9 +31,9 @@ class mbstring_test extends CI_TestCase { */ public function test_mb_strpos() { - $this->assertEquals(ICONV_ENABLED ? 3 : 6, mb_strpos('тест', 'с')); + $this->assertEquals(ICONV_ENABLED ? 2 : 4, mb_strpos('тест', 'с')); $this->assertFalse(mb_strpos('тест', 'с', 3)); - $this->assertEquals(ICONV_ENABLED ? 3 : 6, mb_strpos('тест', 'с', 1, 'UTF-8')); + $this->assertEquals(ICONV_ENABLED ? 2 : 4, mb_strpos('тест', 'с', 1, 'UTF-8')); } // ------------------------------------------------------------------------ @@ -46,9 +46,9 @@ class mbstring_test extends CI_TestCase { $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2)); $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2)); $this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2)); - $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2, 'UTF-8')); - $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2, 'UTF-8')); + $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2, NULL, 'UTF-8')); + $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2, NULL, 'UTF-8')); $this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2, 'UTF-8')); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 7a7dc0a12..5be1837b8 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -64,6 +64,11 @@ class Text_helper_test extends CI_TestCase { public function test_convert_accented_characters() { + if (substr(PHP_VERSION, 0, 3) === '7.4') + { + return $this->markTestSkipped('For some reason all PHP 7.4 instances on GitHub Actions trigger a parse error when foreign_chars.php is loaded'); + } + $this->ci_vfs_clone('application/config/foreign_chars.php'); $this->assertEquals('AAAeEEEIIOOEUUUeY', convert_accented_characters('ÀÂÄÈÊËÎÏÔŒÙÛÜŸ')); $this->assertEquals('a e i o u n ue', convert_accented_characters('á é í ó ú ñ ü')); @@ -171,4 +176,4 @@ class Text_helper_test extends CI_TestCase { $this->assertEquals(strpos(word_wrap($string), "\n"), 73); } -} \ No newline at end of file +} diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 574d3ae53..cc76bd681 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From 22f4f5079b9fdf9090add2ac728fafd91a24ed2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 17:37:56 +0200 Subject: [ci skip] Update test cmd in build script --- build-release.sh | 3 +-- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build-release.sh b/build-release.sh index 6b3b31d12..30967fc2e 100755 --- a/build-release.sh +++ b/build-release.sh @@ -47,7 +47,7 @@ fi echo "Running tests ..." -cd tests/ +php -d zend.enable_gc=0 -d date.timezone=UTC -d mbstring.func_overload=7 -d mbstring.internal_encoding=UTF-8 vendor/bin/phpunit --coverage-text --configuration tests/travis/sqlite.phpunit.xml phpunit if [ $? -ne 0 ] @@ -56,7 +56,6 @@ then exit 1 fi -cd .. cd user_guide_src/ echo "" diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index cc76bd681..a46b4c016 100755 Binary files a/tests/mocks/database/ci_test.sqlite and b/tests/mocks/database/ci_test.sqlite differ -- cgit v1.2.3-24-g4f1b From 4362b7d9f39189472950589ce47a483b6025f5e9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 17:52:40 +0200 Subject: Merge pull request #6025 from gxgpet/develop SameSite attribute implementation for CI_Input::set_cookie --- application/config/config.php | 2 ++ system/core/Input.php | 42 ++++++++++++++++++++++++++++--- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/libraries/input.rst | 21 +++++++++------- 4 files changed, 54 insertions(+), 12 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 9ab8248e3..161b95699 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -397,6 +397,7 @@ $config['sess_regenerate_destroy'] = FALSE; | 'cookie_path' = Typically will be a forward slash | 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists. | 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript) +| 'cookie_samesite' = Cookie's samesite attribute (Lax, Strict or None) | | Note: These settings (with the exception of 'cookie_prefix' and | 'cookie_httponly') will also affect sessions. @@ -407,6 +408,7 @@ $config['cookie_domain'] = ''; $config['cookie_path'] = '/'; $config['cookie_secure'] = FALSE; $config['cookie_httponly'] = FALSE; +$config['cookie_samesite'] = 'Lax'; /* |-------------------------------------------------------------------------- diff --git a/system/core/Input.php b/system/core/Input.php index c3a0a9094..7205a7aa2 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -357,14 +357,15 @@ class CI_Input { * @param string $prefix Cookie name prefix * @param bool $secure Whether to only transfer cookies via SSL * @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript) + * @param string $samesite SameSite attribute * @return void */ - public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL) + public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL, $samesite = NULL) { if (is_array($name)) { // always leave 'name' in last place, as the loop will break otherwise, due to $$item - foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item) + foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name', 'samesite') as $item) { if (isset($name[$item])) { @@ -405,7 +406,42 @@ class CI_Input { $expire = ($expire > 0) ? time() + $expire : 0; } - setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly); + isset($samesite) OR $samesite = config_item('cookie_samesite'); + if (isset($samesite)) + { + $samesite = ucfirst(strtolower($samesite)); + in_array($samesite, array('Lax', 'Strict', 'None'), TRUE) OR $samesite = 'Lax'; + } + else + { + $samesite = 'Lax'; + } + + if ($samesite === 'None' && ! $secure) + { + log_message('error', $name.' cookie sent with SameSite=None, but without Secure attribute.'); + } + + if (is_php('7.3')) + { + $setcookie_options = array( + 'expires' => $expire, + 'path' => $path, + 'domain' => $domain, + 'secure' => $secure, + 'httponly' => $httponly, + 'samesite' => $samesite, + ); + setcookie($prefix.$name, $value, $setcookie_options); + } + else + { + $cookie_header = 'Set-Cookie: '.$prefix.$name.'='.rawurlencode($value); + $cookie_header .= ($expire === 0 ? '' : '; expires='.gmdate('D, d-M-Y H:i:s T', $expire)); + $cookie_header .= '; path='.$path.($domain !== '' ? '; domain='.$domain : ''); + $cookie_header .= ($secure ? '; secure' : '').($httponly ? '; HttpOnly' : '').'; SameSite='.$samesite; + header($cookie_header); + } } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 1fbb0116e..0c61136c3 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -16,6 +16,7 @@ Release Date: Not Released - Added method :doc:`Database Library ` method ``trans_active()`` to expose transaction state. - Updated :doc:`Database Library ` 'pdo' driver to attempt to free resources in order to allow connections to be closed. - Added ``SameSite=Strict`` attribute to the CSRF cookie sent by the :doc:`Security Class `. + - Added ``$config['cookie_samesite']`` option and ``$samesite`` parameter to :doc:`Input Library ` method ``set_cookie()``. - Added a wrapper class around :doc:`Session ` drivers to deal with compatibility between PHP 8.1 and older versions. - Updated a lot of code for PHP 8.0 and 8.1 compatibility. diff --git a/user_guide_src/source/libraries/input.rst b/user_guide_src/source/libraries/input.rst index 300f47112..3dc734c12 100644 --- a/user_guide_src/source/libraries/input.rst +++ b/user_guide_src/source/libraries/input.rst @@ -285,7 +285,7 @@ Class Reference This method is identical to ``get()``, ``post()`` and ``cookie()``, only it fetches the *php://input* stream data. - .. php:method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]]) + .. php:method:: set_cookie($name = ''[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL[, $samesite = NULL]]]]]]]]) :param mixed $name: Cookie name or an array of parameters :param string $value: Cookie value @@ -295,6 +295,7 @@ Class Reference :param string $prefix: Cookie name prefix :param bool $secure: Whether to only transfer the cookie through HTTPS :param bool $httponly: Whether to only make the cookie accessible for HTTP requests (no JavaScript) + :param string $samesite: SameSite attribute ('Lax', 'Strict', 'None') :rtype: void @@ -308,13 +309,14 @@ Class Reference parameter:: $cookie = array( - 'name' => 'The Cookie Name', - 'value' => 'The Value', - 'expire' => '86500', - 'domain' => '.some-domain.com', - 'path' => '/', - 'prefix' => 'myprefix_', - 'secure' => TRUE + 'name' => 'The Cookie Name', + 'value' => 'The Value', + 'expire' => 86500, + 'domain' => '.some-domain.com', + 'path' => '/', + 'prefix' => 'myprefix_', + 'secure' => TRUE, + 'samesite' => 'Strict' ); $this->input->set_cookie($cookie); @@ -340,13 +342,14 @@ Class Reference The *httponly* and *secure* flags, when omitted, will default to your ``$config['cookie_httponly']`` and ``$config['cookie_secure']`` settings. + The *samesite* parameter can be ``'Lax'``, ``'Strict'`` or ``'None'``. If not set, the same-site cookie attribute will default to ``'Lax'``. **Discrete Parameters** If you prefer, you can set the cookie by passing data using individual parameters:: - $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); + $this->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure, $samesite); .. php:method:: ip_address() -- cgit v1.2.3-24-g4f1b From f370f2c042905e521fa3a25283f7e275606a8724 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 18:23:06 +0200 Subject: Polish changes from PR #6025 --- system/core/Input.php | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/system/core/Input.php b/system/core/Input.php index 7205a7aa2..47bdbfc5d 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -422,26 +422,31 @@ class CI_Input { log_message('error', $name.' cookie sent with SameSite=None, but without Secure attribute.'); } - if (is_php('7.3')) - { - $setcookie_options = array( - 'expires' => $expire, - 'path' => $path, - 'domain' => $domain, - 'secure' => $secure, - 'httponly' => $httponly, - 'samesite' => $samesite, - ); - setcookie($prefix.$name, $value, $setcookie_options); - } - else + if ( ! is_php('7.3')) { + $maxage = $expire - time(); + if ($maxage < 1) + { + $maxage = 0; + } + $cookie_header = 'Set-Cookie: '.$prefix.$name.'='.rawurlencode($value); - $cookie_header .= ($expire === 0 ? '' : '; expires='.gmdate('D, d-M-Y H:i:s T', $expire)); - $cookie_header .= '; path='.$path.($domain !== '' ? '; domain='.$domain : ''); - $cookie_header .= ($secure ? '; secure' : '').($httponly ? '; HttpOnly' : '').'; SameSite='.$samesite; + $cookie_header .= ($expire === 0 ? '' : '; Expires='.gmdate('D, d-M-Y H:i:s T', $expire)).'; Max-Age='.$maxage; + $cookie_header .= '; Path='.$path.($domain !== '' ? '; Domain='.$domain : ''); + $cookie_header .= ($secure ? '; Secure' : '').($httponly ? '; HttpOnly' : '').'; SameSite='.$samesite; header($cookie_header); - } + return; + } + + $setcookie_options = array( + 'expires' => $expire, + 'path' => $path, + 'domain' => $domain, + 'secure' => $secure, + 'httponly' => $httponly, + 'samesite' => $samesite, + ); + setcookie($prefix.$name, $value, $setcookie_options); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1a2651040ef701e750b1c13cd69cc70814b079d0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 18:52:24 +0200 Subject: Add SameSite cookie support to Session library --- application/config/config.php | 5 ++ system/libraries/Session/Session.php | 83 ++++++++++++++++++++++------ system/libraries/Session/Session_driver.php | 24 ++++++-- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/libraries/sessions.rst | 2 + 5 files changed, 94 insertions(+), 21 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 161b95699..ee599c7aa 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -341,6 +341,10 @@ $config['encryption_key'] = ''; | | The session cookie name, must contain only [0-9a-z_-] characters | +| 'sess_samesite' +| +| Session cookie SameSite attribute: Lax (default), Strict or None +| | 'sess_expiration' | | The number of SECONDS you want the session to last. @@ -381,6 +385,7 @@ $config['encryption_key'] = ''; */ $config['sess_driver'] = 'files'; $config['sess_cookie_name'] = 'ci_session'; +$config['sess_samesite'] = 'Lax'; $config['sess_expiration'] = 7200; $config['sess_save_path'] = NULL; $config['sess_match_ip'] = FALSE; diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index ed379146d..1c5c980ae 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -154,15 +154,36 @@ class CI_Session { // unless it is being currently created or regenerated elseif (isset($_COOKIE[$this->_config['cookie_name']]) && $_COOKIE[$this->_config['cookie_name']] === session_id()) { - setcookie( - $this->_config['cookie_name'], - session_id(), - (empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']), - $this->_config['cookie_path'], - $this->_config['cookie_domain'], - $this->_config['cookie_secure'], - TRUE - ); + $expires = empty($this->_config['cookie_lifetime']) ? 0 : time() + $this->_config['cookie_lifetime']; + if (is_php('7.3')) + { + setcookie( + $this->_config['cookie_name'], + session_id(), + array( + 'expires' => $expires, + 'path' => $this->_config['cookie_path'], + 'domain' => $this->_config['cookie_domain'], + 'secure' => $this->_config['cookie_secure'], + 'httponly' => TRUE, + 'samesite' => $this->_config['cookie_samesite'] + ) + ); + } + else + { + $header = 'Set-Cookie: '.$this->_config['cookie_name'].'='.session_id(); + $header .= empty($expires) ? '' : '; Expires='.gmdate('D, d-M-Y H:i:s T', $expires).'; Max-Age='.$this->_config['cookie_lifetime']; + $header .= '; Path='.$this->_config['cookie_path']; + $header .= ($this->_config['cookie_domain'] !== '' ? '; Domain='.$this->_config['cookie_domain'] : ''); + $header .= ($this->_config['cookie_secure'] ? '; Secure' : '').'; HttpOnly; SameSite='.$this->_config['cookie_samesite']; + header($header); + } + + if ( ! $this->_config['cookie_secure'] && $this->_config['cookie_samesite'] === 'None') + { + log_message('error', 'Session:', $this->_config['cookie_name'].' cookie sent with SameSite=None, but without Secure attribute.'); + } } $this->_ci_init_vars(); @@ -284,13 +305,43 @@ class CI_Session { isset($params['cookie_domain']) OR $params['cookie_domain'] = config_item('cookie_domain'); isset($params['cookie_secure']) OR $params['cookie_secure'] = (bool) config_item('cookie_secure'); - session_set_cookie_params( - $params['cookie_lifetime'], - $params['cookie_path'], - $params['cookie_domain'], - $params['cookie_secure'], - TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons - ); + isset($params['cookie_samesite']) OR $params['cookie_samesite'] = config_item('sess_samesite'); + if ( ! isset($params['cookie_samesite']) && is_php('7.3')) + { + $params['cookie_samesite'] = ini_get('session.cookie_samesite'); + } + + if (isset($params['cookie_samesite'])) + { + $params['cookie_samesite'] = ucfirst(strtolower($params['cookie_samesite'])); + in_array($params['cookie_samesite'], array('Lax', 'Strict', 'None'), TRUE) OR $params['cookie_samesite'] = 'Lax'; + } + else + { + $params['cookie_samesite'] = 'Lax'; + } + + if (is_php('7.3')) + { + session_set_cookie_params(array( + 'lifetime' => $params['cookie_lifetime'], + 'path' => $params['cookie_path'], + 'domain' => $params['cookie_domain'], + 'secure' => $params['cookie_secure'], + 'httponly' => $params['cookie_httponly'], + 'samesite' => $params['cookie_samesite'] + )); + } + else + { + session_set_cookie_params( + $params['cookie_lifetime'], + $params['cookie_path'], + $params['cookie_domain'], + $params['cookie_secure'], + TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons + ); + } if (empty($expiration)) { diff --git a/system/libraries/Session/Session_driver.php b/system/libraries/Session/Session_driver.php index d78492b5e..b1b1b073e 100644 --- a/system/libraries/Session/Session_driver.php +++ b/system/libraries/Session/Session_driver.php @@ -140,14 +140,28 @@ abstract class CI_Session_driver { */ protected function _cookie_destroy() { + if ( ! is_php('7.3')) + { + $header = 'Set-Cookie: '.$this->_config['cookie_name'].'='; + $header .= '; Expires='.gmdate('D, d-M-Y H:i:s T', 1).'; Max-Age=-1'; + $header .= '; Path='.$this->_config['cookie_path']; + $header .= ($this->_config['cookie_domain'] !== '' ? '; Domain='.$this->_config['cookie_domain'] : ''); + $header .= ($this->_config['cookie_secure'] ? '; Secure' : '').'; HttpOnly; SameSite='.$this->_config['cookie_samesite']; + header($header); + return; + } + return setcookie( $this->_config['cookie_name'], NULL, - 1, - $this->_config['cookie_path'], - $this->_config['cookie_domain'], - $this->_config['cookie_secure'], - TRUE + array( + 'expires' => 1, + 'path' => $this->_config['cookie_path'], + 'domain' => $this->_config['cookie_domain'], + 'secure' => $this->_config['cookie_secure'], + 'httponly' => TRUE, + 'samesite' => $this->_config['cookie_samesite'] + ) ); } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 0c61136c3..0e347f891 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -17,6 +17,7 @@ Release Date: Not Released - Updated :doc:`Database Library ` 'pdo' driver to attempt to free resources in order to allow connections to be closed. - Added ``SameSite=Strict`` attribute to the CSRF cookie sent by the :doc:`Security Class `. - Added ``$config['cookie_samesite']`` option and ``$samesite`` parameter to :doc:`Input Library ` method ``set_cookie()``. + - Added ``SameSite`` support through ``$config['sess_samesite']`` option to the :doc:`Session Library `. - Added a wrapper class around :doc:`Session ` drivers to deal with compatibility between PHP 8.1 and older versions. - Updated a lot of code for PHP 8.0 and 8.1 compatibility. diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 994dc2e08..ced4463d0 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -438,6 +438,8 @@ Preference Default Options ============================ =============== ======================================== ============================================================================================ **sess_driver** files files/database/redis/memcached/*custom* The session storage driver to use. **sess_cookie_name** ci_session [A-Za-z\_-] characters only The name used for the session cookie. +**sess_samesite** ci_session 'Lax', 'Strict' or 'None' SameSite attribute value for session cookies. + Defaults to ``session.cookie_samesite`` on PHP 7.3+ or 'Lax' if not present at all. **sess_expiration** 7200 (2 hours) Time in seconds (integer) The number of seconds you would like the session to last. If you would like a non-expiring session (until browser is closed) set the value to zero: 0 **sess_save_path** NULL None Specifies the storage location, depends on the driver being used. -- cgit v1.2.3-24-g4f1b From 73295d264410f4d0b5ae802e77d4d6b47172f64a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 19:09:23 +0200 Subject: [ci skip] Merge pull request #5896 from ytetsuro/patch-3 fix too many connection for oracle --- system/database/drivers/oci8/oci8_driver.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index a9d75ebf2..511ef0e64 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -682,6 +682,16 @@ class CI_DB_oci8_driver extends CI_DB { */ protected function _close() { + if (is_resource($this->curs_id)) + { + oci_free_statement($this->curs_id); + } + + if (is_resource($this->stmt_id)) + { + oci_free_statement($this->stmt_id); + } + oci_close($this->conn_id); } -- cgit v1.2.3-24-g4f1b From b8445bf3f5ac18b6325e1205e068a24d80a19307 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 20:57:43 +0200 Subject: [ci skip] Merge pull request #5690 from Lohith94/develop Corrected some grammar --- application/config/config.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index ee599c7aa..1abe32c00 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -13,9 +13,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | | WARNING: You MUST set this value! | -| If it is not set, then CodeIgniter will try guess the protocol and path -| your installation, but due to security concerns the hostname will be set -| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise. +| If it is not set, then CodeIgniter will try to guess the protocol and +| path your installation, but due to security concerns the hostname will +| be set to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise. | The auto-detection mechanism exists only for convenience during | development and MUST NOT be used in production! | -- cgit v1.2.3-24-g4f1b From b8ad8411998b028f829db4231b3ef1db0eef8813 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 20:59:30 +0200 Subject: [ci skip] Another minor grammar correction following #5690 --- application/config/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/config/config.php b/application/config/config.php index 1abe32c00..35ace5cc9 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -13,8 +13,8 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | | WARNING: You MUST set this value! | -| If it is not set, then CodeIgniter will try to guess the protocol and -| path your installation, but due to security concerns the hostname will +| If it is not set, then CodeIgniter will try to guess the protocol and +| path to your installation, but due to security concerns the hostname will | be set to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise. | The auto-detection mechanism exists only for convenience during | development and MUST NOT be used in production! -- cgit v1.2.3-24-g4f1b From 25ae2a3c0a8f20098181e20d55a61c0c42559ee9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Jan 2022 23:46:50 +0200 Subject: [ci skip] Suggest random_bytes() over random_string() (fix #3432) --- user_guide_src/source/helpers/string_helper.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/helpers/string_helper.rst b/user_guide_src/source/helpers/string_helper.rst index 6dabc60d3..f08f56b0b 100644 --- a/user_guide_src/source/helpers/string_helper.rst +++ b/user_guide_src/source/helpers/string_helper.rst @@ -36,7 +36,6 @@ The following functions are available: :rtype: string Generates a random string based on the type and length you specify. - Useful for creating passwords or generating random hashes. The first parameter specifies the type of string, the second parameter specifies the length. The following choices are available: @@ -53,6 +52,10 @@ The following functions are available: echo random_string('alnum', 16); + .. note:: Usage of this function is NOT suitable for password generation + or other security-sensitive purposes. Please use + `random_bytes() `_ instead. + .. note:: Usage of the *unique* and *encrypt* types is DEPRECATED. They are just aliases for *md5* and *sha1* respectively. -- cgit v1.2.3-24-g4f1b From 3853472a6ea2db4fbaf7d259184245b35b004fdf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 7 Jan 2022 13:05:03 +0200 Subject: [ci skip] Fix #6083 --- system/libraries/Session/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 1c5c980ae..87113e2b5 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -328,7 +328,7 @@ class CI_Session { 'path' => $params['cookie_path'], 'domain' => $params['cookie_domain'], 'secure' => $params['cookie_secure'], - 'httponly' => $params['cookie_httponly'], + 'httponly' => TRUE, 'samesite' => $params['cookie_samesite'] )); } -- cgit v1.2.3-24-g4f1b From 413381e7c9f297f94dff156adc4db00ba6ba2c9b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Jan 2022 01:32:39 +0200 Subject: [ci skip] Fix CI_Session_driver_interface for PHP 5 (ref #6078) --- system/libraries/Session/OldSessionWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Session/OldSessionWrapper.php b/system/libraries/Session/OldSessionWrapper.php index 5934b5218..a8bc1d0c0 100644 --- a/system/libraries/Session/OldSessionWrapper.php +++ b/system/libraries/Session/OldSessionWrapper.php @@ -49,7 +49,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); */ class CI_SessionWrapper implements SessionHandlerInterface { - protected CI_Session_driver_interface $driver; + protected $driver; public function __construct(CI_Session_driver_interface $driver) { -- cgit v1.2.3-24-g4f1b From 52d04d27b6e172093d7d9f70c6e77846b6742742 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Jan 2022 16:57:19 +0200 Subject: [ci skip] Actually use the Session wrapper (ref #6078) --- system/libraries/Session/Session.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 87113e2b5..9d4561616 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -107,17 +107,17 @@ class CI_Session { $wrapper = new CI_SessionWrapper($class); if (is_php('5.4')) { - session_set_save_handler($class, TRUE); + session_set_save_handler($wrapper, TRUE); } else { session_set_save_handler( - array($class, 'open'), - array($class, 'close'), - array($class, 'read'), - array($class, 'write'), - array($class, 'destroy'), - array($class, 'gc') + array($wrapper, 'open'), + array($wrapper, 'close'), + array($wrapper, 'read'), + array($wrapper, 'write'), + array($wrapper, 'destroy'), + array($wrapper, 'gc') ); register_shutdown_function('session_write_close'); -- cgit v1.2.3-24-g4f1b From 2d4ddf57cc64f37a76e53403bc1442a54cc01897 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Jan 2022 17:02:48 +0200 Subject: [ci skip] Attempt to hack SameSite into session_set_cookie_params() pre-PHP7.3 --- system/libraries/Session/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 9d4561616..8d3ba2857 100644 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -336,7 +336,7 @@ class CI_Session { { session_set_cookie_params( $params['cookie_lifetime'], - $params['cookie_path'], + $params['cookie_path'].'; SameSite='.$params['cookie_samesite'], $params['cookie_domain'], $params['cookie_secure'], TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons -- cgit v1.2.3-24-g4f1b From e1ea92843ce0139417aad0933ec32d7e589d0de9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Jan 2022 22:39:06 +0200 Subject: .gitignore tests/mocks/database/ci_test.sqlite --- .gitignore | 1 + tests/mocks/database/ci_test.sqlite | Bin 19456 -> 0 bytes 2 files changed, 1 insertion(+) delete mode 100755 tests/mocks/database/ci_test.sqlite diff --git a/.gitignore b/.gitignore index 269044ea9..323f06468 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ application/logs/* !application/*/.htaccess composer.lock +tests/mocks/database/ci_test.sqlite user_guide_src/build/* user_guide_src/cilexer/build/* diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite deleted file mode 100755 index a46b4c016..000000000 Binary files a/tests/mocks/database/ci_test.sqlite and /dev/null differ -- cgit v1.2.3-24-g4f1b From d678dbb1937a4a3a44d335118149e53f6aacaacf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Jan 2022 22:43:04 +0200 Subject: [ci skip] Merge pull request #5729 from emrulmax2/patch-1 NOT BETWEEN syntax error DB where() issue solved --- system/database/DB_driver.php | 1 + 1 file changed, 1 insertion(+) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 6e1d8d11e..fd7cd5543 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1576,6 +1576,7 @@ abstract class CI_DB_driver { '\s+EXISTS\s*\(.*\)', // EXISTS(sql) '\s+NOT EXISTS\s*\(.*\)', // NOT EXISTS(sql) '\s+BETWEEN\s+', // BETWEEN value AND value + '\s+NOT BETWEEN\s+', // NOT BETWEEN value AND value '\s+IN\s*\(.*\)', // IN(list) '\s+NOT IN\s*\(.*\)', // NOT IN (list) '\s+LIKE\s+\S.*('.$_les.')?', // LIKE 'expr'[ ESCAPE '%s'] -- cgit v1.2.3-24-g4f1b From ad57720c57c11620c77181655d637a5bfdbe2643 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Jan 2022 22:45:05 +0200 Subject: [ci skip] Add changelog entry for #5729 --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 0e347f891..4b75a9739 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -34,6 +34,7 @@ Bug fixes for 3.1.12 - Fixed a bug (#5903) - :doc:`common function ` :php:func:`set_status_header()` didn't recognize 'HTTP/2.0' as a valid ``$_SERVER['SERVER_PROTOCOL']``. - Fixed a bug (#6013) - :doc:`Session ` flashdata didn't work on PHP 8. - Fixed a bug (#6006) - ``is_callable()`` change in PHP 8 broke :doc:`Migrations `, a part of :doc:`XML-RPC ` and an edge case in 404 detection logic. +- Fixed a bug (#5729) - :doc:`Query Builder ` possibly not detecting ``NOT BETWEEN`` expression. Version 3.1.11 ============== -- cgit v1.2.3-24-g4f1b