Files
mtusi2026lab7/scripts/scan_summary.py
T
sendormeco d15f2a3631
Application stack (lab7) / stack (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
7 — Т2302 — ебедев — на 5
2026-11-22 23:26:17 +03:00

42 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Сводка Trivy-сканов evidence/scan/*.json: HIGH/CRITICAL по образам и сверка с security/scan-triage.json.
Находка без решения (по CVE или GHSA) печатается как UNTRIAGED и даёт exit 1.
python3 scripts/scan_summary.py evidence/scan
"""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
triage = json.loads((ROOT / "security" / "scan-triage.json").read_text())
decisions = dict(triage["decisions"])
for k, v in triage.get("trivy", {}).items():
decisions[k] = v
d = Path(sys.argv[1] if len(sys.argv) > 1 else ROOT / "evidence" / "scan")
untriaged = 0
for f in sorted(d.glob("image-*.json")) + [d / "repo.json"]:
if not f.exists():
continue
try:
data = json.loads(f.read_text() or "{}")
except ValueError:
print("%s: not JSON" % f.name)
continue
rows = []
for res in data.get("Results") or []:
for v in res.get("Vulnerabilities") or []:
if v.get("Severity") not in ("HIGH", "CRITICAL"):
continue
t = decisions.get(v["VulnerabilityID"]) or decisions.get(v.get("PkgName", "") + ":" + v["VulnerabilityID"])
untriaged += t is None
rows.append(" %-8s %-18s %-28s %-14s fixed=%-12s %s" % (
v["Severity"], v["VulnerabilityID"], v.get("PkgName", "")[:28], v.get("InstalledVersion", "")[:14],
(v.get("FixedVersion") or "-")[:12], (t or {"decision": "UNTRIAGED"})["decision"]))
for s in res.get("Secrets") or []:
untriaged += 1
rows.append(" SECRET %s %s:%s" % (s.get("RuleID"), res.get("Target"), s.get("StartLine")))
print("%s: %d HIGH/CRITICAL" % (f.name, len(rows)))
print("\n".join(rows))
sys.exit(1 if untriaged else 0)