8000 [SecurityBundle] Empty line starting with dash under "access_control" causes all rules to be skipped by monteiro · Pull Request #40330 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[SecurityBundle] Empty line starting with dash under "access_control" causes all rules to be skipped #40330

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
8000
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ private function createAuthorization(array $config, ContainerBuilder $container)
$attributes[] = $this->createExpression($container, $access['allow_if']);
}

$emptyAccess = 0 === \count(array_filter($access));

if ($emptyAccess) {
throw new InvalidConfigurationException('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
}

$container->getDefinition('security.access_map')
->addMethodCall('add', [$matcher, $attributes, $access['requires_channel']]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,56 @@ public function testSwitchUserWithSeveralDefinedProvidersButNoFirewallRootProvid
$this->assertEquals(new Reference('security.user.provider.concrete.second'), $container->getDefinition('security.authentication.switchuser_listener.foobar')->getArgument(1));
}

public function testInvalidAccessControlWithEmptyRow()
{
$container = $this->getRawContainer();

$container->loadFromExtension('security', [
'providers' => [
'default' => ['id' => 'foo'],
],
'firewalls' => [
'some_firewall' => [
'pattern' => '/.*',
'http_basic' => [],
],
],
'access_control' => [
[],
['path' => '/admin', 'roles' => 'ROLE_ADMIN'],
],
]);

$this->expectException(InvalidConfigurationException::class);
$this->expectExceptionMessage('One or more access control items are empty. Did you accidentally add lines only containing a "-" under "security.access_control"?');
$container->compile();
}

public function testValidAccessControlWithEmptyRow()
{
$container = $this->getRawContainer();

$container->loadFromExtension('security', [
'providers' => [
'default' => ['id' => 'foo'],
],
'firewalls' => [
'some_firewall' => [
'pattern' => '/.*',
'http_basic' => [],
],
],
'access_control' => [
['path' => '^/login'],
['path' => '^/', 'roles' => 'ROLE_USER'],
],
]);

$container->compile();

$this->assertTrue(true, 'extension throws an InvalidConfigurationException if there is one more more empty access control items');
}

protected function getRawContainer()
{
$container = new ContainerBuilder();
Expand Down
0