Skip to content

Commit

Permalink
Count cookie parts before accessing the second
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat committed Aug 23, 2022
1 parent 447f8b5 commit 3ca3eb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions RememberMe/RememberMeDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function __construct(string $userFqcn, string $userIdentifier, int $expir
public static function fromRawCookie(string $rawCookie): self
{
$cookieParts = explode(self::COOKIE_DELIMITER, base64_decode($rawCookie), 4);
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
}
if (4 !== \count($cookieParts)) {
throw new AuthenticationException('The cookie contains invalid data.');
}
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
}

return new static(...$cookieParts);
}
Expand Down
8 changes: 8 additions & 0 deletions Tests/Authenticator/RememberMeAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,12 @@ public function testAuthenticateWithoutOldToken()
$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => base64_encode('foo:bar')]);
$this->authenticator->authenticate($request);
}

public function testAuthenticateWithTokenWithoutDelimiter()
{
$this->expectException(AuthenticationException::class);

$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => 'invalid']);
$this->authenticator->authenticate($request);
}
}

0 comments on commit 3ca3eb2

Please sign in to comment.