Skip to content

fix: add int type hint to gc() in session database handlers#10418

Open
gr8man wants to merge 5 commits into
codeigniter4:developfrom
gr8man:fix/session-gc-sqli-type-hint
Open

fix: add int type hint to gc() in session database handlers#10418
gr8man wants to merge 5 commits into
codeigniter4:developfrom
gr8man:fix/session-gc-sqli-type-hint

Conversation

@gr8man

@gr8man gr8man commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

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:

  • Securely signed commits
  • PHPDoc blocks updated
  • Unit testing
  • User guide updated
  • Conforms to style guide

gr8man added 3 commits July 20, 2026 00:57
- 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.

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
gr8man force-pushed the fix/session-gc-sqli-type-hint branch from 4079bbb to fc5d53c Compare July 20, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants