{"record":{"id":"ac4a7fd84bd4a87f","repo":"JuliusBrussee/caveman","slug":"w-rule-q-s","errorCode":null,"errorMessage":"%w: rule %q: %s","messagePattern":"%w: rule %q: (.+?)","errorType":"validation","errorClass":"ErrInvalidRule","httpStatus":null,"severity":"error","filePath":"shared/platform/redact/payload.go","lineNumber":586,"sourceCode":"\t\t\t// A reference to the unconditional floor. Nothing to run, and\n\t\t\t// nothing it could switch off.\n\t\t\tcontinue\n\t\tcase RuleTypeRegex:\n\t\tcase RuleTypeJSONPath, RuleTypeHeader:\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: %q (rule %q)\", ErrRuleUnsupported, r.Type, r.Name)\n\t\tdefault:\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: %q (rule %q)\", ErrRuleUnsupported, r.Type, r.Name)\n\t\t}\n\n\t\tif strings.TrimSpace(r.Name) == \"\" {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: empty name\", ErrInvalidRule)\n\t\t}\n\t\tif r.Pattern == \"\" {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q has an empty pattern\", ErrInvalidRule, r.Name)\n\t\t}\n\t\tre, err := regexp.Compile(r.Pattern)\n\t\tif err != nil {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q: %s\", ErrInvalidRule, r.Name, err)\n\t\t}\n\t\tif re.MatchString(\"\") {\n\t\t\t// Such a pattern matches at every position and would replace the\n\t\t\t// whole body with placeholders. Refuse it rather than destroy the\n\t\t\t// capture.\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q matches the empty string\", ErrInvalidRule, r.Name)\n\t\t}\n\t\trepl := r.Replacement\n\t\tif repl == \"\" {\n\t\t\trepl = \"[REDACTED:\" + r.Name + \"]\"\n\t\t}\n\t\tout = append(out, compiledRule{\n\t\t\tname:                 r.Name,\n\t\t\torigin:               OriginOrg,\n\t\t\tre:                   re,\n\t\t\treplIntroducesNeedle: introducesNeedle([]byte(repl)),\n\t\t\t// The replacement is operator-supplied data, not a regexp\n\t\t\t// template: a literal replace keeps \"$1\" from expanding a captured","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/redact/payload.go#L568-L604","documentation":"The rule's Pattern could not be compiled by regexp.Compile; compileOrgRules wraps ErrInvalidRule and includes the rule name plus the regexp/syntax error text. This keeps invalid patterns from silently disabling redaction.","triggerScenarios":"A pattern with unbalanced parens/brackets, a bad escape (e.g. \\\\q), an invalid repeat (e.g. * at start), or unsupported syntax for Go RE2 (e.g. backreferences or lookaheads) passed in Rule.Pattern to redact.Payload.","commonSituations":"Patterns copied from PCRE/JavaScript sources using (?=...) lookaheads or \\\\1 backreferences, which Go's RE2 does not support; hand-edited patterns with a dropped brace or slash.","solutions":["Fix the pattern syntax per Go RE2 rules; test it with regexp.Compile before deploying.","Remove RE2-unsupported constructs (backreferences, lookarounds) and restructure the pattern.","Validate all rules at startup with a compile pre-pass so bad patterns fail before traffic flows."],"exampleFix":"// before\nPattern: \"(?<=Bearer )eyJ[\\\\w.-]+\" // lookbehind unsupported in RE2\n// after\nPattern: \"Bearer\\\\s+(eyJ[\\\\w.-]+)\"","handlingStrategy":"validation","validationCode":"for _, r := range rules {\n    if _, err := regexp.Compile(r.Pattern); err != nil {\n        return fmt.Errorf(\"rule %q: invalid pattern: %v\", r.Name, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"_, _, err := redact.Payload(body, rules)\nif errors.Is(err, redact.ErrInvalidRule) {\n    // log the compile error and reject the rule set\n}","preventionTips":["Test patterns with Go regexp before shipping (RE2-compatible syntax only)","Ban backreferences/lookarounds in pattern review","Compile all rules once at startup to fail fast"],"tags":["redaction","regex","invalid-rule"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}