2017 © Pedro Peláez
 

library module-csrfprotection

A means to provide token based CSRF protection

image

rhubarbphp/module-csrfprotection

A means to provide token based CSRF protection

  • Monday, January 15, 2018
  • by acuthbert
  • Repository
  • 4 Watchers
  • 0 Stars
  • 5,236 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 32 % Grown

The README.md

Module.CsrfProtection

Provides a mechanism for CSRF protection, (*1)

Usage

Simply require the module using composer:, (*2)

composer require rhubarbphp/module-csrfprotection

There are two types of validation provided, (*3)

Header validation

Simply call the validateHeaders method of the library to compare Origin and Referrer headers with the active request., (*4)

``` php CsrfProtection::singleton()->validateHeaders($request);, (*5)


$request should be the active WebRequest object. If you don't have a reference to it you can get it using ``` php $request = Request::current();

This validation should be done for every POST request. It can also be done for GET requests, however it isn't recommended as it will fail on the first request a client makes to the site., (*6)

This approach should be used in conjunction with header validation and compares a posted value against a previously generated random token stored in a cookie on the client., (*7)

When you output a form tag include the CSRF cookie token:, (*8)

$csrfProtector = CsrfProtection::singleton();

print '<input type="hidden" name="' . CsrfProtection::TOKEN_COOKIE_NAME . '" value="' . htmlentities($csrfProtector->getCookie()) . '" />';

When handling the post back, validate headers and the cookie:, (*9)

if ($request->server('REQUEST_METHOD') == 'POST'){
    CsrfProtection::singleton()->validateHeaders($request);
    CsrfProtection::singleton()->validateCookie($request);
}

Handling failures

If validation fails a CsrfViolationException is thrown which should be caught and handled appropriately., (*10)

The Versions

15/01 2018

dev-master

9999999-dev http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

15/01 2018

1.0.5

1.0.5.0 http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

15/01 2018

dev-feature/HttpOnlyToken

dev-feature/HttpOnlyToken http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

10/01 2018

1.0.4

1.0.4.0 http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

20/11 2017

1.0.2

1.0.2.0 http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

16/11 2017

1.0.1

1.0.1.0 http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

12/11 2017

dev-hotfix/PortSupport

dev-hotfix/PortSupport http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb

10/11 2017

1.0.0

1.0.0.0 http://www.rhubarbphp.com/

A means to provide token based CSRF protection

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

framework php token csrf protection rhubarb