Skip to main content

redact_binary_blobs

Function redact_binary_blobs 

Source
pub fn redact_binary_blobs(text: &str) -> Cow<'_, str>
Expand description

Replace long contiguous base64-alphabet runs with a length/hash marker.

Guards against tool output that embeds raw binary data (e.g. a vision tool returning image bytes as plain text instead of a typed image part) from being written unredacted to debug dumps. Returns Cow::Borrowed when no run is found (zero-allocation fast path).

Known limitations (accepted for this MVP heuristic, not solved): base64 wrapped with embedded newlines (e.g. 76-char MIME line length) does not form one contiguous run and slips through undetected. Similarly, two adjacent blobs concatenated with no separator can either merge into one run that still clears the threshold, or — if an internal = from an unaligned blob boundary sits mid-string — get split into two independently-scored fragments that can each fall under the 200-character threshold and escape redaction even though the combined data would have tripped the heuristic as a single run.