Skip to content

[SecurityBundle] Remove deprecated hide_user_not_found option #60928

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
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
14 changes: 14 additions & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,20 @@ Security
* Remove `AbstractListener::__invoke`
* Remove `LazyFirewallContext::__invoke()`

SecurityBundle
--------------

* Remove the deprecated `hide_user_not_found` configuration option, use `expose_security_errors` instead

```diff
# config/packages/security.yaml
security:
- hide_user_not_found: false
+ expose_security_errors: true
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct, is it? The new option is a none/all/account_status enum, not a boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, will fix it soon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

```

Note: `expose_security_errors: true` is equivalent to `hide_user_not_found: false`. The logic is inverted.

Serializer
----------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/SecurityBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
8.0
---

* Remove the deprecated `hide_user_not_found` configuration option, use `expose_security_errors` instead
* Remove `LazyFirewallContext::__invoke()`

7.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,12 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode
->docUrl('https://symfony.com/doc/{version:major}.{version:minor}/reference/configuration/security.html', 'symfony/security-bundle')
->beforeNormalization()
->always()
->then(function ($v) {
if (isset($v['hide_user_not_found']) && isset($v['expose_security_errors'])) {
throw new InvalidConfigurationException('You cannot use both "hide_user_not_found" and "expose_security_errors" at the same time.');
}

if (isset($v['hide_user_not_found']) && !isset($v['expose_security_errors'])) {
$v['expose_security_errors'] = $v['hide_user_not_found'] ? ExposeSecurityLevel::None : ExposeSecurityLevel::All;
}

return $v;
})
->end()
->children()
->scalarNode('access_denied_url')->defaultNull()->example('/foo/error403')->end()
->enumNode('session_fixation_strategy')
->values([SessionAuthenticationStrategy::NONE, SessionAuthenticationStrategy::MIGRATE, SessionAuthenticationStrategy::INVALIDATE])
->defaultValue(SessionAuthenticationStrategy::MIGRATE)
->end()
->booleanNode('hide_user_not_found')
->setDeprecated('symfony/security-bundle', '7.3', 'The "%node%" option is deprecated and will be removed in 8.0. Use the "expose_security_errors" option instead.')
->end()
->enumNode('expose_security_errors')
->beforeNormalization()->ifString()->then(fn ($v) => ExposeSecurityLevel::tryFrom($v))->end()
->values(ExposeSecurityLevel::cases())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,42 +259,4 @@ public static function provideHideUserNotFoundData(): iterable
yield [['expose_security_errors' => 'all'], ExposeSecurityLevel::All];
}

/**
* @dataProvider provideHideUserNotFoundLegacyData
*
* @group legacy
*/
public function testExposeSecurityErrorsWithLegacyConfig(array $config, ExposeSecurityLevel $expectedExposeSecurityErrors, ?bool $expectedHideUserNotFound)
{
$this->expectUserDeprecationMessage('Since symfony/security-bundle 7.3: The "hide_user_not_found" option is deprecated and will be removed in 8.0. Use the "expose_security_errors" option instead.');

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

$processor = new Processor();
$configuration = new MainConfiguration([], []);
$processedConfig = $processor->processConfiguration($configuration, [$config]);

$this->assertEquals($expectedExposeSecurityErrors, $processedConfig['expose_security_errors']);
$this->assertEquals($expectedHideUserNotFound, $processedConfig['hide_user_not_found']);
}

public static function provideHideUserNotFoundLegacyData(): iterable
{
yield [['hide_user_not_found' => true], ExposeSecurityLevel::None, true];
yield [['hide_user_not_found' => false], ExposeSecurityLevel::All, false];
}

public function testCannotUseHideUserNotFoundAndExposeSecurityErrorsAtTheSameTime()
{
$processor = new Processor();
$configuration = new MainConfiguration([], []);

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('You cannot use both "hide_user_not_found" and "expose_security_errors" at the same time.');

$processor->processConfiguration($configuration, [static::$minimalConfig + [
'hide_user_not_found' => true,
'expose_security_errors' => ExposeSecurityLevel::None,
]]);
}
}
Loading