We Detected It on 169 Files and Scored 1
Our SQL-injection detection flagged 169 of the vulnerable files in a public benchmark corpus.
The benchmark scored us 1.
Both numbers were correct. The detector was working. The scorer was working. Nothing had errored, and nothing had warned. The gap between them was one character: a leading zero.
How both were true at once
We emitted CWE-089. The benchmark’s answer key said CWE-89. Scoring matches on the pair of file and weakness
identifier, and a strict key cannot match across that padding. So a correct detection on the right file scored as a
miss: of the 169 files we flagged, 146 carried the padded label.
The defect sat in the one component meant to prevent it.
We already had a normaliser for weakness identifiers. It was the declared single taxonomy, the one place every
identifier was supposed to pass through. It matched the digits and wrote them back out as captured, so normalising
CWE-089 returned CWE-089. The fix’s own commit message says it plainly: “A normalizer that preserves the very
thing it exists to normalize is worse than none, because every consumer trusted it.”
The padded form appeared 405 times. It had been in our output for months, and our own test corpus had never shown it. That corpus held only four SQL-injection cases, a class too small there to register as a gap. The benchmark was the first one we had not written, and it found the defect within a day of being adopted. It found a second one the same day: one weakness identifier sprayed across 776 findings that had no business claiming it.
Why nothing failed loudly
A mismatched label does not throw. It produces a non-match, and a non-match is indistinguishable from a miss. Every stage downstream of the detector received a well-formed finding, joined it against the answer key, found no partner, and recorded the absence faithfully. The score was an accurate count of a comparison that could never succeed.
This is the shape of a whole family of failures. The zero was real; it just was not a measurement of what it was labelled as. One hit at SQL injection meant one hit at matching our spelling to theirs.
Where the fix went
The tempting fix was one line in the scorer: canonicalise both sides at comparison, and the number goes up. It would have produced a correct benchmark result and left every other consumer of the identifier wrong. Deduplication keys, analytics rollups, cross-tool comparison, and the UI would all still carry the padded form. And it would have been harder to notice, because the one number anyone was watching would have looked right.
So the fix went to the point of creation:
- the normaliser now strips the padding, through one canonical function that every path routes through;
- the finding type canonicalises the identifier at construction, so every producer, whether a rule engine or a model lane, emits the canonical form whether it remembers to or not;
- and the scorer canonicalises both sides as well, for output that never passed through our finding type: other tools’ results, and scans already on disk.
There are tests that fail if a padded identifier does not canonicalise, if padded and unpadded forms are not the same scoring key, if any producer’s finding is not canonicalised at construction, and if an unrecognised token is dropped instead of kept verbatim. Losing an identifier silently would just be the same bug with a different symptom.
The result: 662 hits became 809. Plus 147, with zero detection work.
The ledger
That was the first entry in a ledger that kept growing. Over the next two days the same pattern repeated three more times. A seam that could not emit a class of finding: plus 218. A list of dangerous calls that was incomplete: plus 149. Rules that validated cleanly but could never match, replaced with ones that could: plus 113.
Roughly 627 hits came from plumbing. In the same stretch we tested a rule set with 1,267 more detection rules than the one we ran. It gained 20, cost more per finding, and we stayed on the smaller set. Recall on the benchmark went from 46.8% to 91.0% across the following day, and almost none of it came from detecting anything new.
We had spent days assuming we needed better detectors. The findings were being made, and then dropped, mislabelled, or flattened on the way out.
The class
The path between “we found it” and “it counted” is where capability disappears, and it is under-examined for a simple reason: it is not the interesting part. It rarely has an owner, every seam in it can drop a result without an error, and the dashboard it feeds reports the loss as a fact about the thing upstream.
Every place you compare identifiers is a place you can be silently wrong. Canonicalise where identifiers are created, not where they are compared, and pin it with a test that fails when they diverge.
The line that stays
A score is a count of matches, and a match is a claim about spelling before it is a claim about capability.
Before you build a better detector, check that the one you have is being counted.