2017 © Pedro Peláez
 

symfony-bundle csrf-route-bundle

Symfony bundle which provides a simple way to add CSRF tokens to routes

image

genedys/csrf-route-bundle

Symfony bundle which provides a simple way to add CSRF tokens to routes

  • Thursday, November 30, 2017
  • by genedys
  • Repository
  • 2 Watchers
  • 2 Stars
  • 10,308 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 11 Versions
  • 12 % Grown

The README.md

GenedysCsrfRouteBundle

This Symfony3 bundle provides route annotation and options to secure routes against CSRF attacks and without using forms., (*1)

Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight, (*2)

Installation

Use Composer to install the bundle:, (*3)

composer require genedys/csrf-route-bundle, (*4)

or add the following line in your composer.json file:, (*5)

    "require": {
        ...
        "genedys/csrf-route-bundle": "^3.0",
        ...
    }

Then, register the bundle in your application's bundles.php file:, (*6)

    // bundles.php
    return [
        // ...
        Genedys\CsrfRouteBundle\GenedysCsrfRouteBundle => ['all' => true],
        // ...
    ];

Configuration

Configuration reference :, (*7)

genedys_csrf_route:
    enabled: true
    field_name: _token
  • enabled : Enable or disable the token verification (default: true);
  • field_name : The name of the field appended to route URLs (default: _token).

Usage

The only thing to do to use this package is to add some configurations to the routes you want to protect., (*8)

The bundle adds a router which can append a token query parameter on route generation and a controller listener validate which validates token on called routes., (*9)

Options configuration

The bundle checks controller calls and search for a csrf_token option. The available parameters for this options are: - token : The token parameter name (by default _token) - intention : The token intention. Different intentions generate different tokens (by default null which results to the route name). - methods : The HTTP method(s) when the CSRF token is validated (by default GET)., (*10)

# app/config/routing.yml
homepage:
    ...
    options:
        - csrf_token:
            - token: '_token'
            - intention: null
            - methods: [GET]

You can also only specify the csrf_token option to true to use default parameters., (*11)

# app/config/routing.yml
homepage:
    ...
    options: { csrf_token: true }

Annotation configuration

If you use annotations to configurate your routes, then the easiest way it to add an additionnal annotation to the sensible actions:, (*12)

<?php
// src Acme\DemoBundle\Controller\DefaultController.php

// ...
use Genedys\CsrfRouteBundle\Annotation\CsrfToken;
// ...

class DefaultController {
    // ...
    /**
     * ...
     * @CsrfToken
     */
    public function sensibleAction()
    {
        //...
    }
    // ...
}

Twig integration

As the bundle provides a custom router, CSRF tokens are automatically appended to url generated with path(...) and url(...) on Twig templates., (*13)

Routers compatibility

This bundle overrides the default Symfony router. In case you use other bundles which does the same thing (for instance JMSI18nRoutingBundle), the router integrated on this bundle works automatically as an adapter on previously configurated router. The only thing to take care is to register the GenedysCsrfRouterBundle after the bundle which overrides the router., (*14)

Credits

Created by Fabien Antoine for Genedys., (*15)

License

This bundle is under the MIT license., (*16)

The Versions

30/11 2017

dev-master

9999999-dev https://github.com/Genedys/csrf-route-bundle

Symfony bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

30/11 2017

3.0.0

3.0.0.0 https://github.com/Genedys/csrf-route-bundle

Symfony bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

31/03 2016

2.0.3

2.0.3.0 https://github.com/Genedys/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

31/03 2016

2.0.2

2.0.2.0 https://github.com/Genedys/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

23/03 2016

2.0.1

2.0.1.0 https://github.com/Genedys/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

17/02 2016

2.0.0

2.0.0.0 https://github.com/Genedys/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

18/08 2015

1.0.4

1.0.4.0 https://github.com/fantoine/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

23/04 2015

1.0.3

1.0.3.0 https://github.com/fantoine/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

16/03 2015

1.0.2

1.0.2.0 https://github.com/fantoine/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

16/03 2015

1.0.1

1.0.1.0 https://github.com/fantoine/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf

20/01 2015

1.0.0

1.0.0.0 https://github.com/fantoine/csrf-route-bundle

Symfony2 bundle which provides a simple way to add CSRF tokens to routes

  Sources   Download

MIT

The Requires

 

by Fabien Antoine

security route csrf