Skip to content

Fixed BC break in csrf protection #9672

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
wants to merge 1 commit into from
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 @@ -120,8 +120,12 @@ private function addFormSection(ArrayNodeDefinition $rootNode)
->canBeEnabled()
->children()
->arrayNode('csrf_protection')
->canBeDisabled()
->treatFalseLike(array('enabled' => false))
->treatTrueLike(array('enabled' => true))
->treatNullLike(array('enabled' => true))
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultNull()->end() // defaults to framework.csrf_protection.enabled
->scalarNode('field_name')->defaultNull()->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public function load(array $configs, ContainerBuilder $container)
private function registerFormConfiguration($config, ContainerBuilder $container, XmlFileLoader $loader)
{
$loader->load('form.xml');
if (null === $config['form']['csrf_protection']['enabled']) {
$config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled'];
}

if ($this->isConfigEnabled($container, $config['form']['csrf_protection'])) {
if (!$this->isConfigEnabled($container, $config['csrf_protection'])) {
throw new \LogicException('CSRF protection needs to be enabled in order to use CSRF protection for forms.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected static function getBundleDefaultConfig()
'form' => array(
'enabled' => false,
'csrf_protection' => array(
'enabled' => true,
'enabled' => null, // defaults to csrf_protection.enabled
'field_name' => null,
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<?php

$container->loadFromExtension('framework', array(
'csrf_protection' => array(
'enabled' => false,
),
'form' => array(
'enabled' => true,
'csrf_protection' => array(
'enabled' => true,
),
),
'session' => array(
'handler_id' => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:form />
<framework:csrf-protection enabled="false" />

<framework:form>
<framework:csrf-protection />
</framework:form>

<framework:session />
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
framework:
csrf_protection: false
secret: s3cr3t
form: ~
form:
csrf_protection: true
session: ~
# CSRF is disabled by default
# csrf_protection: ~