Skip to main content

Overview

Bot policy configuration defines rules for identifying and handling different types of traffic. Each rule specifies matching criteria and an action to take when traffic matches.

BotConfig

Defines a bot detection rule with matching criteria and action.

Type Definition

Fields

string
required
Unique identifier for this bot rule. Used in logs and metrics.
Rule
required
Action to take when traffic matches this rule. See Rule enum.
*string
Regular expression to match against the User-Agent header. Cannot be used with PathRegex.
*string
Regular expression to match against the request path. Cannot be used with UserAgentRegex.
map[string]string
Map of header names to regular expressions. All specified headers must match for the rule to apply.
*ExpressionOrList
CEL (Common Expression Language) expression for advanced matching logic. See ExpressionOrList.
[]string
List of CIDR ranges to match against the client IP address (e.g., "192.168.1.0/24").
*ChallengeRules
Challenge configuration when Action is CHALLENGE. See challenge-rules.
*Weight
Weight adjustment when Action is WEIGH. If not set, defaults to {Adjust: 5}.
*GeoIP
Geographic IP matching configuration. See GeoIP.
*ASNs
Autonomous System Number matching configuration. See ASNs.

Validation Rules

  • Must set Name
  • Must set at least one matching criterion: UserAgentRegex, PathRegex, HeadersRegex, RemoteAddr, Expression, GeoIP, or ASNs
  • Cannot set both UserAgentRegex and PathRegex
  • Regular expressions must not end with newline (use >- in YAML instead of >)
  • RemoteAddr entries must be valid CIDR notation
  • If Action is CHALLENGE, must set Challenge
  • If Action is WEIGH and Weight is nil, defaults to {Adjust: 5}

Example

Rule Enum

Defines actions to take when traffic matches a bot rule.

Type Definition

Values

string
Immediately allow the request without further checks.
string
Block the request with a configured status code.
string
Present a proof-of-work challenge to the client. Requires Challenge configuration.
string
Add weight to the client’s score. When thresholds are exceeded, triggers challenges or blocks.
string
Debug action for performance testing. Logs timing without affecting traffic.

ExpressionOrList

Flexible expression matching supporting single expressions or logical combinations.

Type Definition

Fields

string
Single CEL expression. Can be set directly as a string in YAML/JSON.
[]string
List of CEL expressions that must all evaluate to true (logical AND).
[]string
List of CEL expressions where at least one must evaluate to true (logical OR).

Validation Rules

  • Must set either Expression, All, or Any
  • Cannot set both All and Any

Example

GeoIP

Geographic IP address matching based on country codes.

Type Definition

Fields

[]string
required
List of two-letter ISO 3166-1 alpha-2 country codes (case-insensitive).

Validation Rules

  • Country codes must be exactly 2 letters matching [a-zA-Z]{2}
  • Country codes are normalized to lowercase

Example

ASNs

Autonomous System Number (ASN) matching for network-based rules.

Type Definition

Fields

[]uint32
required
List of ASNs to match against the client’s network.

Validation Rules

  • ASNs must not be in private use ranges (RFC 6996):
    • 64512-65534
    • 4200000000-4294967294

Example

Weight

Score adjustment for traffic matching a WEIGH rule.

Type Definition

Fields

int
required
Integer value to add to the client’s weight score. Can be negative to reduce weight.

Example

ImportStatement

Import bot rules from external files.

Type Definition

Fields

string
required
Path to YAML file containing bot rules. Use (data)/ prefix to load from embedded data.

Example

Errors