invalid csrf token Authentication Origin: Application & API Last updated 14 Oct 2026

ForbiddenError: invalid csrf token (EBADCSRFTOKEN)

The request’s CSRF token is missing or doesn’t match the token tied to the user’s session/cookie.

Exact message you may see invalid csrf tokenForbiddenError: invalid csrf tokenCSRF token mismatchCSRF token missing
Seen on: REST API

Meaning

Forms and AJAX must include the token; it’s bound to the session/secret cookie. Cached pages, cookies not sent (cross-site/SameSite), session store resets and missing headers cause mismatches.

Common causes

  • Token not included in form/AJAX header
  • Session or secret cookie lost (restart with memory store, SameSite)
  • Page cached with an old token
  • Multiple tabs/old forms

⚡ Quick fix

  1. Include the token (hidden input or X-CSRF-Token header)
  2. Use a persistent session store; send cookies with credentials
  3. Don’t cache pages containing tokens

Detailed fix by platform

JavaScript

  1. fetch("/api/profile", { method: "POST", credentials: "same-origin", headers: { "Content-Type": "application/json", "X-CSRF-Token": csrfToken }, body: JSON.stringify(data) });

How to diagnose

  1. Request — Token present?
  2. Cookie — Session/secret cookie sent?
  3. Cache — Page cached?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0x800704EC — 0x800704EC: This program is blocked by group policy (Windows Defender) (Windows)0x800704EC1005 — Cloudflare Error 1005: Access denied — The owner of this website has banned the autonomous system number (ASN) your IP address is in (Cloudflare)10051006 — Cloudflare Error 1006 / 1007 / 1008: Access denied — Your IP address has been banned (Cloudflare)10061009 — Cloudflare Error 1009: Access denied — The owner of this website has banned the country or region your IP address is in (Cloudflare)10091010 — Cloudflare Error 1010: The owner of this website has banned your access based on your browser's signature (Cloudflare)10101011 — Cloudflare Error 1011: Access denied (Hotlinking denied) (Cloudflare)10111012 — Cloudflare Error 1012: Access denied (Cloudflare)10121015 — Cloudflare Error 1015: You are being rate limited (Cloudflare)1015invalid c…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.