Skip to content

[SecurityBundle] Rename firewalls.logout.csrf_token_generator to firewalls.logout.csrf_token_manager #48387

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 1 commit into from
Dec 22, 2022
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
3 changes: 2 additions & 1 deletion UPGRADE-6.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ SecurityBundle
Validator
--------------

* Implementing the `ConstraintViolationInterface` without implementing the `getConstraint()` method is deprecated
* Implementing the `ConstraintViolationInterface` without implementing the `getConstraint()` method is deprecated
* Deprecate the `security.firewalls.logout.csrf_token_generator` config option, use `security.firewalls.logout.csrf_token_manager` instead
Copy link
Member

Choose a reason for hiding this comment

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

this should not be in the Validator section

Copy link
Member

Choose a reason for hiding this comment

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

fixed in 377982f

1 change: 1 addition & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CHANGELOG
* Add `StatelessAuthenticatorFactoryInterface` for authenticators targeting `stateless` firewalls only and that don't require a user provider
* Modify "icon.svg" to improve accessibility for blind/low vision users
* Make `Security::login()` return the authenticator response
* Deprecate the `security.firewalls.logout.csrf_token_generator` config option, use `security.firewalls.logout.csrf_token_manager` instead

6.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,20 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
->treatTrueLike([])
->canBeUnset()
->beforeNormalization()
->ifTrue(fn ($v): bool => \is_array($v) && (isset($v['csrf_token_generator']) xor isset($v['enable_csrf'])))
->ifTrue(fn ($v): bool => isset($v['csrf_token_generator']) && !isset($v['csrf_token_manager']))
->then(function (array $v): array {
if (isset($v['csrf_token_generator'])) {
$v['csrf_token_manager'] = $v['csrf_token_generator'];

return $v;
})
->end()
->beforeNormalization()
->ifTrue(fn ($v): bool => \is_array($v) && (isset($v['csrf_token_manager']) xor isset($v['enable_csrf'])))
->then(function (array $v): array {
if (isset($v['csrf_token_manager'])) {
$v['enable_csrf'] = true;
} elseif ($v['enable_csrf']) {
$v['csrf_token_generator'] = 'security.csrf.token_manager';
$v['csrf_token_manager'] = 'security.csrf.token_manager';
}

return $v;
Expand All @@ -232,7 +240,14 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
->booleanNode('enable_csrf')->defaultNull()->end()
->scalarNode('csrf_token_id')->defaultValue('logout')->end()
->scalarNode('csrf_parameter')->defaultValue('_csrf_token')->end()
->scalarNode('csrf_token_generator')->end()
->scalarNode('csrf_token_generator')
->setDeprecated(
'symfony/security-bundle',
'6.3',
'The "%node%" option is deprecated. Use "csrf_token_manager" instead.'
)
->end()
->scalarNode('csrf_token_manager')->end()
->scalarNode('path')->defaultValue('/logout')->end()
->scalarNode('target')->defaultValue('/')->end()
->booleanNode('invalidate_session')->defaultTrue()->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $

// add CSRF provider
if ($firewall['logout']['enable_csrf']) {
$logoutListener->addArgument(new Reference($firewall['logout']['csrf_token_generator']));
$logoutListener->addArgument(new Reference($firewall['logout']['csrf_token_manager']));
}

// add session logout listener
Expand All @@ -482,7 +482,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
$firewall['logout']['path'],
$firewall['logout']['csrf_token_id'],
$firewall['logout']['csrf_parameter'],
isset($firewall['logout']['csrf_token_generator']) ? new Reference($firewall['logout']['csrf_token_generator']) : null,
isset($firewall['logout']['csrf_token_manager']) ? new Reference($firewall['logout']['csrf_token_manager']) : null,
false === $firewall['stateless'] && isset($firewall['context']) ? $firewall['context'] : null,
])
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testCsrfAliases()
'firewalls' => [
'stub' => [
'logout' => [
'csrf_token_generator' => 'a_token_generator',
'csrf_token_manager' => 'a_token_manager',
'csrf_token_id' => 'a_token_id',
],
],
Expand All @@ -82,8 +82,8 @@ public function testCsrfAliases()
$processor = new Processor();
$configuration = new MainConfiguration([], []);
$processedConfig = $processor->processConfiguration($configuration, [$config]);
$this->assertArrayHasKey('csrf_token_generator', $processedConfig['firewalls']['stub']['logout']);
$this->assertEquals('a_token_generator', $processedConfig['firewalls']['stub']['logout']['csrf_token_generator']);
$this->assertArrayHasKey('csrf_token_manager', $processedConfig['firewalls']['stub']['logout']);
$this->assertEquals('a_token_manager', $processedConfig['firewalls']['stub']['logout']['csrf_token_manager']);
$this->assertArrayHasKey('csrf_token_id', $processedConfig['firewalls']['stub']['logout']);
$this->assertEquals('a_token_id', $processedConfig['firewalls']['stub']['logout']['csrf_token_id']);
}
Expand All @@ -92,13 +92,13 @@ public function testLogoutCsrf()
{
$config = [
'firewalls' => [
'custom_token_generator' => [
'custom_token_manager' => [
'logout' => [
'csrf_token_generator' => 'a_token_generator',
'csrf_token_manager' => 'a_token_manager',
'csrf_token_id' => 'a_token_id',
],
],
'default_token_generator' => [
'default_token_manager' => [
'logout' => [
'enable_csrf' => true,
'csrf_token_id' => 'a_token_id',
Expand All @@ -121,18 +121,18 @@ public function testLogoutCsrf()
$processedConfig = $processor->processConfiguration($configuration, [$config]);

$assertions = [
'custom_token_generator' => [true, 'a_token_generator'],
'default_token_generator' => [true, 'security.csrf.token_manager'],
'custom_token_manager' => [true, 'a_token_manager'],
'default_token_manager' => [true, 'security.csrf.token_manager'],
'disabled_csrf' => [false, null],
'empty' => [false, null],
];
foreach ($assertions as $firewallName => [$enabled, $tokenGenerator]) {
foreach ($assertions as $firewallName => [$enabled, $tokenManager]) {
$this->assertEquals($enabled, $processedConfig['firewalls'][$firewallName]['logout']['enable_csrf']);
if ($tokenGenerator) {
$this->assertEquals($tokenGenerator, $processedConfig['firewalls'][$firewallName]['logout']['csrf_token_generator']);
if ($tokenManager) {
$this->assertEquals($tokenManager, $processedConfig['firewalls'][$firewallName]['logout']['csrf_token_manager']);
$this->assertEquals('a_token_id', $processedConfig['firewalls'][$firewallName]['logout']['csrf_token_id']);
} else {
$this->assertArrayNotHasKey('csrf_token_generator', $processedConfig['firewalls'][$firewallName]['logout']);
$this->assertArrayNotHasKey('csrf_token_manager', $processedConfig['firewalls'][$firewallName]['logout']);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ security:
logout:
path: /logout_path
target: /
csrf_token_generator: security.csrf.token_manager
csrf_token_manager: security.csrf.token_manager

access_control:
- { path: .*, roles: IS_AUTHENTICATED_FULLY }