Skip to main content

Overview

The ChallengeRules struct configures proof-of-work challenges presented to clients when a bot rule with the CHALLENGE action is triggered. Challenges require clients to solve computational puzzles, which legitimate browsers can complete but automated bots typically cannot.

Type Definition

Fields

string
required
Challenge algorithm to use. Anubis supports multiple challenge implementations.Available algorithms:
  • "fast" - Fast proof-of-work algorithm (default)
  • "preact" - Preact-based interactive challenge
  • "metarefresh" - Meta-refresh based challenge
The algorithm must be registered with the challenge system. Unknown algorithms will fail validation.
int
required
Computational difficulty level for the challenge. Valid range: 0-64.
  • Lower values (5-15): Easy challenges, suitable for high-traffic sites
  • Medium values (16-25): Moderate challenges, balanced protection
  • Higher values (26-40): Hard challenges, strong bot protection
  • Very high values (41-64): Very hard challenges, may impact user experience
Default difficulty is defined by anubis.DefaultDifficulty (typically 20).
int
Optional HTTP status code to report in metrics when this challenge is served. Useful for tracking different challenge types separately. Does not affect the actual HTTP response code sent to clients.When not set, challenges use the configured challenge status code from StatusCodes.Challenge.

Validation Rules

The Valid() method enforces these constraints:
  • Algorithm must be set (non-empty)
  • Difficulty must be greater than or equal to 0
  • Difficulty must be less than or equal to 64

Errors

Usage Examples

Basic Challenge Configuration

High-Security Challenge

Easy Challenge for Known Bots

Multiple Algorithms

Integration with Thresholds

Challenges are often used with threshold rules that trigger based on accumulated weight:

Algorithm Selection

fast

The default and most commonly used algorithm. Provides good bot protection with minimal user impact. Recommended for most use cases.

preact

Interactive challenge using the Preact framework. Better user experience for complex challenges but requires JavaScript.

metarefresh

Simple meta-refresh based challenge. Works without JavaScript but easier for sophisticated bots to bypass.

Difficulty Tuning

Difficulty affects how long challenges take to solve:
  • BotConfig - Bot rule configuration using challenges
  • Threshold - Threshold rules that trigger challenges
  • StatusCodes - HTTP status code configuration

See Also