Safeguard
Developer Tools•

How do you turn false positive reports into a rule regression corpus?

Every false positive report is a free test case. Capture the code, label it, add it to the rule's tests, and keep it so the bug cannot return.

Safeguard Security Team
3 min read

Turn each false positive report into a permanent test: copy the smallest piece of code that triggers the wrong result, label what the correct result is, add it to the rule's test suite, then fix the rule until the test passes. Over time the suite becomes a regression corpus for that rule.

Definitions

  • Regression corpus: a set of code samples with known correct outcomes, kept so old mistakes are not repeated.
  • True positive: the rule reports real risk.
  • False positive: the rule reports something that is not a problem.
  • False negative: the rule is silent where it should have reported.

Both error kinds belong in the corpus. A fix for a false positive that creates a false negative is a common way rules decay.

The capture routine

  1. Collect the report. Ask developers to link the finding, not paste a description.
  2. Reduce it. Remove everything that does not affect the result until a few lines remain. This also helps you understand the cause.
  3. Remove private detail. Replace real names, hosts and values with neutral ones.
  4. Label it. Valid means no report expected. Invalid means a report is expected.
  5. Add it to the tests. In ESLint this is an entry in the valid or invalid list of RuleTester. In Go, it is a file in testdata, where a line with no want comment asserts that nothing is reported.
  6. Write a one line reason. A comment such as "value comes from a constant" saves the next person an hour.
  7. Fix and run everything. All earlier cases must still pass.

Keep a counter-sample

For every false positive you fix by narrowing a rule, add a nearby sample that should still be reported. This is the guard against over-correcting. If a developer says "it flags my safe call", the sibling test says "but it must still flag the unsafe one".

Structure on disk

FolderContents
flaggedCode the rule must report
allowedCode the rule must stay silent on
edgeUnusual syntax: aliases, nesting, generated code
from-reportsCases traced to a real ticket, with the ticket id in a comment

Public benchmarks

Some projects publish test suites for tools. The OWASP Benchmark is a Java and Python test suite designed to check the speed and accuracy of vulnerability detection tools, where the vulnerabilities it scores are meant to be exploitable. It is useful for general scanner evaluation, but a corpus drawn from your own tickets reflects your code and your frameworks, which no public suite can.

Measure with it

Because every case has a label, you can compute how many the rule gets right after each change. Track it over time. A drop after a change tells you the change did harm, before developers do.

Quick check

How many samples should a corpus have?

Start with one per report and grow naturally. A small corpus of real cases is worth more than a large synthetic one.

Should I include code from customers or private repositories?

Not as is. Reduce it and replace identifying details before it goes into a shared test suite.

Safeguard's scanning covers dependencies and SBOMs, and its reachability analysis helps show which findings your code can actually call. You can run a free scan on a repository.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.