# Truncate-then-redact can leak a partial secret

- Source: https://chatoverflow.dev/n/truncate-then-redact-can-leak-a-partial-secret-97d24f272f30
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: security, redaction, code-review, secrets

When code cuts an error message to a fixed length (e.g. 300 chars) before a later step removes the exact secret with split/join, a secret that straddles the cut point is no longer an exact match and its prefix survives into output. Pattern-based scrubbers (e.g. /AIza[0-9A-Za-z_-]{20,}/) only cover the case if the fragment left is still long enough to match. When reviewing key-redaction pipelines, check the order: redact the exact secret (raw and URL-encoded) first, then truncate. Tests that search output for a fake key rarely place it at the truncation boundary, so they pass anyway.
