Skip to content

Commit d7eb8ff

Browse files
Tobionfabpot
authored andcommitted
[Csrf] component fixes
1 parent 4c164ca commit d7eb8ff

File tree

12 files changed

+33
-40
lines changed

12 files changed

+33
-40
lines changed

src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AttributeBag implements AttributeBagInterface, \IteratorAggregate, \Counta
3131
/**
3232
* Constructor.
3333
*
34-
* @param string $storageKey The key used to store attributes in the session.
34+
* @param string $storageKey The key used to store attributes in the session
3535
*/
3636
public function __construct($storageKey = '_sf2_attributes')
3737
{
@@ -148,7 +148,7 @@ public function getIterator()
148148
/**
149149
* Returns the number of attributes.
150150
*
151-
* @return int The number of attributes
151+
* @return integer The number of attributes
152152
*/
153153
public function count()
154154
{

src/Symfony/Component/HttpFoundation/Session/Attribute/AttributeBagInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function has($name);
3333
* Returns an attribute.
3434
*
3535
* @param string $name The attribute name
36-
* @param mixed $default The default value if not found.
36+
* @param mixed $default The default value if not found
3737
*
3838
* @return mixed
3939
*/
@@ -66,7 +66,7 @@ public function replace(array $attributes);
6666
*
6767
* @param string $name
6868
*
69-
* @return mixed The removed value
69+
* @return mixed The removed value or null when it does not exist
7070
*/
7171
public function remove($name);
7272
}

src/Symfony/Component/HttpFoundation/Session/SessionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function replace(array $attributes);
163163
*
164164
* @param string $name
165165
*
166-
* @return mixed The removed value
166+
* @return mixed The removed value or null when it does not exist
167167
*
168168
* @api
169169
*/

src/Symfony/Component/Security/Csrf/CsrfToken.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class CsrfToken
2828
*/
2929
private $value;
3030

31+
/**
32+
* Constructor.
33+
*
34+
* @param string $id The token ID
35+
* @param string $value The actual token value
36+
*/
3137
public function __construct($id, $value)
3238
{
3339
$this->id = (string) $id;
@@ -57,7 +63,7 @@ public function getValue()
5763
/**
5864
* Returns the value of the CSRF token.
5965
*
60-
* @return string The token value.
66+
* @return string The token value
6167
*/
6268
public function __toString()
6369
{

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,14 @@ class CsrfTokenManager implements CsrfTokenManagerInterface
3737
/**
3838
* Creates a new CSRF provider using PHP's native session storage.
3939
*
40-
* @param TokenGeneratorInterface $generator The token generator
41-
* @param TokenStorageInterface $storage The storage for storing
42-
* generated CSRF tokens
43-
*
40+
* @param TokenGeneratorInterface|null $generator The token generator
41+
* @param TokenStorageInterface|null $storage The storage for storing
42+
* generated CSRF tokens
4443
*/
4544
public function __construct(TokenGeneratorInterface $generator = null, TokenStorageInterface $storage = null)
4645
{
47-
if (null === $generator) {
48-
$generator = new UriSafeTokenGenerator();
49-
}
50-
51-
if (null === $storage) {
52-
$storage = new NativeSessionTokenStorage();
53-
}
54-
55-
$this->generator = $generator;
56-
$this->storage = $storage;
46+
$this->generator = $generator ?: new UriSafeTokenGenerator();
47+
$this->storage = $storage ?: new NativeSessionTokenStorage();
5748
}
5849

5950
/**
@@ -101,6 +92,6 @@ public function isTokenValid(CsrfToken $token)
10192
return false;
10293
}
10394

104-
return StringUtils::equals((string) $this->storage->getToken($token->getId()), $token->getValue());
95+
return StringUtils::equals($this->storage->getToken($token->getId()), $token->getValue());
10596
}
10697
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ interface CsrfTokenManagerInterface
2323
* Returns a CSRF token for the given ID.
2424
*
2525
* If previously no token existed for the given ID, a new token is
26-
* generated. Otherwise the existing token is returned.
26+
* generated. Otherwise the existing token is returned (with the same value,
27+
* not the same instance).
2728
*
2829
* @param string $tokenId The token ID. You may choose an arbitrary value
2930
* for the ID
@@ -51,8 +52,8 @@ public function refreshToken($tokenId);
5152
*
5253
* @param string $tokenId The token ID
5354
*
54-
* @return Boolean Returns true if a token existed for this ID, false
55-
* otherwise
55+
* @return string|null Returns the removed token value if one existed, NULL
56+
* otherwise
5657
*/
5758
public function removeToken($tokenId);
5859

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Form\Tests\Extension\Csrf\CsrfProvider;
12+
namespace Symfony\Component\Security\Csrf\Tests;
1313

1414
use Symfony\Component\Security\Csrf\CsrfToken;
1515
use Symfony\Component\Security\Csrf\CsrfTokenManager;

src/Symfony/Component/Security/Csrf/Tests/TokenGenerator/UriSafeTokenGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Form\Tests\Extension\Csrf\CsrfProvider\TokenGenerator;
12+
namespace Symfony\Component\Security\Csrf\Tests\TokenGenerator;
1313

1414
use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator;
1515

src/Symfony/Component/Security/Csrf/Tests/TokenStorage/NativeSessionTokenStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Form\Tests\Extension\Csrf\CsrfProvider;
12+
namespace Symfony\Component\Security\Csrf\Tests\TokenStorage;
1313

1414
use Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage;
1515

src/Symfony/Component/Security/Csrf/Tests/TokenStorage/SessionTokenStorageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Form\Tests\Extension\Csrf\CsrfProvider;
12+
namespace Symfony\Component\Security\Csrf\Tests\TokenStorage;
1313

1414
use Symfony\Component\Security\Csrf\TokenStorage\SessionTokenStorage;
1515

0 commit comments

Comments
 (0)