Skip to content
FunnelGuard

Fix guide by FunnelsGuard

CSRF token expired: form rejects submit (how to fix it)

CNV-380High impactDetectedBy FunnelGuardPublished Updated
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.

Where the funnel breaks
  1. Form page loadsToken is issued and stored in a hidden field
  2. Visitor fills in formTakes a few minutes; session or token ages out
  3. Submit rejectedServer says token expired or invalid
  4. Lead email and CRM entryNever created
  5. 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.

Submits lost to expired tokensExample numbers
Submits lost to expired tokens (example)Under 1 minute: 1 %; 5 minutes: 4 %; 30 minutes: 18 %; 2 hours: 45 %01734141845Under 1 minute5 minutes30 minutes2 hours%

Example: share of submits rejected depending on how long the visitor spends on the form page. Illustrative numbers only.

Common causes

Why a valid-looking form gets a rejected token
CauseWhat happensTypical sign
Token lifetime too shortVisitor takes longer than the token or session allowsFails only after a pause
Full-page cacheCache serves one visitor's token to everyoneFails for many visitors, works for you when logged in
Session cookie lost or blockedServer cannot match token to a sessionFails at once, on some browsers or in iframes
Session expired on serverShort session lifetime or server restartFails after long idle time
Page left open in a tabVisitor returns hours later and submitsFails on old tabs
Domain or www mismatchCookie set on one host, form posts to anotherFails on one version of the URL

How to check if your site has it

Test the form yourself
  1. Open the form in a private window

    Use a fresh session with no cookies, as a new visitor would have.

  2. Submit straight away

    Confirm a normal submit reaches the thank-you page and the lead arrives.

  3. Repeat after waiting

    Load the form, wait 30 to 60 minutes, then submit. Repeat with a two-hour wait if your sessions are long.

  4. 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.

  5. 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.

Fix by platform
  1. 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.

  2. Shorten cache lifetime

    If you must cache the page, set cache lifespan to under 12 hours so the nonce is refreshed in time.

  3. 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.

  4. Clear all caches

    Purge plugin, server and CDN caches after changing the settings, then retest.

Example: a form that refreshes its token before submithtml
<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>
Form behaviour before and after

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

Confirmation checks
  • 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

Prevention habits
  • 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.

How a token failure unfolds without monitoring
  1. Day 0

    A cache plugin update starts caching the form page

  2. Day 1

    Cached tokens expire; some visitors get errors

  3. Day 5

    Leads drop, but ad reports show only a small dip

  4. Day 14

    Someone notices and reports the error

  5. 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.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: submit fails.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.