Repository navigation
fix(security): redact a known secret in embedded base64, hex, JSON escapes and zero-width splits - #699
Merged
Conversation
…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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
SecretSet::redactnow also redacts a known secret when it appears inside a larger base64 payload, as hex, with JSON\/or\uXXXXescapes, 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 dockerconfig.jsonauth, a base64'd.env,xxd -phex, 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 theweb_fetch"URL carries a known secret" refusal the same way.Changes
crates/tole-core/src/secrets.rsforms(): 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\uXXXXescapes (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 ondevelop(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.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_formagrees 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.\/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 --workspaceandcargo test -p tole-core --no-default-featurespass.