On this page
What this issue is
Browsers automatically attach your cookies to any request sent to your site, even when the request starts on a different website. If your form handler trusts the cookie alone, an attacker's page can submit a hidden form to your site and your server will treat it as a real action by the logged-in user.
A CSRF token is a random value your server puts in the form and checks when the form comes back. A third-party page cannot read it, so it cannot forge a valid request.
Why it costs you leads or sales
A forged request can change a customer's email, address or settings, place or alter orders, or let an attacker act as a logged-in admin. That damages trust, creates refund and support work, and can trigger data-protection duties if personal data is changed or exposed.
It can also pollute your lead data. Forged submissions to unprotected forms fill your CRM and inbox with junk, and you waste time sorting real leads from fake ones.
- Customer logged inSession cookie stored in the browser
- Visits a bad pageHidden form auto-submits to your site
- Your server accepts itNo token or origin check
- Account changedEmail, address or order altered
- Trust and revenue lostSupport load, refunds, complaints
The break is at the server: it accepts the request because the cookie is valid, without checking where it came from.
How to check if your site has it
Only test sites you own or have written permission to test. Start with a quick look at the form markup, then try a controlled replay.
Inspect the form HTML
Open the page, right-click the form, choose Inspect, and look for a hidden input named like csrf_token, _token, authenticity_token, __RequestVerificationToken or _wpnonce. No hidden token on a logged-in, state-changing form is a warning sign.
Check the cookies
In browser DevTools, open Application (or Storage) and Cookies. Look at the SameSite attribute on your session cookie. Missing or None raises risk.
Replay the request without the token
In the Network tab, copy the form submission as cURL, remove the token field, and send it from a test account on a staging copy. If the server still accepts it, the form is not protected.
Try a wrong Origin
Send the same request with an Origin header set to another domain. A protected server rejects it with 403.
Run a security scan
Use a web application security scanner or a penetration tester to cover every form and endpoint, not just the ones you thought of.
How to fix it
Use layers. The token is the main defence. SameSite cookies and Origin checks add protection if one layer is missed. Never use GET requests for actions that change data.
Use nonces in custom forms
Add wp_nonce_field('my_action','my_nonce') inside the form and check it with check_admin_referer or wp_verify_nonce before processing.
Update form plugins
Keep your form plugin and theme updated. Well-maintained plugins already use nonces. Replace plugins that are abandoned.
Use the built-in form tag
In Liquid themes, wrap forms in {% form 'contact' %} or {% form 'customer' %}. These add the authenticity token Shopify checks for you.
Avoid hand-written forms
If a custom form posts to a Shopify route without the form tag, rebuild it with the tag.
Use native Webflow forms
Webflow-hosted forms are handled by Webflow. For custom endpoints you added, make sure they check a token or an Origin header.
Use Wix forms and Velo carefully
Native Wix forms are handled by the platform. If you wrote Velo backend web methods or HTTP functions, check authentication and Origin on the server rather than trusting the page.
Use built-in form blocks
Squarespace form blocks are managed by the platform. Avoid posting to external endpoints that lack their own token or origin checks.
Turn on your framework's CSRF middleware
Most frameworks include it: Django CsrfViewMiddleware with {% csrf_token %}, Laravel @csrf, Rails protect_from_forgery, ASP.NET Core antiforgery. Make sure it is not disabled or exempted.
Set SameSite on session cookies
Use SameSite=Lax (or Strict where it fits) together with Secure and HttpOnly.
Check Origin or Referer
Reject state-changing requests whose Origin header is not your own domain.
<form method="post" action="/account/update">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<input type="email" name="email" required>
<button type="submit">Save</button>
</form><?php
// In the form
wp_nonce_field( 'save_profile', 'profile_nonce' );
// In the handler
if ( ! isset( $_POST['profile_nonce'] ) || ! wp_verify_nonce( $_POST['profile_nonce'], 'save_profile' ) ) {
wp_die( 'Invalid request', 403 );
}Set-Cookie: session=abc123; Secure; HttpOnly; SameSite=Lax; Path=/Unprotected
- Server trusts the session cookie only
- No hidden token in the form
- Cookie has no SameSite attribute
- Actions allowed over GET
Protected
- Per-session token checked on every POST
- SameSite=Lax cookies with Secure and HttpOnly
- Origin header must match your domain
- State changes only over POST
How to confirm it's fixed
Submit normally
Use the form as a real user and confirm it still works and the token is in the markup.
Remove the token
Replay the request without the token. The server should return 403 or a validation error, and nothing should change.
Use a wrong token and wrong Origin
Both should be rejected.
Check cookie flags
In DevTools confirm SameSite, Secure and HttpOnly on the session cookie.
Test cached pages
Make sure caching or a CDN does not serve one visitor's token to others, and that tokens do not expire so fast that real users see errors.
How to prevent it happening again
- Keep CSRF middleware enabled by default and review any exemptions
- Add a CSRF test to code review for every new form or endpoint
- Update CMS, plugins and themes promptly
- Use POST, PUT or DELETE for any change, never GET
- Set SameSite, Secure and HttpOnly on all session cookies
- Run a security scan or penetration test after major releases
- Exclude token-bearing pages from shared caching
How FunnelGuard handles this
CSRF is outside what FunnelGuard checks. It needs a web application security tool, such as a vulnerability scanner or a penetration test, that probes your forms and server responses for missing tokens and origin checks.
What FunnelGuard does do is run your real lead forms and checkouts on a schedule and confirm they still work after a fix. After you add tokens, a robot visitor submitting the form and checking that the test lead reaches your inbox and CRM can show that the change did not break the journey. That is a check on the form working, not on whether it is secure.
Questions people ask
What is CSRF and how does it work?
CSRF (cross-site request forgery) is an attack where a malicious page makes a visitor's browser send a request to your site. The browser adds the visitor's login cookie automatically, so your server may treat the request as genuine. A secret token in each form stops this.
How do I fix CSRF on my forms?
Add a random, per-session token to each state-changing form and verify it on the server before acting. Also set SameSite=Lax on session cookies and check the Origin header. Most frameworks and CMSs have built-in support, so turn it on rather than building your own.
Does a contact form need CSRF protection?
A public contact form with no login has little to forge, so risk is lower. Protection is still useful against forced junk submissions and is essential on any form tied to a logged-in account, checkout or admin screen.
Does SameSite=Lax stop CSRF?
It blocks cookies on most cross-site POST requests, which helps a lot, but it is not a full fix. It has exceptions, browser behaviour differs, and same-site attacks still work. Use it together with CSRF tokens.
Why do I get an invalid nonce or token expired error on my form?
The token is missing, expired or doesn't match the session. Common causes are full-page caching that serves an old token, a session that timed out, or a form left open too long. Exclude the page from caching or load the token with a small request on page load.
How do I test my site for CSRF?
On a site you own, copy a form submission from DevTools, remove the token, and replay it from a logged-in test account on staging. If it succeeds, the form is vulnerable. A security scanner can check all forms at scale.
Can FunnelGuard detect CSRF vulnerabilities?
No. CSRF testing needs a web application security scanner or penetration test. FunnelGuard checks that your funnels, tracking and lead delivery work, which is useful for confirming a fix did not break your forms.
Do WordPress and Shopify forms have CSRF protection by default?
Core WordPress features use nonces and Shopify's form tag adds an authenticity token. Custom forms, outdated plugins or hand-built endpoints may not, so check any form you added yourself.
Related issues
- OPS-175Cookies without Secure/HttpOnly/SameSiteFix guide
- OPS-177Reflected XSS in form fields or searchFix guide
- OPS-178Stored XSS via form submissions into adminFix guide
- OPS-179SQL injection in formsFix guide
- OPS-171Missing X-Frame-Options / frame-ancestors (clickjacking)Fix guide
- OPS-176Open redirect on site (abused for phishing, ad disapproval)Fix guide