{
    "title": "CSRF (cross-site request forgery)",
    "seo_title": "CSRF: definition, example and protection with nonces",
    "h1": "CSRF (cross-site request forgery)",
    "description": "CSRF explained: how a third-party page makes your browser act on your behalf, the role of SameSite cookies and why WordPress nonces stop it.",
    "lead": "CSRF (cross-site request forgery) is an attack that makes a logged-in user's browser send a request, without their knowledge, to a site where their session is open. The site believes it is a deliberate action: email address changed, setting modified, account created.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-feint.com/glossary/csrf/",
    "canonical": "https://www.wp-feint.com/glossary/csrf/",
    "markdown": "https://www.wp-feint.com/glossary/csrf/index.md",
    "json": "https://www.wp-feint.com/glossary/csrf/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-11-22T12:06:59+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "CSRF (cross-site request forgery)",
            "url": "https://www.wp-feint.com/glossary/csrf/",
            "markdown": "https://www.wp-feint.com/glossary/csrf/index.md",
            "json": "https://www.wp-feint.com/glossary/csrf/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "CSRF",
            "url": "https://www.wp-feint.com/fr/definitions/csrf/",
            "markdown": "https://www.wp-feint.com/fr/definitions/csrf/index.md",
            "json": "https://www.wp-feint.com/fr/definitions/csrf/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "CSRF",
            "url": "https://www.wp-feint.com/es/glosario/csrf/",
            "markdown": "https://www.wp-feint.com/es/glosario/csrf/index.md",
            "json": "https://www.wp-feint.com/es/glosario/csrf/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "CSRF (Cross-Site Request Forgery)",
            "url": "https://www.wp-feint.com/de/glossar/csrf/",
            "markdown": "https://www.wp-feint.com/de/glossar/csrf/index.md",
            "json": "https://www.wp-feint.com/de/glossar/csrf/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "CSRF (cross-site request forgery)",
            "url": "https://www.wp-feint.com/it/glossario/csrf/",
            "markdown": "https://www.wp-feint.com/it/glossario/csrf/index.md",
            "json": "https://www.wp-feint.com/it/glossario/csrf/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "CSRF",
            "url": "https://www.wp-feint.com/pt/glossario/csrf/",
            "markdown": "https://www.wp-feint.com/pt/glossario/csrf/index.md",
            "json": "https://www.wp-feint.com/pt/glossario/csrf/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "CSRF (cross-site request forgery)",
            "url": "https://www.wp-feint.com/nl/woordenlijst/csrf/",
            "markdown": "https://www.wp-feint.com/nl/woordenlijst/csrf/index.md",
            "json": "https://www.wp-feint.com/nl/woordenlijst/csrf/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "CSRF (cross-site request forgery)"
        },
        {
            "level": 2,
            "text": "How a CSRF attack works"
        },
        {
            "level": 2,
            "text": "The role of SameSite cookies"
        },
        {
            "level": 2,
            "text": "For WordPress: nonces and permission checks"
        },
        {
            "level": 2,
            "text": "How to protect your site as an owner"
        },
        {
            "level": 2,
            "text": "Common mistakes"
        }
    ],
    "body": "CSRF exploits an automatic browser behavior: with every request to a site, the browser attaches that site's cookies, including the session cookie. An external page can therefore trigger a request to your site, and the server receives it with the logged-in user's credentials. Nothing distinguishes it from a deliberate click, unless the site checks that it really comes from its own forms. MITRE lists it as CWE-352; it is also written XSRF.\n\n## How a CSRF attack works\n\nThe attacker prepares a page that contains a request to the target site: an invisible image whose URL triggers an action, or a hidden form submitted automatically by JavaScript. All that's left is to lure the victim to that page, through a link in an email, a comment or a message. If they are logged in to the target site at the same time, the request goes out with their session.\n\n![Five-step CSRF attack: the administrator is logged in, visits a malicious page, a hidden form is sent to the site with their session cookie, the site performs the action without any check, whereas a verified nonce would have caused the request to be rejected](https://www.wp-feint.com/media/2026/10/csrf-sequence-en.webp)\n\nAs OWASP points out, the attacker doesn't see the server's response. CSRF therefore targets requests that change something: modifying an account's email address, changing a setting, creating a user, deleting content. In a WordPress admin area, those actions are often enough to take over the site.\n\n## The role of SameSite cookies\n\nThe `SameSite` cookie attribute limits when cookies are sent from another site. With `Strict`, the cookie only accompanies requests coming from the same site; with `Lax`, it is also sent during top-level navigation with a safe method, such as a plain GET link. MDN notes that some browsers apply `Lax` by default when the attribute is missing. It is a useful but partial protection: an action triggered by a GET link still goes through, and not all browsers behave the same way. It therefore adds to anti-CSRF tokens without replacing them.\n\n*Video: “Cross-Site Request Forgery (CSRF) Explained” (PwnFunction)*\n\n## For WordPress: nonces and permission checks\n\nWordPress protects its forms and action links with [nonces](https://www.wp-feint.com/glossary/nonce/): tokens tied to the user, their session and the requested action, which a third-party site can't guess. Their lifetime is 24 hours by default, split into two 12-hour windows. A plugin that adds its own actions must use them too:\n\n```\n// In the form\nwp_nonce_field( 'myplugin_save', 'myplugin_nonce' );\n\n// When processing\ncheck_admin_referer( 'myplugin_save', 'myplugin_nonce' );\nif ( ! current_user_can( 'manage_options' ) ) {\n    wp_die( 'Access denied' );\n}\n```\n\n- `wp_nonce_field()` and `wp_nonce_url()` add the token to a form or a URL;\n- `check_admin_referer()` verifies it in the admin area, `check_ajax_referer()` in an AJAX request, `wp_verify_nonce()` elsewhere;\n- `current_user_can()` is still mandatory: the WordPress documentation points out that a nonce is not meant for authentication or access control.\n\n## How to protect your site as an owner\n\nMissing nonces are still common in plugins: CSRF is among the vulnerability categories regularly disclosed, as [the numbers on WordPress plugin vulnerabilities](https://www.wp-feint.com/wordpress-plugin-vulnerabilities-statistics/) show. On the owner's side, the habits are simple: update, avoid clicking unknown links during an admin session, log out after working on the site, and don't multiply administrator accounts. Neither WP Feint nor any Dashboard setting fixes a missing nonce in a plugin: only updating the plugin does.\n\n## Common mistakes\n\n- Checking the nonce without checking permissions: a logged-in subscriber who picks up a valid nonce displayed on a page they can access can call an action meant for administrators. That opens the door to [IDOR](https://www.wp-feint.com/glossary/idor/) or access control vulnerabilities.\n- Changing data on a plain GET request, which goes through even with `SameSite=Lax` cookies.\n- Forgetting that a [cross-site scripting flaw](https://www.wp-feint.com/glossary/xss/) cancels the protection: a script running in the page reads the nonces it contains.\n- Confusing CSRF with [clickjacking](https://www.wp-feint.com/glossary/clickjacking/): the latter makes the victim click on your real page, displayed in an invisible frame, which a nonce doesn't prevent.\n\n## Related terms\n\n- [Nonce](https://www.wp-feint.com/glossary/nonce/)\n- [XSS (cross-site scripting)](https://www.wp-feint.com/glossary/xss/)\n- [Clickjacking](https://www.wp-feint.com/glossary/clickjacking/)\n- [IDOR (insecure direct object reference)](https://www.wp-feint.com/glossary/idor/)\n- [SQL injection](https://www.wp-feint.com/glossary/sql-injection/)\n\n\n## Sources\n\n- [OWASP : Cross Site Request Forgery (CSRF)](https://owasp.org/www-community/attacks/csrf)\n- [MITRE CWE-352 : Cross-Site Request Forgery (CSRF)](https://cwe.mitre.org/data/definitions/352.html)\n- [WordPress Developer Resources : Nonces](https://developer.wordpress.org/apis/security/nonces/)\n- [MDN : Set-Cookie, attribut SameSite](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie)",
    "definition": "CSRF (cross-site request forgery) is an attack that makes a logged-in user's browser send a request, without their knowledge, to a site where their session is open. The site believes it is a deliberate action: email address changed, setting modified, account created.",
    "group": "Web security",
    "aka": [
        "cross-site request forgery",
        "XSRF",
        "session riding",
        "CWE-352"
    ],
    "related": [
        {
            "title": "Nonce",
            "url": "https://www.wp-feint.com/glossary/nonce/",
            "markdown": "https://www.wp-feint.com/glossary/nonce/index.md"
        },
        {
            "title": "XSS (cross-site scripting)",
            "url": "https://www.wp-feint.com/glossary/xss/",
            "markdown": "https://www.wp-feint.com/glossary/xss/index.md"
        },
        {
            "title": "Clickjacking",
            "url": "https://www.wp-feint.com/glossary/clickjacking/",
            "markdown": "https://www.wp-feint.com/glossary/clickjacking/index.md"
        },
        {
            "title": "IDOR (insecure direct object reference)",
            "url": "https://www.wp-feint.com/glossary/idor/",
            "markdown": "https://www.wp-feint.com/glossary/idor/index.md"
        },
        {
            "title": "SQL injection",
            "url": "https://www.wp-feint.com/glossary/sql-injection/",
            "markdown": "https://www.wp-feint.com/glossary/sql-injection/index.md"
        }
    ],
    "sources": [
        {
            "title": "OWASP : Cross Site Request Forgery (CSRF)",
            "url": "https://owasp.org/www-community/attacks/csrf"
        },
        {
            "title": "MITRE CWE-352 : Cross-Site Request Forgery (CSRF)",
            "url": "https://cwe.mitre.org/data/definitions/352.html"
        },
        {
            "title": "WordPress Developer Resources : Nonces",
            "url": "https://developer.wordpress.org/apis/security/nonces/"
        },
        {
            "title": "MDN : Set-Cookie, attribut SameSite",
            "url": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie"
        }
    ],
    "format": "application/json"
}