You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CookieLogin: client can bypass remember-me TTL by setting expires=0 #125
Auto-login cookie value is plain JSON: [id, key, expires] (no integrity check on the payload).
CookieLoginMiddleware enforces lifetime only when expires !== 0:
if ($expires !== 0 && $expires < time()) {
// reject as expiredreturn;
}
$this->currentUser->login($identity);
Steps:
Issue a timed cookie via CookieLogin::addCookie() with a non-null DateInterval
→ payload like ["user-1","valid-key",<future-timestamp>] → auth accepted.
Keep the same id and key, set expires to a past timestamp
→ auth rejected (TTL works).
Keep the same id and key, set expires to 0
→ auth accepted again.
So a client who can edit the cookie value turns a finite remember-me cookie into one the server never treats as expired.
Note: browser Set-Cookie Max-Age/Expires is separate. An attacker who sets the cookie themselves can also choose a long browser lifetime; the bug is that server-side TTL in JSON is not binding.
What is the expected result?
If the application issued a finite-duration remember-me cookie, the server must reject auth after that time even if the client changes the expires field (unless the whole payload is integrity-protected or the token is looked up server-side).
What do you get instead?
After validateCookieLoginKey() succeeds, expires === 0 skips the lifetime check. Changing expires to 0 disables that check for an otherwise valid key.
Additional info
Q
A
Version
yiisoft/user2.3.2
PHP version
8.3
Relevant code
CookieLoginMiddleware (TTL gate):
if ($expires !== 0 && $expires < time()) {
$this->logger->warning('Unable to authenticate user by cookie. Lifetime has expired.');
return;
}
$this->currentUser->login($identity);
CookieLogin::addCookie() (writes 0 for session-cookie mode, otherwise a timestamp; value is json_encode of [id, key, expires] with no MAC):
Protecting a cookie's value against client-side tampering is not something yiisoft/user implements itself — it's already handled by yiisoft/cookies that provides CookieSigner / CookieEncryptor and a CookieMiddleware that signs/encrypts outgoing Set-Cookie values and validates/decrypts incoming ones by cookie name.
It would be good to add a note about this to the README's "Auto login through cookie" section.
The bad thing about #126 is that it stays insecure by default and it doesn't error. It's silent.
We can make it secure by default by introducing built-in HMAC signing of the value right into this package. The drawback — while configuring CookieMiddleware to sign cookies, we should exclude our cookie or else it silently breaks auto-login functionality. Also, it is a backwards compatibility break to introduce it.
The bad thing about #126 is that it stays insecure by default and it doesn't error. It's silent.
We can make it secure by default by introducing built-in HMAC signing of the value right into this package. The drawback — while configuring CookieMiddleware to sign cookies, we should exclude our cookie or else it silently breaks auto-login functionality. Also, it is a backwards compatibility break to introduce it.
It is implemented as optional signing: #126
In the major version, we will make the $signatureKey specification mandatory so that the user makes an informed choice.
It would be better to use the existing functionality than to create a duplicate:
This is a fairly simple functionality, so I prefer remove yiisoft/cookies dependency (see #134)
It not clear from the #134 issue what exactly you plan to do beside remove yiisoft/cookies dependency.
I'm wondering whether classes CookieLogin, CookieLoginIdentityInterface and CookieLoginMiddleware have been removed too?
It not clear from the #134 issue what exactly you plan to do beside remove yiisoft/cookies dependency. I'm wondering whether classes CookieLogin, CookieLoginIdentityInterface and CookieLoginMiddleware have been removed too?
Implement cookie creating into yiisoft/user without yiisoft/cookie usage. CookieLogin, CookieLoginIdentityInterface, and CookieLoginMiddleware will remain.
Users of the yiisoft/cookies package may have encountered a configuration issue when signing and/or encrypting cookies, as both the yiisoft/cookies and yiisoft/user packages require a key. However, the yiisoft/cookies package allows you to use the same key for both.
Using Yiisoft\Cookies\CookieEncryptor for encryption in addition to signing would be a good option.
Activity
vjik commentedon Aug 16, 2026
Protecting a cookie's value against client-side tampering is not something
yiisoft/userimplements itself — it's already handled by yiisoft/cookies that providesCookieSigner/CookieEncryptorand aCookieMiddlewarethat signs/encrypts outgoingSet-Cookievalues and validates/decrypts incoming ones by cookie name.It would be good to add a note about this to the README's "Auto login through cookie" section.
Sakanweb commentedon Aug 16, 2026
Thanks - documenting this via
yiisoft/cookiesis a good approach. PR looks good.samdark commentedon Aug 30, 2026
The bad thing about #126 is that it stays insecure by default and it doesn't error. It's silent.
We can make it secure by default by introducing built-in HMAC signing of the value right into this package. The drawback — while configuring
CookieMiddlewareto sign cookies, we should exclude our cookie or else it silently breaks auto-login functionality. Also, it is a backwards compatibility break to introduce it.vjik commentedon Sep 1, 2026
It is implemented as optional signing: #126
In the major version, we will make the $signatureKey specification mandatory so that the user makes an informed choice.
klsoft-web commentedon Sep 1, 2026
It would be better to use the existing functionality than to create a duplicate:
Then add this to CookieLoginMiddleware:
vjik commentedon Sep 2, 2026
This is a fairly simple functionality, so I prefer remove
yiisoft/cookiesdependency (see #134)klsoft-web commentedon Sep 2, 2026
It not clear from the #134 issue what exactly you plan to do beside remove
yiisoft/cookiesdependency.I'm wondering whether classes
CookieLogin,CookieLoginIdentityInterfaceandCookieLoginMiddlewarehave been removed too?vjik commentedon Sep 2, 2026
Implement cookie creating into
yiisoft/userwithoutyiisoft/cookieusage.CookieLogin,CookieLoginIdentityInterface, andCookieLoginMiddlewarewill remain.klsoft-web commentedon Sep 2, 2026
yiisoft/cookiespackage may have encountered a configuration issue when signing and/or encrypting cookies, as both theyiisoft/cookiesandyiisoft/userpackages require a key. However, theyiisoft/cookiespackage allows you to use the same key for both.Yiisoft\Cookies\CookieEncryptorfor encryption in addition to signing would be a good option.