publishing-kit / csrf
CSRF implementation
0.0.4
2021-05-09 09:57 UTC
Requires
- php: >=7.4
Requires (Dev)
- infection/infection: ^0.15.0
- laminas/laminas-session: ^2.9
- mockery/mockery: ^1.3
- php-coveralls/php-coveralls: ^2.2
- phpunit/phpunit: >=8.0
- psy/psysh: ^0.9.12
- squizlabs/php_codesniffer: ^3.0
- symfony/http-foundation: ^5.0
- vimeo/psalm: ^4.3
This package is auto-updated.
Last update: 2024-10-09 17:05:21 UTC
README
Simple CSRF implementation.
Install
Via Composer
$ composer require publishing-kit/csrf
You will also need to include one of the supported session libraries. Currently these are:
symfony/http-foundation
laminas/laminas-session
Usage
Here is an example of using the library to create and validate a token using the Laminas backend:
$session = new Laminas\Session\Container(); $storage = new PublishingKit\Csrf\LaminasSessionTokenStorage($session); $reader = new PublishingKit\Csrf\StoredTokenReader($storage); $token = $reader->read('foo'); $validator = new PublishingKit\Csrf\StoredTokenValidator($storage); $validator->validate('foo', $token);
And here we use the Symfony backend:
$session = new Symfony\Component\HttpFoundation\Session\Session( new Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage() ); $storage = new PublishingKit\Csrf\SymfonySessionTokenStorage($session); $reader = new PublishingKit\Csrf\StoredTokenReader($storage); $token = $reader->read('foo'); $validator = new PublishingKit\Csrf\StoredTokenValidator($storage); $validator->validate('foo', $token);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email 450801+matthewbdaly@users.noreply.github.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.