Giter Site home page Giter Site logo

omatamix / session-lock Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 2.0 646 KB

Securely manage and preserve session data.

Home Page: https://omatamix.github.io/session-lock/

License: MIT License

PHP 99.99% Hack 0.01%
php session-management session-fingerprinting session-handlers cache null secure

session-lock's Introduction

Session Lock

Continuous Integration

Installation

The best way to install Session Lock is through composer. If you do not have composer installed you can install it directly from the composer website. After composer is successfully installed run the command line code below.

composer require omatamix/session-lock

Usage

Session Manager

The session manger comes with a simple api.

use Omatamix\SessionLock\SessionManager;

// Construct a new session manager.
$session = new SessionManager();

Start or resume a session.

$session->start();

Check to see if our session is running.

if ($session->exists()) {
    echo "The session is running!";
}

The put method sets a session variable.

$session->put('hello', 'world');

This checks to see if this session variable is set.

if ($session->has('hello')) {
    echo "The session variable exists.";
}

The delete method deletes a session variable.

$session->delete('hello');

The get method gets the session variables value.

echo "Hello " . $session->get('hello') . "!";

The flash method does the same as get but flash will delete the session variable after retrievale.

echo "Hello " . $session->flash('hello') . "!";

Stop a session.

$session->stop();

Session Regeneration

It is very easy to update the current session id with a newly generated one.

$session->regerate();

Session Fingerprinting

This session manager comes with a built-in session fingerprinting which in a way improves session security. When you create a session handler instance, session fingerprinting is enabled by defualt, it binds your remote ip and user agent. If you do not want this enabled you can turn it off with.

$session = new SessionManager([
    'fingerprinting' => false,
]);

You can also disable binding the remote ip or user agent like this.

$session = new SessionManager([
    'bind_ip_address' => false, // If set to true we will bind the ip address else dont.
    'bind_user_agent' => false, // If set to true we will bind the user agent else dont.
]);

If you are using a trusted proxy you can set the remote ip with this.

$session = new SessionManager([
    'use_ip' => '127.0.0.1',
]);

Session Handlers

You can also set how you session information is stored using session handlers,

use Omatamix\SessionLock\SessionHandlers\CacheSessionHandler;

$session = new SessionManager();
$session->setSaveHandler(new CacheSessionHandler(/** A `psr/cache` or `psr/simple-cache` pool. */));

Supported

  • Omatamix\SessionLock\SessionHandlers\CacheSessionHandler::class
  • Omatamix\SessionLock\SessionHandlers\CookieSessionHandler::class
  • Omatamix\SessionLock\SessionHandlers\DatabaseSessionHandler::class
  • Omatamix\SessionLock\SessionHandlers\NullSessionHandler::class

Encryption Adapters

This library also includes encrypted session handlers.

use Defuse\Crypto\Key;
use Omatamix\SessionLock\Encryption\Adapter\Defuse;
use Omatamix\SessionLock\Encryption\Encrypted;

$session = new SessionManager();
$session->setSaveHandler(new Encrypeted(new CacheSessionHandler(/** A `psr/cache` or `psr/simple-cache` pool. */), new Defuse(Key::createNewRandomKey()));

// All session data will now be encrpyted using the `defuse` adapter.

Supported

  • Omatamix\SessionLock\Encryption\Adapter\Defuse::class
  • Omatamix\SessionLock\Encryption\Adapter\Halite::class

Session Config

You can also pass session configuration through the session manager constructor method.

$session = new SessionManager([
    'config' => [
        'use_cookies'      => true,
        'use_only_cookies' => true,
        'cookie_httponly'  => true,
        'cookie_samesite'  => 'Lax',
        'use_strict_mode'  => true,
    ]
]);

Security Vulnerabilities

If you discover a security vulnerability within Session Lock, please send an e-mail to Nicholas via [email protected]. All security vulnerabilities will be promptly addressed.

Contributing

All contributions are welcome! If you wish to contribute.

License

This project is licensed under the terms of the MIT License.

session-lock's People

Contributors

dependabot[bot] avatar kooser6 avatar omatamix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

volkron kooser06

session-lock's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.