Design a secrets-redacting structured logger

Design a structured logger that keeps credentials out of logs by default: key-name and value-pattern redaction, a Secret type that cannot be printed, URL and error scrubbing, bounds on depth, size and cycles, reserved fields that callers cannot overwrite, keyed fingerprints for correlation, and canary tests that prove it works.

● Hard🔒 PROBy ·Design problem·17 min read·Advanced → Staff
loggingredactionsecretsstructured loggingPIIlog injection

01Understand the problem

✓What you will learn
  • Combine key-based and pattern-based redaction, and know the failure modes of each
  • Make secrets unprintable by type so redaction does not depend on reviewers
  • Bound the logger against hostile input: depth, size, cycles, and reserved fields
  • Correlate redacted values with keyed fingerprints, and prove the logger works with canaries
◎Interview radar

What they probe: where redaction happens (before serialisation, at the sink), how you catch a token logged under an innocent key, what happens with a circular object or a 50 MB string, whether a caller can overwrite level, and how you would know it is working in production. Where candidates slip: a regex over the final JSON string, redaction only by exact key names, SHA-256 of a secret as a 'safe' fingerprint, and exceptions whose messages contain connection strings.

Secrets reach logs through ordinary code: log.info('calling api', { headers }), an exception message with a connection string, a URL with ?token=, a debug dump of a request object. Logs then travel to aggregators, vendors, laptops and backups with broad read access. A redacting logger makes the safe outcome the default: the call site does nothing special, and the logger removes what should never be stored.

  1. Fields whose key names suggest a secret (password, authorization, apiKey, set-cookie) are replaced with [REDACTED].
  2. String values anywhere are scanned for credential shapes (JWTs, AWS access key ids, GitHub tokens, PEM private keys, bearer headers, credentials in URLs).
  3. Values wrapped in a Secret type are always redacted.
  4. Errors are logged as name, scrubbed message and optional scrubbed stack.
  5. Depth, keys per object, array length and string length are capped; cycles are detected.
  6. Reserved fields (ts, level, msg) cannot be overwritten by caller data.
TechniqueCatchesMisses
Key-name denylist{ password: 'x' }, { 'X-Api-Key': 'y' }A token under { value: ... } or inside free text
Value patternsKnown formats anywhere: eyJ..., AKIA..., ghp_..., PEM blocksRandom secrets with no recognisable shape
Secret typeAnything the code already knows is secretSecrets that arrive as plain strings from elsewhere
Field allow-list (schema)Everything not explicitly permittedNothing, but needs a schema per event type

This is an advanced module

Problems: policy and crypto engines is part of the Pro pass. 4 more sections — the deep dives, the final design, follow-ups and the test — unlock with it.

Already a cyart.io or studio.cyart.io member? Your pass code is in your Studio account.