Skip to content

[Form] Changing CSRF token default name #60537

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

Closed

Conversation

ThomasLandauer
Copy link
Contributor

Q A
Branch? 7.3
Bug fix? no
New feature? not really
Deprecations? no
Issues Fix #60534
License MIT

See #60534 (comment)

Copy link
Contributor

@Spomky Spomky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. No comment.

@OskarStark OskarStark changed the title [Form] Changing CSRF token default name #60534 [Form] Changing CSRF token default name May 25, 2025
@ThomasLandauer
Copy link
Contributor Author

Is it worth an entry in CHANGELOG? If yes, as bug or feature?

@nicolas-grekas
Copy link
Member

On my side, I think it's fine merging as "minor". Let's see if anyone else thinks different.

@xabbuh
Copy link
Member

xabbuh commented May 25, 2025

I am not convinced. This has the potential to break applications where people render forms by referencing the CSRF field explicitly with the „old“ name.

@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
@stof
Copy link
Member

stof commented May 27, 2025

I think this deserves being mentioned in the changelog, to account for the fact it might impact projects accessing the field by name.

Note that this PR does not change the name for users of the fullstack framework as you haven't changed the default value in the FrameworkBundle config.

@@ -253,7 +253,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
->children()
->scalarNode('enabled')->defaultNull()->end() // defaults to framework.csrf_protection.enabled
->scalarNode('token_id')->defaultNull()->end()
->scalarNode('field_name')->defaultValue('_token')->end()
->scalarNode('field_name')->defaultValue('_csrf_token')->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am still 👎 on this change as I don't think it's worth it potentially breaking applications just to change the name of this field.

If we really want to change the default name we should IMO follow the usual deprecation-first approach: Meaning here that not setting the value explicitly would trigger a deprecation which would then allow us to change the default in 8.0.

@ThomasLandauer
Copy link
Contributor Author

Thanks, I now changed it there too (and in the tests), and created a CHANGELOG.md file.

@Spomky Spomky self-requested a review May 28, 2025 06:45
@Spomky
Copy link
Contributor

Spomky commented May 28, 2025

Hi,

I tested this on a project where the field is rendered manually, and as @xabbuh pointed out, it does break the token verification.
I have reconsidered my position and now agree with the downvoters as this change could indeed break applications.

@nicolas-grekas
Copy link
Member

Let's close then. Thanks for proposing @ThomasLandauer but this looks like too costly for too little benefits.

@ThomasLandauer ThomasLandauer deleted the renaming_csrf_token branch May 28, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Form] Rename CSRF token field from _token to _csrf_token
8 participants