{"record":{"id":"3f516a39a11d6f67","repo":"JuliusBrussee/caveman","slug":"redact-unsupported-redaction-rule-type","errorCode":null,"errorMessage":"redact: unsupported redaction rule type","messagePattern":"redact: unsupported redaction rule type","errorType":"exception","errorClass":"ErrRuleUnsupported","httpStatus":null,"severity":"error","filePath":"shared/platform/redact/payload.go","lineNumber":75,"sourceCode":")\n\n// Origin values distinguish the built-in floor from operator-supplied rules in\n// the report.\nconst (\n\tOriginBuiltin = \"builtin\"\n\tOriginOrg     = \"org\"\n)\n\nvar (\n\t// ErrBodyTooLarge means the body exceeded MaxPayloadBytes.\n\tErrBodyTooLarge = errors.New(\"redact: payload exceeds redaction size limit\")\n\t// ErrInvalidRule means a rule could not be compiled or was structurally\n\t// unusable (empty name/pattern, or a pattern that matches the empty\n\t// string and would therefore rewrite the entire body).\n\tErrInvalidRule = errors.New(\"redact: invalid redaction rule\")\n\t// ErrRuleUnsupported means the rule's type is not implementable against an\n\t// opaque body by this pass.\n\tErrRuleUnsupported = errors.New(\"redact: unsupported redaction rule type\")\n)\n\n// Rule is one enabled row of the redaction_rules table, minus the columns that\n// are the caller's business. Field names and JSON tags are pinned to that\n// table's columns so the two cannot drift.\n//\n// Deliberately absent:\n//   - id / organization_id / project_id — tenancy is the caller's concern.\n//   - enabled — filtering disabled rows is the caller's concern; a rule that\n//     reaches Payload is a rule that runs.\n//\n// A row with rule_type='builtin' is accepted and treated as a no-op reference:\n// the built-in floor is unconditional, so such a row can neither add to nor\n// subtract from it.\ntype Rule struct {\n\tName        string `json:\"name\"`\n\tType        string `json:\"rule_type\"`\n\tPattern     string `json:\"pattern\"`","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/redact/payload.go#L57-L93","documentation":"ErrRuleUnsupported is returned by compileOrgRules when a rule's Type is not implementable against an opaque body by this redaction pass: jsonpath and header rule types are rejected explicitly, as is any unrecognized type. Only regex rules are currently executable, so the library fails loudly rather than silently skipping a rule the org believes is active.","triggerScenarios":"Persisting a redaction_rules row with type='jsonpath', type='header', or a typo'd/unknown type value and then calling Payload with those rules loaded from the table.","commonSituations":"Rules authored for a different redaction engine (HTTP-header scrubbers, JSON-tree rewriters) being loaded into this pass; a new RuleType enum value added to the table before the engine implements it; data-entry typos like 'regeex'.","solutions":["Convert the rule to type 'regex' with an equivalent regular expression","Remove or disable the jsonpath/header rule rows until this pass supports them","Add a constraint/enum check on redaction_rules.type so unsupported types are rejected at insert time","Match the default/unknown branch: verify the exact stored type string for typos"],"exampleFix":"// before\nredact.Rule{Name: \"auth\", Type: redact.RuleTypeHeader, Pattern: \"Authorization\"} // unsupported\n// after\nredact.Rule{Name: \"auth\", Type: redact.RuleTypeRegex, Pattern: \"(?i)authorization\\\":\\s*\\\"[^\\\"]+\\\"\"}","handlingStrategy":"validation","validationCode":"switch r.Type {\ncase redact.RuleTypeRegex:\n    // ok\ndefault:\n    return fmt.Errorf(\"rule %q type %q unsupported; use regex\", r.Name, r.Type)\n}","typeGuard":"func isSupportedRuleType(t redact.RuleType) bool { return t == redact.RuleTypeRegex }","tryCatchPattern":"redacted, report, err := redact.Payload(body, rules)\nif err != nil && errors.Is(err, redact.ErrRuleUnsupported) {\n    log.Errorf(\"rule type not implementable on opaque body: %v\", err)\n    return err\n}","preventionTips":["Restrict redaction_rules.type to 'regex' via a DB enum/constraint","Migrate jsonpath/header rules to equivalent regex rules before loading","When adding a new RuleType, implement it in compileOrgRules in the same change","Log and alert on ErrRuleUnsupported so dormant unsupported rules are surfaced early"],"tags":["redaction","unsupported","rule-type","validation"],"backgroundTag":"unsupported-enum-value","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"}