feat(detectors): built-in detector for oversized base64 blobs (#212)
Your AI's guard dog to stop it from going rogue.
Brought to you by:
doberman
Originally created by: harshitagrawal2O
Adds Base64BlobDetector, a second built-in subjective detector (mirroring TokenChannelDetector), that flags a suspiciously large base64-looking blob in a tool call's arguments — a common encode-and-exfiltrate shape, where bulk file or secret contents are smuggled out as one encoded payload.
AUTH (the execution rule clamps a subjective BLOCK to AUTH); it never blocks and never lowers a verdict.min_blob_chars, default ~1500 base64 chars ≈ 1.1 KB) — not a magic number baked into the logic. A character-diversity heuristic (mixed case + digits + ≥20 distinct chars) rejects long hex / identifier / repetitive-filler runs that merely share the base64 charset.ReasonCode.oversized_encoded_blob, registered in BUILTIN_DETECTOR_TYPES.Scope: this targets bulk encoded dumps. Small credentials (an API key, a short token) are below the threshold by design and remain the objective secrets rule's job.
tests/unit/test_detector_base64_blob.py — 14 tests: oversized blob → AUTH; short/benign → PASS; long lowercase-hex / letters-only / repetitive-filler runs do not flag; configurable threshold; newline-wrapped (PEM/MIME) blob is caught; space-separated short tokens do not merge; blob in target/destination caught; never BLOCK (raise-only); the blob never appears in the explanation (redaction); wired into SubjectiveGuardrail as a built-in and disable-able.test_detector_never_blocks and the raise-only subjective contract enforce itoversized_encoded_blob + a one-line explanation on every AUTHTokenChannelDetector, this detector calls collect_scan_strings(action, ctx) itself rather than sharing one collected list across detectors. Sharing collection across the built-in detector fan-out is a separate infra change, out of scope here.
Ticket changed by: fu351
Originally posted by: fu351
Solid work, and the honesty in it is what makes it good. A shape-only base64 heuristic will false-positive on a legitimate large embedded asset, and instead of hiding that you documented it in the docstring, README, and CHANGELOG and bounded it by only ever raising to AUTH, never BLOCK. That's the correct call for a defense-in-depth signal: the cost of a false positive is one confirmation prompt, not a broken workflow. The redaction test (asserting a slice of the blob never reaches the explanation or a reason code) and the false-positive guards (hex dumps, long word runs, whitespace-separated short tokens) are exactly the tests this kind of detector needs.
Merging. You've got the detector seam down now, so [#321] (a PII / financial-data-class exfil detector) is the natural next one — same seam, and it would give the lethal-trifecta floor a real target leg to line up on. Want it? I can assign it to you.
If you're not already in the Discord: https://discord.gg/Sfy5XGNqty
Thanks, harshitagrawal2O.
Related
Tickets:
#321