Skip to content

Commit

Permalink
Dispatch event on CSRF form field value change (#1376)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smnandre authored Jan 20, 2025
1 parent a986520 commit 84862d3
Showing 1 changed file with 1 addition and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ document.addEventListener('submit', function (event) {
if (!csrfCookie && nameCheck.test(csrfToken)) {
csrfField.setAttribute('data-csrf-protection-cookie-value', csrfCookie = csrfToken);
csrfField.defaultValue = csrfToken = btoa(String.fromCharCode.apply(null, (window.crypto || window.msCrypto).getRandomValues(new Uint8Array(18))));
csrfField.dispatchEvent(new Event('change', {bubbles: true}));
}

if (csrfCookie && tokenCheck.test(csrfToken)) {
Expand Down

0 comments on commit 84862d3

Please sign in to comment.