Safeguard
Security Guides•

Should you redact logs at the source or in the pipeline?

Redact at the source first so secrets never leave the process, then add a pipeline filter as a backstop. A comparison of both with steps to set up each.

Safeguard Security Team
3 min read

Do both, in that order. Redact at the source so a secret never leaves the process, then add a pipeline filter as a safety net for what slips through. Source redaction is more reliable. Pipeline redaction is easier to roll out across many services.

Definitions

Source redaction means the application removes, masks or never records a sensitive value when it builds the log line. Pipeline redaction means a collector or shipper rewrites events after they leave the process but before they reach storage.

The OWASP Logging Cheat Sheet lists data that should usually be removed, masked, sanitized, hashed or encrypted rather than logged directly: source code, session identifiers, access tokens, passwords, database connection strings, encryption keys, payment data and some personal data. It also says that in some systems, sanitization can be done after log collection and before log display, which is the pipeline option.

Comparison

FactorAt the sourceIn the pipeline
Secret leaves the processNoYes, briefly
Local log files protectedYesNo, files hold the raw value
Works for every languageNo, needs code changesYes
Speed to roll outSlowFast
Pattern guessing neededRarely, you know the fieldYes, regex on text
Risk of missing a caseLow for known fieldsHigher for free text

The row that decides most arguments is local files. A pipeline filter does nothing about the log file on the host or the container stdout buffer, which administrators and crash tooling can read.

Steps

  1. Start with an allow list of fields for structured events, so unknown fields are not logged. See log field allow list versus deny list.
  2. Wrap logging of request objects. Log selected fields, never the whole object.
  3. Replace secrets with a fixed marker at the source. Use a stable hashed value only when you need to correlate events and the original is not guessable.
  4. Add a pipeline processor for known patterns such as authorization headers and card numbers. See OpenTelemetry collector redaction and filter processors.
  5. Alert when the pipeline redacts something. A hit means a source bug that should be fixed.
  6. Test both layers with fake values. See test log redaction with canary values.

Where each layer fails

Source redaction fails when a developer logs a new field or an exception message that embeds a value. Pipeline redaction fails on formats the patterns do not expect, such as a token split across lines or encoded. Neither layer is complete alone, which is why the second one is a backstop and not a plan.

Treat a pipeline redaction hit as an incident of low severity: rotate if the value was live, and fix the source.

Quick check

Is hashing a password in a log enough?

The OWASP guidance says passwords should not be logged at all. Do not record them in any form.

If I redact in the pipeline, are my log files safe?

No. The raw value still exists in local files and buffers before the pipeline sees it.

Safeguard's policies and gates can block risky dependency changes before they ship. A free scan is at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.