Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 393f9ae

Browse filesBrowse files
committed
minor #32285 [CSRF] add more parameter types (Tobion)
This PR was merged into the 5.0-dev branch. Discussion ---------- [CSRF] add more parameter types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | /no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #32179 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Those have been missing in #32208 Commits ------- d442028 [CSRF] add more parameter types
2 parents f800d01 + d442028 commit 393f9ae
Copy full SHA for 393f9ae

File tree

6 files changed

+17
-26
lines changed
Filter options

6 files changed

+17
-26
lines changed

‎src/Symfony/Component/Security/Csrf/CsrfTokenManager.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Csrf/CsrfTokenManager.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function isTokenValid(CsrfToken $token)
114114
return hash_equals($this->storage->getToken($namespacedId), $token->getValue());
115115
}
116116

117-
private function getNamespace()
117+
private function getNamespace(): string
118118
{
119119
return \is_callable($ns = $this->namespace) ? $ns() : $ns;
120120
}

‎src/Symfony/Component/Security/Csrf/CsrfTokenManagerInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Csrf/CsrfTokenManagerInterface.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public function refreshToken(string $tokenId);
4949
/**
5050
* Invalidates the CSRF token with the given ID, if one exists.
5151
*
52-
* @param string $tokenId The token ID
53-
*
5452
* @return string|null Returns the removed token value if one existed, NULL
5553
* otherwise
5654
*/

‎src/Symfony/Component/Security/Csrf/Tests/CsrfTokenManagerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Csrf/Tests/CsrfTokenManagerTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public function testRemoveToken($namespace, $manager, $storage)
160160
public function testNamespaced()
161161
{
162162
$generator = $this->getMockBuilder('Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface')->getMock();
163+
$generator->expects($this->once())->method('generateToken')->willReturn('random');
163164
$storage = $this->getMockBuilder('Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface')->getMock();
164165

165166
$requestStack = new RequestStack();
@@ -169,6 +170,7 @@ public function testNamespaced()
169170

170171
$token = $manager->getToken('foo');
171172
$this->assertSame('foo', $token->getId());
173+
$this->assertSame('random', $token->getValue());
172174
}
173175

174176
public function getManagerGeneratorAndStorage()

‎src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Csrf/TokenStorage/NativeSessionTokenStorage.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(string $namespace = self::SESSION_NAMESPACE)
4141
/**
4242
* {@inheritdoc}
4343
*/
44-
public function getToken($tokenId)
44+
public function getToken(string $tokenId)
4545
{
4646
if (!$this->sessionStarted) {
4747
$this->startSession();
@@ -57,19 +57,19 @@ public function getToken($tokenId)
5757
/**
5858
* {@inheritdoc}
5959
*/
60-
public function setToken($tokenId, $token)
60+
public function setToken(string $tokenId, string $token)
6161
{
6262
if (!$this->sessionStarted) {
6363
$this->startSession();
6464
}
6565

66-
$_SESSION[$this->namespace][$tokenId] = (string) $token;
66+
$_SESSION[$this->namespace][$tokenId] = $token;
6767
}
6868

6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function hasToken($tokenId)
72+
public function hasToken(string $tokenId)
7373
{
7474
if (!$this->sessionStarted) {
7575
$this->startSession();
@@ -81,7 +81,7 @@ public function hasToken($tokenId)
8181
/**
8282
* {@inheritdoc}
8383
*/
84-
public function removeToken($tokenId)
84+
public function removeToken(string $tokenId)
8585
{
8686
if (!$this->sessionStarted) {
8787
$this->startSession();

‎src/Symfony/Component/Security/Csrf/TokenStorage/SessionTokenStorage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Csrf/TokenStorage/SessionTokenStorage.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(SessionInterface $session, string $namespace = self:
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
public function getToken($tokenId)
47+
public function getToken(string $tokenId)
4848
{
4949
if (!$this->session->isStarted()) {
5050
$this->session->start();
@@ -60,19 +60,19 @@ public function getToken($tokenId)
6060
/**
6161
* {@inheritdoc}
6262
*/
63-
public function setToken($tokenId, $token)
63+
public function setToken(string $tokenId, string $token)
6464
{
6565
if (!$this->session->isStarted()) {
6666
$this->session->start();
6767
}
6868

69-
$this->session->set($this->namespace.'/'.$tokenId, (string) $token);
69+
$this->session->set($this->namespace.'/'.$tokenId, $token);
7070
}
7171

7272
/**
7373
* {@inheritdoc}
7474
*/
75-
public function hasToken($tokenId)
75+
public function hasToken(string $tokenId)
7676
{
7777
if (!$this->session->isStarted()) {
7878
$this->session->start();
@@ -84,7 +84,7 @@ public function hasToken($tokenId)
8484
/**
8585
* {@inheritdoc}
8686
*/
87-
public function removeToken($tokenId)
87+
public function removeToken(string $tokenId)
8888
{
8989
if (!$this->session->isStarted()) {
9090
$this->session->start();

‎src/Symfony/Component/Security/Csrf/TokenStorage/TokenStorageInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Csrf/TokenStorage/TokenStorageInterface.php
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,29 @@ interface TokenStorageInterface
2121
/**
2222
* Reads a stored CSRF token.
2323
*
24-
* @param string $tokenId The token ID
25-
*
2624
* @return string The stored token
2725
*
2826
* @throws \Symfony\Component\Security\Csrf\Exception\TokenNotFoundException If the token ID does not exist
2927
*/
30-
public function getToken($tokenId);
28+
public function getToken(string $tokenId);
3129

3230
/**
3331
* Stores a CSRF token.
34-
*
35-
* @param string $tokenId The token ID
36-
* @param string $token The CSRF token
3732
*/
38-
public function setToken($tokenId, $token);
33+
public function setToken(string $tokenId, string $token);
3934

4035
/**
4136
* Removes a CSRF token.
4237
*
43-
* @param string $tokenId The token ID
44-
*
4538
* @return string|null Returns the removed token if one existed, NULL
4639
* otherwise
4740
*/
48-
public function removeToken($tokenId);
41+
public function removeToken(string $tokenId);
4942

5043
/**
5144
* Checks whether a token with the given token ID exists.
5245
*
53-
* @param string $tokenId The token ID
54-
*
5546
* @return bool Whether a token exists with the given ID
5647
*/
57-
public function hasToken($tokenId);
48+
public function hasToken(string $tokenId);
5849
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.