Switch runner to 14-category CWE prompt and strict scoring

- Add sast_v2 prompt covering all BenchmarkPython CWEs
- Accept boolean vulnerable plus CWE and derive category from CWE
- Score flag accuracy separately from strict flag+CWE accuracy
- Report wrong-category true positives explicitly
- Run DeepSeek v2 on all 200 original and obfuscated samples
- Extend LLM and SAST exports with strict correctness and CWE fields
This commit is contained in:
Joren committed 2026-11-10 22:58:36 +01:00
1 parent 033e5d0ea3
commit 26da3173e9
29 files changed
+15498 -1629

No files matched your search

+49 -15
View File
@@ -101,8 +101,46 @@ See `sast_tools/README.md` for the mapping rules and results.
## DeepSeek comparison
### v2 prompt: all fourteen categories
Two runs were executed with `opencode-go/deepseek-v4.1-flash` and
`prompts/sast_v1.txt`:
`prompts/sast_v2.txt`, covering all 200 samples:
| Metric | Original | Obfuscated v2 |
|---|---:|---:|
| TP | 65 | 67 |
| FP | 14 | 18 |
| TN | 119 | 115 |
| FN | 2 | 0 |
| Accuracy | 92.0% | 91.0% |
| Strict accuracy (flag + CWE) | 92.0% | 91.0% |
| Precision | 82.3% | 78.8% |
| Recall | 97.0% | 100% |
| FPR | 10.5% | 13.5% |
| Balanced accuracy | 93.2% | 93.2% |
| F1 | 89.0% | 88.2% |
| MCC | 0.835 | 0.826 |
| Category accuracy (TP) | 100% | 100% |
| CWE accuracy (TP) | 100% | 100% |
| Wrong-category TPs | 0 | 0 |
| Total tokens | 378,040 | 505,773 |
| API calls | 200 | 200 |
Paired McNemar test on all 200 samples: **p = 0.774**. The small
original-vs-obfuscated difference is not statistically significant. The
original run missed two `hash` samples; the obfuscated run detected all 67
vulnerable samples but produced four more false positives.
**Strict accuracy** requires the vulnerable/safe flag to be correct and, for
vulnerable samples, the predicted CWE to match the benchmark CWE. A vulnerable
sample flagged vulnerable with the wrong CWE is a detection true positive but
not a strict-correct classification; `wrong_category_tp` counts these. There
were zero in both v2 runs, so strict accuracy equals flag accuracy here.
### v1 prompt: nine categories (pilot)
The earlier pilot used `prompts/sast_v1.txt` and scored only the 157 samples in
its nine target categories:
| Metric | Original | Obfuscated v2 |
|---|---:|---:|
@@ -113,21 +151,14 @@ Two runs were executed with `opencode-go/deepseek-v4.1-flash` and
| Accuracy | 91.7% | 88.5% |
| Precision | 78.0% | 71.9% |
| Recall | 100% | 100% |
| Category accuracy (TP) | 100% | 100% |
| CWE accuracy (TP) | 100% | 100% |
| Total tokens | 381,410 | 472,990 |
| API calls | 201 | 202 |
Paired McNemar test on the 157 in-scope samples: **p = 0.125**, so the +5
false-positive difference is not statistically significant in this single run.
Paired McNemar on the 157 in-scope samples: **p = 0.125**. This pilot is kept for
comparison but is superseded by the v2 all-category runs.
Caveat: the original run used `--workers 4` and the obfuscated run used
`--workers 1`, so wall-clock times are not comparable. See
`deepseek_comparison.md` for the per-category breakdown, new false positives,
and the recommended replication.
Raw per-sample outputs are in `deepseek/*.csv`; `deepseek/summary.csv` contains
the comparison table in machine-readable form.
Raw per-sample outputs are in `results/deepseek-v2-*.csv` and the older
`deepseek/*.csv` pilot files. The SPSS exports use the v2 runs by default.
## SPSS exports
@@ -163,9 +194,12 @@ validation/
│ └── obfuscated_v2.json # raw Semgrep JSON, obfuscated
├── deepseek_comparison.md # original vs obfuscated analysis
├── deepseek/
│ ├── deepseek-original.csv # per-sample original results
│ ├── deepseek-v4.1-flash.csv # per-sample obfuscated results
│ └── summary.csv # comparison metrics
│ ├── deepseek-v2-original.csv # v2, all 200, original
│ ├── deepseek-v2-obfuscated.csv # v2, all 200, obfuscated
│ ├── summary_v2.csv # v2 comparison metrics
│ ├── deepseek-original.csv # v1 pilot, original
│ ├── deepseek-v4.1-flash.csv # v1 pilot, obfuscated
│ └── summary.csv # v1 comparison metrics
├── sast_tools/
│ ├── findings.csv
│ ├── bandit_findings.csv