#!/usr/bin/env python3 """A severity gate for osv-scanner, which has no built-in threshold flag. gate.py osv.json exits 1 when any finding has a CVSS score >= the minimum """ import os, subprocess, sys HERE = os.path.dirname(os.path.abspath(__file__)) out = subprocess.run([sys.executable, os.path.join(HERE, "normalise.py"), "osv", sys.argv[1]], capture_output=True, text=True, check=True).stdout limit = float(sys.argv[2]) bad = [] for line in out.splitlines(): _, comp, vid, score = line.split("\t") if score and float(score) >= limit: bad.append((score, vid, comp)) for score, vid, comp in sorted(bad, reverse=True)[:5]: print(f" {score:>5} {vid} {comp}") print(f"{len(bad)} finding(s) with CVSS >= {limit}") sys.exit(1 if bad else 0)