Skip to content

Commit a8d5dd0

Browse files
jakzalfabpot
authored andcommitted
[Security][SecurityBundle] Use csrf_token_id instead of deprecated intention
1 parent 9d6057c commit a8d5dd0

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

Firewall/LogoutListener.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,21 @@ public function __construct(TokenStorageInterface $tokenStorage, HttpUtils $http
5757
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
5858
}
5959

60+
if (isset($options['intention'])) {
61+
if (isset($options['csrf_token_id'])) {
62+
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__));
63+
}
64+
65+
@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);
66+
67+
$options['csrf_token_id'] = $options['intention'];
68+
}
69+
6070
$this->tokenStorage = $tokenStorage;
6171
$this->httpUtils = $httpUtils;
6272
$this->options = array_merge(array(
6373
'csrf_parameter' => '_csrf_token',
64-
'intention' => 'logout',
74+
'csrf_token_id' => 'logout',
6575
'logout_path' => '/logout',
6676
), $options);
6777
$this->successHandler = $successHandler;
@@ -101,7 +111,7 @@ public function handle(GetResponseEvent $event)
101111
if (null !== $this->csrfTokenManager) {
102112
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
103113

104-
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
114+
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
105115
throw new LogoutException('Invalid CSRF token.');
106116
}
107117
}

Firewall/SimpleFormAuthenticationListener.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,24 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
7070
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
7171
}
7272

73+
if (isset($options['intention'])) {
74+
if (isset($options['csrf_token_id'])) {
75+
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__));
76+
}
77+
78+
@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);
79+
80+
$options['csrf_token_id'] = $options['intention'];
81+
}
82+
7383
$this->simpleAuthenticator = $simpleAuthenticator;
7484
$this->csrfTokenManager = $csrfTokenManager;
7585

7686
$options = array_merge(array(
7787
'username_parameter' => '_username',
7888
'password_parameter' => '_password',
7989
'csrf_parameter' => '_csrf_token',
80-
'intention' => 'authenticate',
90+
'csrf_token_id' => 'authenticate',
8191
'post_only' => true,
8292
), $options);
8393

@@ -104,7 +114,7 @@ protected function attemptAuthentication(Request $request)
104114
if (null !== $this->csrfTokenManager) {
105115
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
106116

107-
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
117+
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
108118
throw new InvalidCsrfTokenException('Invalid CSRF token.');
109119
}
110120
}

Firewall/UsernamePasswordFormAuthenticationListener.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
4848
throw new InvalidArgumentException('The CSRF token manager should be an instance of CsrfProviderInterface or CsrfTokenManagerInterface.');
4949
}
5050

51+
if (isset($options['intention'])) {
52+
if (isset($options['csrf_token_id'])) {
53+
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__));
54+
}
55+
56+
@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);
57+
58+
$options['csrf_token_id'] = $options['intention'];
59+
}
60+
5161
parent::__construct($tokenStorage, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, array_merge(array(
5262
'username_parameter' => '_username',
5363
'password_parameter' => '_password',
5464
'csrf_parameter' => '_csrf_token',
55-
'intention' => 'authenticate',
65+
'csrf_token_id' => 'authenticate',
5666
'post_only' => true,
5767
), $options), $logger, $dispatcher);
5868

@@ -79,7 +89,7 @@ protected function attemptAuthentication(Request $request)
7989
if (null !== $this->csrfTokenManager) {
8090
$csrfToken = ParameterBagUtils::getRequestParameterValue($request, $this->options['csrf_parameter']);
8191

82-
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['intention'], $csrfToken))) {
92+
if (false === $this->csrfTokenManager->isTokenValid(new CsrfToken($this->options['csrf_token_id'], $csrfToken))) {
8393
throw new InvalidCsrfTokenException('Invalid CSRF token.');
8494
}
8595
}

Tests/Firewall/LogoutListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private function getListener($successHandler = null, $tokenManager = null)
213213
$successHandler ?: $this->getSuccessHandler(),
214214
$options = array(
215215
'csrf_parameter' => '_csrf_token',
216-
'intention' => 'logout',
216+
'csrf_token_id' => 'logout',
217217
'logout_path' => '/logout',
218218
'target_url' => '/',
219219
),

0 commit comments

Comments
 (0)