Skip to content
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

[security-bundle/5.3] Configure auto password hasher #981

Merged
merged 1 commit into from
Aug 12, 2021

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented Aug 9, 2021

Q A
License MIT
Doc issue/PR -

This PR configures a default "auto" password hasher on 5.3.

If one creates a user class implementing PasswordAuthenticatedUserInterface (i.e. authenticated via password), then one just has to use the password-hashing related services that are wired from this config.
In case these services are not used anywhere, they are just removed from the container as usual.

Fixes symfony/symfony#42071

@github-actions
Copy link

github-actions bot commented Aug 9, 2021

Diff between recipe versions

Thanks for the PR 😍

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

symfony/security-bundle

3.3 vs 4.4
diff --git a/symfony/security-bundle/3.3/config/packages/security.yaml b/symfony/security-bundle/4.4/config/packages/security.yaml
index f7ae4b7..811681e 100644
--- a/symfony/security-bundle/3.3/config/packages/security.yaml
+++ b/symfony/security-bundle/4.4/config/packages/security.yaml
@@ -7,7 +7,7 @@ security:
             pattern: ^/(_(profiler|wdt)|css|images|js)/
             security: false
         main:
-            anonymous: true
+            anonymous: lazy
             provider: users_in_memory
 
             # activate different ways to authenticate
4.4 vs 5.1
diff --git a/symfony/security-bundle/4.4/config/packages/security.yaml b/symfony/security-bundle/5.1/config/packages/security.yaml
index 811681e..0e4cf3d 100644
--- a/symfony/security-bundle/4.4/config/packages/security.yaml
+++ b/symfony/security-bundle/5.1/config/packages/security.yaml
@@ -7,7 +7,8 @@ security:
             pattern: ^/(_(profiler|wdt)|css|images|js)/
             security: false
         main:
-            anonymous: lazy
+            anonymous: true
+            lazy: true
             provider: users_in_memory
 
             # activate different ways to authenticate
5.1 vs 5.3
diff --git a/symfony/security-bundle/5.1/config/packages/security.yaml b/symfony/security-bundle/5.3/config/packages/security.yaml
index 0e4cf3d..7510cc1 100644
--- a/symfony/security-bundle/5.1/config/packages/security.yaml
+++ b/symfony/security-bundle/5.3/config/packages/security.yaml
@@ -1,4 +1,9 @@
 security:
+    # https://symfony.com/doc/current/security/experimental_authenticators.html
+    enable_authenticator_manager: true
+    # https://symfony.com/doc/current/security.html#c-hashing-passwords
+    password_hashers:
+        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
     # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
     providers:
         users_in_memory: { memory: null }
@@ -7,7 +12,6 @@ security:
             pattern: ^/(_(profiler|wdt)|css|images|js)/
             security: false
         main:
-            anonymous: true
             lazy: true
             provider: users_in_memory
 

@fabpot fabpot merged commit a03800e into symfony:master Aug 12, 2021
@chalasr chalasr deleted the pwd-hashers branch August 12, 2021 10:09
leofeyer pushed a commit to contao/contao that referenced this pull request Aug 24, 2023
Description
-----------

In Symfony 5.3 this config was added to the default security config in order to enable the `auto` password hasher for all user classes that implement this interface (see symfony/recipes#981) - which `Contao\User` also implements.

I think we should do the same in the `contao/managed-edition`. This way you don't have to define this yourself in case you are using HTTP Basic Authentication for some controller outside Contao's own firewalls. For instance, in [this example](#6220 (comment)) the line

```php
$extensionConfig['password_hashers'][InMemoryUser::class] = 'auto';
```

could be omitted then.

Commits
-------

84c6d47 set auto password hasher to auto for all
ab0a671 also set password hasher for Contao\User specifically
593d244 update README and test config
leofeyer pushed a commit to contao/core-bundle that referenced this pull request Aug 24, 2023
Description
-----------

In Symfony 5.3 this config was added to the default security config in order to enable the `auto` password hasher for all user classes that implement this interface (see symfony/recipes#981) - which `Contao\User` also implements.

I think we should do the same in the `contao/managed-edition`. This way you don't have to define this yourself in case you are using HTTP Basic Authentication for some controller outside Contao's own firewalls. For instance, in [this example](contao/contao#6220 (comment)) the line

```php
$extensionConfig['password_hashers'][InMemoryUser::class] = 'auto';
```

could be omitted then.

Commits
-------

84c6d47a set auto password hasher to auto for all
ab0a6719 also set password hasher for Contao\User specifically
593d2448 update README and test config
leofeyer pushed a commit to contao/manager-bundle that referenced this pull request Aug 24, 2023
Description
-----------

In Symfony 5.3 this config was added to the default security config in order to enable the `auto` password hasher for all user classes that implement this interface (see symfony/recipes#981) - which `Contao\User` also implements.

I think we should do the same in the `contao/managed-edition`. This way you don't have to define this yourself in case you are using HTTP Basic Authentication for some controller outside Contao's own firewalls. For instance, in [this example](contao/contao#6220 (comment)) the line

```php
$extensionConfig['password_hashers'][InMemoryUser::class] = 'auto';
```

could be omitted then.

Commits
-------

84c6d47a set auto password hasher to auto for all
ab0a6719 also set password hasher for Contao\User specifically
593d2448 update README and test config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security] Use default password hasher by default
5 participants