Skip to content

[PasswordHasher] Generates a PHP fatal error when using auto algorithm #41571

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

Closed
matason opened this issue Jun 6, 2021 · 0 comments · Fixed by #41572
Closed

[PasswordHasher] Generates a PHP fatal error when using auto algorithm #41571

matason opened this issue Jun 6, 2021 · 0 comments · Fixed by #41572

Comments

@matason
Copy link
Contributor

matason commented Jun 6, 2021

Symfony version(s) affected: 5.3.x

Description
When using the auto algorithm in the PasswordHasher component outside of a Symfony project, a PHP warning and fatal error is generated:

PHP Notice:  Undefined index: hash_algorithm in /symfony/password-hasher/Hasher/PasswordHasherFactory.php on line 119
PHP Fatal error:  Uncaught InvalidArgumentException: "class" must be set in {"algorithm":null} in /symfony/password-hasher/Hasher/PasswordHasherFactory.php:86

How to reproduce

  • Create a simple project: composer init && composer require symfony/password-hasher
  • Create a PHP file with the following code to exercise the PasswordHasher
<?php

require './vendor/autoload.php';

use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;

$factory = new PasswordHasherFactory(
    [
        'auto' => ['algorithm' => 'auto'],
    ]
);

$passwordHasher = $factory->getPasswordHasher('auto');

Possible Solution
Check if $config['hash_algorithm'] is set before adding it to the list of algorithms (and prevent a null being added).

Additional context
N/A

@matason matason added the Bug label Jun 6, 2021
derrabus added a commit that referenced this issue Jun 7, 2021
…lgorithm (matason)

This PR was merged into the 5.3 branch.

Discussion
----------

[PasswordHasher] Prevent PHP fatal error when using auto algorithm

| Q             | A
| ------------- | ---
| Branch?       | 5.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #41571
| License       | MIT
| Doc PR        | N/A

Fixes a PHP fatal error that occurs when using the auto algorithm of the PasswordHasher in a standalone project.

Commits
-------

dca28a2 [PasswordHasher] Prevent PHP fatal error when using auto algorithm
@matason matason closed this as completed Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants