Do you have a CSRF risk?
- Cookie-based sessions: yes, review it.
- Bearer tokens that your JavaScript adds to each request: the browser will not add them for another site, so classic CSRF does not apply.
- Any GET route that changes data is unsafe regardless of the session type.
Check where the request came from
For POST, PUT, PATCH and DELETE, compare the Origin header with your own host and reject mismatches.
const origin = request.headers.get('origin');
const host = request.headers.get('host');
if (!origin || new URL(origin).host !== host) {
return new Response('Forbidden', { status: 403 });
}Use tokens for sensitive actions
For money movement, email or password changes and account deletion, require a per-session token that a cross-site page cannot read, or ask the user to re-enter their password.
Frequently asked questions
Does SameSite=Lax fully stop CSRF?
It blocks most cross-site POST requests, but it is one layer. Keep origin checks and never change data on GET.
Do single-page apps need CSRF protection?
Only if they authenticate with cookies. Token-in-header apps rely on other protections.