Skip to main content
Policies in Anubis define how to identify and handle different types of traffic. They consist of bot rules (pattern-based detection) and thresholds (weight-based triggers).

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):
Match against the User-Agent header:
Implementation: lib/policy/checker.go:NewUserAgentChecker()
Match against the request path:
Implementation: lib/policy/checker.go:NewPathChecker()
Match multiple headers with different patterns:
Use .* to check if a header exists:
Implementation: lib/policy/checker.go:NewHeadersChecker()
Match against client IP addresses:
Implementation: lib/policy/checker.go:NewRemoteAddrChecker() using gaissmai/bart prefix table
Advanced matching with Common Expression Language:
Available variables:
  • req.method (string)
  • req.path (string)
  • req.headers (map)
  • req.query (map)
  • DNS lookups (via expressions)
Implementation: lib/policy/celchecker.go:NewCELChecker()
Match by country code (requires Thoth):
Requires: Thoth service configured via ANUBIS_THOTH_URLImplementation: lib/thoth/geoipchecker.go
Match by Autonomous System Number:
Requires: Thoth serviceImplementation: lib/thoth/asnchecker.go
All 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

Order matters! Place ALLOW rules for verified bots first, then WEIGH rules to accumulate suspicion, and finally DENY/CHALLENGE rules.

Thresholds

Thresholds evaluate accumulated weight from WEIGH actions using CEL expressions:

Threshold Evaluation

Thresholds are evaluated in order. The first matching threshold determines the action.

Threshold Definition

Thresholds cannot use the WEIGH action - this validation error occurs at config load time:

Rule Hashing

Each bot rule is hashed to detect policy changes:
This hash is embedded in JWTs. When you update your policy:
  1. Rule hash changes
  2. Existing JWTs with old hash fail validation
  3. Clients must re-solve challenges
This prevents bypassing updated security rules with old tokens.

Check Result

Policy evaluation returns a CheckResult:
This is logged and exposed in Prometheus metrics:

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:
This “default allow” behavior means Anubis is not a firewall by itself. It only challenges/blocks traffic that matches your rules. Combine it with proper network security.

Metrics and Monitoring

Policy decisions are tracked:
Request headers include policy metadata:

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