{"record":{"id":"3e47a0766a701011","repo":"caddyserver/caddy","slug":"regexp-pattern-too-long-d-characters-maximum-d","errorCode":null,"errorMessage":"regexp pattern too long: %d characters (maximum %d)","messagePattern":"regexp pattern too long: (.+?) characters \\(maximum (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/logging/filters.go","lineNumber":1008,"sourceCode":"\t\t}\n\t}\n\treturn result\n}\n\n// AddOperation adds a single regexp operation to the filter with validation.\n// This is used when merging multiple RegexpFilter instances.\nfunc (f *MultiRegexpFilter) AddOperation(rawRegexp, value string) error {\n\t// Security checks\n\tif len(f.Operations) >= maxRegexpOperations {\n\t\treturn fmt.Errorf(\"cannot add operation: maximum %d operations allowed\", maxRegexpOperations)\n\t}\n\n\tif rawRegexp == \"\" {\n\t\treturn fmt.Errorf(\"regexp pattern cannot be empty\")\n\t}\n\n\tif len(rawRegexp) > maxPatternLength {\n\t\treturn fmt.Errorf(\"regexp pattern too long: %d characters (maximum %d)\", len(rawRegexp), maxPatternLength)\n\t}\n\n\tf.Operations = append(f.Operations, regexpFilterOperation{\n\t\tRawRegexp: rawRegexp,\n\t\tValue:     value,\n\t})\n\treturn nil\n}\n\n// RenameFilter is a Caddy log field filter that\n// renames the field's key with the indicated name.\ntype RenameFilter struct {\n\tName string `json:\"name,omitempty\"`\n}\n\n// CaddyModule returns the Caddy module information.\nfunc (RenameFilter) CaddyModule() caddy.ModuleInfo {\n\treturn caddy.ModuleInfo{","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/logging/filters.go#L990-L1026","documentation":"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.","triggerScenarios":"Calling AddOperation with a pattern longer than 1000 characters, typically in code that merges or generates regexp filter operations.","commonSituations":"Generated alternation lists of redaction tokens; concatenating patterns with | while merging filters; embedding large literals into the expression.","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"],"exampleFix":"// before\nmf.AddOperation(hugePattern, \"REDACTED\") // len(hugePattern) > 1000\n\n// after\nfor _, p := range splitPattern(hugePattern, 1000) {\n    if err := mf.AddOperation(p, \"REDACTED\"); err != nil {\n        return err\n    }\n}","handlingStrategy":"validation","validationCode":"if len(rawRegexp) > 1000 {\n    return fmt.Errorf(\"pattern too long: split it across operations\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk generated patterns before AddOperation","Test generators against the 1000-char limit"],"tags":["caddy","logging","regexp","limits"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}