rocket-session-store
rocket-session-store is a library for the rocket web framework. It manages sessions by using cookies and a customizable store.
Quickstart
Using this library consists of two steps:
- Setting up the session store fairing when building the rocket.
- Using the session request guard.
use ;
use ;
use Duration;
// Using the `Session` request guard
async
Security
-
When running Rocket behind a reverse proxy it is important to ensure that all
http://requests are redirected tohttps://before they reach Rocket. If this is not done correctly, it is possible for a session cookie to be sent over an insecure connection, which would allow session hijacking (note that this is a separate issue from theSecureattribute; theSecureattribute is intended to prevent clients from sending cookies over insecure connections, this is about preventing the server from sending a cookie over an insecure connection, which is possible regardless of whether theSecureattribute is present). -
Rocket automatically sets the
Secureattribute on all cookies by default to prevent clients from sending cookies over insecure connections. When developing locally it may be necessary to disable this attribute, but it should always be set in production. -
Rocket likewise defaults to setting
SameSitetoLax, which, for browsers that support it, effectively prevents CSRF attacks as long as there are no GET requests that can change the application state (which is a bit vague, but basically if something is persisted in a database and it's not related to logging, it shouldn't be changed in a GET request). Current versions of all major browsers now support theSameSiteattribute, but it's still recommended to use other CSRF prevention techniques as well. As of April 2022 Can I use reports that 91.43% of users are using browsers that supportSameSite. -
To prevent session fixation attacks, it is important to regenerate the session token when a user logs in. There is an example of how to do this here.
Contributing
If you wish to contribute, please read CONTRIBUTING.md.