fix: add int type hint to gc() in session database handlers#10418
Open
gr8man wants to merge 5 commits into
Open
fix: add int type hint to gc() in session database handlers#10418gr8man wants to merge 5 commits into
gr8man wants to merge 5 commits into
Conversation
- Add int type hint to parameter in DatabaseHandler::gc() and PostgreHandler::gc() to match PHP SessionHandlerInterface - Change return type to int|false to match the interface - Add test for TypeError on non-int input (SQLi protection) - Add edge case tests for gc(0) and gc(-1) Fixes potential SQL injection via unescaped in INTERVAL clause with = false.
…l type violation test
michalsn
requested changes
Jul 20, 2026
michalsn
left a comment
Member
There was a problem hiding this comment.
Quite an unrealistic scenario, but still a valid fix.
Please add a changelog entry.
Comment on lines
+136
to
+146
| public function testGCWithZero(): void | ||
| { | ||
| $handler = $this->getInstance(); | ||
| $this->assertSame(1, $handler->gc(0)); | ||
| } | ||
|
|
||
| public function testGCWithNegativeValue(): void | ||
| { | ||
| $handler = $this->getInstance(); | ||
| $this->assertSame(1, $handler->gc(-1)); | ||
| } |
Member
There was a problem hiding this comment.
Please remove these two tests, as zero and negative values are unrelated to the fix.
gr8man
added a commit
to gr8man/CodeIgniter4
that referenced
this pull request
Jul 20, 2026
- Add Unreleased section to CHANGELOG.md with PR codeigniter4#10418 entry - Consolidate testGCRejectsNonInt to test 6 non-int types in one method - Remove unrelated testGCWithZero and testGCWithNegativeValue tests - Add v4.7.5 RST changelog entry for session gc type hint
- 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
gr8man
force-pushed
the
fix/session-gc-sqli-type-hint
branch
from
July 20, 2026 18:09
4079bbb to
fc5d53c
Compare
michalsn
requested changes
Jul 21, 2026
michalsn
left a comment
Member
There was a problem hiding this comment.
Please rebase into the 4.8 branch, as this will be a more appropriate release for these changes. Also, please change this method signature for all handlers.
| $this->fail('TypeError expected for value: ' . gettype($malicious)); | ||
| } catch (TypeError) { | ||
| $this->addToAssertionCount(1); | ||
| } |
Member
There was a problem hiding this comment.
Please use DataProvider instead of a loop.
|
|
||
| - **Content Security Policy:** Fixed a bug where empty ``Content-Security-Policy``, ``Content-Security-Policy-Report-Only``, and ``Reporting-Endpoints`` response headers were generated when no corresponding values existed. | ||
| - **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors. | ||
| - **Session:** Added ``int`` type hint to ``DatabaseHandler::gc()`` and ``PostgreHandler::gc()`` to prevent SQL injection from non-integer ``$max_lifetime`` values. |
Member
There was a problem hiding this comment.
Please add something like this under the Method Signature Changes section:
- **Session:** The ``$max_lifetime`` parameter of the following ``gc()`` methods
now has the native ``int`` type, matching ``SessionHandlerInterface``.
You can also list all affected handlers - this will match other entries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added int type hint to $max_lifetime in DatabaseHandler::gc() and PostgreHandler::gc() to match SessionHandlerInterface. This prevents SQL injection from unescaped input by rejecting non-integer values with a
TypeError.Checklist: