Policy evaluation and bot classification
Policy evaluation turns a request and its client signals into one protection decision. It first tests ordered bot rules, then uses any weight collected from matching WEIGH rules to select an ordered threshold outcome, and finally allows the request when no rule applies. See protected request processing for the surrounding request flow and challenge lifecycle for what happens after a challenge decision.
Policy decision flow
The decision flow separates request classification from protection handling. A matched bot rule can end evaluation at once, while weight-only rules pass a risk value to the threshold stage.
This diagram shows how request data becomes a named result and then an allow, deny, challenge, or benchmark response.
flowchart TD
A[HTTP request] --> B[Validate path and client address]
B --> C[Evaluate bot rules in order]
C -->|ALLOW, DENY, CHALLENGE, or DEBUG_BENCHMARK| D[Return bot result]
C -->|WEIGH matches| E[Adjust weight]
E --> C
C -->|No terminal bot rule| F[Evaluate thresholds in order]
F -->|Threshold matches| G[Return threshold result]
F -->|No threshold matches| H[Return default allow]
D --> I[Protection handler]
G --> I
H --> I
The result carries a name, an action, and the final weight. The protection handler uses the action to pass the request, reject it, show a challenge, or serve a benchmark page. A threshold result also carries a policy identity so later challenge checks remain tied to the rule that issued it.
References: lib/anubis.go• L855-946 lib/anubis.go• L447-487
Policy definitions
An individual bot definition combines a match condition with an action. The definition can identify a client by request fields or by network and location data, and it can attach challenge settings or a weight change to that match.
The available actions have these roles:
| Action | Role in evaluation |
|---|---|
ALLOW | Stop evaluation and pass the request to the origin. |
DENY | Stop evaluation and reject the request. |
CHALLENGE | Stop evaluation and start the challenge flow. |
WEIGH | Add its configured adjustment to the running weight, then continue. |
DEBUG_BENCHMARK | Stop evaluation and serve the benchmark response. |
Policy loading validates each definition before it becomes active. A definition needs a name, at least one match source, and a valid action. A WEIGH definition without an explicit adjustment receives the default adjustment of five.
References: lib/…/config.go• L35-73 lib/…/config.go• L96-200 lib/…/bot.go• L9-17
Rule matching
Rule matching is an AND operation across all match sources in one definition. Each checker must return true for the bot definition to match, and evaluation stops at the first false result or checker error.
The supported signal groups are:
- Client address ranges from
X-Real-IPor a remote address list. - User-agent and header presence or regular-expression matches.
- Request path matches.
- CEL expressions over request data and selected host signals.
- ASN and country matches when the related GeoIP data is available.
- Address ranges loaded from a remote address source.
In subrequest mode, path checks can use X-Original-Uri first and X-Forwarded-Uri second. Normal deployments use the actual request path, which prevents forwarded headers from changing policy scope. Policy path checks remove the query part from forwarded paths and collapse repeated slashes for matching.
References: lib/…/checker.go• L12-54 lib/…/checker.go• L21-60 lib/…/checker.go• L67-189 lib/…/checker.go• L103-137 lib/…/checker.go• L192-231 lib/…/policy.go• L150-233
Expression evaluation
CEL expressions provide one shared way to combine client signals that do not fit a single matcher. Bot expressions evaluate against request data, while threshold expressions evaluate only the running weight.
Bot expressions can read these main request values:
remoteAddress,host,method,userAgent, andcontentLength.path,query, andheaders.- Recent system load values.
- Registered bot variables and DNS helper functions.
An expression may be written as one CEL string or as an all or any list. The list form becomes a single expression with AND or OR behavior before it is compiled. Expressions are compiled during policy loading, so invalid names and types fail before request traffic uses the policy.
References: lib/…/expressionorlist.go• L17-47 lib/…/expressionorlist.go• L102-129 lib/…/celchecker.go• L22-56 lib/…/celchecker.go• L58-105 lib/…/environment.go• L15-30 lib/…/environment.go• L199-203 lib/…/environment.go• L246-265
Client signals
Client signals are the request facts that policy uses to classify traffic. The policy layer reads the client address from X-Real-IP, so the reverse proxy must supply a valid address before evaluation can produce a result.
Signals have different trust and setup needs:
| Signal | Policy use | Required support |
|---|---|---|
| Request path and headers | Match route and client traits. | Request metadata and, for subrequests, trusted forwarded URI headers. |
| Remote address | Match address ranges and expose remoteAddress to CEL. | A valid X-Real-IP address. |
| ASN and country | Match network owner or country. | The matching GeoIP database. |
| DNS data | Check host identity or reverse records in CEL. | The configured DNS service and cache. |
| JA4H header | Match an HTTP fingerprint. | A bot rule that references the fingerprint header. |
If a policy asks for ASN or country data without the needed database, that rule is skipped during policy setup. Other valid rules remain active. The policy also avoids computing the JA4H signal unless a bot rule uses it.
References: lib/anubis.go• L864-878 lib/…/celchecker.go• L65-104 lib/…/policy.go• L117-148 lib/…/policy.go• L217-233 lib/…/policy.go• L301-322
Weight and thresholds
Weight is a running score built by matching WEIGH bot definitions. It starts at zero and changes only when a matching weight rule applies. A terminal bot action returns before thresholds run, so thresholds control only requests that have no terminal bot match.
Thresholds are ordered expressions over weight. The first expression that returns true selects the result. A threshold can allow, deny, or challenge a request. Thresholds cannot add more weight, and a challenge threshold must define its challenge settings.
When no threshold matches, the system returns default/allow with the accumulated weight. If no thresholds are configured, policy loading supplies the default threshold that challenges when weight > 0.
References: lib/anubis.go• L878-946 lib/…/threshold.go• L10-37 lib/…/threshold.go• L39-78 lib/…/thresholds.go• L9-45 lib/…/config.go• L464-475
Checker results
A checker produces a boolean match or an error. A true result contributes to its enclosing bot definition; an error stops request evaluation and becomes a policy-check failure instead of a protection decision.
The final CheckResult is the contract between policy evaluation and response handling:
| Field | Meaning |
|---|---|
Name | The matched source, such as bot/<name> or threshold/<name>. |
Rule | The selected protection action. |
Weight | The score at the point of selection. |
The selected bot or threshold is also returned to the response path. For challenges, its challenge settings and stable identity bind challenge issuance and validation to the same policy decision. The result is exposed in logs and in downstream risk headers when traffic is allowed or challenged.
References: lib/…/checkresult.go• L9-20 lib/anubis.go• L855-860 lib/anubis.go• L889-935 lib/anubis.go• L317-322 lib/anubis.go• L681-685
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the action set aligned between configuration validation, request evaluation, and response handling.
- Keep bot expression variables aligned between the CEL environment and request name resolution.
- Keep threshold expression inputs aligned with the weight updates and the default threshold.
- Preserve the selected rule identity and challenge settings across challenge issuance and validation.
- Treat changes to forwarded URI handling as trust-boundary changes for subrequest and normal modes.
- Keep GeoIP availability behavior aligned with rule construction so missing databases do not create silent false matches.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
X-Real-IP is absent or not an IP address. | Evaluation fails before any policy result is returned. | Configure the reverse proxy to pass the client address. |
| A checker returns an error. | The request receives a check failure instead of falling through to another rule. | Validate address and expression inputs before enabling the policy. |
| A rule uses ASN or country matching without its GeoIP database. | That rule is omitted from the active policy. | Configure the matching GeoIP database. |
| A threshold expression errors at request time. | That threshold is skipped and evaluation continues. | Keep threshold expressions limited to the supported weight input. |
| A challenge is validated against a different selected rule or settings. | Validation fails and the client does not receive the protected request. | Keep the policy stable between challenge issue and validation. |
Key files
| File | Why to read it |
|---|---|
| lib/anubis.go | Shows the full ordered evaluation flow and the handoff to protection handling. |
| lib/…/config.go | Defines bot actions, match sources, and bot validation rules. |
| lib/…/threshold.go | Defines threshold actions, defaults, and validation constraints. |
| lib/…/checker.go | Defines checker contracts and AND behavior within one bot rule. |
| lib/…/checker.go | Shows the request and network signal matchers. |
| lib/…/celchecker.go | Connects CEL expressions to request signals. |
| lib/…/thresholds.go | Connects threshold expressions to the running weight. |
| lib/…/policy.go | Shows how configuration becomes active bot rules and thresholds. |