Skip to content

fix(privacy): mask an env-style secret next to a non-ASCII character or a bare [REDACTED - #1810

Merged
ajianaz merged 2 commits into
developfrom
fix/privacy-env-secret-edge-1794
Nov 26, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/privacy-env-secret-edge-1794

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

What

An NAME=value secret stuck to a non-ASCII character, a guillemet or a bare [REDACTED is now masked. Before, API_KEY=«<24-char token>» and API_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-privacy into tole: anyone who can place a «, an accented letter or [REDACTED next to a secret in text that is later redacted could switch the detector off for that candidate. I reproduced the table of the issue on develop before changing anything (6 of 7 cases unmasked).

Two causes, both in uteke-privacy:

  • For a name that is not a password, prose = !v.is_ascii() made any value that touches one non-ASCII character prose, so it was never checked as a secret.
  • is_placeholder treated any value that contains [REDACTED as 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:

  • The non-ASCII characters at both ends of a value are trimmed before it is judged (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 »).
  • [REDACTED is 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, so redact is still idempotent. A bare [REDACTED glued to a secret is decoration: it is skipped when the value is read, and is not a placeholder.
  • is_placeholder itself 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 --workspace passes
  • cargo fmt --all -- --check passes
  • cargo clippy --workspace --all-targets -- -D warnings passes
  • Cora review run locally (cora review --base origin/develop)
  • Manual smoke-test of the affected feature

The seven lines of the issue's table are pinned with exact outputs (the character stays, the token is gone, a second redact changes 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 with match_indices so it ends whatever a mutation does to its step.

Related Issues

Closes #1794

Checklist

  • Branch name follows convention (fix/, feat/, docs/, chore/, refactor/, test/, perf/, security/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

…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.
@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 ba72477 into develop Nov 26, 2026
18 checks passed
ajianaz added a commit that referenced this pull request Nov 26, 2026
Patch release v0.24.2: doc create on stores that went through schema v11 (#1806), the website build (#1813), the secret detector gap (#1794, #1810, #1816), list_pinned with schema v28 (#1804), dependency updates and the MCP Registry rename. See the CHANGELOG entry [0.24.2].
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.

fix(privacy): env-style secret next to a non-ASCII character or a guillemet is not masked

1 participant