Skip to content

[Security] Removal deprecated RememberMeToken::getSecret() and RememberMeToken's $secret property #61011

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

Open
wants to merge 4 commits into
base: 8.0
Choose a base branch
from
Open
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 @@ -21,8 +21,6 @@
*/
class RememberMeToken extends AbstractToken
{
private ?string $secret = null;

/**
* @throws \InvalidArgumentException
*/
Expand All @@ -32,11 +30,6 @@ public function __construct(
) {
parent::__construct($user->getRoles());

if (\func_num_args() > 2) {
trigger_deprecation('symfony/security-core', '7.2', 'The "$secret" argument of "%s()" is deprecated.', __METHOD__);
$this->secret = func_get_arg(2);
}

if (!$firewallName) {
throw new InvalidArgumentException('$firewallName must not be empty.');
}
Expand All @@ -49,25 +42,20 @@ public function getFirewallName(): string
return $this->firewallName;
}

/**
* @deprecated since Symfony 7.2
*/
public function getSecret(): string
{
trigger_deprecation('symfony/security-core', '7.2', 'The "%s()" method is deprecated.', __METHOD__);

return $this->secret ??= base64_encode(random_bytes(8));
}

public function __serialize(): array
{
// $this->firewallName should be kept at index 1 for compatibility with payloads generated before Symfony 8
return [$this->secret, $this->firewallName, parent::__serialize()];
// Newly serialized data removes the secret deprecated since Symfony 7.2 and removed in Symfony 8.0
Copy link
Contributor

Choose a reason for hiding this comment

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

to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the comment ? or the method ?

return [$this->firewallName, parent::__serialize()];
}

public function __unserialize(array $data): void
{
[$this->secret, $this->firewallName, $parentData] = $data;
// BC Layer with payloads generated before Symfony 8.0
if (count($data) === 3) {
[, $this->firewallName, $parentData] = $data;
} else {
[$this->firewallName, $parentData] = $data;
}
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
parent::__unserialize($parentData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ public function testConstructor()
$this->assertSame($user, $token->getUser());
}

/**
* @group legacy
*/
public function testSecret()
{
$user = $this->getUser();
$token = new RememberMeToken($user, 'fookey', 'foo');

$this->assertEquals('foo', $token->getSecret());
}

protected function getUser($roles = ['ROLE_FOO'])
{
$user = $this->createMock(UserInterface::class);
Expand Down
1 change: 0 additions & 1 deletion src/Symfony/Component/Security/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"require": {
"php": ">=8.4",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/event-dispatcher-contracts": "^2.5|^3",
"symfony/password-hasher": "^7.4|^8.0",
"symfony/service-contracts": "^2.5|^3"
Expand Down
Loading