csrfPreventionFilter

package
v0.0.0-...-fd23dd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2019 License: OSL-3.0 Imports: 8 Imported by: 2

README

CSRF Prevention Filter

This package provides middleware for CSRF security prevention (Cross-Site Request Forgery).

Configuration

By default, there are three parameters supported by module:

  • "all" - defines if all POST forms should be CSRF secured (default is false)
  • "secret" - defines key for AES encryption (16, 24 or 32 bytes for AES-128, AES-192 or AES-256)
  • "ttl" - defines max time (in seconds) validation for some token (default is 15 minutes)
csrf:
  all: false
  secret: "somethingSuperSecret"
  ttl: 900

Specific form

In case when it's not required to secure all forms, it's possible just to put middleware just for particular handler. In that case, only POST request for that handler will be secured.

type (
  routes struct {
    someController  *controller.SomeController
    csrfMiddleware  *interfaces.CsrfMiddleware
  }
)

func (r *routes) Routes(registry *router.Registry) {
  registry.HandlePost("some.handler", r.csrfMiddleware.Secured(r.someController.Handler))
}

Template

To add hidden input token into template, use template function:

!= csrfInput()

To add just token into template, use template function:

input(type="hidden" name="csrftoken" value=csrfToken())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	All bool `inject:"config:csrf.all"`
}

Module for core/csrfPreventionFilter

func (*Module) Configure

func (m *Module) Configure(injector *dingo.Injector)

Configure DI

func (*Module) DefaultConfig

func (m *Module) DefaultConfig() config.Map

DefaultConfig for this module

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL