
The Scanner That Passed Its Own Exam
A score on the corpus a detector was tuned against measures the tuning, so each review needs a corpus nobody has tuned against.
View companion repoIt caught 63 of 63, then missed 8 of 40
A secret scanner that one of my agents wrote scored 63 of 63 on its review corpus, with no false positives and no leaked values. On a corpus it had never seen, the same scanner at the same commit caught 32 of 40, flagged one non-secret, and could still print a password. The first number measured how well the scanner had been tuned. Only the second measured the scanner.
The scanner belongs to a rework of my Claude Code configuration repo. One agent, which I will call lane A, wrote bin/setup-audit --scan, with the detector in lib/secret_scan.py. It gates every commit in the rework, so a miss can put a credential into a commit. A second agent reviewed lane A, read-only. Its brief said to "build your own corpus of realistic credentials it has never seen". The reviewer's session describes the cases as "values generated randomly and never printed", and I am not printing any here either. Every number below comes from the reviewer's tool output. I did not re-run the corpora to write this.
Stage one: 65 of 65 on the author's own cases
Lane A's report listed the scanner check as a "65-case corpus" at "65/65", with a "20,000-random miss rate <0.1% at 16 chars". The reviewer ran its own 93 cases, 63 credentials and 30 non-secrets, against the same commit:
$ tail -3 runs/corpus-table.txt
positives 63 misses 17 miss rate 27.0%
negatives 30 false positives 4 FP rate 13.3%
value leaks to stdout/stderr: 1
The two reports do not contradict each other. A corpus written by the person who wrote the detector holds the shapes that person was thinking about. The worst class of miss was passwords with symbols, because the value pattern stopped at ; , ) } ]. The reviewer re-ran the random-value test over three alphabets, 20,000 values each:
alnum len 16: miss 16/20000 = 0.08%
hex len 16: miss 9/20000 = 0.04%
symbols len 16: miss 4624/20000 = 23.12%
The reviewer's report puts it this way: "the author's <0.1% figure at 16 characters holds only for alnum". The figure was true for the alphabet it was measured on.
The reviewer's report said "the secret scanner misses 27% of my corpus, so it is not ready to gate commits as-is." It also named the corpus script and how to run it, so lane A could reproduce the misses. The team lead agent's later message names the risk: "since lane A had your corpus to tune against". The record does not show whether lane A opened the script. It shows that the reviewer's cases were available to it.
Stage two: a perfect score on the tuning set
Lane A committed a fix, 39b2306, and the reviewer re-ran its original corpus first. It came back 63 of 63 with 0 of 30 false positives and 0 leaks. The reviewer's note on that result: "The original corpus is now clean (it was the tuning set, as expected). Building a fresh holdout corpus the scanner has never seen."
The holdout had 40 credentials and 20 non-secrets, in shapes the first corpus did not include: Bearer tokens in a JWT header line, curl --user, wget --password, an MCP args array, webhook URLs, a PEM body inside a JSON string, UTF-16 files with and without a byte-order mark. By the record's timestamps it came back 68 seconds after the original corpus did. The reviewer's summary line: "The original 63/30 corpus is now clean, but the holdout corpus misses 9 of 40."
Lane A committed again while the review ran, d129d46, which added Slack webhooks. That turned 9 misses into 8. The reviewer re-ran both corpora on the new head and showed this:
$ tail -1 runs/holdout-r3.txt
positives 40 misses 8 (20.0%); negatives 20 FPs 1 (5.0%); leaks 0
$ tail -3 runs/corpus-r3.txt
positives 63 misses 0 miss rate 0.0%
negatives 30 false positives 0 FP rate 0.0%
value leaks to stdout/stderr: 0
$ python3 clone2/bin/setup-audit --scan probe2/keyleak.json | grep -c -F "$(cat probe2/pw.txt)"
1
The same commit, two corpora, 0.0% and 20.0%.
The eight misses were these:
MISS rc=0 .env lowercase 18-char secret
MISS rc=0 curl -H x-api-key hex
MISS rc=0 MCP args ['-k', value]
MISS rc=0 redis:// userinfo no user
MISS rc=0 Discord webhook
MISS rc=0 PEM body in JSON string, no header
MISS rc=0 gh secret set --body
MISS rc=0 credential-shaped JSON key, non-shape
The reviewer still called the scanner fit to gate commits, with two fixes to land first. It gave a reason for accepting the miss rate: "Real secrets nearly always contain digits or capitals, and the real secrets live in .env behind ${VAR}." That is a judgment about likelihood. The record contains no measurement of it.
The leak a known-shape rule could not see
The last line of that block is the leak. In the original corpus a JSON object key was itself a token, and the scanner printed it. The reviewer traced the cause: "json_hits builds the reported path from dict keys, so when a JSON object key is itself a credential, the hit line prints it." The first report quoted the output as keyed.json: tokens.ghp_<full token>.note (bearer token).
Lane A's fix redacted keys that matched a known token format, and the original corpus went to 0 leaks. The holdout probe used a key shaped like admin: followed by a password. That matches no token format, so it printed:
rc=1
value occurrences in output: 1
probe2/keyleak.json: logins.admin:<PW-MASKED>.password
The <PW-MASKED> is the reviewer's own sed mask. The scanner printed the password. A second probe with a password inside URL userinfo, used as a key, did the same. The redaction rule was a second detector, tuned on the shapes someone had thought of.
Lane A's next commit, a335079, changed the rule. Its message says "L1: a JSON key that holds a credential (text hit, URL userinfo, or user:password)" is redacted, and any key that is not identifier-shaped or path-shaped prints as an index. The same probes after the fix:
keyleak.json rc=1 leaks=0
probe2/keyleak.json: logins.<REDACTED> (user:password key)
probe2/keyleak.json: logins.<REDACTED>.password
Each fix spent the corpus that found it
With a335079 the first holdout went to 40 of 40. The reviewer did not count that as progress: "Lane A fixed every holdout miss by name, so that corpus is now tuning data as well." Later, in its summary, it wrote: "Lane A fixed each miss I had named in the first holdout, so that corpus no longer measures generalization."
So it built a second holdout, after a335079 landed, with different shapes and fresh negatives: 24 credentials and 16 non-secrets. Result: "positives 24 misses 5 (20.8%); negatives 16 FPs 0 (0.0%); leaks 0". The misses were a fish set -gx assignment, a launchd plist with the name on one line and the token on the next, a DigitalOcean token, mysql -p<password>, and os.environ.setdefault.
The first holdout had missed 22.5 percent, then 20.0 after another commit. The second missed 20.8. Twice, the set lane A had seen scored perfectly. Twice, the set it had not seen missed about a fifth.
The reviewer's verdict stayed fit: "A second never-seen corpus still misses about 20%, all low-likelihood shapes for this repo". Its supporting fact was a check on real files: none of the five shapes appeared in any tracked file.
Two more lane A commits landed. One, cbf4254, added a rule, in lane A's words: "ISO date/timestamp, number, UUID and boolean/null values are never secrets." The record does not say which false positive the rule was written for; the team lead's message mentions a timestamp false positive. The other, 6fb81cc, closed the five holdout shapes. With both in, the original corpus, the first holdout and the second holdout all scored 0 misses. The reviewer wrote new probes anyway, and gave its reason: "I wrote fresh probes for this review, since lane A has now tuned against all three of my earlier corpora."
The probes found that the scanner had stopped catching things it caught before. The reviewer's verdict: "Its new rule that literals are never secrets now waves through two kinds of real credential that the earlier commit a335079 caught."
uuid_key.env HEROKU_API_KEY=<uuid> a335079 rc=1 2439e10 rc=0
uuid_key.json {"env":{"HEROKU_API_KEY":"<uuid>"}} a335079 rc=1 2439e10 rc=0
uuid_secret.env CLIENT_SECRET=<uuid> a335079 rc=1 2439e10 rc=0
uuid_password.env DB_PASSWORD=<uuid> a335079 rc=1 2439e10 rc=0
Seven probes regressed: UUID-shaped keys under key, secret and password names, and all-digit PINs under a password name. The reviewer's summary of the corpora at that commit: "The original corpus and both holdouts all pass at 2439e10, and the JSON-key leak probes print the password 0 times." Then: "Lane A has tuned against all three, so the fresh probes are what found the regression."
That is the stage-two pattern from the other direction. A corpus the author has been passing cannot show what the latest change broke.
Lane A changed the exemption so that a UUID counts as a secret under credential names and stays exempt under id-style names, and a run of six or more digits counts under password names. The reviewer ran a final set it had not shown lane A: 14 positives, all caught, and 8 negatives, 7 clean. The one false positive was SESSION_UUID=<uuid>, which blocks a commit and leaks nothing. The verdict was fit, with that false positive listed as open. Lane A fixed it in d5bcdf8, and the reviewer's rerun on main read: "SESSION_UUID now scans clean, and every credential probe is still caught."
My masking missed one
While classifying scanner hits in a folder of mined prompt text, the reviewer made the mistake it had been testing for. Its report: "my masking regex missed one line." About 40 characters of what looked like a real Google API key reached its tool output. Its words for it: "That is my error." It asked for the key to be rotated, for the other credential-shaped values in that file to be rotated if still valid, and for the folder to be redacted or moved. The folder is gitignored and nothing was committed. The rotation outlived the review. The reviewer's last message: "The only item still open is NICK-ACTIONS 19, rotating the key I partially exposed earlier."
The parallel is mine, not the record's. A masking regex is a small detector, and this one missed a line while the scanner under test was being judged on the same kind of miss.
What stayed unverified
The miss rates are rates over script-built corpora of 24 to 63 credentials. They count shapes, and say nothing about the fraction of real files that would leak. The judgment that the remaining misses were unlikely in this repo was a judgment, supported only by a scan of tracked files that came back clean.
The final fit verdict rests on a 14-positive set that lane A had not seen. Once its results go to lane A, that set is spent too. The key rotation was still open when the review ended.
The rule
A score on a corpus means something only if the thing being scored has not seen the corpus. Once a miss list goes back to the author, that corpus is tuning data, and its next result is a measure of the tuning. Record each corpus as tuned or unseen, report the two scores separately, and build a new unseen set for each round. The person who builds it should not be the person who will read the fix.
Add probes in the opposite direction whenever a change reduces false positives. An exemption that makes three corpora pass can still stop the detector catching something it caught the day before. Compare the new head against the old head on fresh cases, not only against a fixed set.
Test a "never print a value" contract on fields the rules know nothing about, such as keys, paths and URL parts, and apply the same test to your own masking. The shapes you did not think of are the ones the exam leaves out.
Continue the series
- 82SeriesThe Anchor Taken After the CutA template matched across a content cut measures how alike two pieces of footage look, and only the confidence score says so.
- 84SeriesThe Audit That Changed What It MeasuredA check that shells out to the tool it audits can set off that tool's one-time migration, so measure before the first call that can write.
- 81SeriesThe Fix Measured in WordsA word count cannot tell prose from structure, so a fix justified by it can delete everything the count never measured.
- 85SeriesThe Session That Edited Its Own HomeA builder that shares a config directory with the setup it rewrites is a tenant of that setup, and a check against an empty directory proves nothing.