Documentation ¶
Overview ¶
Package csrfbanana creates a token to protect against CSRF attacks
Index ¶
- Constants
- Variables
- func Clear(w http.ResponseWriter, r *http.Request, sess *sessions.Session)
- func Token(w http.ResponseWriter, r *http.Request, sess *sessions.Session) string
- func TokenWithPath(w http.ResponseWriter, r *http.Request, sess *sessions.Session, urlPath string) string
- type CSRFHandler
- type StringMap
Constants ¶
View Source
const (
// the HTTP status code for the default failure handler
FailureCode = 400
)
Variables ¶
View Source
var ( TokenLength = 32 // Length of the token TokenName = "token" // Name of the token in the session variables SingleToken = false // True is one token for entire session, false is unique token for each URL )
Functions ¶
func Token ¶
Token will return a token. If SingleToken = true, it will return the same token for every page.
func TokenWithPath ¶
func TokenWithPath(w http.ResponseWriter, r *http.Request, sess *sessions.Session, urlPath string) string
Token will return a token for the specified URL. SingleToken is ignored.
Types ¶
type CSRFHandler ¶
type CSRFHandler struct {
// contains filtered or unexported fields
}
CSRFHandler contains the configuration for the CSRF structure
func New ¶
func New(next http.Handler, sessStore *sessions.CookieStore, sessName string) *CSRFHandler
New can be used as middleware because it returns an http.HandlerFunc
func (*CSRFHandler) ClearAfterUsage ¶
func (h *CSRFHandler) ClearAfterUsage(bl bool)
RegenerateEveryRequest will regenerate a token everytime it's checked (prevents double submit problem)
func (*CSRFHandler) ExcludeRegexPaths ¶
func (h *CSRFHandler) ExcludeRegexPaths(strings []string)
ExcludeRegexPath excludes a list of paths from the token middleware
func (*CSRFHandler) FailureHandler ¶
func (h *CSRFHandler) FailureHandler(handler http.Handler)
FailureHandler sets the handler if the token check fails
func (*CSRFHandler) ServeHTTP ¶
func (h *CSRFHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP will valid a token and it is does not match, it will show the FailureHandler
Click to show internal directories.
Click to hide internal directories.