Overview
The policy package defines bot detection rules, threshold-based actions, and policy configuration parsing. Policies determine when to allow, deny, or challenge requests based on pattern matching and weighted scoring.Types
Bot
A bot detection rule with matching conditions and an action.checker.Impl
Checker implementation that determines if this rule matches a request.Can be a single checker or a
checker.List combining multiple conditions.*config.ChallengeRules
Challenge configuration for CHALLENGE actions
*config.Weight
Weight adjustment for WEIGH actions
string
Unique identifier for this rule (e.g., “googlebot”, “known-bad-bot”)
config.Rule
Action to take when this rule matchesValues:
ALLOW: Permit request immediatelyDENY: Block request immediatelyCHALLENGE: Issue a challengeWEIGH: Adjust weight and continue evaluationDEBUG_BENCHMARK: Show benchmark page
lib/policy/bot.go:11-17
Bot.Hash
Computes a deterministic hash of the bot rule configuration.string
Hex-encoded hash of the rule name and checker configuration
lib/policy/bot.go:19-21
CheckResult
The result of evaluating policy rules against a request.string
Identifier of the matched rulePrefixes:
bot/: Direct bot rule matchthreshold/: Threshold rule matchdefault/: Fell through to default action
config.Rule
Action determined by policy evaluation
int
Cumulative weight from all matched WEIGH rules
lib/policy/checkresult.go:9-13
ParsedConfig
Fully parsed and validated policy configuration.store.Interface
Storage backend instance
*config.Impressum
Legal/contact information
config.OpenGraph
OpenGraph tag caching configuration
[]Bot
Parsed bot detection rules (evaluated in order)
[]*Threshold
Weight-based threshold rules
config.StatusCodes
HTTP status codes for CHALLENGE and DENY actions
int
Default proof-of-work difficulty (0-64)
bool
Enable DroneBL blocklist checking
*slog.Logger
Structured logger instance
lib/policy/policy.go:36-49
Functions
ParseConfig
Parses a policy configuration from YAML.context.Context
required
Context (may contain Thoth client for ASN/GeoIP features)
io.Reader
required
Reader containing YAML policy configuration
string
required
Filename for error messages
int
required
Default challenge difficulty (0-64)
string
required
Log level: “debug”, “info”, “warn”, or “error”
*ParsedConfig
Parsed and validated configuration
error
Validation or parse errors
lib/policy/policy.go:59-248
Checker Implementations
Policy rules use checker implementations to match requests.NewRemoteAddrChecker
Creates a checker that matches IP addresses against CIDR ranges.[]string
required
List of CIDR ranges (e.g., [“192.168.1.0/24”, “10.0.0.0/8”])
checker.Impl
IP address matcher using efficient prefix tree
error
Error if CIDR parsing fails
lib/policy/checker.go:25-41
NewUserAgentChecker
Creates a checker that matches the User-Agent header against a regex.string
required
Regular expression pattern
checker.Impl
User-Agent matcher
error
Error if regex compilation fails
lib/policy/checker.go:72-74
NewPathChecker
Creates a checker that matches the request path against a regex.string
required
Regular expression pattern for path matching
checker.Impl
Path matcher
error
Error if regex compilation fails
lib/policy/checker.go:101-107
NewHeadersChecker
Creates a checker that matches multiple HTTP headers.map[string]string
required
Map of header names to regex patternsSpecial value: Use
".*" to check for header existence without pattern matchingchecker.Impl
Multi-header matcher (all headers must match)
error
Error if any regex compilation fails
lib/policy/checker.go:148-172
NewCELChecker
Creates a checker using Common Expression Language (CEL).*config.ExpressionOrList
required
CEL expression or list of expressions
*dns.Dns
required
DNS resolver for reverse DNS lookups in expressions
checker.Impl
CEL expression evaluator
error
Error if expression compilation fails
request.method: HTTP methodrequest.path: Request pathrequest.headers: Header maprequest.query: Query parametersrequest.remote_addr: Client IPenv: Environment variablesdns.reverse(ip): Reverse DNS lookup
lib/policy/celchecker.go
Checker Interface
Check
Evaluates if a request matches this checker’s conditions.*http.Request
required
HTTP request to evaluate
bool
True if the request matches this checker
error
Error if check evaluation fails
Hash
Returns a deterministic hash of the checker configuration.string
Hex-encoded hash string
Checker.List
Combines multiple checkers with AND semantics.- Returns
trueonly if ALL checkers returntrue - Short-circuits on first
false - Returns error if any checker errors
lib/policy/checker/checker.go:25-55
YAML Configuration
Example policy.yaml:Related Types
- Anubis Server - Policy enforcement
- Challenge - Challenge implementation
- Store - Policy data persistence