Skip to content

feat(secrets): mask unknown secret shapes with the shared uteke-privacy detector - #909

Merged
ajianaz merged 5 commits into
developfrom
feat/597-shared-secret-detector
Nov 17, 2026
Merged

ajianaz merged 5 commits into
developfrom
feat/597-shared-secret-detector

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

Mask secrets tole never knew (pasted by the owner, printed by a command) with the ruleset shared with uteke, uteke-privacy 0.24.1, at every sink SecretSet already covers. The mask is prefix[REDACTED:<kind>].

Why

Closes #597 (epic #594). Owner decision of 2026-11-11: one shape detector shared with uteke, wired into SecretSet after known-value redaction at the same sinks, false positives through an allowlist. The blocker codecoradev/uteke#1732 is closed and uteke-privacy 0.24.1 is on crates.io (Apache-2.0, depends on regex only, no IO).

Changes

  • New crates/tole-core/src/secrets/shape.rs: wraps uteke_privacy::redact, with set_allowlist, check_allowlist, redact_shapes and masked_kinds. secrets/mod.rs runs it after the known-value pass in redact and redact_value. Every sink that goes through the set is covered: provider request, session log and pinned system prompt, live observer events, MCP arguments, web query and URL, systemone, router, advisor, memory loop, uteke documents, discussion sanitize, sandbox argv, and the tole-cli sinks.
  • Behaviour changes:
    • SecretSet::redact and redact_value on an EMPTY set are no longer a no-op.
    • A JSON object field is masked by its name too ({"api_key": "<random>"}).
    • A web_fetch URL that looks like a secret is refused, like one holding a known value (new wording that names redaction_allowlist).
    • A log entry lists shape:<kind> in its redacted field (no new wire field; old logs replay unchanged).
    • New config redaction_allowlist (regexes), user layer only. A project config's value is ignored with a warning.
    • scan_secrets and plugin_scan use the known-value pass only (redact_known).
    • Basic-auth of another value is now masked as [REDACTED:basic-auth].
  • Marker stand-in design: a known «NAME» marker, whatever characters its name holds, is swapped for a letters-and-digits stand-in qzk..k<i>x while the detector runs. The run of k is longer than any in the text, so the prefix cannot occur in the input, and restore is one bounds-checked pass that only touches stand-ins this call created. Markers are kept only where they are the whole secret position (anchored allow patterns), so text that carries a marker cannot hide a secret next to it.
  • Docs in the same PR: README, docs/epics.md, docs/threat-model.md (coverage and residuals), docs/secrets-integrations-design.md, docs/migrating-0.11.md, CHANGELOG. The README status line does not mention feat: shared shape-detector ruleset with uteke for unknown secrets #597, so it is not stale.
  • New dependency: uteke-privacy 0.24.1 and regex 1.13.1 (plus aho-corasick, memchr, regex-automata, regex-syntax): 6 new Cargo.lock packages. Release binary size delta not measured.

Testing

  • cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace --no-fail-fast (2766 passed, 0 failed), cargo check -p tole-core --no-default-features --tests, and cora review --staged --no-llm (no issues).
  • New tests: tests/shape_redaction.rs (mask form, idempotency, known-before-shape, no-leak sweep over redact, redact_value, router, log, provider request, header, whole turn), tests/shape_marker.rs (marker smuggling, legitimate marker positions, JSON fields, shape:<kind>, control bytes, stand-in look-alikes, PEM, unusual names, 50,000-marker restore, longest marker wins), tests/shape_allowlist.rs, and a config test.
  • Mutants, each killed by the new tests: detector not wired; detector before the known-value pass; early return restored in redact_payload; unanchored marker allow; swap skipped on control bytes; non-alphanumeric stand-in; fixed prefix with no collision avoidance; known names not swapped; longest-first sort dropped.
  • Independent review: four rounds by fresh read-only reviewers. Round 1 found a blocker (unanchored marker allow), round 2 two leaks (control bytes, PEM), round 3 a blocker (unusual marker names) and a restore performance issue, round 4 no blocker. The residuals that remain are documented in docs/threat-model.md.
  • cora callers redact lists about 50 callers, mostly in provider/openai.rs, turn/mod.rs, web.rs, children/memory.rs, session/storage.rs, discussion, advisor, plugin_lock, sandbox/report and tole-cli discuss/delegation. Callers that compare redact output to the input (web.rs, web_builtin.rs) were verified by grep. cora affected listed about 99 test files; the tests to rerun are the full workspace, which passed.
  • scripts/review-local.sh was not run (no LLM key); cora review --staged --no-llm was clean.
  • Not verified locally (CI only): iOS/Android cross-compile, cargo audit.
  • Not in this PR: the per-request detector cost, tracked in perf: bound the cost of the shape-detector pass on large histories #908.

…cy detector (#597)

SecretSet::redact and redact_value now run the uteke-privacy shape ruleset after the known-value pass, at every sink the set covers (provider request, session log, live events, MCP arguments, web, memory loop), masking as prefix[REDACTED:<kind>]. It runs for an empty set too and keeps the known-value marker. A redaction_allowlist (user config only) keeps false positives.
…rd shape kinds (#597)

Review fixes: a known-value marker is swapped for an ASCII stand-in while the detector runs and kept only where it is the whole secret position, so text carrying a marker cannot hide a secret next to it. JSON object fields are masked by their field name. Log entries list shape:<kind> in redacted. web_fetch refusals name secret shapes and redaction_allowlist. A project redaction_allowlist is ignored with a warning. Migration and changelog entries added.
)

The marker stand-in is letters and digits only (qzk..k<i>x), with a run of k one longer than any in the text, so it cannot occur in the input, keeps PEM and token shapes intact, and is never skipped because of control bytes. Docs: second pass can only mask more, redacted field documents shape kinds, threat model lists literal guillemets as non-ASCII neighbours.
…ne pass (#597)

The set's exact marker strings are swapped for the stand-in, so a name with other characters no longer leaves a non-ASCII marker that hides a glued secret. Restore is a single pass with bounds-checked indexes instead of one replace per marker. Threat model lists the word-character, keyword and lone-guillemet residuals.
The longest-first marker order is built once in the set instead of per call. A test pins that the longest known marker wins. Threat model names the vendor-token adjacency cases.
@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit f525fbb into develop Nov 17, 2026
23 checks passed
@ajianaz
ajianaz deleted the feat/597-shared-secret-detector branch November 20, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: shared shape-detector ruleset with uteke for unknown secrets

2 participants