Logging Redaction at Source
Redact values where they are written rather than where they are found, because a log that has already shipped retains every copy you failed to stop
Use when: a value was found in logs, traces or telemetry and the emitting code is under your control
Avoid when: the emitting component is a third party you cannot modify and only retention can be changed
Procedure
- Trace each logged value back to the exact statement or serializer that produced it.
- Redact at the emitting statement by allow-listing fields, or by masking values whose key matches a sensitive name.
- Prefer structural redaction over pattern replacement, since a pattern misses values it has never seen.
- Verify with a fixture: emit a synthetic sensitive value and confirm the log output does not contain it.
- Address retention for the copies already written, since fixing the source does not touch existing log files.
- Record the emitting statement changed, the fixture result and the retention action for existing copies.
Signals
- A structured log serializes a whole object, capturing fields the author never named
- Redaction is done by pattern, so a new value format slips through
- The source was fixed while existing log files still hold the values
- No fixture proves the redaction actually removes the value
Patterns
1. Emit record
statement: app.log:118 serializer=whole object | fix: allow-list of fields | fixture: synthetic value absent from output: yes
2. Allow-list over deny-list
log the fields you mean to log; a deny-list of sensitive keys fails on the key name you did not anticipate
3. Retention pairing
source fix plus retention action on existing files, both recorded, because only the pair closes the exposure
Pitfalls
- Fixing the source and leaving months of log files holding the values
- Redacting by pattern and declaring the pipeline clean when a new format will bypass it
- Writing a redaction test that never proves the value is absent from output
Done when
- Each emitting statement is changed with a fixture proving absence from output
- A retention action for existing copies is recorded alongside the source fix