Skip to main content

Module redact

Module redact 

Source
Expand description

Shape-based, best-effort secret redaction — the one Rust implementation SPEC_ERROR_COPY_EVERYWHERE_2026_09_24.md §4.5 asks every formatter that puts error/log text on the clipboard to share, instead of each inventing its own. Moved here from crates/srv-core/src/backend/continuity.rs, which only recognized credential-prefixed tokens and PEM private keys — enough for a continuation packet, not enough for raw stderr and request details (Codex P1 on #3689).

Deliberately manual string scanning, not the regex crate: nothing in this workspace depends on regex today, and continuity.rs’s own pre-existing redaction (kept here unchanged) already established that as the house style for this kind of text scan.

Mirrored on the TypeScript side by frontend/app/errors/redact.ts, and both are tested against the same docs/specs/fixtures/redaction-vectors.json so the two can’t drift apart (§4.5).

Constants§

SECRET_PREFIXES
The prefixes a credential-shaped token starts with. Public so a caller can tell cheaply, before decoding, that a text may hold one: a plain substring test, which no escaping of the text around a token can hide.

Functions§

redact_private_keys
Blanks PEM private keys (-----BEGIN ... PRIVATE KEY----- blocks), never a certificate. Public — continuity.rs’s own tests exercise this pass in isolation (ReAgent P0 on #3643: a certificate ahead of a key must not end the scan and let the key through).
redact_secrets
The full redaction pipeline. Order matters: the original credential-prefix and private-key passes run first (unchanged, so their existing callers’ exact output is preserved byte-for-byte on inputs that only they match), then the newer, broader shape-based passes.
redact_token_shapes
Blanks credential-prefixed tokens that start a word, and PEM private keys, and nothing else: the two passes of redact_secrets that look for a secret by its shape alone, without its key: value passes. Unlike redact_secrets, a prefix inside a word does not count, so page text such as disk-usage-report-weekly (sk- inside disk-) comes back whole. Linear in the length of the text.