Skip to content

fix(security): redact a known secret in embedded base64, hex, JSON escapes and zero-width splits - #699

Merged
ajianaz merged 2 commits into
developfrom
security/secret-encodings
Nov 14, 2026
Merged

ajianaz merged 2 commits into
developfrom
security/secret-encodings

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What

SecretSet::redact now also redacts a known secret when it appears inside a larger base64 payload, as hex, with JSON \/ or \uXXXX escapes, or split by a zero-width character.

Why

Closes #681. The matcher knew only the value alone, its JSON escape, base64 of the value alone and percent-encoding. HTTP Basic base64("user:" + token), a docker config.json auth, a base64'd .env, xxd -p hex, Python/PHP JSON escapes and a value split by a zero-width character reached the provider, the durable log and every other sink unredacted, and bypassed the web_fetch "URL carries a known secret" refusal the same way.

Changes

  • crates/tole-core/src/secrets.rs
    • forms(): base64 (standard and URL-safe) of the value embedded at offsets 0, 1 and 2 mod 3, keeping only the characters that do not depend on neighbouring bytes (leading mixed characters and the trailing partial group are dropped); lower- and uppercase hex; JSON forms with \/ and \uXXXX escapes (lower/upper hex digits, surrogate pairs, and the all-characters-escaped form). At most 24 needles per value (MAX_FORMS), none shorter than the 8-character floor, still one byte scan.
    • redact(): text that holds an invisible format character (zero-width, bidi, soft hyphen, BOM...) gets a second scan on a copy without them, with an offset map back to the original; spans of both scans are merged. Text without any is scanned once (byte-level check, no decoding).
  • docs/threat-model.md: the egress row lists the new forms and documents the residual (arbitrary transforms: line-wrapped base64, mixed-case hex, compression, ROT13, pieces, written-out escapes of invisible characters), which the shape detector (feat: shared shape-detector ruleset with uteke for unknown secrets #597) cannot close either.
  • docs/perf.md: measured throughput before/after (about 660 to 350 MB/s on mixed text, no-secret set unchanged).
  • CHANGELOG.md: entry under Security.

Testing

  • crates/tole-core/tests/secret_encodings.rs (public API; the scratch audit tests turned real): fails on develop (base64 Basic leaked; hex, \/ and zero-width split missed), passes here, plus a no-false-positive test. The test secret is deliberately not token-shaped so secret scanners do not flag it.
  • Unit tests in secrets.rs: every offset in both alphabets (including a value that exercises +/ vs -_), surrounding text kept, hex both cases, \/ and \uXXXX (both cases, surrogate pair, all-escaped), json_form agrees with serde, invisible splits (several characters, multibyte neighbours, split encoded form), merge with the plain scan and idempotence, invisible characters alone redact nothing, a secret that holds an invisible character still matches, needle bound and floor, byte check agrees with char check for all of the BMP, 4 MiB linear-time guard.
  • Mutation checks (each caught): offsets 0..3 narrowed, leading-skip table zeroed, trailing partial group kept, hex upper removed, hex lower removed, \/ form removed, invisible second scan disabled, span end mapping off by one, span merge removed, URL-safe alphabet removed.
  • cargo fmt, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo clippy -p tole-core --no-default-features, cargo test --workspace and cargo test -p tole-core --no-default-features pass.

…capes and zero-width splits

SecretSet matched only the value alone, its JSON escape, base64 of the
value alone and percent-encoding, so Basic auth, a docker config auth,
a base64'd .env, hex, JSON \/ and \uXXXX escapes and a value split by
a zero-width character reached every sink unredacted.

Add base64 needles for the value inside a larger payload at each offset
mod 3 (standard and URL-safe, edge characters that depend on neighbours
dropped), lower/upper hex, and the \/ and \uXXXX JSON forms (24 needles
per value at most). Text with invisible format characters gets a second
scan with them removed, mapped back onto the original.

Document the residual (arbitrary transforms) in the threat model.

Closes #681
Trivy flagged the ghp_ test constant as a GitHub PAT.
@github-actions

github-actions Bot commented Nov 14, 2026 •

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 b01c88d into develop Nov 14, 2026
19 checks passed
@ajianaz
ajianaz deleted the security/secret-encodings branch November 20, 2026 08:40
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.

security(secrets): SecretSet misses a known value inside a larger base64 payload, hex and other common encodings

2 participants