Verified against Semitexa Ultimate 2026.10.03.1952
CSRF
The session cookie is SameSite=Lax, so a browser leaves it off most requests that another
site starts. Lax is not a guarantee: a page on a sibling subdomain is the same site and still
gets the cookie sent. Semitexa therefore checks every unsafe request (POST, PUT, PATCH, DELETE)
that carries the session cookie, signed in or not, and refuses it unless it proves it came
from your own page. A request without the session cookie is not checked.
How it works
Each session holds one token (CsrfToken, a typed session payload). It is created with the
session and rotated when the session is regenerated at sign-in. CsrfListener compares it,
in constant time, with what the request presents:
-
a plain HTML form presents the
_csrffield. Write it withcsrf_field(), which renders the hidden input for the request being served:<form method="post" action="/account/logout"> {{ csrf_field() }} <button type="submit">Sign out</button> </form> -
JavaScript sends the
X-CSRF-Tokenheader. The token is also in the readableXSRF-TOKENcookie, andwithCsrf()fromplatform-ui/coreadds the header for you.csrf_token()returns the raw value when a template needs it, for example in a data attribute. -
Platform UI forms (
platform.formwith asubmitAction) carry their own per-submit token and need neither of these.
A guest is checked too. A guest session holds state (a cart, a draft, the sign-in form
itself), and a form on another site posting into it is the same attack. Every session has its
token from its first response, so a guest form presents it the same way: a guest form without
csrf_field() is refused with 403. A webhook or machine route opts out with #[CsrfExempt]
on its payload. Outside a request (CLI, a test), csrf_field() renders nothing.
Why this matters
Before csrf_field(), every handler that rendered a form read the token from the session and
passed it through its resource into the template. One missed handler meant a form that every
signed-in user saw refused. Until guests were checked as well, a guest form without the token
worked in development and was refused only once its author signed in. The helper reads the
session of the request being rendered, so it also carries the new token on a page rendered
right after sign-in.