01 · Before and afterThe pattern
// before: chunks redacted independently; "sk-ab" + "cd12" passes through
out.write(redact(chunk));
// after: hold back a tail that could still begin a secret
buf += chunk;
const safe = lastSafeCut(buf, secrets); // no partial or straddling match before it
out.write(redact(buf.slice(0, safe)));
buf = buf.slice(safe);02 · Run it on your appThe check
If you mask secrets in streamed logs or LLM output, what happens when a secret arrives split across two chunks?
If the honest answer is no or not sure, this is worth a look before it reaches production.