Policy Structure
Anubis policies are configured in YAML and loaded at startup:Bot Rules
Bot rules are evaluated sequentially. The first matching rule with a terminal action (ALLOW, DENY, CHALLENGE, BENCHMARK) determines the request’s fate.
Rule Definition
Matching Conditions
Rules can match requests using multiple conditions (AND logic):User Agent (Regex)
User Agent (Regex)
Match against the Implementation:
User-Agent header:lib/policy/checker.go:NewUserAgentChecker()Path (Regex)
Path (Regex)
Match against the request path:Implementation:
lib/policy/checker.go:NewPathChecker()Headers (Regex Map)
Headers (Regex Map)
Match multiple headers with different patterns:Use Implementation:
.* to check if a header exists:lib/policy/checker.go:NewHeadersChecker()Remote Addresses (CIDR)
Remote Addresses (CIDR)
Match against client IP addresses:Implementation:
lib/policy/checker.go:NewRemoteAddrChecker() using gaissmai/bart prefix tableCEL Expressions
CEL Expressions
Advanced matching with Common Expression Language:Available variables:
req.method(string)req.path(string)req.headers(map)req.query(map)- DNS lookups (via expressions)
lib/policy/celchecker.go:NewCELChecker()GeoIP (Thoth Integration)
GeoIP (Thoth Integration)
Match by country code (requires Thoth):Requires: Thoth service configured via
ANUBIS_THOTH_URLImplementation: lib/thoth/geoipchecker.goASN (Thoth Integration)
ASN (Thoth Integration)
Match by Autonomous System Number:Requires: Thoth serviceImplementation:
lib/thoth/asnchecker.goAll conditions within a single bot rule are AND-ed together. If you specify both
user_agent_regex and path_regex, the request must match both.Rule Validation
Rules are validated on startup:Actions
Bot rules can specify five different actions:action
Immediately proxy the request to upstream without challenge.
action
Block the request with a 403 Forbidden response.
action
Issue a proof-of-work challenge. Requires
challenge configuration.action
Adjust the request’s suspicion weight and continue evaluation.Default weight adjustment is
5 if not specified.action
Render a benchmark page for testing challenge performance.
Action Flow
Thresholds
Thresholds evaluate accumulated weight fromWEIGH actions using CEL expressions:
Threshold Evaluation
Threshold Definition
Rule Hashing
Each bot rule is hashed to detect policy changes:- Rule hash changes
- Existing JWTs with old hash fail validation
- Clients must re-solve challenges
Check Result
Policy evaluation returns aCheckResult:
Import Statements
Reuse bot rules across multiple configs:Use the
(data)/ prefix to import built-in bot policies shipped with Anubis. These are embedded at compile time.CEL Expressions
Anubis supports Common Expression Language for advanced matching:Available Functions
Environment Variables
Expressions have access to:Example Policies
Default Behavior
If no bot rules or thresholds match, Anubis allows the request:Metrics and Monitoring
Policy decisions are tracked:Best Practices
Order Rules Carefully
Place
ALLOW rules first, then WEIGH, then terminal actions.Use Imports
Reuse verified bot lists with
import: "(data)/verified-bots.yaml".Start Conservative
Begin with
WEIGH actions and observe metrics before adding DENY rules.Test Expressions
Use
DEBUG_BENCHMARK action on test endpoints to verify CEL expressions.Next Steps
Challenges
Configure challenge difficulty and algorithms
Architecture
Understand how policies integrate with the proxy