Skip to content

Fix hardcoded csrf field name for actions#1163

Open
michalkaczmarek-bitbag wants to merge 4 commits into
Sylius:1.14from
michalkaczmarek-bitbag:bugfix/fix-hardcode-csrf-field-name-in-actions
Open

Fix hardcoded csrf field name for actions#1163
michalkaczmarek-bitbag wants to merge 4 commits into
Sylius:1.14from
michalkaczmarek-bitbag:bugfix/fix-hardcode-csrf-field-name-in-actions

Conversation

@michalkaczmarek-bitbag

@michalkaczmarek-bitbag michalkaczmarek-bitbag commented May 15, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets Sylius/Sylius#19001, Sylius/Sylius#19008, Sylius/Sylius#19011
License MIT

Summary

Fixes hardcoded _csrf_token field name in ResourceController actions.
The field name is now configurable, allowing applications to customize the
CSRF token parameter expected in request bodies.

Problem

ResourceController::deleteAction(), bulkDeleteAction(), and
applyStateMachineTransitionAction() had _csrf_token hardcoded as the
request field name. Applications that need to use a different field name
(e.g. to avoid collisions or follow internal conventions) had no way to
override it.

Solution

Added a new configuration option with _csrf_token as default — fully
backward compatible.

sylius_resource:
    settings:
        csrf_parameter: _my_csrf_field   # default: _csrf_token

The configured value is:
- injected into ResourceController constructor as the 18th argument
(default _csrf_token),
- exposed in Twig via the sylius_csrf_parameter() function so templates
can render the right field name.

<input type="hidden" name="{{ sylius_csrf_parameter() }}" value="{{
csrf_token(resource.id) }}">

@michalkaczmarek-bitbag

Copy link
Copy Markdown
Contributor Author

@loic425 Hi, please check PR. These changes are strongly related with changes Sylius/Sylius. Merge this branch is needed for continue work on bugfix in Sylius. Details in attached PR's

@loic425

loic425 commented May 18, 2026

Copy link
Copy Markdown
Member

Could you a few tests on SyliusResourceExtensionTest?

@michalkaczmarek-bitbag

Copy link
Copy Markdown
Contributor Author

Could you a few tests on SyliusResourceExtensionTest?

I added tests. You can check @loic425

@michalkaczmarek-bitbag

Copy link
Copy Markdown
Contributor Author

@loic425 I add one more change in ResourceController. I change visibility variable from private to protected to child classes they can inherit this variable (csrf_parameter)

@michalkaczmarek-bitbag

Copy link
Copy Markdown
Contributor Author

@loic425 I changed base branch from 1.15 to 1.14 after consult with @Wojdylak . Please look does it's ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants