All Projects → sobstel → Sesshin

sobstel / Sesshin

Licence: mit
PHP secure advanced session manager.

Labels

Projects that are alternatives of or similar to Sesshin

Koa Redis
Redis storage for Koa session middleware/cache with Sentinel and Cluster support
Stars: ✭ 324 (+406.25%)
Mutual labels:  session
Silhouette
Silhouette is a framework agnostic authentication library for Scala that supports several authentication methods, including OAuth2, OpenID Connect, Credentials, Basic Authentication or custom authentication schemes.
Stars: ✭ 18 (-71.87%)
Mutual labels:  session
Session
A session handler for PHP and Slim 4+
Stars: ✭ 33 (-48.44%)
Mutual labels:  session
Vim Workspace
📑 Automated Vim session management with file auto-save and persistent undo history
Stars: ✭ 374 (+484.38%)
Mutual labels:  session
Session
Simple session middleware for Express
Stars: ✭ 5,571 (+8604.69%)
Mutual labels:  session
Vue express session nodb
这是一个带有express session验证的vue项目,其中server适用于其他任何前端框架,开发者可以根据自己的需求进行更改;另外session存储不涉及数据库存储,使用的是内存存储。
Stars: ✭ 24 (-62.5%)
Mutual labels:  session
Jaguar
Jaguar, a server framework built for speed, simplicity and extensible. ORM, Session, Authentication & Authorization, OAuth
Stars: ✭ 286 (+346.88%)
Mutual labels:  session
Beauty
A microframework based on mymysql,net/http,jwt-go and mux.
Stars: ✭ 61 (-4.69%)
Mutual labels:  session
Session
Simple session middleware for koa
Stars: ✭ 824 (+1187.5%)
Mutual labels:  session
Nsudo
Series of System Administration Tools
Stars: ✭ 945 (+1376.56%)
Mutual labels:  session
Akka Http Session
Web & mobile client-side akka-http sessions, with optional JWT support
Stars: ✭ 429 (+570.31%)
Mutual labels:  session
Smart App Rate
An Android library that encourages users to rate the app on the Google Play.
Stars: ✭ 609 (+851.56%)
Mutual labels:  session
Cookie Session
Simple cookie-based session middleware
Stars: ✭ 928 (+1350%)
Mutual labels:  session
Pode
Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
Stars: ✭ 329 (+414.06%)
Mutual labels:  session
Pg variables
Session wide variables for PostgreSQL
Stars: ✭ 44 (-31.25%)
Mutual labels:  session
Many People Blog
🎈基于vue+node+mysql的多人博客,带后台管理系统。支持:登陆/注册,留言,评论/回复,点赞,记录浏览数量,带有相册功能,内容丰富,当然也可以发表文章。欢迎使用!
Stars: ✭ 300 (+368.75%)
Mutual labels:  session
Fasthttpsession
A fast and powerful session package for fasthttp servers
Stars: ✭ 19 (-70.31%)
Mutual labels:  session
Django Qsessions
Extended session backends for Django (Sessions store IP, User Agent, and foreign key to User)
Stars: ✭ 64 (+0%)
Mutual labels:  session
Example Auth
User auth, session & JWT example for ReactQL
Stars: ✭ 51 (-20.31%)
Mutual labels:  session
Scs
HTTP Session Management for Go
Stars: ✭ 847 (+1223.44%)
Mutual labels:  session

Sesshin

Object-oriented, extendable advanced session handling component written with security in mind that mitigates attacks like Session Hijacking, Session Fixation, Session Exposure, Sesion Poisoning, Session Prediction.

Awarded 1st place in php.pl contest.

Features:

  • smart session expiry control
  • prevents session adoption, i.e. session ids generated only by the component are acceptable (strict model)
  • sends cookie only when session really created
  • session id rotation (anti session hijacking), based on time and/or number of requests
  • configurable:
  • unlike PHP native mechanism, you don't have to use cron or resource-consuming 100% garbage collecting probability to ensure sessions are removed exactly after specified time
  • convention over configuration - possible to configure user-defined stores, listeners (observers), entropy callback and fingerprint generators, but all of them have defaults set out-of-the-box
  • 100% independent from insecure native PHP session extension

Build Status Scrutinizer Code Quality

Usage

Installation

composer require sobstel/sesshin

Create new session

Only when create() called, session cookie is created (for native PHP session handler cookie is present all the time whether it's needed or not).

$session->create();

Open existing session

If session was not created earlier, session is not opened and false is returned.

$session->open();

If you want to create new session if it does not exist already, just pass true as argument. It will call create() transparently.

$session->open(true);

Regenerate session id

// auto-regenerate after specified time (secs)
$session->setIdTtl(300);

// auto-regenerate after specified number of requests
$session->setIdRequestsLimit(10);

// manually
$session->regenerateId();

Listen to special events

use Sesshin\Event\Event;

$eventEmitter = $session->geEmitter();

$eventEmitter->addListener('sesshin.no_data_or_expired', function(Event $event) {
  die('Session expired or session adoption attack!');
});
$eventEmitter->addListener('sesshin.expired', function(Event $event) {
  die(sprintf('Session %s expired!', $event->getSession()->getId()));
});
$eventEmitter->addListener('sesshin.invalid_fingerprint', function(Event $event) {
  die('Invalid fingerprint, possible attack!');
});

User session

use Sesshin\User\Session as UserSession;
use Sesshin\Store\FileStore;

$userSession = new UserSession(new FileStore('/path/to/dir'));

$userSession->create();
$userSession->login(123);

if ($userSession->isLogged()) {
  echo sprintf('User %s is logged', $userSession->getUserId());

  // Or if you have some kind of UserRepository class, which can be used to fetch user data
  $user = UserRepository::find($userSession->getUserId());
  echo sprintf('User %s is logged', $user->getUsername());
}

Store

Sesshin provides default FileStore.

use Sesshin\Session;
use Sesshin\Store\FileStore;

$session = new Session(new FileStore('/path/to/dir'));

Note! Using /tmp as a directory is not secure on shared hosting.

Alternatively you can use one of numerous doctrine/cache providers.

use Sesshin\Store\DoctrineCache;
use Doctrine\Common\Cache\MemcachedCache;

$memcached = new Memcached;
// here configure memcached (add servers etc)

$session = new Session(new DoctrineCache(new MemcachedCache($memcached)));

You can also implement your own store using Sesshin\Store\StoreInterface.

Change entropy algorithm

Entropy is used to generate session id.

$session->getIdHandler()->setEntropyGenerator(new MyFancyEntropyGenerator());

MyFancyEntropyGenerator must implement Sesshin\EntropyGenerator\EntropyGeneratorInterface.

Change session ID store

By default session ID is stored in cookie, but sometimes you may need to force session id, eg. based on some token, query string var, etc.

$session->getIdHandler()->setIdStore(new MyFancyIdStore());

MyFancyIdStore must implement Sesshin\Id\Store\StoreInterface.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].