Skip to content

refactor: add int type hint to gc() in all session handlers - #10418

Merged
michalsn merged 1 commit into
codeigniter4:4.8from
gr8man:fix/session-gc-sqli-type-hint
Jul 31, 2026
Merged

refactor: add int type hint to gc() in all session handlers#10418
michalsn merged 1 commit into
codeigniter4:4.8from
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 all 6 session handlers' gc() to match SessionHandlerInterface. This prevents SQL injection from non-integer input by rejecting it with a TypeError.

Affected handlers: ArrayHandler, DatabaseHandler, FileHandler, MemcachedHandler, PostgreHandler, RedisHandler.

Checklist:

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

@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 thread tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php Outdated
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
@gr8man
gr8man force-pushed the fix/session-gc-sqli-type-hint branch from 4079bbb to fc5d53c Compare July 20, 2026 18:09

@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.

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.

Comment thread tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php Outdated
Comment thread user_guide_src/source/changelogs/v4.7.5.rst Outdated

@paulbalandan paulbalandan 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.

This is a refactor, and as mentioned should be targeting 4.8 branch instead.

Comment thread tests/system/Session/Handlers/Database/AbstractHandlerTestCase.php Outdated
@michalsn michalsn added needs rework Changes requested by reviewer that are still pending wrong branch PRs sent to wrong branch labels Jul 22, 2026
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.
@gr8man
gr8man force-pushed the fix/session-gc-sqli-type-hint branch from 2124cc3 to e4bb6fd Compare July 29, 2026 20:10
@github-actions github-actions Bot added the github_actions Pull requests that update Github_actions code label Jul 29, 2026
@gr8man
gr8man changed the base branch from develop to 4.8 July 29, 2026 20:11
@gr8man gr8man changed the title fix: add int type hint to gc() in session database handlers fix: add int type hint to gc() in all session handlers Jul 29, 2026
@michalsn michalsn added 4.8 PRs that target the `4.8` branch. and removed github_actions Pull requests that update Github_actions code needs rework Changes requested by reviewer that are still pending wrong branch PRs sent to wrong branch labels Jul 30, 2026
@michalsn michalsn changed the title fix: add int type hint to gc() in all session handlers refactor: add int type hint to gc() in all session handlers Jul 30, 2026

@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.

Looks good. Thank you!

@michalsn
michalsn merged commit b1dc98a into codeigniter4:4.8 Jul 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants