Skip to content

[FrameworkBundle] Revert " Don't auto-register form/csrf when the corresponding components are not installed" #58943

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 1 commit into from
Nov 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,8 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
->children()
->arrayNode('form')
->info('Form configuration')
->treatFalseLike(['enabled' => false])
->treatTrueLike(['enabled' => true])
->treatNullLike(['enabled' => true])
->addDefaultsIfNotSet()
->{$enableIfStandalone('symfony/form', Form::class)}()
->children()
->scalarNode('enabled')->defaultNull()->end() // defaults to !class_exists(FullStack::class) && class_exists(Form::class)
->arrayNode('csrf_protection')
->treatFalseLike(['enabled' => false])
->treatTrueLike(['enabled' => true])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,6 @@ public function load(array $configs, ContainerBuilder $container): void
$this->readConfigEnabled('profiler', $container, $config['profiler']);
$this->readConfigEnabled('workflows', $container, $config['workflows']);

// csrf depends on session or stateless token ids being registered
if (null === $config['csrf_protection']['enabled']) {
$this->writeConfigEnabled('csrf_protection', ($config['csrf_protection']['stateless_token_ids'] || $this->readConfigEnabled('session', $container, $config['session'])) && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf', CsrfTokenManagerInterface::class, ['symfony/framework-bundle']), $config['csrf_protection']);
}

if (null === $config['form']['enabled']) {
$this->writeConfigEnabled('form', !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/form', Form::class, ['symfony/framework-bundle']), $config['form']);
}

if (null === $config['form']['csrf_protection']['enabled']) {
$this->writeConfigEnabled('form.csrf_protection', $config['csrf_protection']['enabled'], $config['form']['csrf_protection']);
}

// A translator must always be registered (as support is included by
// default in the Form and Validator component). If disabled, an identity
// translator will be used and everything will still work as expected.
Expand Down Expand Up @@ -479,6 +466,10 @@ public function load(array $configs, ContainerBuilder $container): void
$container->removeDefinition('test.session.listener');
}

// csrf depends on session or stateless token ids being registered
if (null === $config['csrf_protection']['enabled']) {
$this->writeConfigEnabled('csrf_protection', ($config['csrf_protection']['stateless_token_ids'] || $this->readConfigEnabled('session', $container, $config['session'])) && !class_exists(FullStack::class) && ContainerBuilder::willBeAvailable('symfony/security-csrf', CsrfTokenManagerInterface::class, ['symfony/framework-bundle']), $config['csrf_protection']);
}
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);

// form depends on csrf being registered
Expand Down Expand Up @@ -763,6 +754,10 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
{
$loader->load('form.php');

if (null === $config['form']['csrf_protection']['enabled']) {
$this->writeConfigEnabled('form.csrf_protection', $config['csrf_protection']['enabled'], $config['form']['csrf_protection']);
}

if ($this->readConfigEnabled('form.csrf_protection', $container, $config['form']['csrf_protection'])) {
if (!$container->hasDefinition('security.csrf.token_generator')) {
throw new \LogicException('To use form CSRF protection, "framework.csrf_protection" must be enabled.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'annotations' => false,
'csrf_protection' => false,
'form' => [
'enabled' => true,
'csrf_protection' => true,
],
'http_method_override' => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'form' => [
'enabled' => true,
'csrf_protection' => [
'enabled' => false,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'enabled_locales' => ['fr', 'en'],
'csrf_protection' => true,
'form' => [
'enabled' => true,
'csrf_protection' => [
'field_name' => '_csrf',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<framework:annotations enabled="false"/>
<framework:php-errors log="true" />
<framework:csrf-protection enabled="false"/>
<framework:form enabled="true">
<framework:form>
<framework:csrf-protection enabled="true"/>
</framework:form>
</framework:config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<framework:config http-method-override="false" handle-all-throwables="true">
<framework:annotations enabled="false" />
<framework:php-errors log="true" />
<framework:form enabled="true">
<framework:form>
<framework:csrf-protection enabled="false" />
</framework:form>
</framework:config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<framework:enabled-locale>fr</framework:enabled-locale>
<framework:enabled-locale>en</framework:enabled-locale>
<framework:csrf-protection />
<framework:form enabled="true">
<framework:form>
<framework:csrf-protection field-name="_csrf"/>
</framework:form>
<framework:esi enabled="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ framework:
annotations: false
csrf_protection: false
form:
enabled: true
csrf_protection: true
http_method_override: false
handle_all_throwables: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ framework:
php_errors:
log: true
form:
enabled: true
csrf_protection:
enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ framework:
enabled_locales: ['fr', 'en']
csrf_protection: true
form:
enabled: true
csrf_protection:
field_name: _csrf
http_method_override: false
Expand Down
Loading