Skip to content

Commit 3ca3eb2

Browse files
committed
Count cookie parts before accessing the second
1 parent 447f8b5 commit 3ca3eb2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

RememberMe/RememberMeDetails.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ public function __construct(string $userFqcn, string $userIdentifier, int $expir
3737
public static function fromRawCookie(string $rawCookie): self
3838
{
3939
$cookieParts = explode(self::COOKIE_DELIMITER, base64_decode($rawCookie), 4);
40-
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
41-
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
42-
}
4340
if (4 !== \count($cookieParts)) {
4441
throw new AuthenticationException('The cookie contains invalid data.');
4542
}
43+
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
44+
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
45+
}
4646

4747
return new static(...$cookieParts);
4848
}

Tests/Authenticator/RememberMeAuthenticatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ public function testAuthenticateWithoutOldToken()
8989
$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => base64_encode('foo:bar')]);
9090
$this->authenticator->authenticate($request);
9191
}
92+
93+
public function testAuthenticateWithTokenWithoutDelimiter()
94+
{
95+
$this->expectException(AuthenticationException::class);
96+
97+
$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => 'invalid']);
98+
$this->authenticator->authenticate($request);
99+
}
92100
}

0 commit comments

Comments
 (0)