Skip to main content

Overview

The Anubis package provides the core Server implementation for bot detection and challenge management. Use lib.New() to create a new server instance, and lib.LoadPoliciesOrDefault() to load policy configurations.

Functions

New

Creates a new Anubis server instance with the specified options.
Options
required
Server configuration options
*Server
Configured Anubis server instance
error
Error if server creation fails
Example

LoadPoliciesOrDefault

Loads policy configuration from a file or uses the built-in default policies.
context.Context
required
Context for loading policies (may include Thoth client)
string
Path to policy YAML file. If empty, uses built-in default policies
int
required
Default proof-of-work difficulty level (0-64, recommended: 15-25)
string
required
Log level: “debug”, “info”, “warn”, or “error”
*policy.ParsedConfig
Parsed and validated policy configuration
error
Error if policy loading or validation fails
Example

Server Type

The Server type implements http.Handler and manages bot detection, challenge issuance, and request validation.

Server Methods

ServeHTTP

Implements the http.Handler interface. Routes requests to static assets, API endpoints, or the validation middleware.
Behavior:
  • Static assets (.within.website/static/*) are served directly
  • API endpoints (.within.website/api/*) handle challenges and validation
  • All other requests go through the bot detection and challenge flow
  • Validated requests with valid JWT cookies are proxied to the upstream handler
Example

MakeChallenge

API endpoint that issues a new challenge for client-side solving. Only available in development builds.
Request Parameters:
  • redir (query string): Redirect URL after challenge completion
Response: JSON with challenge data
See lib/anubis.go:361-432

PassChallenge

API endpoint that validates a completed challenge and issues a JWT cookie upon success.
Request Parameters:
  • redir (query string, required): Redirect URL after successful validation
  • id (query string, required): Challenge ID
  • Challenge-specific validation parameters (varies by algorithm)
Response:
  • On success: HTTP 302 redirect with JWT cookie set
  • On failure: Error page with details
Security:
  • Validates redirect domain against RedirectDomains whitelist
  • Prevents double-spend attacks (challenges can only be solved once)
  • Binds JWT to HTTP header if JWTRestrictionHeader is set
See lib/anubis.go:434-585

HTTP Endpoints

Anubis registers the following endpoints (all prefixed with BasePrefix, default /.within.website):
  • Challenge - Challenge data structures and interface
  • Policy - Bot detection rules and configuration
  • Store - Storage backend interface