Skip to content

Commit acc70c9

Browse files
committed
[Security] Fix invalid cookie when migrating to new Security
1 parent 6bf4c31 commit acc70c9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

RememberMe/RememberMeDetails.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public static function fromRawCookie(string $rawCookie): self
4040
if (false === $cookieParts[1] = base64_decode($cookieParts[1], true)) {
4141
throw new AuthenticationException('The user identifier contains a character from outside the base64 alphabet.');
4242
}
43+
if (4 !== \count($cookieParts)) {
44+
throw new AuthenticationException('The cookie contains invalid data.');
45+
}
4346

4447
return new static(...$cookieParts);
4548
}

Tests/Authenticator/RememberMeAuthenticatorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
1818
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
19+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1920
use Symfony\Component\Security\Core\User\InMemoryUser;
2021
use Symfony\Component\Security\Http\Authenticator\RememberMeAuthenticator;
2122
use Symfony\Component\Security\Http\RememberMe\RememberMeDetails;
@@ -80,4 +81,12 @@ public function testAuthenticateWithoutToken()
8081

8182
$this->authenticator->authenticate(Request::create('/'));
8283
}
84+
85+
public function testAuthenticateWithoutOldToken()
86+
{
87+
$this->expectException(AuthenticationException::class);
88+
89+
$request = Request::create('/', 'GET', [], ['_remember_me_cookie' => base64_encode('foo:bar')]);
90+
$this->authenticator->authenticate($request);
91+
}
8392
}

0 commit comments

Comments
 (0)