Overview
TheChallengeRules 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
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
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
anubis.DefaultDifficulty (typically 20).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
TheValid() method enforces these constraints:
Algorithmmust be set (non-empty)Difficultymust be greater than or equal to 0Difficultymust 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:Related Types
- BotConfig - Bot rule configuration using challenges
- Threshold - Threshold rules that trigger challenges
- StatusCodes - HTTP status code configuration