-
Notifications
You must be signed in to change notification settings - Fork 90
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
Introduce DirectiveSetBuilderInterface
to allow runtime modification
#348
Introduce DirectiveSetBuilderInterface
to allow runtime modification
#348
Conversation
8ea7fa0
to
7126387
Compare
7126387
to
65a8e55
Compare
65a8e55
to
e86b401
Compare
Sorry but I won't manage to review this one right now, seems solid at first sight but I'd rather give it some more thought. |
@Seldaek Any chance this can be looked at? Thanks in advance! |
Thanks - what would be great is if someone can provide some code sample for the docs on how this can be used to configure extra values |
I now implemented my CSP exceptions like this: public function page(ContentSecurityPolicyListener $cspListener) {
// Allow *.doubleclick.net as extra script-src
$cspListener->getEnforcement()->setDirective('script-src', $cspListener->getEnforcement()->getDirective('script-src') . ' *.doubleclick.net');
return $this->render('exampe.html.twig');
}
Can an example be provided how to achieve the same behaviour in the new way? |
The idea is that your app or bundle can now provide its own
And register it in the container
In your controller you can then inject
The I will look at creating a PR to add some examples to the documentation. |
is this really a gain compared to the previous way of doing it 😅 |
This PR introduces the
DirectiveSetBuilderInterface
and the default implementationConfigurationDirectiveSetBuilder
proposed in #347, to allow for runtime modification of the CSP directive sets. The major changes are:DirectiveSetBuilderInterface
andConfigurationDirectiveSetBuilder
;ContentSecurityPolicyListener
constructor now takesDirectiveSetBuilderInterface
instead of the directive sets directly;NelmioSecurityExtension
to provide the configuration to theConfigurationDirectiveSetBuilder
s, which in turn are injected intoContentSecurityPolicyListener
(instead of the directive sets).This adds a layer between the configuration (and the directive sets built from it) and
ContentSecurityPolicyListener
. This layer provides an integration point for application code to modify the directive sets based on the request (e.g., in a controller or a kernel event listener).