Skip to content

[Security\Http] Fix handling secure: auto using the new RememberMeAuthenticator #41254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
$loader->load('security_authenticator_remember_me.php');
}

if ('auto' === $config['secure']) {
$config['secure'] = null;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the corresponding logic from the old implementation:

if ('auto' === $mergedOptions['secure']) {
$mergedOptions['secure'] = null;
}

It is needed for:
$this->options['secure'] ?? $request->isSecure(),


// create remember me handler (which manage the remember-me cookies)
$rememberMeHandlerId = 'security.authenticator.remember_me_handler.'.$firewallName;
if (isset($config['service']) && isset($config['token_provider'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ public function testSessionRememberMeSecureCookieFlagAuto($https, $expectedSecur
]);

$cookies = $client->getResponse()->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
$this->assertSame($expectedSecureFlag, $cookies['']['/']['REMEMBERME']->isSecure());
}

/** @dataProvider getSessionRememberMeSecureCookieFlagAutoHttpsMap */
public function testOldSessionRememberMeSecureCookieFlagAuto($https, $expectedSecureFlag)
{
$client = $this->createClient(['test_case' => 'RememberMeCookie', 'root_config' => 'legacy_config.yml']);

$this->assertEquals($expectedSecureFlag, $cookies['']['/']['REMEMBERME']->isSecure());
$client->request('POST', '/login', [
'_username' => 'test',
'_password' => 'test',
], [], [
'HTTPS' => (int) $https,
]);

$cookies = $client->getResponse()->headers->getCookies(ResponseHeaderBag::COOKIES_ARRAY);
$this->assertSame($expectedSecureFlag, $cookies['']['/']['REMEMBERME']->isSecure());
}

public function getSessionRememberMeSecureCookieFlagAutoHttpsMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ imports:
- { resource: ./../config/framework.yml }

security:
enable_authenticator_manager: true
password_hashers:
Symfony\Component\Security\Core\User\InMemoryUser: plaintext

Expand All @@ -22,4 +23,3 @@ security:
secret: key
secure: auto
logout: ~
anonymous: ~
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
imports:
- { resource: ./../config/framework.yml }

security:
password_hashers:
Symfony\Component\Security\Core\User\InMemoryUser: 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: ~