Skip to content

[Security] remove plaintext password hasher usage #20986

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from
Open
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
90 changes: 40 additions & 50 deletions security/passwords.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,75 +124,65 @@

.. code-block:: yaml

# config/packages/test/security.yaml
security:
# ...

password_hashers:
# Use your user class name here
App\Entity\User:
algorithm: plaintext # disable hashing (only do this in tests!)

# or use the lowest possible values
App\Entity\User:
algorithm: auto # This should be the same value as in config/packages/security.yaml
cost: 4 # Lowest possible value for bcrypt
time_cost: 3 # Lowest possible value for argon
memory_cost: 10 # Lowest possible value for argon
# config/packages/security.yaml
when@test:
security:
# ...

password_hashers:
# Use your user class name here
App\Entity\User:
algorithm: auto
cost: 4 # Lowest possible value for bcrypt
time_cost: 3 # Lowest possible value for argon
memory_cost: 10 # Lowest possible value for argon

Check failure on line 138 in security/passwords.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Cache Warmup] In SecurityExtension.php line 98: The SecurityBundle is enabled but is not configured. Try running "composer symfony:recipes:install symfony/security-bundle".

.. code-block:: xml

<!-- config/packages/test/security.xml -->
<!-- config/packages/security.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<srv:container xmlns="http://symfony.com/schema/dic/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:srv="http://symfony.com/schema/dic/services"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<config>
<!-- class: Use your user class name here -->
<!-- algorithm: disable hashing (only do this in tests!) -->
<security:password-hasher
class="App\Entity\User"
algorithm="plaintext"
/>

<!-- or use the lowest possible values -->
<!-- algorithm: This should be the same value as in config/packages/security.yaml -->
<!-- cost: Lowest possible value for bcrypt -->
<!-- time_cost: Lowest possible value for argon -->
<!-- memory_cost: Lowest possible value for argon -->
<security:password-hasher
class="App\Entity\User"
algorithm="auto"
cost="4"
time_cost="3"
memory_cost="10"
/>
</config>
<when env="test">
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not super confident on these xml/php config changes - please review.

Copy link
Member

Choose a reason for hiding this comment

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

should be <srv:when> as this code snippet defines the SecurityBundle XML namespace as the default namespace and uses the srv alias for the XML namespace of the DI component

Copy link
Member

Choose a reason for hiding this comment

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

hmm, actually, this XML code snippet is already a mess, as it mixes cases, sometimes using a security alias (not registered on the top-level element) for nodes of the SecurityBundle config

<config>
<!-- class: Use your user class name here -->
<!-- cost: Lowest possible value for bcrypt -->
<!-- time_cost: Lowest possible value for argon -->
<!-- memory_cost: Lowest possible value for argon -->
<security:password-hasher
class="App\Entity\User"
algorithm="auto"
cost="4"
time_cost="3"
memory_cost="10"
/>
</config>
</when>
</srv:container>

.. code-block:: php

// config/packages/test/security.php
// config/packages/security.php
use App\Entity\User;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Config\SecurityConfig;

return static function (SecurityConfig $security): void {
return static function (SecurityConfig $security, ContainerConfigurator $container): void {
// ...

// Use your user class name here
$security->passwordHasher(User::class)
->algorithm('plaintext'); // disable hashing (only do this in tests!)

// or use the lowest possible values
$security->passwordHasher(User::class)
->algorithm('auto') // This should be the same value as in config/packages/security.yaml
->cost(4) // Lowest possible value for bcrypt
->timeCost(2) // Lowest possible value for argon
->memoryCost(10) // Lowest possible value for argon
;
if ('test' === $container->env()) {
// Use your user class name here
$security->passwordHasher(User::class)
->algorithm('auto') // This should be the same value as in config/packages/security.yaml
->cost(4) // Lowest possible value for bcrypt
->timeCost(2) // Lowest possible value for argon
->memoryCost(10) // Lowest possible value for argon
;
}
};

Hashing the Password
Expand Down
Loading