Skip to content

Commit fc5d53c

Browse files
committed
docs: add changelog entry and improve SQLi rejection tests
- Add v4.7.5 RST changelog entry for session gc type hint - Consolidate testGCRejectsNonInt to test 6 non-int types in one method - Remove unrelated testGCWithZero and testGCWithNegativeValue tests
1 parent 5a53402 commit fc5d53c

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use CodeIgniter\Test\DatabaseTestTrait;
1919
use CodeIgniter\Test\ReflectionHelper;
2020
use Config\Database as DatabaseConfig;
21+
use stdClass;
2122
use Tests\Support\Database\Seeds\CITestSeeder;
2223
use TypeError;
2324

@@ -125,23 +126,16 @@ public function testGC(): void
125126
}
126127

127128
public function testGCRejectsNonInt(): void
128-
{
129-
$handler = $this->getInstance();
130-
$malicious = 'malicious; DROP TABLE sessions; --';
131-
132-
$this->expectException(TypeError::class);
133-
$handler->gc($malicious); // @phpstan-ignore argument.type
134-
}
135-
136-
public function testGCWithZero(): void
137129
{
138130
$handler = $this->getInstance();
139-
$this->assertSame(1, $handler->gc(0));
140-
}
141131

142-
public function testGCWithNegativeValue(): void
143-
{
144-
$handler = $this->getInstance();
145-
$this->assertSame(1, $handler->gc(-1));
132+
foreach (['malicious; DROP TABLE sessions; --', null, 1.5, [], new stdClass(), true] as $malicious) {
133+
try {
134+
$handler->gc($malicious); // @phpstan-ignore argument.type
135+
$this->fail('TypeError expected for value: ' . gettype($malicious));
136+
} catch (TypeError) {
137+
// Expected — type hint blocks SQL injection
138+
}
139+
}
146140
}
147141
}

user_guide_src/source/changelogs/v4.7.5.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Bugs Fixed
3131
**********
3232

3333
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
34+
- **Session:** Added ``int`` type hint to ``DatabaseHandler::gc()`` and ``PostgreHandler::gc()`` to prevent SQL injection from non-integer ``$max_lifetime`` values.
3435

3536
See the repo's
3637
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)