|
| 1 | +--- |
| 2 | +version: v1 |
| 3 | +type: rule-type |
| 4 | +name: osv_vulnerabilities |
| 5 | +display_name: Detect Vulnerable Dependencies in OSV |
| 6 | +context: {} |
| 7 | +severity: |
| 8 | + value: low # TODO: We should derive the severity from the rule type output itself. |
| 9 | +release_phase: alpha |
| 10 | +short_failure_message: Vulnerable dependencies found in this repository matching the OSV database. |
| 11 | +description: | |
| 12 | + This rule identifies dependencies in the repository with known vulnerabilities according to the OSV (Open Source Vulnerabilities) database. It helps ensure your project avoids using libraries or packages that could introduce security risks. |
| 13 | + |
| 14 | + By regularly scanning and updating dependencies, you can mitigate the risk of exploits and maintain secure development practices. |
| 15 | + |
| 16 | + Documentation: https://osv.dev/ |
| 17 | +guidance: | |
| 18 | + Check the dependencies in the repository for updates or patches. Resolve vulnerabilities by upgrading to a secure version. Refer to the following documentation for remediation steps: |
| 19 | + |
| 20 | + - OSV: https://osv.dev |
| 21 | +def: |
| 22 | + in_entity: repository |
| 23 | + param_schema: {} |
| 24 | + rule_schema: {} |
| 25 | + ingest: |
| 26 | + type: deps |
| 27 | + deps: {} |
| 28 | + eval: |
| 29 | + type: rego |
| 30 | + data_sources: |
| 31 | + - name: osv |
| 32 | + rego: |
| 33 | + type: constraints |
| 34 | + def: | |
| 35 | + package minder |
| 36 | + |
| 37 | + import rego.v1 |
| 38 | + |
| 39 | + default skip = false |
| 40 | + |
| 41 | + violations[{"msg": msg}] if { |
| 42 | + node := input.ingested.node_list.nodes[_] |
| 43 | + |
| 44 | + name := node.name |
| 45 | + version := node.version |
| 46 | + ecosystem := get_ecosystem(node.properties) |
| 47 | + |
| 48 | + reqparams := { |
| 49 | + "query": { |
| 50 | + "version": version, |
| 51 | + "package": { |
| 52 | + "name": name, |
| 53 | + "ecosystem": ecosystem |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + out := minder.datasource.osv.query(reqparams) |
| 59 | + vulns := out.body.vulns |
| 60 | + |
| 61 | + count(vulns) > 0 |
| 62 | + |
| 63 | + vulnid := vulns[_].id |
| 64 | + |
| 65 | + msg := sprintf("Package %v version %v has a vulnerability %v", [name, version, vulnid]) |
| 66 | + } |
| 67 | + |
| 68 | + get_ecosystem(properties) := eco if { |
| 69 | + count(properties) >= 1 |
| 70 | + prop := properties[_] |
| 71 | + |
| 72 | + prop.name == "sourceFile" |
| 73 | + eco := get_ecosystem_from_file(prop.data) |
| 74 | + } |
| 75 | + |
| 76 | + get_ecosystem_from_file(file) = "PyPI" if { |
| 77 | + file == "requirements.txt" |
| 78 | + } |
| 79 | + |
| 80 | + get_ecosystem_from_file(file) = "npm" if { |
| 81 | + file == "package.json" |
| 82 | + } |
| 83 | + |
| 84 | + get_ecosystem_from_file(file) = "RubyGems" if { |
| 85 | + file == "Gemfile" |
| 86 | + } |
| 87 | + |
| 88 | + get_ecosystem_from_file(file) = "Go" if { |
| 89 | + file == "go.mod" |
| 90 | + } |
| 91 | + |
| 92 | + get_ecosystem_from_file(file) = "crates.io" if { |
| 93 | + file == "Cargo.toml" |
| 94 | + } |
| 95 | +
|
0 commit comments