csrf

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package CSRF provides middleware for handling Cross-Site Request Forgery (CSRF) protection in web applications

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(conf *Config) echo.MiddlewareFunc

Middleware creates the CSRF middleware from the provided config.

Types

type Config

type Config struct {
	// Enabled indicates whether CSRF protection is enabled.
	Enabled bool `json:"enabled" koanf:"enabled" default:"false"`
	// Header specifies the header name to look for the CSRF token.
	Header string `json:"header" koanf:"header" default:"X-CSRF-Token"`
	// Cookie specifies the cookie name used to store the CSRF token.
	Cookie string `json:"cookie" koanf:"cookie" default:"ol.csrf-token"`
	// Secure sets the Secure flag on the CSRF cookie.
	Secure bool `json:"secure" koanf:"secure" default:"true"`
	// SameSite configures the SameSite attribute on the CSRF cookie. Valid
	// values are "Lax", "Strict", "None" and "Default".
	SameSite string `json:"samesite" koanf:"samesite" default:"Lax"`
	// CookieHTTPOnly indicates whether the CSRF cookie is HTTP only.
	CookieHTTPOnly bool `json:"cookiehttponly" koanf:"cookiehttponly" default:"false"`
	// CookieDomain specifies the domain for the CSRF cookie, default to no domain
	CookieDomain string `json:"cookiedomain" koanf:"cookiedomain" default:""`
	// CookiePath specifies the path for the CSRF cookie, default to "/"
	CookiePath string `json:"cookiepath" koanf:"cookiepath" default:"/"`
}

Config defines configuration for the CSRF middleware wrapper.

func NewConfig

func NewConfig() *Config

NewConfig returns a Config populated with default values.

Jump to

Keyboard shortcuts

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