{
    "title": "Nonce",
    "seo_title": "Nonce: definition, CSP nonces and WordPress nonces",
    "h1": "Nonce",
    "description": "Nonce: a one-time value in cryptography, a CSP attribute and WordPress's anti-CSRF token valid 12 to 24 hours. How each is used and common mistakes.",
    "lead": "A nonce is a value, in principle random and used only once, added to an exchange to prevent it from being replayed or forged. In WordPress, a nonce is a token tied to an action, a user and their session, valid for 12 to 24 hours, mainly used to protect against CSRF attacks.",
    "language": "en",
    "locale": "en-US",
    "type": "definition",
    "url": "https://www.wp-feint.com/glossary/nonce/",
    "canonical": "https://www.wp-feint.com/glossary/nonce/",
    "markdown": "https://www.wp-feint.com/glossary/nonce/index.md",
    "json": "https://www.wp-feint.com/glossary/nonce/index.json",
    "published": "2026-10-28T08:00:00+00:00",
    "modified": "2026-11-22T12:08:07+00:00",
    "site": {
        "name": "WP Feint",
        "url": "https://www.wp-feint.com/"
    },
    "translations": [
        {
            "language": "en",
            "hreflang": "en-US",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/glossary/nonce/",
            "markdown": "https://www.wp-feint.com/glossary/nonce/index.md",
            "json": "https://www.wp-feint.com/glossary/nonce/index.json"
        },
        {
            "language": "fr",
            "hreflang": "fr-FR",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/fr/definitions/nonce/",
            "markdown": "https://www.wp-feint.com/fr/definitions/nonce/index.md",
            "json": "https://www.wp-feint.com/fr/definitions/nonce/index.json"
        },
        {
            "language": "es",
            "hreflang": "es-ES",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/es/glosario/nonce/",
            "markdown": "https://www.wp-feint.com/es/glosario/nonce/index.md",
            "json": "https://www.wp-feint.com/es/glosario/nonce/index.json"
        },
        {
            "language": "de",
            "hreflang": "de-DE",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/de/glossar/nonce/",
            "markdown": "https://www.wp-feint.com/de/glossar/nonce/index.md",
            "json": "https://www.wp-feint.com/de/glossar/nonce/index.json"
        },
        {
            "language": "it",
            "hreflang": "it-IT",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/it/glossario/nonce/",
            "markdown": "https://www.wp-feint.com/it/glossario/nonce/index.md",
            "json": "https://www.wp-feint.com/it/glossario/nonce/index.json"
        },
        {
            "language": "pt",
            "hreflang": "pt-BR",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/pt/glossario/nonce/",
            "markdown": "https://www.wp-feint.com/pt/glossario/nonce/index.md",
            "json": "https://www.wp-feint.com/pt/glossario/nonce/index.json"
        },
        {
            "language": "nl",
            "hreflang": "nl-NL",
            "title": "Nonce",
            "url": "https://www.wp-feint.com/nl/woordenlijst/nonce/",
            "markdown": "https://www.wp-feint.com/nl/woordenlijst/nonce/index.md",
            "json": "https://www.wp-feint.com/nl/woordenlijst/nonce/index.json"
        }
    ],
    "headings": [
        {
            "level": 1,
            "text": "Nonce"
        },
        {
            "level": 2,
            "text": "How nonces are used on the web"
        },
        {
            "level": 2,
            "text": "WordPress nonces: not really nonces"
        },
        {
            "level": 2,
            "text": "For WordPress: using nonces correctly"
        },
        {
            "level": 2,
            "text": "Common mistakes"
        }
    ],
    "body": "The word stands for “number used once.” In cryptography, MDN defines it as an arbitrary value used only once in a communication, to prevent an intercepted message from being replayed, to guarantee that a response is fresh or to add randomness to a computation. On the web, however, the term covers two fairly different things that are best kept apart: the “pure” cryptographic nonce and the WordPress nonce.\n\n## How nonces are used on the web\n\n- **In protocols**: [TLS](https://www.wp-feint.com/glossary/tls-ssl/) handshakes and many authentication mechanisms include random one-time values so that a recorded conversation cannot simply be replayed.\n- **In a Content Security Policy**: the server generates a random value for each response, places it in the `script-src 'nonce-…'` directive and in the `nonce` attribute of allowed scripts. A strict [CSP](https://www.wp-feint.com/glossary/content-security-policy/) only runs scripts that carry the right value. MDN stresses that it must change with every response and stay unpredictable.\n- **Against forged requests**: a secret token added to forms proves that the request really comes from a page on the site, which blocks [CSRF](https://www.wp-feint.com/glossary/csrf/) attacks. This is the main role of WordPress nonces.\n\n## WordPress nonces: not really nonces\n\nThe official WordPress documentation admits it: its nonces are neither numbers nor single-use. The `wp_create_nonce()` function computes a ten-character hash from the requested action, the user ID, their session token and a time window. The computation uses the `NONCE_KEY` and `NONCE_SALT` keys from `wp-config.php`, which is why a unique [salt](https://www.wp-feint.com/glossary/password-salting/) matters.\n\n- **Lifetime**: one day by default, split into two 12-hour windows. Depending on when it was created, a nonce therefore stays valid for 12 to 24 hours. The `nonce_life` filter changes this duration.\n- **Reusable**: WordPress doesn't check that a nonce has been used only once. It therefore doesn't protect against replay during its validity period.\n- **Logged-out visitors**: their user ID is 0, so all anonymous visitors can receive the same nonce for the same action.\n\n![Five-step diagram: WordPress creates a nonce tied to the action, the user, their session and a 12-hour window; the user submits the form with the token; a request forged on another site arrives without the right token; check_admin_referer or wp_verify_nonce rejects it; current_user_can finally checks the capability before acting](https://www.wp-feint.com/media/2026/10/nonce-wordpress-verification-en.webp)\n\n## For WordPress: using nonces correctly\n\nFor a theme or plugin developer, the rule boils down to three functions and a permission check:\n\n```\n// In the form\nwp_nonce_field( 'delete_post_' . $post_id );\n\n// When processing\ncheck_admin_referer( 'delete_post_' . $post_id );\nif ( ! current_user_can( 'delete_post', $post_id ) ) {\n    wp_die( 'You are not allowed to do this.' );\n}\n```\n\n- `check_admin_referer()` checks the nonce and the referrer on admin screens, `check_ajax_referer()` checks only the nonce for AJAX requests, and `wp_verify_nonce()` covers the other cases.\n- Name the action precisely (including the object ID) rather than using a generic name shared across the whole site.\n- Never rely on the nonce for authorization: the documentation says to protect every function with `current_user_can()`.\n\n## Common mistakes\n\nA good share of the plugin vulnerabilities reported each year comes from a missing nonce or a forgotten capability check, as our article [on WordPress plugin vulnerabilities by the numbers](https://www.wp-feint.com/wordpress-plugin-vulnerabilities-statistics/) shows. The typical case: an AJAX action checks the nonce but not the user's permission. Yet a nonce can leak into the code of a public page; if it is the only barrier, a mere subscriber can sometimes trigger an administrator action, which leads to [privilege escalation](https://www.wp-feint.com/glossary/privilege-escalation/). Our guide to WordPress roles and capabilities explains the logic of least privilege.\n\nAnother trap: a page cached for more than 12 to 24 hours serves an expired nonce, and the form fails with the message “The link you followed has expired.” Exclude pages containing forms meant for logged-in users from the cache.\n\n## Related terms\n\n- [CSRF (cross-site request forgery)](https://www.wp-feint.com/glossary/csrf/)\n- [Content Security Policy (CSP)](https://www.wp-feint.com/glossary/content-security-policy/)\n- [Privilege escalation](https://www.wp-feint.com/glossary/privilege-escalation/)\n- [Password salting](https://www.wp-feint.com/glossary/password-salting/)\n- [TLS / SSL](https://www.wp-feint.com/glossary/tls-ssl/)\n\n\n## Sources\n\n- [WordPress Common APIs Handbook : Nonces](https://developer.wordpress.org/apis/security/nonces/)\n- [WordPress Developer Resources : wp_create_nonce()](https://developer.wordpress.org/reference/functions/wp_create_nonce/)\n- [MDN : Nonce (glossaire)](https://developer.mozilla.org/en-US/docs/Glossary/Nonce)\n- [OWASP : Cross-Site Request Forgery Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html)",
    "definition": "A nonce is a value, in principle random and used only once, added to an exchange to prevent it from being replayed or forged. In WordPress, a nonce is a token tied to an action, a user and their session, valid for 12 to 24 hours, mainly used to protect against CSRF attacks.",
    "group": "Web security",
    "aka": [
        "number used once",
        "anti-CSRF token",
        "wp_nonce",
        "WordPress nonce"
    ],
    "related": [
        {
            "title": "CSRF (cross-site request forgery)",
            "url": "https://www.wp-feint.com/glossary/csrf/",
            "markdown": "https://www.wp-feint.com/glossary/csrf/index.md"
        },
        {
            "title": "Content Security Policy (CSP)",
            "url": "https://www.wp-feint.com/glossary/content-security-policy/",
            "markdown": "https://www.wp-feint.com/glossary/content-security-policy/index.md"
        },
        {
            "title": "Privilege escalation",
            "url": "https://www.wp-feint.com/glossary/privilege-escalation/",
            "markdown": "https://www.wp-feint.com/glossary/privilege-escalation/index.md"
        },
        {
            "title": "Password salting",
            "url": "https://www.wp-feint.com/glossary/password-salting/",
            "markdown": "https://www.wp-feint.com/glossary/password-salting/index.md"
        },
        {
            "title": "TLS / SSL",
            "url": "https://www.wp-feint.com/glossary/tls-ssl/",
            "markdown": "https://www.wp-feint.com/glossary/tls-ssl/index.md"
        }
    ],
    "sources": [
        {
            "title": "WordPress Common APIs Handbook : Nonces",
            "url": "https://developer.wordpress.org/apis/security/nonces/"
        },
        {
            "title": "WordPress Developer Resources : wp_create_nonce()",
            "url": "https://developer.wordpress.org/reference/functions/wp_create_nonce/"
        },
        {
            "title": "MDN : Nonce (glossaire)",
            "url": "https://developer.mozilla.org/en-US/docs/Glossary/Nonce"
        },
        {
            "title": "OWASP : Cross-Site Request Forgery Prevention Cheat Sheet",
            "url": "https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html"
        }
    ],
    "format": "application/json"
}