Same-origin writes
Browsers attach Cookies to requests that other sites start. For the methods in writeMethods (POST, PUT, PATCH and DELETE by default), the guard therefore asks for proof that the request came from your own pages.
The check
- If the request has
Sec-Fetch-Site, onlysame-originandnonepass.same-siteis rejected, so a sibling subdomain cannot write. - Without
Sec-Fetch-Site, theOriginheader must equal the request's own origin: protocol, host and port. The guard readsX-Forwarded-HostandX-Forwarded-Proto, so a trusted reverse proxy must overwrite them. - With neither header, the request is rejected.
A failure answers 403. The check runs after verifyUser on protected routes and on its own on public routes.
Visitor routes are stricter
Routes with access: 'visitor' accept only Sec-Fetch-Site: same-origin, for every method including GET, and do not fall back to Origin. See Sites without users.
Bearer clients
When verifyUser returned { viaBearer: true } for a request whose Authorization header holds a Bearer token, the check is skipped. Another site cannot make the browser send your token, and mobile apps or CLI tools do not send Origin at all.
Server-to-server POSTs
Webhooks and other server-to-server calls send neither header and cannot use a Bearer token you verify, so a wrapped route rejects them. Serve them from a folder outside routePatterns; see Webhooks.
GET must not change state
Methods outside writeMethods are never checked. Keep GET and HEAD free of side effects, or add the method to writeMethods.
With nuxt-csurf
The origin check and a CSRF token protect against the same attack in different ways. You can use both; see CSRF tokens with nuxt-csurf.