8000 merged branch simensen/framework-secret (PR #5631) · markross/symfony@264a5cc · GitHub
[go: up one dir, main page]

Skip to content

Commit 264a5cc

Browse files
committed
merged branch simensen/framework-secret (PR symfony#5631)
This PR was merged into the master branch. Commits ------- 8bc9f75 Make secret not be required Discussion ---------- [FrameworkBundle] Make secret not be required Bug fix: no Feature addition: yes Backwards compatibility break: no (questionable) Symfony2 tests pass: yes License of the code: MIT Fixes the following tickets: - Todo: - License of the code: MIT Documentation PR: - Framework bundle currently requires that the `secret` key under `framework` be set. The end result is that `kernel.secret` is made available. This is, as far as I can tell, the only required configuration for Framework bundle. The only thing that currently uses `kernel.secret` is the Form component and then only if CSRF protection is enabled. In the spirit of making Framework more decoupled and not requiring things in the case you don't need them I would like to make framework secret optional. I followed the pattern used by CSRF support for when Session is disabled to throw a `LogicException` stating that if CSRF support is enabled then the secret should be set. For anyone who currently depends on `kernel.secret`, if someone ends up *not* defining `kernel.secret` there will be a dependency error on kernel configuration as `kernel.secret` will not be made available. The biggest downside to this that I could see is that the error message may be slightly confusing; it will complain that there is a dependency on `kernel.secret` when that is generally set by way of adding the Framework secret to the configuration. As this relates to Symfony Standard Edition, there should be no changes as there is a default secret set there already anyway.
2 parents dda2f7c + 8bc9f75 commit 264a5cc

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function getConfigTreeBuilder()
6262
->end()
6363
->end()
6464
->scalarNode('trust_proxy_headers')->defaultFalse()->end()
65-
->scalarNode('secret')->isRequired()->end()
65+
->scalarNode('secret')->end()
6666
->scalarNode('ide')->defaultNull()->end()
6767
->booleanNode('test')->end()
6868
->scalarNode('default_locale')->defaultValue('en')->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public function load(array $configs, ContainerBuilder $container)
5959
$configuration = $this->getConfiguration($configs, $container);
6060
$config = $this->processConfiguration($configuration, $configs);
A105 6161

62-
$container->setParameter('kernel.secret', $config['secret']);
62+
if (isset($config['secret'])) {
63+
$container->setParameter('kernel.secret', $config['secret']);
64+
}
6365

6466
$container->setParameter('kernel.trust_proxy_headers', $config['trust_proxy_headers']);
6567

@@ -156,6 +158,9 @@ private function registerFormConfiguration($config, ContainerBuilder $container,
156158
if (!isset($config['session'])) {
157159
throw new \LogicException('CSRF protection needs that sessions are enabled.');
158160
}
161+
if (!isset($config['secret'])) {
162+
throw new \LogicException('CSRF protection needs a secret to be set.');
163+
}
159164
$loader->load('form_csrf.xml');
160165

161166
$container->setParameter('form.type_extension.csrf.enabled', $config['csrf_protection']['enabled']);

0 commit comments

Comments
 (0)
0