pub struct CookieStore { /* private fields */ }Expand description
Keeps the whole session in the cookie, signed with HMAC-SHA256 so a client cannot edit it.
No server-side state, which makes it the simplest thing that works. Two properties are worth being explicit about:
- Signed, not encrypted. The values are readable by whoever holds the cookie. Do not put anything in it the visitor should not see.
- The contents travel on every request. This suits a user id and a flash message, not a shopping cart.
- Expiry is carried inside the signature.
Set-Cookie’sMax-Ageis only a hint to a well-behaved client; a copied cookie ignores it. When the session plugin sets a max age, the deadline is signed into the payload and checked on load, so a captured cookie stops working. - There is still no revocation. Logging out clears the client’s copy, but a copy taken beforehand stays valid until its deadline, because nothing server-side records that it was withdrawn. A store backed by server state is what fixes that.
Use a key with at least 32 bytes of entropy, and keep it out of source control.
Implementations§
Source§impl CookieStore
impl CookieStore
Sourcepub fn with_max_age(self, secs: i64) -> Self
pub fn with_max_age(self, secs: i64) -> Self
Sign an expiry secs in the future into every cookie this store issues.
Set by Sessions::max_age; without it a cookie is valid for as long
as the signing key is.
Trait Implementations§
Source§impl SessionStore for CookieStore
impl SessionStore for CookieStore
Source§fn store<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
data: &'life1 BTreeMap<String, String>,
_previous: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn store<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
data: &'life1 BTreeMap<String, String>,
_previous: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
previous is unused: the whole session lives in the cookie, so there is
no server-side record to withdraw. Nothing here can fail either, for the
same reason — signing a payload asks nothing of anybody — so this never
returns Err, and an emptied session simply re-signs an empty payload.
Source§fn with_session_max_age(&self, secs: i64) -> Option<Box<dyn SessionStore>>
fn with_session_max_age(&self, secs: i64) -> Option<Box<dyn SessionStore>>
Adopt the session lifetime configured on
Sessions::max_age. Read moreAuto Trait Implementations§
impl Freeze for CookieStore
impl RefUnwindSafe for CookieStore
impl Send for CookieStore
impl Sync for CookieStore
impl Unpin for CookieStore
impl UnsafeUnpin for CookieStore
impl UnwindSafe for CookieStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more