Skip to content

Commit 84862d3

Browse files
authored
Dispatch event on CSRF form field value change (#1376)
This allow support / compatibility with LiveComponent when action are done between form first render and submit (ex: another form submit with Turbo and double header check) See symfony/ux#2505
1 parent a986520 commit 84862d3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ document.addEventListener('submit', function (event) {
1515
if (!csrfCookie && nameCheck.test(csrfToken)) {
1616
csrfField.setAttribute('data-csrf-protection-cookie-value', csrfCookie = csrfToken);
1717
csrfField.defaultValue = csrfToken = btoa(String.fromCharCode.apply(null, (window.crypto || window.msCrypto).getRandomValues(new Uint8Array(18))));
18+
csrfField.dispatchEvent(new Event('change', {bubbles: true}));
1819
}
1920

2021
if (csrfCookie && tokenCheck.test(csrfToken)) {

0 commit comments

Comments
 (0)