Skip to content

Commit

Permalink
Merge pull request #171 from youyoumu/docs/csrf-protection
Browse files Browse the repository at this point in the history
Add note about X-XSRF-TOKEN header
  • Loading branch information
bknoles authored Jan 11, 2025
2 parents 0f69e56 + 65a1a51 commit cb692eb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/guide/csrf-protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Axios automatically checks for the existence of an `XSRF-TOKEN` cookie. If it's

The easiest way to implement this is using server-side middleware. Simply include the `XSRF-TOKEN` cookie on each response, and then verify the token using the `X-XSRF-TOKEN` header sent in the requests from axios. (That's basically what `inertia_rails` does).

> [!NOTE]
> `X-XSRF-TOKEN` header only works for [Inertia requests](/guide/the-protocol#inertia-responses). If you want to send a normal request you can use `X-CSRF-TOKEN` instead.
## Handling mismatches

When a CSRF token mismatch occurs, Rails raises the `ActionController::InvalidAuthenticityToken` error. Since that isn't a valid Inertia response, the error is shown in a modal.
Expand Down

0 comments on commit cb692eb

Please sign in to comment.