Log date · Wed
How can boundary mutations test secret scanners?
Mutate credential boundaries and check full matches to expose misses and truncation in secret-scanner rules.
Can boundary mutations expose secret scanner misses?
A secret scanner can miss a credential, or report only part of it, because of how its last character meets the surrounding text. In three fake-credential cases, our fixed-length rule missed a trailing hyphen, the variable-length rule returned a truncated match, and a token-boundary rule passed all three.
This is the question raised by Shweta Mishra’s paper, submitted on 2026-09-02 (UTC): mutate credential boundaries and inspect outcomes per rule. [1] A clean scan says the configured rules found nothing in the input; it does not establish that a release contains no secrets.
| Question | Result |
|---|---|
| Ordinary ending | All three rules returned the full value |
| Trailing hyphen | Fixed rule missed; variable rule returned a truncated value |
| Another allowed character follows | Both word-boundary rules matched; token-boundary rule rejected |
Experiment: compare the match, not just the alert
We used Python 3.9.1 re to write three rules and three synthetic source lines, all containing invalid DEMO placeholders. This is an illustration with another tool of the same class of boundary problem, not a test of any scanner or version in the paper or a replication of its statistics.
The first two rules require either four characters or three to four characters after the prefix and then a word boundary. The third still requires four, but uses a negative lookahead to check that the next character is outside the toy alphabet. The continuation case is negative: a fifth allowed character means this is not a complete four-character token.
fixed-word-boundary | normal | DEMO-ABC1 | pass
fixed-word-boundary | hyphen | none | FAIL
fixed-word-boundary | continuation | DEMO-ABC- | FAIL
variable-word-boundary | normal | DEMO-ABC1 | pass
variable-word-boundary | hyphen | DEMO-ABC | FAIL
variable-word-boundary | continuation | DEMO-ABC- | FAIL
fixed-token-boundary | normal | DEMO-ABC1 | pass
fixed-token-boundary | hyphen | DEMO-ABC- | pass
fixed-token-boundary | continuation | none | passThe test compares the entire matched value, so a truncated match is not counted as success. Counting only whether an alert exists would conceal that distinction. A real scanner may apply entropy thresholds, redaction or verification after matching; test its final alert as well, checking the rule, location and match span without exposing real credentials.
Why the hyphen changes the result
Python defines a word boundary as a position between a word and a non-word character, not the end of an arbitrary token. [2] Both the hyphen and the following quote are non-word characters, so there is no word boundary after the full DEMO-ABC-. The fixed rule cannot shorten to three characters and misses; the variable rule backtracks to DEMO-ABC, where C and the hyphen form a boundary.
Conversely, in DEMO-ABC-X the hyphen and following X form a word boundary, so both rules mistake the prefix for a complete value. The third rule rejects that position using the allowed character set. It is specific to our toy format: derive the real alphabet, lengths and delimiters from the credential format, and check counterexamples.
(DEMO-[A-Z0-9-]{4})\b
(DEMO-[A-Z0-9-]{3,4})\b
(DEMO-[A-Z0-9-]{4})(?![A-Z0-9-])Changing a boundary does not automatically improve overall quality. A wider rule may add false positives, while an overly narrow delimiter set may miss new contexts. Keep known positive and negative cases and run them together after each rule change.
The paper’s results and practical decisions
The paper evaluated the method on a 43-rule open-source scanner, Gitleaks 8.21.2 and TruffleHog 3.82.13. In the primary subject, detection was at least 0.9976 across ten contexts but fell to 0.5233 for credentials ending in a hyphen, affecting five rules; two fixed-count rules failed completely and deterministically. A plausible first repair also regressed two other rules. [1]
The paper reports a separate source-confirmed Gitleaks defect and no boundary fragility but the narrowest coverage for TruffleHog. The recall differences did not reach statistical significance, so the authors do not rank the tools. These results concern the versions and corpora studied; retest your own configuration after upgrades.
| Case | Recommendation |
|---|---|
| Rule change | Keep the full positive and negative suite and rerun it |
| Clean source scan | Also inspect build-injected configuration and release artifacts |
| Too many false positives | Record location and rule; tune against representative negatives and rerun positives |
| Real exposure | Revoke and rotate first, then inspect old releases and access records |
Run boundary regression on your own project
We built a small sample that does not access real credentials, ran three rules and inspected their output. Use the commands below to reproduce the results, then create a separate test directory for your scanner.
python3 --version
python3 - <<'PYTHON'
import re
rules = {
'fixed-word-boundary': re.compile(r'(DEMO-[A-Z0-9-]{4})\b'),
'variable-word-boundary': re.compile(r'(DEMO-[A-Z0-9-]{3,4})\b'),
'fixed-token-boundary': re.compile(r'(DEMO-[A-Z0-9-]{4})(?![A-Z0-9-])'),
}
cases = {
'normal': ('key = "DEMO-ABC1"', 'DEMO-ABC1'),
'hyphen': ('key = "DEMO-ABC-"', 'DEMO-ABC-'),
'continuation': ('key = "DEMO-ABC-X"', None),
}
for rule, pattern in rules.items():
for name, (line, expected) in cases.items():
match = pattern.search(line)
actual = match.group(1) if match else None
verdict = 'pass' if actual == expected else 'FAIL'
print(f'{rule} | {name} | {actual or "none"} | {verdict}')
PYTHONFor each format, create invalid fixtures covering first and last characters, minimum and maximum length, quotes, spaces, newlines and adjacent allowed characters. Record the expected value, rule and file location; include near misses that must not alert. Run the scanner with its own pinned version and configuration, asserting the full span rather than only an exit code or total alert count.
In an isolated test environment, inspect both source and unpacked release artifacts because a build can inject configuration. Record tool and rule versions and the results; keep real secrets out of fixtures, command lines and shared logs. If a release carried a real credential, restrict its privileges and rotate it, verify the old value no longer works, and inspect a new build.
Your checklist
- Use invalid placeholders for credential character and length boundaries.
- Assert the full match, rule and location.
- Keep near-miss negatives and rerun the whole suite after rule edits.
- Scan source and unpacked release artifacts.
- Revoke and rotate real exposures and verify invalidation.
Primary sources
- arXiv: Boundary-Mutation Testing for Pattern-Based Secret Detection (2609.02983) · Source date 2026-09-02 · Checked 2026-10-12
- Python: Regular expression operations · Checked 2026-11-11