-
-
Notifications
You must be signed in to change notification settings - Fork 497
[Turbo] Correctly fix framework.csrf_protection.check_header
configuration
#1440
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
[Turbo] Correctly fix framework.csrf_protection.check_header
configuration
#1440
Conversation
Thanks for the PR 😍 How to test these changes in your application
Diff between recipe versionsIn order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes. symfony/ux-turbo2.19 vs 2.20diff --git a/symfony/ux-turbo/2.20/config/packages/ux_turbo.yaml b/symfony/ux-turbo/2.20/config/packages/ux_turbo.yaml
new file mode 100644
index 0000000..c2a6a44
--- /dev/null
+++ b/symfony/ux-turbo/2.20/config/packages/ux_turbo.yaml
@@ -0,0 +1,4 @@
+# Enable stateless CSRF protection for forms and logins/logouts
+framework:
+ csrf_protection:
+ check_header: true
diff --git a/symfony/ux-turbo/2.19/manifest.json b/symfony/ux-turbo/2.20/manifest.json
index 1fa03bf..7dd9f95 100644
--- a/symfony/ux-turbo/2.19/manifest.json
+++ b/symfony/ux-turbo/2.20/manifest.json
@@ -1,5 +1,13 @@
{
"bundles": {
"Symfony\\UX\\Turbo\\TurboBundle": ["all"]
+ },
+ "copy-from-recipe": {
+ "config/": "%CONFIG_DIR%/"
+ },
+ "aliases": ["turbo"],
+ "conflict": {
+ "symfony/framework-bundle": "<7.2",
+ "symfony/security-csrf": "<7.2"
}
} |
b2f5098
to
2941b64
Compare
After running composer require symfony/webapp-pack, Symfony Flex installs the latest symfony/framework-bundle recipe, which now generates an invalid YAML file: File: config/packages/csrf.yaml A colon cannot be used in an unquoted mapping value at line 3 (near "token_id: submit") token_id: 'submit' Symfony version: [7.3.1] PHP version: 8.3 Symfony CLI or Composer install Please fix or update the recipe in recipes/symfony/framework-bundle. |
The thing is that this solution only works if the developer didn't change/rearrange the content of the file. I don't have a better idea though that doesn't involve updating Flex to be more flexible when it comes to adding lines to existing config files. :/ |
What about dropping the UX Turbo recipe, and directly add That's far from being ideal, but better that the solution proposed in this PR. |
The UX Turbo recipe could also create a new file with just the following content instead of trying to patch the existing file: # Enable stateless CSRF protection for forms and logins/logouts
framework:
csrf_protection:
check_header: true |
Indeed, didn't think about this but I feel like this is the best alternative we have without touching Flex. I'm updating the PR |
Head branch was pushed to by a user without write access
2941b64
to
f05c33d
Compare
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.
LGTM
Following #1439 (comment)
Old alternative with `position: 'bottom'`
The solution is fragile and kind of ugly (note the extra line before
check_header: true
, as it generates the following file:But it works:
There are other alternatives, like:
before_target
foradd-lines
modifier but it requires to update Flex code and people to upgrade Flex# check_header: true
(with a comment) to thecsrf.yaml
from Form recipeApplied @xabbuh 's suggestion from #1440 (comment)