silverstripe / hybridsessions
Cookie/DB session support for SilverStripe
Installs: 374 437
Dependents: 4
Suggesters: 0
Security: 1
Stars: 16
Watchers: 11
Forks: 21
Open Issues: 3
Type:silverstripe-vendormodule
Requires
- php: ^8.1
- silverstripe/framework: ^5
Requires (Dev)
- 4.x-dev
- 3.x-dev
- 3.0.x-dev
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-rc1
- 3.0.0-beta3
- 3.0.0-beta2
- 3.0.0-beta1
- 2.x-dev
- 2.7.x-dev
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.7.0-rc1
- 2.7.0-beta1
- 2.6.x-dev
- 2.6.0
- 2.6.0-rc1
- 2.6.0-beta1
- 2.5.x-dev
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.x-dev
- 2.4.1
- 2.4.0
- 2.3.x-dev
- 2.3.0
- 2.3.0-rc1
- 2.3.0-beta1
- 2.2.x-dev
- 2.2.1
- 2.2.0
- 2.1.x-dev
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.x-dev
- 2.0.0
- 2.0.0-beta2
- 2.0.0-beta1
- 1.x-dev
- 1.2.x-dev
- 1.2.0
- 1.2.0-rc1
- 1.1.x-dev
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.x-dev
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-2.6-release
- dev-master
This package is auto-updated.
Last update: 2024-11-10 22:14:50 UTC
README
Introduction
Adds a session handler that tries storing the session in an encrypted cookie when possible, and if not ( because the session is too large, or headers have already been set) stores it in the database.
This allows using Silverstripe on multiple servers without sticky sessions (as long as you solve other multi-server issues like asset storage and databases).
Limitations
- MySQL database is the only supported DB store.
Installation
composer require silverstripe/hybridsessions
Setup
/dev/build?flush=all
to setup the necessary tables- In order to initiate the session handler is is necessary to add a snippet of code to your
_config.php
file, along with a private key used to encrypt user cookies.
in app/src/_config.php
:
// Ensure that you define a sufficiently indeterminable value for SS_SESSION_KEY in your `.env` use SilverStripe\Core\Environment; use SilverStripe\HybridSessions\HybridSession; HybridSession::init(Environment::getEnv('SS_SESSION_KEY'));
Security
As long as the key is unguessable and secret, generally this should be as secure as server-side-only cookies. The one exception is that cookie sessions are vulnerable to replay attacks. This is only a problem if you're storing stuff you shouldn't in the session anyway, but it's important you understand the issue. Ruby on rails has good documentation of the issue at http://guides.rubyonrails.org/security.html#replay-attacks-for-cookiestore-sessions
Crypto handlers
This module ships with two default cryptographic handlers:
OpenSSLCrypto
: uses the OpenSSL library (default).
You can also implement your own cryptographic handler by creating a class that implements the
SilverStripe\HybridSessions\Crypto\CryptoHandler
interface.
To configure the active handler, add YAML configuration to your project:
--- Name: myappsessionstores After: sessionstores --- SilverStripe\HybridSessions\HybridSession: SilverStripe\HybridSessions\Crypto\CryptoHandler: class: MyCustomCryptoHandler
Caveats
This module is not fully compatible with the testsession module, as the database store is not available prior to DB connectivity, which uses the session to dictate DB connections. Data smaller than 1000 bytes may still be stored via the cookie store, but larger data sets will be lost.