Skip to content

Commit 07a7592

Browse files
committed
bug #14678 [Security] AbstractRememberMeServices::encodeCookie() validates cookie parts (MacDada)
This PR was squashed before being merged into the 2.3 branch (closes #14678). Discussion ---------- [Security] AbstractRememberMeServices::encodeCookie() validates cookie parts | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14577 | License | MIT | Doc PR | no `AbstractRememberMeServices::encodeCookie()` guards against `COOKIE_DELIMITER` in `$cookieParts`. * it would make `AbstractRememberMeServices::cookieDecode()` broken * all current extending classes do it anyway (see #14670 ) * added tests – it's not a public method, but it is expected to be used by user implementations – as such, it's good to know that it works properly Commits ------- 464c39a [Security] AbstractRememberMeServices::encodeCookie() validates cookie parts
2 parents 819c0de + f83e715 commit 07a7592

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

RememberMe/AbstractRememberMeServices.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,17 @@ protected function decodeCookie($rawCookie)
268268
* @param array $cookieParts
269269
*
270270
* @return string
271+
*
272+
* @throws \InvalidArgumentException When $cookieParts contain the cookie delimiter. Extending class should either remove or escape it.
271273
*/
272274
protected function encodeCookie(array $cookieParts)
273275
{
276+
foreach ($cookieParts as $cookiePart) {
277+
if (false !== strpos($cookiePart, self::COOKIE_DELIMITER)) {
278+
throw new \InvalidArgumentException(sprintf('$cookieParts should not contain the cookie delimiter "%s"', self::COOKIE_DELIMITER));
279+
}
280+
}
281+
274282
return base64_encode(implode(self::COOKIE_DELIMITER, $cookieParts));
275283
}
276284

RememberMe/TokenBasedRememberMeServices.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ protected function onLoginSuccess(Request $request, Response $response, TokenInt
119119
* @param int $expires The Unix timestamp when the cookie expires
120120
* @param string $password The encoded password
121121
*
122-
* @throws \RuntimeException if username contains invalid chars
123-
*
124122
* @return string
125123
*/
126124
protected function generateCookieValue($class, $username, $expires, $password)
@@ -141,8 +139,6 @@ protected function generateCookieValue($class, $username, $expires, $password)
141139
* @param int $expires The Unix timestamp when the cookie expires
142140
* @param string $password The encoded password
143141
*
144-
* @throws \RuntimeException when the private key is empty
145-
*
146142
* @return string
147143
*/
148144
protected function generateCookieHash($class, $username, $expires, $password)

0 commit comments

Comments
 (0)