Skip to content

fix(Session): destroy Redis and Memcached session records without a lock - #10850

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix/session-destroy-without-lock
Open

gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix/session-destroy-without-lock

Conversation

@gr8man

@gr8man gr8man commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Description
destroy() in the Redis and Memcached session handlers skipped deleting the session record when the handler did not hold the session lock, leaving the record in the store. The record is now removed whenever the handler is connected, matching FileHandler.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

RedisHandler::destroy() and MemcachedHandler::destroy() only removed the
session record when $lockKey was set. A handler that had not acquired the
lock (no prior read(), or a lock already released) skipped the delete and
returned false, leaving the record in the store and the session cookie in
place. FileHandler and DatabaseHandler don't depend on the lock here.

Remove the record whenever the connection is available, and always destroy
the cookie through destroyCookie().

Adds regression tests: a MemcachedHandler test in the existing suite and a
new RedisHandlerTest. Both fail on the previous code.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@carson-codeigniter4 carson-codeigniter4 Bot added needs template Opened issues not following the bug form template bug Verified issues on the current code behavior or pull requests that will fix them labels Dec 5, 2026
@carson-codeigniter4

This comment has been minimized.

@carson-codeigniter4 carson-codeigniter4 Bot removed the needs template Opened issues not following the bug form template label Dec 5, 2026
The regression tests read the session back through the handler, which only
checks that the value is unreadable. Check the Memcached and Redis store
directly so a record left behind by destroy() fails the test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant