fix(core): keep encrypted session slots readable across key drift (imp #66)#174
Merged
Conversation
This was referenced Jun 25, 2026
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.
Summary
Fixes the "Invalid PKCS#7 padding byte" fatal that surfaces during portal render when an encrypted session slot's per-session key has drifted from the ciphertext it protects (cookie eviction, session-id rotation without re-encrypt, upgrade boundary).
Four layered changes in one commit:
HordeSession::getEncryptedcatches decrypt failures and returnsnullinstead of letting the throwable escape.AuthCredentialStore::getalready turns null intofalse, so consumers degrade gracefully.Horde_Core_Alarm_Handler_Mail(new, extendsHorde_Alarm_Handlerdirectly) defersHorde_Mailresolution to the firstnotify()call. Removes the eager IMAP-credential dereference from every portal render that touches the alarm notifier decorator.SessionLifecycle::regenerate()drains plaintexts under the old key, callssession_regenerate_id(true)+secret->setKey(), re-encrypts under the new key. A newHordeSession::reEncryptAll(\Closure $rotate)packages the drain/rotate/refill sequence; slots that fail to decrypt under the current key are dropped from both the data and the encryption map.Horde_Core_Secret_Cbcnow persists the per-session key in the session payload ($_SESSION['_secret']['key']) via a newSessionSecret::setSession()wiring point onHordeSessionFactory::create(). Migrates the value from the legacyhorde_secret_keycookie on first read; cookie continues to be written for BC. This removes the cookie-only dependency that made the bug reproducible in the wild.Threat-model note: collocating the key with the ciphertext is a deliberate trade. The split-trust property (an attacker with only the session row gets useless bytes) is restored by a follow-up HKDF design filed under
~/php/horde-development/libraries/core/session-encryption-hkdf-strategy-2026-06-25.md.Related: horde/imp#66, horde/imp#72.