The basics
CSRF
On web routes, every request whose method is not GET, HEAD, OPTIONS or TRACE (POST, PUT, PATCH,
DELETE, and any other method a Router::any route answers) must carry the session's token in a _token field
(URL-encoded or multipart form) or an X-CSRF-TOKEN header. A multipart body is read only up to its _token field
(at most BODY_LIMIT bytes; @csrf comes first in a form), and the rest streams on to the handler. @csrf in a Mold form writes the field.
@csrf, csrf_token() and the Sparks csrf-token meta tag show the token masked with a fresh random pad in every
response (session.csrf_token()), so the page's bytes never repeat it and a compressed HTTPS page cannot leak it
(BREACH); every masked form verifies, and so does the unmasked session.token(). Never put session.token() in a
page or response: render csrf_token() (or session.csrf_token()? in Rust) instead. A missing or
wrong token answers 419 "Page Expired" ({"error": "CSRF token mismatch"} for JSON clients). API routes are not
checked. Under APP_ENV=testing the check is off; TestApp::new(build).with_csrf() turns it on for a test.
Signing in and signing out give the session a new token, so a token from before is refused (a form left open in
another tab answers 419 once).