Skip to main content

Module session

Module session 

Source
Expand description

What a request by session carries: the cookie, the CSRF token and the origin it must come from.

A session is a row in the registry (crate::tenants), found by the SHA-256 of a random 256-bit id. The id travels in the cookie COOKIE and nowhere else. The CSRF token is made from the id (csrf_token), so GET /session can hand it to the page again while the registry keeps only its hash; page script cannot read the cookie, and the token does not show the id.

Structs§

Origin
A listener’s public origin (public_origin, operator.public_origin): https:// and a host, with a port when it is not 443, as a browser writes it in the Origin header of a request from the listener’s pages.

Constants§

COOKIE
The session cookie’s name. The __Host- prefix has a browser refuse the cookie unless it is Secure, has Path=/ and names no domain, so no other host and no plain-HTTP page can set or read it.
CSRF_HEADER
The request header that carries the session’s CSRF token.

Functions§

set_cookie
The Set-Cookie value that gives a browser the session with this id. It names no lifetime: the browser drops it when it closes, and the registry holds the limits. A sign-in method answers with it once Tenants::start_session has given it the id; none is built yet.