Add vuln-scan: Dependency-Check 13.0.0 vs Trivy 0.76.2 vs OSV-Scanner 2.7.1
Same Maven project scanned three ways (pom.xml, SBOM, jars): captured output, false-positive evidence, suppression files with expiry, CI gate, -Pfixed profile. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b7h4ZNF4BDUpJk3Zou
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
f32c088174
commit
7c677a39d2
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reads the JSON report of osv-scanner, Trivy or Dependency-Check and prints one normalised
|
||||
record per finding: <tool> <group:artifact:version> <id> <severity-or-score>
|
||||
|
||||
Normalisation rules (kept deliberately simple so the comparison is easy to audit):
|
||||
* the id is the CVE alias when the report has one, otherwise the advisory id (GHSA-...)
|
||||
* the component is group:artifact:version in Maven coordinates
|
||||
Usage: normalise.py osv|trivy|dc report.json
|
||||
"""
|
||||
import json, re, sys
|
||||
|
||||
def osv(d):
|
||||
for res in d["results"]:
|
||||
for p in res["packages"]:
|
||||
pkg = p["package"]; comp = f'{pkg["name"]}:{pkg["version"]}'
|
||||
scores = {}
|
||||
for g in p.get("groups", []):
|
||||
for i in g["ids"]:
|
||||
scores[i] = g.get("max_severity", "")
|
||||
for v in p["vulnerabilities"]:
|
||||
cves = [a for a in v.get("aliases", []) if a.startswith("CVE-")]
|
||||
yield comp, (cves[0] if cves else v["id"]), scores.get(v["id"], "")
|
||||
|
||||
def trivy(d):
|
||||
for res in d.get("Results", []):
|
||||
for v in res.get("Vulnerabilities", []) or []:
|
||||
yield f'{v["PkgName"]}:{v["InstalledVersion"]}', v["VulnerabilityID"], v.get("Severity", "")
|
||||
|
||||
def dc(d):
|
||||
for dep in d.get("dependencies", []):
|
||||
pk = next((p["id"] for p in dep.get("packages", []) if p["id"].startswith("pkg:maven/")), None)
|
||||
if pk:
|
||||
m = re.match(r"pkg:maven/([^/]+)/([^@]+)@(.+)", pk)
|
||||
comp = f"{m.group(1)}:{m.group(2)}:{m.group(3)}"
|
||||
else:
|
||||
comp = dep["fileName"]
|
||||
for v in dep.get("vulnerabilities", []) or []:
|
||||
sev = v.get("severity", "")
|
||||
cv = v.get("cvssv3", {}).get("baseScore") or v.get("cvssv2", {}).get("score") or ""
|
||||
yield comp, v["name"], f"{sev}:{cv}" if cv != "" else sev
|
||||
|
||||
if __name__ == "__main__":
|
||||
tool, path = sys.argv[1], sys.argv[2]
|
||||
data = json.load(open(path))
|
||||
for comp, vid, sev in {"osv": osv, "trivy": trivy, "dc": dc}[tool](data):
|
||||
print(tool, comp, vid, sev, sep="\t")
|
||||
Reference in New Issue
Block a user