NikoM
NikoM
CDCloudflare Developers
Created by NikoM on 10/7/2023 in #workers-help
worker throws an error CSRF token injection
addEventListener('fetch', async (event) => { // Get the request object. const request = event.request; // Check if the request is a POST request. if (request.method === 'POST') { // Regenerate the CSRF token. const csrfToken = generateCsrfToken(); // Add the CSRF token to the request headers. request.headers.set('X-CSRF-Token', csrfToken); } // Fetch the response from the origin server. const response = await fetch(request); // Return the response. event.respondWith(response); }); function generateCsrfToken() { // Generate a random CSRF token. const csrfToken = Math.random().toString(36).substring(7); // Return the CSRF token. return csrfToken; } Above is the actual code.
1 replies
CDCloudflare Developers
Created by NikoM on 9/30/2023 in #general-help
Getting token mismatch for all ajax requests when cache level is set to everything
This is for e-commerce website on which we tried cache everything. However we are getting token mismatch for all ajax requests. We had set up the rules like this: https://staging.mtgacodes.com/ajax/* Cache level: Bypass https://staging.mtgacodes.com/* Cache level: Cache everything
1 replies