Conversation
EncryptedCookieHandler encrypts cookie values with Encryption\Encrypter: XChaCha20-Poly1305 via ext-sodium, with a list of keys where the first encrypts and every key decrypts, so a key can be rotated without invalidating existing cookies at once. Payloads match cubex/framework 2.7, so either can read the other's cookies with the same keys. A handler can now reject a request cookie by throwing InvalidCookieException, and the jar leaves that cookie out. A cookie that fails to decrypt is dropped rather than read as an empty value. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
|
Closing: no Cubex 4 app uses encrypted cookies today. If one needs them, the encrypter belongs in its own package (e.g. packaged/encrypt) alongside a cookie handler, with only the InvalidCookieException hook here. The code stays on the encrypted-cookies branch. |
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.
Adds
EncryptedCookieHandler, which encrypts cookie values through theCookieJarhandler chain:Encryption\Encrypteruses XChaCha20-Poly1305 via ext-sodium (orparagonie/sodium_compat, both suggested, not required).security.encryption_keycan be a list: the first key encrypts and every key decrypts, so a key can be rotated without signing everyone out. Payloads match cubex/framework 2.7, so apps on either can share cookies with the same keys.A cookie that fails to decrypt is left out of the jar rather than read as an empty string. To support that, a handler can now throw
InvalidCookieExceptionfromdecodeValue(), andhydrate()drops that cookie.Test plan
PHPUnit passes on PHP 8.2 and 8.5 (75 tests). New tests cover round trips through a request and response, decrypting with a previous key, dropping forged and retired-key cookies, plain-text exclusions, and the encrypter's tamper, malformed-payload and key-validation cases.
🤖 Generated with Claude Code