Help us shape the future of Go! Take the 2026 Go Developer Survey

websecurity

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOriginDenied  = errors.New("request origin is denied")
	ErrCSRFRequired  = errors.New("csrf token is required")
	ErrCSRFInvalid   = errors.New("csrf token is invalid")
	ErrScopeRequired = errors.New("trusted request scope is required")
)

Functions

func WithRequestContext

func WithRequestContext(ctx context.Context, requestContext RequestContext) context.Context

Types

type Guard

type Guard interface {
	Evaluate(r *http.Request) (RequestContext, OriginDecision, error)
	ValidateCSRF(r *http.Request, sessionHash string) error
}

type OriginDecision

type OriginDecision string
const (
	OriginTrustedParent OriginDecision = "trusted_parent"
	OriginDeny          OriginDecision = "deny"
)

type RequestContext

type RequestContext struct {
	Origin string       `json:"origin"`
	Route  string       `json:"route"`
	Method string       `json:"method"`
	Scope  RequestScope `json:"scope"`
}

func RequestContextFromContext

func RequestContextFromContext(ctx context.Context) (RequestContext, bool)

type RequestScope

type RequestScope struct {
	OwnerSessionHash     string `json:"owner_session_hash"`
	OwnerUserHash        string `json:"owner_user_hash,omitempty"`
	SessionChannelIDHash string `json:"session_channel_id_hash"`
}

func (RequestScope) Valid

func (s RequestScope) Valid() bool

Jump to

Keyboard shortcuts

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