caddyserver/caddy · error
regexp pattern too long: %d characters (maximum %d)
Error message
regexp pattern too long: %d characters (maximum %d)
What it means
AddOperation enforces maxPatternLength (1000 characters) on the rawRegexp argument. It mirrors the Validate() length cap so that programmatically merged filters cannot bypass the config-time limit.
Source
Thrown at modules/logging/filters.go:1008
}
}
return result
}
// AddOperation adds a single regexp operation to the filter with validation.
// This is used when merging multiple RegexpFilter instances.
func (f *MultiRegexpFilter) AddOperation(rawRegexp, value string) error {
// Security checks
if len(f.Operations) >= maxRegexpOperations {
return fmt.Errorf("cannot add operation: maximum %d operations allowed", maxRegexpOperations)
}
if rawRegexp == "" {
return fmt.Errorf("regexp pattern cannot be empty")
}
if len(rawRegexp) > maxPatternLength {
return fmt.Errorf("regexp pattern too long: %d characters (maximum %d)", len(rawRegexp), maxPatternLength)
}
f.Operations = append(f.Operations, regexpFilterOperation{
RawRegexp: rawRegexp,
Value: value,
})
return nil
}
// RenameFilter is a Caddy log field filter that
// renames the field's key with the indicated name.
type RenameFilter struct {
Name string `json:"name,omitempty"`
}
// CaddyModule returns the Caddy module information.
func (RenameFilter) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{View on GitHub (pinned to 50e54ee279)
Solutions
- Split the long pattern into multiple operations (respecting the 50-op cap)
- Shorten with grouping/character classes, or use a purpose-built filter (hash_query, delete) for redaction
- Add a length assertion in the generator so oversized patterns never reach AddOperation
Example fix
// before
mf.AddOperation(hugePattern, "REDACTED") // len(hugePattern) > 1000
// after
for _, p := range splitPattern(hugePattern, 1000) {
if err := mf.AddOperation(p, "REDACTED"); err != nil {
return err
}
} Defensive patterns
Strategy: validation
Validate before calling
if len(rawRegexp) > 1000 {
return fmt.Errorf("pattern too long: split it across operations")
} Prevention
- Chunk generated patterns before AddOperation
- Test generators against the 1000-char limit
When it happens
Trigger: Calling AddOperation with a pattern longer than 1000 characters, typically in code that merges or generates regexp filter operations.
Common situations: Generated alternation lists of redaction tokens; concatenating patterns with | while merging filters; embedding large literals into the expression.
Related errors
- cannot add operation: maximum %d operations allowed
- regexp pattern cannot be empty
- server %s: logger name must not have a port: %s
- provisioning fallback encoder module: %v
- loading wrapped encoder module: %v
AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15).
Data as JSON: /api/errors/3e47a0766a701011.
Report an issue: GitHub.