Skip to content

fix(drift): redact free-text reason before ledger writes and observer fan-out#84

Merged
fu351 merged 1 commit into
mainfrom
fix/drift/redact-reason
Jul 6, 2026
Merged

fix(drift): redact free-text reason before ledger writes and observer fan-out#84
fu351 merged 1 commit into
mainfrom
fix/drift/redact-reason

Conversation

@fu351

@fu351 fu351 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Slice

Closes #80

What this PR does

The reason parameter of apply_change / apply_enforcement_change / log_change was written verbatim to the policy-change ledger and fanned out unredacted to DriftObserver plugins — contradicting the module's own "observers receive redacted events" promise. A pasted token in a reason would have been persisted and shipped to any enterprise sink.

Adds _redact_reason, applied once at the entry of each chokepoint so the scrubbed value flows everywhere (ledger, observers, rendered confirm diff):

  • Reuses the existing detectors from doberman.engine.rules.secrets (credential-shape patterns + high-entropy heuristic) — no new detection logic; lazy import, policy→engine is within the import contract (lint-imports green).
  • Redacts before truncating (a secret straddling the cap is still fully scanned), then caps at 300 chars.
  • Fails safe: any internal error stores the fixed placeholder [reason redaction failed] — never the raw string, never raises.

Tests added (run in CI)

tests/unit/test_drift_reason_redaction.py (9): synthetic AWS key + high-entropy token never appear in ledger rows or observer events across all three paths; pass-through for normal reasons; truncation; empty string; monkeypatched redaction failure → placeholder stored, call still completes.

Security checklist

  • Fails closed on error (placeholder, never raw)
  • No secret logged or persisted (that's the point; tested end-to-end)
  • Raise-only untouched (redaction never alters classification/gating)
  • lint-imports 2/2 contracts kept

… fan-out (#80)

The reason parameter of apply_change, apply_enforcement_change, and log_change
was written verbatim to the policy-change ledger and fanned out unredacted to
DriftObserver plugins, despite the docstrings promising redacted events. Add
_redact_reason, reusing doberman.engine.rules.secrets' credential patterns and
high-entropy-token check to scrub secret-shaped substrings and cap length,
applied once at the entry of all three chokepoints.
@fu351 fu351 merged commit 85ba38b into main Jul 6, 2026
6 checks passed
@fu351 fu351 deleted the fix/drift/redact-reason branch July 6, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redact the free-text reason before it reaches the drift ledger and DriftObservers

1 participant