2017 © Pedro Peláez
 

library csrf

CSRF protection library that compares provided token to session token to ensure request validity.

image

volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  • Tuesday, September 19, 2017
  • by volnix
  • Repository
  • 5 Watchers
  • 41 Stars
  • 27,191 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 11 Forks
  • 3 Open issues
  • 12 Versions
  • 14 % Grown

The README.md

Volnix\CSRF

Build Status Downloads Latest Stable Version Code Coverage, (*1)

CSRF protection library that compares provided token to session token to ensure request validity. Token values are stored in session and validated against that session store to verify the request. Tokens are changed on every request so ensure frequently changes and increase the difficulty in guessing the token value., (*2)

Installation

This package is installed via composer and is pulled in as the volnix/csrf package., (*3)


"require": { "volnix/csrf": "~1.0" }

Unit Tests

The unit tests for this application live in the ./tests directory. There is a test for each library in the security package. The PHPUnit xml file is in the root of the project (./phpunit.xml)., (*4)

Usage

This library is used for preventing cross-site request forgery. Currently you can retrieve the token, a pre-built query string, or a pre-built hidden input tag., (*5)

There are two main pieces to this library:, (*6)

  1. Injection of a CSRF token
  2. Validation of the CSRF token

1. Injection of token

There are a variety of ways to get your CSRF token into your form markup:, (*7)

Value only:, (*8)


Hidden input string:, (*9)




= \Volnix\CSRF\CSRF::getHiddenInputString() ?>

Query string:, (*10)




If a different token name is desired, you may pass it in on any call that retrieves the token (getToken(), getHiddenInputString(), getQueryString()):, (*11)




= \Volnix\CSRF\CSRF::getHiddenInputString('custom_token_name') ?>

2. Validation of token

To validate your token, just pass in your array of POST/GET/REQUEST data. If you have a custom token name, then there is an optional second argument for it., (*12)

Note: token validation is done using a constant-time comparison method to protect against timing attacks., (*13)

Basic POST data validation:, (*14)


// generic POST data if ( CSRF::validate($_POST) ) { // good token } else { // bad token }

Using Symfony's HTTP Foundation:, (*15)


// symfony object $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); if ( CSRF::validate($request->request->all()) ) { // good token } else { // bad token }

Validating a custom-named token:, (*16)


// validating with a custom token name if ( CSRF::validate($_POST, 'my_custom_name') ) { // good token } else { // bad token }

The Versions

19/09 2017

dev-master

9999999-dev https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nick Volgas

19/09 2017

1.2.1

1.2.1.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nick Volgas

24/11 2015

1.2.0

1.2.0.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nick Volgas

30/03 2015

1.1.2

1.1.2.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nick Volgas

30/03 2015

1.1.1

1.1.1.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nick Volgas

30/03 2015

1.1.0

1.1.0.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.3

 

The Development Requires

by Nick Volgas

15/02 2015

1.0.5

1.0.5.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Nick Volgas

13/02 2015

1.0.4

1.0.4.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Nick Volgas

13/02 2015

1.0.3

1.0.3.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Nick Volgas

13/02 2015

1.0.2

1.0.2.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Nick Volgas

13/02 2015

1.0.1

1.0.1.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Nick Volgas

13/02 2015

1.0.0

1.0.0.0 https://github.com/volnix/csrf

CSRF protection library that compares provided token to session token to ensure request validity.

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

The Development Requires

by Nick Volgas