hkvstore/samesite-cookie

Secure your site with SameSite cookies

Maintainers

πŸ‘ hkvstore

Package info

github.com/hkvstore/samesite-cookie

Homepage

pkg:composer/hkvstore/samesite-cookie

Statistics

Installs: 36 811

Dependents: 0

Suggesters: 0

Stars: 0

0.3.5 2023-10-12 03:39 UTC

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 7766e189676b667c56b966f51927468783f403df

cookiecsrfsamesitesamesite-cookie

This package is auto-updated.

Last update: 2026-06-12 09:37:55 UTC


README

A PSR-15 middleware to secure your site with SameSite cookies πŸͺ

πŸ‘ Latest Version on Packagist
πŸ‘ Software License
πŸ‘ Build Status
πŸ‘ Coverage Status
πŸ‘ Quality Score
πŸ‘ Total Downloads

Requirements

  • PHP 8.0+

Installation

composer require selective/samesite-cookie

SameSite cookies

πŸ‘ image

Same-site cookies ("First-Party-Only" or "First-Party") allow servers to mitigate the risk of CSRF and information leakage attacks by asserting that a particular cookie should only be sent with requests initiated from the same registrable domain.

Warning: SameSite cookies doesn't work at all for old Browsers and also not for some Mobil Browsers e.g. IE 10, Blackberry, Opera Mini, IE Mobile, UC Browser for Android.

Further details can be found here:

Slim 4 integration

<?php

use Selective\SameSiteCookie\SameSiteCookieMiddleware;
use Slim\Factory\AppFactory;

$app = AppFactory::create();

// ...

// Register the samesite cookie middleware
$app->add(new SameSiteCookieMiddleware());

// ...

$app->run();

Example with configuration and the session starter middleware.

Slim 4 uses a LIFO (last in, first out) middleware stack, so we have to add the middleware in reverse order:

<?php

use Selective\SameSiteCookie\SameSiteCookieConfiguration;
use Selective\SameSiteCookie\SameSiteCookieMiddleware;
use Selective\SameSiteCookie\SameSiteSessionMiddleware;
use Slim\Factory\AppFactory;

$app = AppFactory::create();

// ...

// Optional: Add custom configuration
$configuration = new SameSiteCookieConfiguration();

// Register the samesite cookie middleware
$app->add(new SameSiteCookieMiddleware($configuration));

// Optional: Start the PHP session
// Use this middleware only if you have no other session starter middleware
$app->add(new SameSiteSessionMiddleware());

// ...

$app->run();

License

The MIT License (MIT). Please see License File for more information.