Repository navigation
fix(privacy): mask an env-style secret next to a non-ASCII character or a bare [REDACTED - #1810
Merged
Merged
Conversation
…or a bare [REDACTED A non-ASCII character stuck to either end of a key or token made the whole value "prose", and `[REDACTED` anywhere in a value (or at its start, where `[` ended the value at once) made it a "placeholder", so `API_KEY=«<token>»` and `API_KEY=[REDACTED<token>` stayed in clear text. - The ASCII run is the value: non-ASCII characters at its ends are trimmed (not for a password name, which already takes a whole non-ASCII token, and not for a value with whitespace, which is a sentence), it is masked and the characters stay. - `[REDACTED` is a placeholder only as a complete mask (`[REDACTED]`, `[REDACTED:kind]`); a bare marker glued to a secret is decoration and is skipped when the value is read. A value that is only masks stays untouched, so redact stays idempotent. Behaviour is documented in the crate docs.
Exact mask lengths, the 8-character boundary of a value that is only masks, a secret in front of a complete mask, and a guillemet-quoted sentence. The mask scan walks match_indices, so it ends whatever a mutation does to its step. The is_empty check of trim_non_ascii_edges was redundant (a value of non-ASCII only gives an empty range, which no rule reads) and is gone.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
This was referenced Nov 26, 2026
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
An
NAME=valuesecret stuck to a non-ASCII character, a guillemet or a bare[REDACTEDis now masked. Before,API_KEY=«<24-char token>»andAPI_KEY=[REDACTED<token>stayed in clear text. The ASCII run is the value: it is masked and the character stays (API_KEY=«[REDACTED:env-secret]»).Why
Closes #1794, found while wiring
uteke-privacyinto tole: anyone who can place a«, an accented letter or[REDACTEDnext to a secret in text that is later redacted could switch the detector off for that candidate. I reproduced the table of the issue ondevelopbefore changing anything (6 of 7 cases unmasked).Two causes, both in
uteke-privacy:prose = !v.is_ascii()made any value that touches one non-ASCII character prose, so it was never checked as a secret.is_placeholdertreated any value that contains[REDACTEDas a placeholder, and an unquoted value ends at[, so[REDACTEDZq8…gave an empty value and the secret behind it was never read.How
The direction recommended in the issue and approved by the owner:
trim_non_ascii_edges), so the ASCII run is evaluated and masked and the characters stay. Not for a password name (it already takes a whole non-ASCII token, fix(privacy): bound the private-key scan, redact non-ASCII passwords, detect sk-ant keys #1775), and not for a value with whitespace (a sentence stays prose, also« token »).[REDACTEDis a placeholder only as a complete mask,[REDACTED]or[REDACTED:kind](mask_len_at,is_masked_only): a value that is only masks, or masks plus fewer than 8 letters or digits (ghp_[REDACTED:github-token]), stays untouched, soredactis still idempotent. A bare[REDACTEDglued to a secret is decoration: it is skipped when the value is read, and is not a placeholder.is_placeholderitself is unchanged for the shape rules that call it; only the assignment rule uses the stricter check.Behaviour is documented in the crate docs, as the issue asks, and in the CHANGELOG. The crate is shared with tole: its
«NAME»stand-in workaround can now go.Behaviour change to be aware of: a secret-like ASCII run of 16+ characters with entropy and a digit, glued to a non-ASCII character, is now masked where it was left. Words, localized text, digits only and sentences stay as they were (tests below).
Testing
cargo test --workspacepassescargo fmt --all -- --checkpassescargo clippy --workspace --all-targets -- -D warningspassescora review --base origin/develop)The seven lines of the issue's table are pinned with exact outputs (the character stays, the token is gone, a second
redactchanges nothing), plus quoted forms, a secret before and after a complete mask, and the exact length of a mask. Checked red without the fix, green with it. Precision tests keep these clean: a short word in guillemets, a localized word followed by digits, a localized word alone, a sentence with a token inside, and« token »with spaces.Mutation gate on the diff (owner rule 2026-08-19),
cargo mutants -p uteke-privacy --in-diff: 64 mutants, 64 caught, 0 missed, 0 timeouts. The first run found 10 missed and 2 timeouts in the new helpers; the second commit kills them (exact mask lengths, the 8-character boundary, a secret in front of a mask) and walks the mask scan withmatch_indicesso it ends whatever a mutation does to its step.Related Issues
Closes #1794
Checklist
fix/,feat/,docs/,chore/,refactor/,test/,perf/,security/)develop