> For the complete documentation index, see [llms.txt](https://coldbox-security.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-security.ortusbooks.com/secure-your-app/route-middleware/verify-csrf.md).

# Verify CSRF

Verify CSRF tokens on routes with the VerifyCsrf middleware.

`VerifyCsrf@cbsecurity` verifies a CSRF token on every request that is not `GET`, `HEAD` or `OPTIONS`. It uses the bundled [cbcsrf](/csrf-and-headers/cross-site-request-forgery-cbcsrf.md) module. A missing or invalid token gets a `403`.

```javascript
route( "/account/email" ).middleware( "VerifyCsrf@cbsecurity" ).to( "account.updateEmail" )
```

Generate the token in your form with the cbcsrf helpers:

```html
<form method="post" action="/account/email">
    #csrfField()#
    ...
</form>
```

The token is read from the `csrf` request key (what `csrfField()` creates) or the `x-csrf-token` header, the same places the cbcsrf auto verifier uses.

| Route meta key | Default   | Description                                                  |
| -------------- | --------- | ------------------------------------------------------------ |
| `csrfKey`      | `default` | The key the token was generated for, see `csrfToken( key )`. |

## Auto Verifier or Middleware?

The cbcsrf auto verifier (`csrf.enableAutoVerifier`) checks every request and uses exclusion patterns. The middleware checks only the routes you name, so it suits apps where most routes are APIs with token authentication and a few are browser forms. Unlike the auto verifier, the middleware also runs in integration tests.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-security.ortusbooks.com/secure-your-app/route-middleware/verify-csrf.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
