8000 [Security/Http] Fix compat of persistent remember-me with legacy tokens by nicolas-grekas · Pull Request #49103 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Security/Http] Fix compat of persistent remember-me with legacy tokens #49103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ final class PersistentRememberMeHandler extends AbstractRememberMeHandler
{
private $tokenProvider;
private $tokenVerifier;
private $secret;

public function __construct(TokenProviderInterface $tokenProvider, string $secret, UserProviderInterface $userProvider, RequestStack $requestStack, array $options, LoggerInterface $logger = null, TokenVerifierInterface $tokenVerifier = null)
{
Expand All @@ -45,7 +44,6 @@ public function __construct(TokenProviderInterface $tokenProvider, string $secre
}
$this->tokenProvider = $tokenProvider;
$this->tokenVerifier = $tokenVerifier;
$this->secret = $secret;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused property after #49078

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we deprecate the constructor argument ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could but not in 5.4

}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Security/Http/RememberMe/RememberMeDetails.php
< 8000 /span>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function __construct(string $userFqcn, string $userIdentifier, int $expir

public static function fromRawCookie(string $rawCookie): self
{
if (!str_contains($rawCookie, self::COOKIE_DELIMITER)) {
$rawCookie = base64_decode($rawCookie);
}
$cookieParts = explode(self::COOKIE_DELIMITER, $rawCookie, 4);
if (4 !== \count($cookieParts)) {
throw new AuthenticationException('The cookie contains invalid data.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,19 @@ public function testConsumeRememberMeCookieExpired()

$this->handler->consumeRememberMeCookie(new RememberMeDetails(InMemoryUser::class, 'wouter', 360, 'series1:tokenvalue'));
}

public function testBase64EncodedTokens()
{
$this->tokenProvider->expects($this->any())
->method('loadTokenBySeries')
->with('series1')
->willReturn(new PersistentToken(InMemoryUser::class, 'wouter', 'series1', 'tokenvalue', new \DateTime('-10 min')))
;

$this->tokenProvider->expects($this->once())->method('updateToken')->with('series1');

$rememberMeDetails = new RememberMeDetails(InMemoryUser::class, 'wouter', 360, 'series1:tokenvalue');
$rememberMeDetails = RememberMeDetails::fromRawCookie(base64_encode($rememberMeDetails->toString()));
$this->handler->consumeRememberMeCookie($rememberMeDetails);
}
}
0