challenge

package
v1.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailed        = errors.New("challenge: user failed challenge")
	ErrMissingField  = errors.New("challenge: missing field")
	ErrInvalidFormat = errors.New("challenge: field has invalid format")
)
View Source
var TimeTaken = promauto.NewHistogramVec(prometheus.HistogramOpts{
	Name:    "anubis_time_taken",
	Help:    "The time taken for a browser to generate a response (milliseconds)",
	Buckets: prometheus.ExponentialBucketsRange(1, math.Pow(2, 20), 20),
}, []string{"method"})

Functions

func Methods

func Methods() []string

func Register

func Register(name string, impl Impl)

Types

type Challenge added in v1.21.0

type Challenge struct {
	ID         string            `json:"id"`         // UUID identifying the challenge
	RandomData string            `json:"randomData"` // The random data the client processes
	IssuedAt   time.Time         `json:"issuedAt"`   // When the challenge was issued
	Metadata   map[string]string `json:"metadata"`   // Challenge metadata such as IP address and user agent
}

Challenge is the metadata about a single challenge issuance.

type Error

type Error struct {
	PrivateReason error
	Verb          string
	PublicReason  string
	StatusCode    int
}

func NewError

func NewError(verb, publicReason string, privateReason error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Impl

type Impl interface {
	// Setup registers any additional routes with the Impl for assets or API routes.
	Setup(mux *http.ServeMux)

	// Issue a new challenge to the user, called by the Anubis.
	Issue(r *http.Request, lg *slog.Logger, in *IssueInput) (templ.Component, error)

	// Validate a challenge, making sure that it passes muster.
	Validate(r *http.Request, lg *slog.Logger, in *ValidateInput) error
}

func Get

func Get(name string) (Impl, bool)

type IssueInput

type IssueInput struct {
	Impressum *config.Impressum
	Rule      *policy.Bot
	Challenge *Challenge
	OGTags    map[string]string
	Store     store.Interface
}

type ValidateInput added in v1.21.0

type ValidateInput struct {
	Rule      *policy.Bot
	Challenge *Challenge
	Store     store.Interface
}

Directories

Path Synopsis
templ: version: v0.3.906
templ: version: v0.3.906

Jump to

Keyboard shortcuts

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