Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Security] Handle properly 'auto' option for remember me cookie security
  • Loading branch information
fliespl committed Mar 22, 2021
commit 2bcf69c07196e83fec65e804e528165ec1f63ffb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
}

// remember-me options
$rememberMeServices->replaceArgument(3, array_intersect_key($config, $this->options));
$mergedOptions = array_intersect_key($config, $this->options);
if ('auto' === $mergedOptions['secure']) {
$mergedOptions['secure'] = null;
}

$rememberMeServices->replaceArgument(3, $mergedOptions);

// attach to remember-me aware listeners
$userProviders = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

use Symfony\Component\HttpFoundation\ResponseHeaderBag;

class RememberMeCookieTest extends AbstractWebTestCase
{
/** @dataProvider getSessionRememberMeSecureCookieFlagAutoHttpsMap */
public function testSessionRememberMeSecureCookieFlagAuto($https, $expectedSecureFlag)
{
$client = $this->createClient(['test_case' => 'RememberMeCookie', 'root_config' => 'config.yml']);

$client->request('POST', '/login', [
'_username' => 'test',
'_password' => 'test',
], [], [
'HTTPS' => (int) $https,
]);

$cookies = $client->getResponse()->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);

$this->assertEquals($expectedSecureFlag, $cookies['']['/']['REMEMBERME']->isSecure());
}

public function getSessionRememberMeSecureCookieFlagAutoHttpsMap()
{
return [
[true, true],
[false, false],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;

return [
new FrameworkBundle(),
new SecurityBundle(),
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
imports:
- { resource: ./../config/framework.yml }

security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext

providers:
in_memory:
memory:
users:
test: { password: test, roles: [ROLE_USER] }

firewalls:
default:
form_login:
check_path: login
remember_me: true
require_previous_session: false
remember_me:
always_remember_me: true
secret: key
secure: auto
logout: ~
anonymous: ~
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
login:
path: /login