Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To disable sessions in form contexts one should use the form config instead.
Now I'm realizing that there is no mention to that config anywhere in the docs (https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php#L163).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I tried to add was just a "reverse" link for what is said on https://symfony.com/doc/current/security/csrf.html:
So in which file is form config happening? Or do you mean
csrf_protection
in framework config?: https://symfony.com/doc/current/reference/configuration/framework.html#csrf-protectionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two available config for
csrf
, the one you referring to, enabling it globally at the framework level:And the one I'm referring to (which does not seem documented and that I linked above), to enable it at the form level only:
(https://github.com/symfony/symfony/blob/4.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php#L169)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't fully understand the source code :-(
The best page to document this would probably be https://symfony.com/doc/current/forms.html - since it's probably not worth an own page?!
But some other questions first:
What happens if
csrf_protection
is true in one, and false in the other file?What else can be configured in
form.yaml
?What's the purpose of
form.yaml
at all? Is there any advantage over doing it inframework.yaml
? Both ways are for users of the full framework only, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
framework.csrf_protection
defines the default value offramework.form.csrf_protection
(see the comment in the link from my previous comment).So defining the global as
true
defines the form protection astrue
, then switching the form one tofalse
would be my approach in the current PR context.In the other hand, defining the global as
false
would make the form protection disabled, then trying to enable it at the form level wouldn't work as expected (however I have not tested if it throws a clear exception or if it just fails silently).The best documentation is your console ;), using:
bin/console config:dump framework # or bin/console config:dump framework form bin/console config:dump framework csrf_protection
Same as
mailer.yaml
or any other component configured by theFrameworkBundle
(i.e serializer, messenger, lock, ...) to avoid having hundred of lines inframework.yaml
.But feel free to decide to add this file or not by inlining this config directly in
framework.yaml
:).Right :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it's
bin/console config:dump framework csrf_protection
🤦 (I've edited my comment).So, I've just tested:
and I got the following:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened symfony/symfony#46960 to try to improve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but still: If you do it the other way around:
... where will CSRF be enabled then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The framework is using the global config to wire services
symfony/security-csrf
component, they can be used elsewhere, not only forms, and can rely on other implementations not using a session (i.e. a specific cookie).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't have a clear enough picture to suggest something. Maybe somebody else has an idea - ping @javiereguiluz