Expand description
CSRF protection via double-submit cookie.
Verifies state-changing POSTs with a double-submit __Host- cookie compared in constant time.
A form carries the cookie’s token masked with a one-time pad drawn for each render, so no two
compressed pages hold the same bytes for an observer to guess from response sizes (BREACH).
Constants§
- COOKIE_
NAME - Names the
__Host--prefixed CSRF cookie. - FIELD_
NAME
Functions§
- current_
token - Reads the current token without setting one, safe inside streamed children.
- ensure_
token - Ensures a request token before headers send, returning
""without a cookie layer. - field
- Renders the hidden field carrying the given token,
masked afresh. - mask
- The value a form posts under
FIELD_NAMEfortoken: the token XORed with a random pad, pad first, in unpadded base64url. Each call draws a new pad, so the same token never renders twice the same;verifyaccepts any of them.""whentokenis not a tokenensure_tokenissued. - verify
- Verifies the value a POST
submittedunderFIELD_NAMEis amaskof the cookie’s token with a constant-time compare, failing closed with 403. The cookie’s token itself, unmasked, is refused: no page renders it.