@@ -12,6 +12,7 @@ import (
1212 "go.uber.org/zap"
1313 "pkg.jsn.cam/caddy-defender/matchers/ip"
1414 "pkg.jsn.cam/caddy-defender/responders"
15+ "pkg.jsn.cam/caddy-defender/responders/headertarpit"
1516 "pkg.jsn.cam/caddy-defender/responders/tarpit"
1617)
1718
@@ -25,13 +26,20 @@ func init() {
2526var (
2627 // DefaultRanges is the default ranges to block if none are specified.
2728 DefaultRanges = []string {"aws" , "gcloud" , "azurepubliccloud" , "openai" , "deepseek" , "githubcopilot" }
29+
2830 // Tarpit Defaults
2931 // defaultTarpitTimeout is the default duration for a request to be closed after.
3032 defaultTarpitTimeout = time .Second * 30
3133 // defaultTarpitBytesPerSecond is the default amount of bytes to stream per second.
3234 defaultTarpitBytesPerSecond = 24
3335 // defaultTarpitResponseCode is the default HTTP respond code for the tarpit responder.
3436 defaultTarpitResponseCode = http .StatusOK
37+
38+ // Header Tarpit Defaults
39+ // defaultHeaderTarpitTimeout is the default duration for a request to be closed after.
40+ defaultHeaderTarpitTimeout = time .Second * 30
41+ // defaultTarpitHeaderDelaySecond is the default delay between each successive header responses
42+ defaultHeaderTarpitDelaySecond = 4
3543)
3644
3745// Defender implements an HTTP middleware that enforces IP-based rules to protect your site from AIs/Scrapers.
@@ -85,7 +93,7 @@ type Defender struct {
8593 URL string `json:"url,omitempty"`
8694
8795 // RawResponder defines the response strategy for blocked requests.
88- // Required. Must be one of: "block", "custom", "drop", "garbage", "redirect", "tarpit"
96+ // Required. Must be one of: "block", "custom", "drop", "garbage", "redirect", "tarpit", "headertarpit"
8997 RawResponder string `json:"raw_responder,omitempty"`
9098
9199 // Ranges specifies IP ranges to block, which can be either:
@@ -103,6 +111,10 @@ type Defender struct {
103111 // Default: {Headers: {}, timeout: 30s, ResponseCode: 200}
104112 TarpitConfig tarpit.Config `json:"tarpit_config,omitempty"`
105113
114+ // An optional configuration for the 'tarpit' responder
115+ // Default: {Headers: {}, timeout: 30s, ResponseCode: 200}
116+ HeaderTarpitConfig headertarpit.Config `json:"header_tarpit_config,omitempty"`
117+
106118 // StatusCode specifies the HTTP status code for 'custom' responder type.
107119 // Optional. Default: 200
108120 StatusCode int `json:"status_code,omitempty"`
@@ -150,6 +162,16 @@ func (m *Defender) Provision(ctx caddy.Context) error {
150162 }
151163 }
152164
165+ if m .RawResponder == "header_tarpit" {
166+ if m .HeaderTarpitConfig .Timeout == 0 {
167+ m .HeaderTarpitConfig .Timeout = defaultHeaderTarpitTimeout
168+ }
169+
170+ if m .HeaderTarpitConfig .DelaySecond == 0 {
171+ m .HeaderTarpitConfig .DelaySecond = defaultHeaderTarpitDelaySecond
172+ }
173+ }
174+
153175 return nil
154176}
155177
0 commit comments