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

Skip to content

[SecurityBundle] Throw on using both "id" and "migrate_from" option in hasher config #51670

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
Closed
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 @@ -435,6 +435,10 @@ private function addPasswordHashersSection(ArrayNodeDefinition $rootNode): void
->canBeUnset()
->performNoDeepMerging()
->beforeNormalization()->ifString()->then(fn ($v) => ['algorithm' => $v])->end()
->validate()
->ifTrue(fn ($v) => isset($v['migrate_from'], $v['id']) && 0 !== \count($v['migrate_from']))
->thenInvalid('You cannot use "migrate_from" when using a custom service id.')
Copy link
Member

Choose a reason for hiding this comment

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

As it was silently ignored before, it would be better to trigger a deprecation than throwing an error, to avoid breaking projects in 6.4

Copy link
Contributor Author

@ogizanagi ogizanagi Sep 18, 2023

Choose a reason for hiding this comment

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

Since it would mean such projects are configured in a way the developers think it'll handle the password migration properly, but is not, making them aware of the issue the hard way during upgrade might be better?

The fix for removing this exception is straightforward enough, unless this config is hidden somehow in a dependency or whatever (but I would expect the issue would have been already spotted in such a case).

->end()
->children()
->scalarNode('algorithm')
->cannotBeEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,27 @@ public function testFirewalls()
$configuration = new MainConfiguration(['stub' => $factory], []);
$configuration->getConfigTreeBuilder();
}

public function testHasherThrowsOnServiceIdWithMigrate()
{
$config = [
'password_hashers' => [
'legacy' => 'bcrypt',
'custom' => [
'id' => 'app.custom_hasher',
'migrate_from' => 'legacy',
],
],
];

$config = array_merge(static::$minimalConfig, $config);

$processor = new Processor();
$configuration = new MainConfiguration([], []);

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('Invalid configuration for path "security.password_hashers.custom": You cannot use "migrate_from" when using a custom service id');

$processor->processConfiguration($configuration, [$config]);
}
}