Skip to content

Commit bc74f2a

Browse files
committed
Import reachability from the scan when available
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent d913770 commit bc74f2a

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

product_portfolio/importers.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,21 +810,38 @@ def import_vulnerability(vulnerability_data, product_package):
810810
if not vulnerabilities:
811811
return
812812

813+
vulnerability = vulnerabilities[0]
814+
813815
if cdx_vulnerability := vulnerability_data.get("cdx_vulnerability_data"):
814816
if analysis_data := cdx_vulnerability.get("analysis"):
815-
# CycloneDX model uses "response" while the local model uses "response"
817+
# CycloneDX model uses "response" while the local model uses "responses"
816818
if response_value := analysis_data.pop("response", None):
817819
analysis_data["responses"] = response_value
818820

819821
VulnerabilityAnalysis.create_from_data(
820822
user=product_package.dataspace,
821823
data={
822824
"product_package": product_package,
823-
"vulnerability": vulnerabilities[0],
825+
"vulnerability": vulnerability,
824826
**analysis_data,
825827
},
826828
)
827829

830+
# Import reachability from the "symbol reachability analysis" scan when available.
831+
is_reachable_raw = vulnerability_data.get("is_reachable")
832+
is_reachable = None
833+
if is_reachable_raw == "yes":
834+
is_reachable = True
835+
elif is_reachable_raw == "no":
836+
is_reachable = False
837+
838+
if is_reachable is not None:
839+
VulnerabilityAnalysis.objects.filter(
840+
product_package=product_package,
841+
vulnerability=vulnerability,
842+
is_reachable__isnull=True,
843+
).update(is_reachable=is_reachable)
844+
828845
def import_package(self, package_data):
829846
# Vulnerabilities are assigned after the package creation.
830847
affected_by_vulnerabilities = package_data.pop("affected_by_vulnerabilities", [])

0 commit comments

Comments
 (0)