- OCaml 100%
osv #
Client for the OSV.dev vulnerability database.
A supply-chain check has to answer whether a given dependency version has a
known vulnerability, and the answers are scattered across NVD, GitHub
Advisories, RustSec, PyPI and dozens of other sources. OSV (Open Source
Vulnerabilities) aggregates them into one schema, OSV Schema v1.6. osv
queries it over HTTPS with Eio, by Package URL, by ecosystem and version, or
by commit hash, and returns typed records with a severity derived from each
record's CVSS v3 base score. The severity follows CVSS v3's qualitative
scale: 9.0 and above is Critical, 7.0 to 8.9 High, 4.0 to 6.9 Medium, above
0 Low, and a record with no score is Unknown.
Installation #
Install with opam:
$ opam install osv
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install osv
Quick Start #
let run () =
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
match
Osv.query_purl ~sw ~net:env#net ~clock:env#clock ~mono:env#mono_clock
"pkg:npm/lodash@4.17.20"
with
| Ok vulns ->
List.iter
(fun v ->
Fmt.pr "%s [%s]: %s@." v.Osv.id
(Osv.string_of_severity v.severity)
v.summary)
vulns
| Error msg -> Fmt.epr "Query failed: %s@." msg
Query Methods #
query_purlqueries by Package URL, such aspkg:npm/lodash@4.17.20.query_packagequeries by ecosystem, name and version.query_commitqueries by git commit hash.query_batchqueries several Package URLs in one API call.
Filtering #
let summarise (vulns : Osv.vulnerability list) =
(* Keep only high and critical vulnerabilities. *)
let critical = Osv.filter_severity ~min:High vulns in
(* Check if a fix is available. *)
let fixable = List.filter Osv.has_fix vulns in
(* Extract CVE identifiers. *)
let cves = List.concat_map Osv.cve_ids vulns in
(List.length critical, List.length fixable, cves)
License #
ISC. See LICENSE.md.