-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Security][SecurityBundle] Use csrf_token_id instead of deprecated intention #16722
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
Changes from all commits
a4823b7
ae4d588
ac35350
50856ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,7 +299,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a | |
$listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.logout_listener')); | ||
$listener->replaceArgument(3, array( | ||
'csrf_parameter' => $firewall['logout']['csrf_parameter'], | ||
'intention' => $firewall['logout']['csrf_token_id'], | ||
'csrf_token_id' => $firewall['logout']['csrf_token_id'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is wrong as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm making changes to the security component just now :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
'logout_path' => $firewall['logout']['path'], | ||
)); | ||
$listeners[] = new Reference($listenerId); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,11 +57,21 @@ public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $http | |
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.'); | ||
} | ||
|
||
if (isset($options['intention'])) { | ||
if (isset($options['csrf_token_id'])) { | ||
throw new \InvalidArgumentException(sprintf('You should only define an option for one of "intention" or "csrf_token_id" for the "%s". Use the "csrf_token_id" as it replaces "intention".', __CLASS__)); | ||
} | ||
|
||
@trigger_error('The "intention" option for the '.__CLASS__.' is deprecated since version 2.8 and will be removed in 3.0. Use the "csrf_token_id" option instead.', E_USER_DEPRECATED); | ||
|
||
$options['csrf_token_id'] = $options['intention']; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about throwing an exception if both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for the other listeners There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's worth it in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mistakes happen and we need to help people fix them so if it's not too much work I'd say yes... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for throwing an exception. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
$this->tokenStorage = $tokenStorage; | ||
$this->httpUtils = $httpUtils; | ||
$this->options = array_merge(array( | ||
'csrf_parameter' => '_csrf_token', | ||
'intention' => 'logout', | ||
'csrf_token_id' => 'logout', | ||
'logout_path' => '/logout', | ||
), $options); | ||
$this->successHandler = $successHandler; | ||
|
@@ -101,7 +111,7 @@ public function handle(GetResponseEvent $event) | |
if (null !== $this->csrfTokenManager) { | ||
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']); | ||
|
||
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) { | ||
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) { | ||
throw new LogoutException('Invalid CSRF token.'); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change also documented in the upgrade file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now it is ;)