Skip to content

Commit f83e715

Browse files
MacDadafabpot
authored andcommitted
[Security] AbstractRememberMeServices::encodeCookie() validates cookie parts
1 parent e906970 commit f83e715

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)