JSON Schema
Caddy Defender can be configured using JSON in the Caddy JSON config file. The module ID ishttp.handlers.defender.
Configuration Fields
raw_responder
Defines the response strategy for blocked requests.Valid values:
"block", "custom", "drop", "garbage", "ratelimit", "redirect", "tarpit"- block
- custom
- drop
- garbage
- ratelimit
- redirect
- tarpit
Returns a
403 Forbidden response with “Access denied” message.ranges
Specifies IP ranges to block using CIDR notation or predefined service keys.Default:
["aws", "gcloud", "azurepubliccloud", "openai", "deepseek", "githubcopilot"]See IP Ranges documentation for all predefined service keys.
whitelist
IP addresses to exclude from blocking. Only supports individual IPs, not ranges.Default:
[]message
Custom response message for the
custom responder type.Required when: raw_responder is "custom"status_code
HTTP status code for the
custom responder type.Default: 200Valid values: Any HTTP status code (200, 403, 404, 451, 503, etc.)url
Redirect URL for the
redirect responder type.Required when: raw_responder is "redirect"serve_ignore
Serves a robots.txt file with
Disallow: / directive to discourage crawlers.Default: falsetarpit_config
Configuration for the
tarpit responder. Controls how data is streamed to slow down bots.Required when: raw_responder is "tarpit"tarpit_config.headers
Custom HTTP headers to include in the tarpit response as key-value pairs.Default:
{}tarpit_config.timeout
Maximum duration (in nanoseconds) before forcefully closing the connection.Default:
30000000000 (30 seconds)Format: Duration in nanoseconds as int64Validation: Must be greater than 0Common durations:
- 30 seconds:
30000000000 - 1 minute:
60000000000 - 2 minutes:
120000000000 - 5 minutes:
300000000000
tarpit_config.bytes_per_second
Number of bytes to stream per second. Lower values slow down bots more effectively.Default:
24Validation: Must be greater than 10tarpit_config.code
HTTP response code for the tarpit response.Default:
200Complete Examples
Block OpenAI and AWS
Custom 403 Response
Redirect to Blocked Page
Tarpit with Custom Configuration
Whitelist Specific IPs
Serve robots.txt Disallow
Multiple Status Codes with Custom
Full Caddy JSON Config Example
Validation Rules
Source Code Reference
The JSON configuration is handled by:config.go:162-220(UnmarshalJSON function)config.go:223-254(Validate function)plugin.go:74-113(Defender struct definition)