Skip to content

Commit a986520

Browse files
[stimulus-bundle] Match name="_csrf_token" when looking for CSRF fields (#1373)
1 parent 7e10c1d commit a986520

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

symfony/stimulus-bundle/2.20/assets/controllers/csrf_protection_controller.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var tokenCheck = /^[-_/+a-zA-Z0-9]{24,}$/;
33

44
// Generate and double-submit a CSRF token in a form field and a cookie, as defined by Symfony's SameOriginCsrfTokenManager
55
document.addEventListener('submit', function (event) {
6-
var csrfField = event.target.querySelector('input[data-controller="csrf-protection"]');
6+
var csrfField = event.target.querySelector('input[data-controller="csrf-protection"], input[name="_csrf_token"]');
77

88
if (!csrfField) {
99
return;
@@ -26,7 +26,7 @@ document.addEventListener('submit', function (event) {
2626
// When @hotwired/turbo handles form submissions, send the CSRF token in a header in addition to a cookie
2727
// The `framework.csrf_protection.check_header` config option needs to be enabled for the header to be checked
2828
document.addEventListener('turbo:submit-start', function (event) {
29-
var csrfField = event.detail.formSubmission.formElement.querySelector('input[data-controller="csrf-protection"]');
29+
var csrfField = event.detail.formSubmission.formElement.querySelector('input[data-controller="csrf-protection"], input[name="_csrf_token"]');
3030

3131
if (!csrfField) {
3232
return;
@@ -41,7 +41,7 @@ document.addEventListener('turbo:submit-start', function (event) {
4141

4242
// When @hotwired/turbo handles form submissions, remove the CSRF cookie once a form has been submitted
4343
document.addEventListener('turbo:submit-end', function (event) {
44-
var csrfField = event.detail.formSubmission.formElement.querySelector('input[data-controller="csrf-protection"]');
44+
var csrfField = event.detail.formSubmission.formElement.querySelector('input[data-controller="csrf-protection"], input[name="_csrf_token"]');
4545

4646
if (!csrfField) {
4747
return;

0 commit comments

Comments
 (0)