|
22 | 22 | from vulnerabilities.triage.rules import ExploitedVulnerabilityTriageRule |
23 | 23 | from vulnerabilities.triage.rules import ReachableVulnerabilityTriageRule |
24 | 24 | from vulnerabilities.triage.rules import RiskScoreTriageRule |
| 25 | +from vulnerabilities.triage.rules import SSVCDecisionTriageRule |
25 | 26 | from vulnerabilities.triage.rules import StaleVulnerabilityTriageRule |
26 | 27 | from vulnerabilities.triage.rules import UnresolvedVulnerabilityTriageRule |
27 | 28 | from vulnerabilities.triage.rules import WeightedRiskTriageRule |
@@ -119,6 +120,81 @@ def test_excludes_vulnerability_with_no_exploitability_set(self): |
119 | 120 | self.assertEqual([], list(matches)) |
120 | 121 |
|
121 | 122 |
|
| 123 | +class SSVCDecisionTriageRuleTestCase(TestCase): |
| 124 | + def setUp(self): |
| 125 | + self.dataspace = Dataspace.objects.create(name="nexB") |
| 126 | + self.product = make_product(self.dataspace) |
| 127 | + |
| 128 | + @staticmethod |
| 129 | + def _ssvc_tree(decision): |
| 130 | + return { |
| 131 | + "vector": "SSVCv2/E:N/A:N/T:P/P:M/B:A/M:M/D:T/2024-07-07T19:07:43Z/", |
| 132 | + "decision": decision, |
| 133 | + "options": [{"Exploitation": "none"}], |
| 134 | + "source_url": "https://github.com/cisagov/vulnrichment", |
| 135 | + } |
| 136 | + |
| 137 | + def test_matches_vulnerability_with_attend_decision(self): |
| 138 | + package = make_package(self.dataspace) |
| 139 | + vulnerability = make_vulnerability( |
| 140 | + self.dataspace, affecting=package, ssvc_trees=[self._ssvc_tree("Attend")] |
| 141 | + ) |
| 142 | + make_product_package(self.product, package=package) |
| 143 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 144 | + self.assertEqual([vulnerability], list(matches)) |
| 145 | + |
| 146 | + def test_matches_vulnerability_with_act_decision(self): |
| 147 | + package = make_package(self.dataspace) |
| 148 | + vulnerability = make_vulnerability( |
| 149 | + self.dataspace, affecting=package, ssvc_trees=[self._ssvc_tree("Act")] |
| 150 | + ) |
| 151 | + make_product_package(self.product, package=package) |
| 152 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 153 | + self.assertEqual([vulnerability], list(matches)) |
| 154 | + |
| 155 | + def test_excludes_vulnerability_with_track_decision(self): |
| 156 | + package = make_package(self.dataspace) |
| 157 | + make_vulnerability(self.dataspace, affecting=package, ssvc_trees=[self._ssvc_tree("Track")]) |
| 158 | + make_product_package(self.product, package=package) |
| 159 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 160 | + self.assertEqual([], list(matches)) |
| 161 | + |
| 162 | + def test_excludes_vulnerability_with_track_star_decision(self): |
| 163 | + package = make_package(self.dataspace) |
| 164 | + make_vulnerability( |
| 165 | + self.dataspace, affecting=package, ssvc_trees=[self._ssvc_tree("Track*")] |
| 166 | + ) |
| 167 | + make_product_package(self.product, package=package) |
| 168 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 169 | + self.assertEqual([], list(matches)) |
| 170 | + |
| 171 | + def test_excludes_vulnerability_with_no_ssvc_trees(self): |
| 172 | + package = make_package(self.dataspace) |
| 173 | + make_vulnerability(self.dataspace, affecting=package) |
| 174 | + make_product_package(self.product, package=package) |
| 175 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 176 | + self.assertEqual([], list(matches)) |
| 177 | + |
| 178 | + def test_matches_when_at_least_one_tree_meets_the_threshold(self): |
| 179 | + # A vulnerability can carry several SSVC trees (e.g. from different sources or |
| 180 | + # re-evaluations). A single matching tree is enough to flag it. |
| 181 | + package = make_package(self.dataspace) |
| 182 | + vulnerability = make_vulnerability( |
| 183 | + self.dataspace, |
| 184 | + affecting=package, |
| 185 | + ssvc_trees=[self._ssvc_tree("Track"), self._ssvc_tree("Act")], |
| 186 | + ) |
| 187 | + make_product_package(self.product, package=package) |
| 188 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 189 | + self.assertEqual([vulnerability], list(matches)) |
| 190 | + |
| 191 | + def test_ignores_vulnerabilities_affecting_packages_outside_the_product(self): |
| 192 | + package = make_package(self.dataspace) |
| 193 | + make_vulnerability(self.dataspace, affecting=package, ssvc_trees=[self._ssvc_tree("Act")]) |
| 194 | + matches = SSVCDecisionTriageRule().get_matching_vulnerabilities(self.product) |
| 195 | + self.assertEqual([], list(matches)) |
| 196 | + |
| 197 | + |
122 | 198 | class ReachableVulnerabilityTriageRuleTestCase(TestCase): |
123 | 199 | def setUp(self): |
124 | 200 | self.dataspace = Dataspace.objects.create(name="nexB") |
|
0 commit comments