pub struct Session(/* private fields */);Expand description
A handle to the current visitor’s session.
Cloneable and cheap; all clones share one map. Extract it as a handler argument.
Implementations§
Source§impl Session
impl Session
Sourcepub fn clear(&self)
pub fn clear(&self)
Drop every value.
Call this on logout. Rotating rather than reusing a session is what stops a fixated session id from surviving a privilege change.
Sourcepub fn rotate(&self)
pub fn rotate(&self)
Keep the contents but ask the store for a new identifier.
This is the session fixation defence for a server-side store: an
attacker who plants a known session id must not still hold a valid one
after the victim’s privileges change. Call it on login, and on any other
privilege change, when you want to keep what is already in the session
(a cart, a locale) rather than dropping it the way clear
does.
It works by removing SESSION_ID_KEY, which a server-side store uses
to remember which record this session is, so the next write mints a new
one. CookieStore keeps no identifier and is unaffected: its payload
is re-signed on every change already, so a planted cookie never carries
the post-login contents.