Skip to content

Commit 466ee55

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: Fix CS quote address names if they contain parentheses [FrameworkBundle] Fail gracefully when forms use disabled CSRF [Mime] Fix inline parts when added via attachPart() Fail gracefully when attempting to autowire composite types [VarDumper] Add a test case for nesting intersection and union types
2 parents 5e70e28 + 3e6d1c8 commit 466ee55

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
669669
}
670670

671671
if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
672+
if (!$container->hasDefinition('security.csrf.token_generator')) {
673+
throw new \LogicException('To use form CSRF protection, "framework.csrf_protection" must be enabled.');
674+
}
675+
672676
$loader->load('form_csrf.php');
673677

674678
$container->setParameter('form.type_extension.csrf.enabled', true);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'csrf_protection' => false,
5+
'form' => [
6+
'csrf_protection' => true,
7+
],
8+
]);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services
7+
https://symfony.com/schema/dic/services/services-1.0.xsd
8+
http://symfony.com/schema/dic/symfony
9+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
10+
>
11+
<framework:config>
12+
<framework:csrf-protection enabled="false"/>
13+
<framework:form enabled="true">
14+
<framework:csrf-protection enabled="true"/>
15+
</framework:form>
16+
</framework:config>
17+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
csrf_protection: false
3+
form:
4+
csrf_protection: true

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public function testFormCsrfProtection()
9797
$this->assertEquals('%form.type_extension.csrf.field_name%', $def->getArgument(2));
9898
}
9999

100+
public function testFormCsrfProtectionWithCsrfDisabled()
101+
{
102+
$this->expectException(\LogicException::class);
103+
$this->expectExceptionMessage('To use form CSRF protection `framework.csrf_protection` must be enabled.');
104+
105+
$this->createContainerFromFile('form_csrf_disabled');
106+
}
107+
100108
public function testPropertyAccessWithDefaultValue()
101109
{
102110
$container = $this->createContainerFromFile('full');

0 commit comments

Comments
 (0)