Skip to content

Commit b1dc98a

Browse files
authored
fix: add int type hint to gc() in all session handlers (#10418)
Add int type hint to $max_lifetime in gc() for all 6 session handlers to match SessionHandlerInterface, preventing SQL injection from non-integer input. Includes changelog entry in v4.8.0.rst under Method Signature Changes.
1 parent 9d27004 commit b1dc98a

7 files changed

Lines changed: 7 additions & 6 deletions

File tree

system/Session/Handlers/ArrayHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function destroy($id): bool
8080
* @param int $max_lifetime Sessions that have not updated
8181
* for the last max_lifetime seconds will be removed.
8282
*/
83-
public function gc($max_lifetime): int
83+
public function gc(int $max_lifetime): int
8484
{
8585
return 1;
8686
}

system/Session/Handlers/Database/PostgreHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function prepareData(string $data): string
5959
* @param int $max_lifetime Sessions that have not updated
6060
* for the last max_lifetime seconds will be removed.
6161
*/
62-
public function gc($max_lifetime): false|int
62+
public function gc(int $max_lifetime): false|int
6363
{
6464
$separator = '\'';
6565
$interval = implode($separator, ['', "{$max_lifetime} second", '']);

system/Session/Handlers/DatabaseHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function destroy($id): bool
276276
*
277277
* @return false|int Returns the number of deleted sessions on success, or false on failure.
278278
*/
279-
public function gc($max_lifetime): false|int
279+
public function gc(int $max_lifetime): false|int
280280
{
281281
return $this->db->table($this->table)->where(
282282
'timestamp <',

system/Session/Handlers/FileHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public function destroy($id): bool
263263
* @param int $max_lifetime Sessions that have not updated
264264
* for the last max_lifetime seconds will be removed.
265265
*/
266-
public function gc($max_lifetime): false|int
266+
public function gc(int $max_lifetime): false|int
267267
{
268268
if (! is_dir($this->savePath) || ($directory = opendir($this->savePath)) === false) {
269269
$this->logger->debug("Session: Garbage collector couldn't list files under directory '" . $this->savePath . "'.");

system/Session/Handlers/MemcachedHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public function destroy($id): bool
255255
* @param int $max_lifetime Sessions that have not updated
256256
* for the last max_lifetime seconds will be removed.
257257
*/
258-
public function gc($max_lifetime): int
258+
public function gc(int $max_lifetime): int
259259
{
260260
return 1;
261261
}

system/Session/Handlers/RedisHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public function destroy($id): bool
341341
* @param int $max_lifetime Sessions that have not updated
342342
* for the last max_lifetime seconds will be removed.
343343
*/
344-
public function gc($max_lifetime): int
344+
public function gc(int $max_lifetime): int
345345
{
346346
return 1;
347347
}

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Method Signature Changes
7373
- **Database:** The following methods have had their signatures updated to remove deprecated parameters:
7474
- ``CodeIgniter\Database\Forge::_createTable()`` no longer accepts the deprecated ``$ifNotExists`` parameter. The method signature is now ``_createTable(string $table, array $attributes)``.
7575
- **Model:** ``CodeIgniter\BaseModel`` now requires the ``chunkRows()``, ``chunkById()``, and ``chunkRowsById()`` methods. Custom classes extending ``BaseModel`` directly must implement them.
76+
- **Session:** The ``$max_lifetime`` parameter of the following ``gc()`` methods now has the native ``int`` type, matching ``SessionHandlerInterface``: ``ArrayHandler::gc()``, ``DatabaseHandler::gc()``, ``FileHandler::gc()``, ``MemcachedHandler::gc()``, ``PostgreHandler::gc()``, ``RedisHandler::gc()``.
7677

7778
Property Scope Changes
7879
======================

0 commit comments

Comments
 (0)