On this page
What this issue is
CSRF stands for cross-site request forgery. To block it, your site puts a hidden token (a random code) in each form and ties it to the visitor's session. When the form is submitted, the server compares the token with the one it expects. If they differ, or the token has expired, the submit is refused.
The visitor did nothing wrong. They filled in the form normally, but the token on the page was too old, came from a cached copy, or belonged to a session that has since ended. Typical messages are 'Page expired' (419 in Laravel), 'CSRF token mismatch', 'Invalid security token', 'Nonce verification failed' or a plain 403.
- Form page loadsToken is issued and stored in a hidden field
- Visitor fills in formTakes a few minutes; session or token ages out
- Submit rejectedServer says token expired or invalid
- Lead email and CRM entryNever created
- Thank-you page and conversion tagNever reached
The visitor reaches the form, but the submit is rejected, so nothing after it happens.
Why it costs you leads or sales
The visitor has already decided to contact you or buy. A rejected submit at that moment is the most expensive place to lose them. Many will not retype a long form. Others will not notice the error and assume it worked, so you never hear from them.
It also hides in your data. The rejected submit never reaches the thank-you page, so no conversion is recorded. Your ad platforms see traffic with no results, and you cannot tell the form is failing from reports alone.
Example: share of submits rejected depending on how long the visitor spends on the form page. Illustrative numbers only.
Common causes
| Cause | What happens | Typical sign |
|---|---|---|
| Token lifetime too short | Visitor takes longer than the token or session allows | Fails only after a pause |
| Full-page cache | Cache serves one visitor's token to everyone | Fails for many visitors, works for you when logged in |
| Session cookie lost or blocked | Server cannot match token to a session | Fails at once, on some browsers or in iframes |
| Session expired on server | Short session lifetime or server restart | Fails after long idle time |
| Page left open in a tab | Visitor returns hours later and submits | Fails on old tabs |
| Domain or www mismatch | Cookie set on one host, form posts to another | Fails on one version of the URL |
How to check if your site has it
Open the form in a private window
Use a fresh session with no cookies, as a new visitor would have.
Submit straight away
Confirm a normal submit reaches the thank-you page and the lead arrives.
Repeat after waiting
Load the form, wait 30 to 60 minutes, then submit. Repeat with a two-hour wait if your sessions are long.
Look at the failed request
In browser DevTools, open the Network tab, submit, and check the form request. A 419, 403 or 400 status, or an error message in the response, points to the token.
View the page source
Search for the hidden token field (names such as _token, csrf, authenticity_token or _wpnonce). Reload from another browser. If the value is identical, a cache is serving one token to everyone.
How to fix it
The right fix depends on the cause. Work through the platform that matches your site, then apply the general steps below.
Exclude form pages from page cache
In your caching plugin or host cache settings, add the form page URL to the 'never cache' list. Cached pages keep an old nonce (WordPress's version of a token), which expires after about 12 to 24 hours.
Shorten cache lifetime
If you must cache the page, set cache lifespan to under 12 hours so the nonce is refreshed in time.
Check your form plugin
Some form plugins offer an option to load the nonce by AJAX or disable the nonce check on public forms. Look in the plugin's settings for the cache or security options.
Clear all caches
Purge plugin, server and CDN caches after changing the settings, then retest.
Raise the session or token lifetime
In Laravel, raise lifetime in config/session.php (minutes). In Django, check SESSION_COOKIE_AGE and CSRF_COOKIE_AGE. In Rails, check the session store expiry.
Send no-store on form pages
Add a Cache-Control: no-store header on pages that contain tokens so CDNs and browsers do not reuse them.
Refresh the token on stale pages
Fetch a new token from an endpoint just before submit, or reload it on a timer, so long-open tabs still work.
Handle failure kindly
On a token error, keep the visitor's entered values, show a clear message and let them resubmit with a new token.
Check that no tag rewrites the form
In GTM Preview mode, look for custom HTML tags that clone, rebuild or submit the form by script. They can drop the hidden token field.
Fix the tag, not the token
Change the tag so it leaves hidden inputs alone, then publish and retest.
Prefer native Webflow forms
Native forms handle submit without a page token you manage. If you post to an outside endpoint with a token, make sure it is generated fresh on each page load.
Check embeds
For embedded third-party forms, confirm the embed script is current and loads on the live domain.
Test the form and cart in a fresh session
Shopify issues its own tokens. Errors after a long wait often come from an expired cart or session, so reload before submit.
Review theme or app code
If a custom form or app posts to your store, make sure it includes the form_type and authenticity token fields from the theme's {% form %} tag.
<form id="lead-form" method="post" action="/contact">
<input type="hidden" name="_token" id="csrf" value="">
<input type="email" name="email" required>
<button type="submit">Send</button>
</form>
<script>
async function refreshToken() {
const res = await fetch('/csrf-token', { credentials: 'same-origin' });
const data = await res.json();
document.getElementById('csrf').value = data.token;
}
refreshToken();
setInterval(refreshToken, 15 * 60 * 1000);
document.getElementById('lead-form').addEventListener('submit', refreshToken);
</script>Before
- Form page is cached with one shared token
- Visitors who wait get 'Page expired'
- Typed answers are lost
- No lead, no conversion recorded
After
- Form page is excluded from cache
- Token is refreshed before submit
- Errors keep the visitor's answers
- Lead and conversion arrive as expected
How to confirm it's fixed
- Submit the form in a private window and see the thank-you page
- Submit again after waiting longer than your old failure point
- Load the form in two browsers and confirm the token values differ
- Confirm the test lead reached your inbox and CRM
- Confirm the conversion tag fired on the thank-you page
- Check the response headers on the form page for the cache rule you set
How to prevent it happening again
- Keep form and checkout pages out of full-page cache and CDN cache
- Re-test forms after every caching, security or plugin change
- Set session and token lifetimes longer than your slowest realistic visitor
- Show a friendly retry message that keeps entered data
- Run the form on a schedule so a break is found in hours, not weeks
How FunnelGuard handles this
FunnelGuard detects this issue today. A robot visitor runs your real form journey on a schedule from the EU or the US, fills in the form and submits it. If the submit fails, the check records a failed step. FunnelGuard then re-checks from a second region before sending one alert, so a one-off glitch does not wake you up.
The alert goes to email, Slack, Teams, WhatsApp, a webhook or PagerDuty, with a screenshot and a likely cause. Note that the check sees that the submit failed. It does not read your server logs, so use the steps above to confirm that the token is the cause. Test traffic is marked (utm_source=funnelguard, fg_test=1) so you can filter it out of reports. The Free plan covers 1 site and 2 journeys with daily checks and no card, and paid plans have a 3-day free trial.
Day 0
A cache plugin update starts caching the form page
Day 1
Cached tokens expire; some visitors get errors
Day 5
Leads drop, but ad reports show only a small dip
Day 14
Someone notices and reports the error
With scheduled checks
The failed submit is caught on the next run and alerted once
Questions people ask
Why does my form say 'token expired' or 'page expired' when I submit?
The hidden security token in the form is older than the server allows, or it no longer matches the visitor's session. This often happens when a visitor leaves the page open for a long time, or when a cache serves an old copy of the page. Reload the page to get a new token, then fix the lifetime or caching.
What does a 419 error mean on a form?
A 419 status means the page expired, most often in Laravel. The CSRF token or session was missing or out of date when the form was submitted. Raise the session lifetime, keep the form page out of cache and make sure cookies are being saved.
Why does my WordPress form fail with 'nonce verification failed'?
A nonce is WordPress's CSRF token and it expires after a limited time. If a caching plugin stores the page, visitors receive an old nonce that has expired. Exclude the form page from cache or shorten the cache lifespan, then purge all caches.
How long should a CSRF token last?
There is no single rule. It should last at least as long as a realistic visitor takes to complete the form, and many sites tie it to the session lifetime. Refreshing the token shortly before submit lets you keep a short lifetime without failing slow visitors.
Can caching cause CSRF token errors?
Yes. If a full-page cache or CDN stores a page containing a token, many visitors get the same token, and it eventually expires or fails to match their session. Exclude pages with forms from cache or load the token separately after the page loads.
Is it safe to turn off CSRF protection to stop the error?
No. Turning it off removes a real defence against forged requests. Fix the cause instead, such as the lifetime, the cache rules or the session cookie.
How can I tell if visitors are hitting a token error?
Submit your form after waiting and check the network request in DevTools for a 419, 403 or 400 response. Your analytics may show form page visits with no matching conversions. A scheduled test that submits the form, such as FunnelGuard's, will flag a failed submit.
Related issues
- CNV-376Session cookie lost between stepsFix guide
- CNV-381Cached page serves stale CSRF/nonce (WordPress cache)Fix guide
- CNV-382Logged-in cache served to visitorsFix guide
- CNV-378SameSite settings break iframe login/checkoutFix guide
- CNV-383Cookie consent state not respected after choiceFix guide
- CNV-377Cookie too large, server 400 errorFix guide