csrf

package
v3.11.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSRF

type CSRF interface {
	// Generate returns a CSRF token suitable for inclusion in a form
	Generate(http.ResponseWriter, *http.Request) string
	// Check returns true if the given token is valid for the given request
	Check(*http.Request, string) bool
}

CSRF handles generating a csrf value, and checking the submitted value

func NewCookieCSRF

func NewCookieCSRF(name, path, domain string, secure bool) CSRF

NewCookieCSRF stores random CSRF tokens in a cookie created with the given options. Empty CSRF tokens or tokens that do not match the value of the cookie on the request are rejected.

type FakeCSRF

type FakeCSRF struct {
	Token string
}

FakeCSRF returns the given token and error for testing purposes

func (*FakeCSRF) Check

func (c *FakeCSRF) Check(req *http.Request, value string) bool

Check implements the CSRF interface

func (*FakeCSRF) Generate

func (c *FakeCSRF) Generate(w http.ResponseWriter, req *http.Request) string

Generate implements the CSRF interface

Jump to

Keyboard shortcuts

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