Redacting a top-level password is not enough when a nested authorization header or arbitrary free-text field can still expose the same secret. We compared three logging strategies using synthetic sentinel strings.
A 120-event redaction comparison
We generated 40 records with a top-level password, 40 with nested authorization and 40 with a sentinel in a free-text comment. A shallow policy masks only the top-level password; a recursive key policy masks password and authorization; a fixed event projection emits neither field nor arbitrary comments.
| Policy | Events retaining a sentinel |
|---|---|
| Shallow key redaction | 80 |
| Recursive key redaction | 40 |
| Fixed event projection | 0 |
These counts are from a deliberately constructed synthetic corpus, not a penetration test of Code Deb production or of the SDK. The zero for fixed projection follows from the fixture's allowed fields excluding all sentinel-bearing values. A real allowlisted field can still contain sensitive text if its contract is violated.
Why a redaction policy must precede serialization
import { redactRecord } from "@codedeb/log-redact";
const event = redactRecord({
event: "request.failed",
headers: { authorization: "Bearer SYNTHETIC_TOKEN" },
errorCode: "TIMEOUT"
});
logger.warn(event);
The current source of Log Redact uses property descriptors instead of evaluating arbitrary object getters, handles cycles and has configurable traversal budgets. It also has pattern-based text masking, which is broader than the simple key policy used in our experiment. Never assume it recognizes all custom secret formats. Unknown fields must be constrained by the event schema.
Project business events before collecting them
Choose fields needed for a specific operational investigation: event type, scoped reference, action, status, duration and reason code. Emit a sanitized error category rather than a complete HTTP request or response. A request identifier must not be an authorization credential. OWASP logging guidance covers sensitive-data exclusions and protection of logs.
The collector is a separate trust boundary
Redaction must apply before stdout, exporters and traces, not just to what a dashboard displays. Restrict the logging destination's credentials and operator permissions. If a secret is exposed, rotate it and follow an incident process; masking previously stored text is not a substitute for revocation. Check nested errors, header casing, URI query parameters, arrays and logging integrations. For signing keys, see webhook rotation.
How to run a useful log-leak test
Generate unique synthetic sentinels for every sensitive test field, exercise each export path, and search each configured sink for those values. Report tested sinks, attempted events, dropped events and surviving sentinel count. Keep the test corpus free of real credentials. Repeat after adding middleware or an observability provider. A zero result means no seeded sentinel escaped that test; it is not proof of universal PII detection. Runtime boundary research and application engineering address the wider trust model.
Method and reproducibility: Controlled synthetic model. See Code Deb's recorded experiment results and reproduction script in the repository. Figures are reproducible from declared inputs, not undisclosed client outcomes. The cited external material is independent of Code Deb's experiment.