csrf

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSRFHookID

type CSRFHookID string
const (
	// HookIDCSRFGenerate identifies the CSRF token generation hook.
	// Generates CSRF tokens for safe requests
	HookIDCSRFGenerate CSRFHookID = "csrf.generate"

	// HookIDCSRFProtect identifies the CSRF protection hook.
	// Validates CSRF tokens on state-changing requests
	HookIDCSRFProtect CSRFHookID = "csrf.protect"
)

Constants for CSRF plugin hook IDs and metadata

func (CSRFHookID) String

func (id CSRFHookID) String() string

type CSRFPlugin

type CSRFPlugin struct {
	// contains filtered or unexported fields
}

func New

func New(config CSRFPluginConfig) *CSRFPlugin

func (*CSRFPlugin) Close

func (p *CSRFPlugin) Close() error

func (*CSRFPlugin) Config

func (p *CSRFPlugin) Config() any

func (*CSRFPlugin) Hooks

func (p *CSRFPlugin) Hooks() []models.Hook

Hooks implements models.PluginWithHooks to provide CSRF protection via hooks

func (*CSRFPlugin) Init

func (p *CSRFPlugin) Init(ctx *models.PluginContext) error

func (*CSRFPlugin) Metadata

func (p *CSRFPlugin) Metadata() models.PluginMetadata

func (*CSRFPlugin) Middleware

func (p *CSRFPlugin) Middleware() func(http.Handler) http.Handler

Middleware returns a CSRF protection middleware that users can add to custom routes.

func (*CSRFPlugin) OnConfigUpdate

func (p *CSRFPlugin) OnConfigUpdate(config *models.Config) error

type CSRFPluginConfig

type CSRFPluginConfig struct {
	Enabled                bool          `json:"enabled" toml:"enabled"`
	CookieName             string        `json:"cookie_name" toml:"cookie_name"`
	HeaderName             string        `json:"header_name" toml:"header_name"`
	MaxAge                 time.Duration `json:"max_age" toml:"max_age"`
	Secure                 bool          `json:"secure" toml:"secure"`
	SameSite               string        `json:"same_site" toml:"same_site"`
	EnableHeaderProtection bool          `json:"enable_header_protection" toml:"enable_header_protection"`
}

func (*CSRFPluginConfig) ApplyDefaults

func (config *CSRFPluginConfig) ApplyDefaults()

Jump to

Keyboard shortcuts

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