Skip to content
Switch branches/tags

Latest commit

The Javascript library searches `document.cookie` to find the CSRF token
value associated with the cookie named after the constant `CSRFP_TOKEN`
(in practice, this is `csrfp_token`). However, the regex does not define
what values may precede the token's name, meaning that a cookie such as
`BNES_csrfp_token` (as was set by the Barracuda WAF) set on the same
domain can be erroneously picked up instead of the correct `csrfp_token`

This commit restricts the regex to only match if it is preceded by
either the start of the string (i.e. nothing) or a semicolon followed by
(a) any amount of whitespace, or (b) nothing, followed by the cookie's
name. This allows it to match if it is the only/first cookie in
`document.cookie` as well as if it follows another cookie in
df629c8 2

Git stats


Failed to load latest commit information.

CSRF Protector

Todo Status Build Status Minimum PHP Version
CSRF protector php, a standalone php library for csrf mitigation in web applications. Easy to integrate in any php web app.

Add to your project using packagist

Add a composer.json file to your project directory

   "require": {
       "owasp/csrf-protector-php": "dev-master"

Then open terminal (or command prompt), move to project directory and run

composer install

## Or alternatively

php composer.phar install

This will add CSRFP (library will be downloaded at ./vendor/owasp/csrf-protector-php) to your project directory. View for more help with composer!


For composer installations: Copy the config.sample.php file into your root folder at config/csrf_config.php For non-composer installations: Copy the libs/csrf/config.sample.php file into libs/csrf/config.php Edit config accordingly. See Detailed Information link below.

Link to wiki - Editing Configurations & Mandatory requirements before using this library

How to use

include_once __DIR__ .'/vendor/owasp/csrf-protector-php/libs/csrf/csrfprotector.php';

// Initialise CSRFProtector library

simply include the library and call the init() function!

More information


Join Discussions at Google Group \ OWASP \ CSRF Protector

For any other queries contact me at: |

How to contribute?

General steps

  • Fork the repo
  • Create your branch
  • Commit your changes
  • Create a pull request


Well, there are various ways to contribute to this project. Find a few of them listed below:

  • Found a bug? Raise a bug in the issue page. Please make sure it's not a duplicate of an existing issue.
  • Have a feature request? Raise one at the issue page. As mentioned above please do a basic check if this enhancement exists in the mentioned link.
  • Want to contribute code to this project?
    • The best way to start is by picking up one of the existing issues with Up For Grab label.
    • Leave a comment, that you intend to help on this > then fork > and then send a pull request to master branch.


  1. What happens if token expires? -
  2. Secure flag in a cookie? - #54
  3. [Deprecated] NoJS support? -