Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #34671 [Security] Fix clearing remember-me cookie after deauthent…
…ication (chalasr) This PR was merged into the 3.4 branch. Discussion ---------- [Security] Fix clearing remember-me cookie after deauthentication | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #26379 | License | MIT | Doc PR | - If you are using the `remember_me` listener and the refreshed user is deauthenticated, you are still logged in because the remember-me cookie does not get cleared. This fixes it. Commits ------- d625a73 [Security] Fix clearing remember-me cookie after deauthentication
- Loading branch information
Showing
9 changed files
with
177 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/Symfony/Bundle/SecurityBundle/Tests/Functional/ClearRememberMeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Tests\Functional; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\User\InMemoryUserProvider; | ||
use Symfony\Component\Security\Core\User\User; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
|
||
class ClearRememberMeTest extends AbstractWebTestCase | ||
{ | ||
public function testUserChangeClearsCookie() | ||
{ | ||
$client = $this->createClient(['test_case' => 'ClearRememberMe', 'root_config' => 'config.yml']); | ||
|
||
$client->request('POST', '/login', [ | ||
'_username' => 'johannes', | ||
'_password' => 'test', | ||
]); | ||
|
||
$this->assertSame(302, $client->getResponse()->getStatusCode()); | ||
$cookieJar = $client->getCookieJar(); | ||
$this->assertNotNull($cookieJar->get('REMEMBERME')); | ||
|
||
$client->request('GET', '/foo'); | ||
$this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
$this->assertNull($cookieJar->get('REMEMBERME')); | ||
} | ||
} | ||
|
||
class RememberMeFooController | ||
{ | ||
public function __invoke(UserInterface $user) | ||
{ | ||
return new Response($user->getUsername()); | ||
} | ||
} | ||
|
||
class RememberMeUserProvider implements UserProviderInterface | ||
{ | ||
private $inner; | ||
|
||
public function __construct(InMemoryUserProvider $inner) | ||
{ | ||
$this->inner = $inner; | ||
} | ||
|
||
public function loadUserByUsername($username) | ||
{ | ||
return $this->inner->loadUserByUsername($username); | ||
} | ||
|
||
public function refreshUser(UserInterface $user) | ||
{ | ||
$user = $this->inner->refreshUser($user); | ||
|
||
$alterUser = \Closure::bind(function (User $user) { $user->password = 'foo'; }, null, User::class); | ||
$alterUser($user); | ||
|
||
return $user; | ||
} | ||
|
||
public function supportsClass($class) | ||
{ | ||
return $this->inner->supportsClass($class); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ClearRememberMe/bundles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Bundle\SecurityBundle\SecurityBundle; | ||
|
||
return [ | ||
new FrameworkBundle(), | ||
new SecurityBundle(), | ||
]; |
32 changes: 32 additions & 0 deletions
32
src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ClearRememberMe/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
imports: | ||
- { resource: ./../config/framework.yml } | ||
|
||
security: | ||
encoders: | ||
Symfony\Component\Security\Core\User\User: plaintext | ||
|
||
providers: | ||
in_memory: | ||
memory: | ||
users: | ||
johannes: { password: test, roles: [ROLE_USER] } | ||
|
||
firewalls: | ||
default: | ||
form_login: | ||
check_path: login | ||
remember_me: true | ||
remember_me: | ||
always_remember_me: true | ||
secret: key | ||
anonymous: ~ | ||
logout_on_user_change: true | ||
|
||
access_control: | ||
- { path: ^/foo, roles: ROLE_USER } | ||
|
||
services: | ||
Symfony\Bundle\SecurityBundle\Tests\Functional\RememberMeUserProvider: | ||
public: true | ||
decorates: security.user.provider.concrete.in_memory | ||
arguments: ['@Symfony\Bundle\SecurityBundle\Tests\Functional\RememberMeUserProvider.inner'] |
7 changes: 7 additions & 0 deletions
7
src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/ClearRememberMe/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
login: | ||
path: /login | ||
|
||
foo: | ||
path: /foo | ||
defaults: | ||
_controller: Symfony\Bundle\SecurityBundle\Tests\Functional\RememberMeFooController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters