Skip to content

Commit cd26c37

Browse files
committed
Move references_links to Vulnerability
1 parent 25f208f commit cd26c37

File tree

5 files changed

+85
-41
lines changed

5 files changed

+85
-41
lines changed

exasol/toolbox/tools/security.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,14 @@ def from_maven(report: str) -> Iterable[Issue]:
105105
)
106106

107107

108-
def identify_pypi_references(
109-
references: list[str], package_name: str
110-
) -> tuple[list[str], list[str], list[str]]:
108+
def identify_pypi_references(references: list[str]) -> tuple[list[str], list[str]]:
111109
refs: dict = {k: [] for k in VulnerabilitySource}
112-
links = []
113110
for reference in references:
114111
if source := VulnerabilitySource.from_prefix(reference.upper()):
115112
refs[source].append(reference)
116-
links.append(source.get_link(package=package_name, vuln_id=reference))
117113
return (
118114
refs[VulnerabilitySource.CVE],
119115
refs[VulnerabilitySource.CWE],
120-
links,
121116
)
122117

123118

@@ -142,6 +137,11 @@ def from_pip_audit(report: str) -> Iterable[Issue]:
142137
"CVE-2025-27516"
143138
],
144139
"description": "An oversight ..."
140+
"coordinates": "jinja2:3.1.5",
141+
"references": [
142+
"https://github.com/advisories/GHSA-cpwx-vrp4-4pq7",
143+
"https://nvd.nist.gov/vuln/detail/CVE-2025-27516"
144+
]
145145
}
146146
]
147147
@@ -153,16 +153,16 @@ def from_pip_audit(report: str) -> Iterable[Issue]:
153153
vulnerabilities = json.loads(report)
154154

155155
for vulnerability in vulnerabilities:
156-
cves, cwes, links = identify_pypi_references(
157-
references=vulnerability["refs"], package_name=vulnerability["name"]
156+
cves, cwes = identify_pypi_references(
157+
references=vulnerability["refs"],
158158
)
159159
if cves:
160160
yield Issue(
161161
cve=sorted(cves)[0],
162162
cwe="None" if not cwes else ", ".join(cwes),
163163
description=vulnerability["description"],
164164
coordinates=vulnerability["coordinates"],
165-
references=tuple(links),
165+
references=tuple(vulnerability["references"]),
166166
)
167167

168168

exasol/toolbox/util/dependencies/audit.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,27 @@ def from_audit_entry(
8383
description=vuln_entry["description"],
8484
)
8585

86+
@property
87+
def references(self) -> list[str]:
88+
return [self.id] + self.aliases
89+
90+
@property
91+
def reference_links(self) -> tuple[str, ...]:
92+
return tuple(
93+
source.get_link(package=self.name, vuln_id=reference)
94+
for reference in self.references
95+
if (source := VulnerabilitySource.from_prefix(reference.upper()))
96+
)
97+
8698
@property
8799
def security_issue_entry(self) -> dict[str, str | list[str]]:
88100
return {
89101
"name": self.name,
90102
"version": str(self.version),
91-
"refs": [self.id] + self.aliases,
103+
"refs": self.references,
92104
"description": self.description,
93105
"coordinates": self.coordinates,
106+
"references": self.reference_links,
94107
}
95108

96109

test/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
from inspect import cleandoc
3-
from typing import Union
43

54
import pytest
65

@@ -60,13 +59,17 @@ def nox_dependencies_audit(self) -> str:
6059
return json.dumps([self.security_issue_entry], indent=2) + "\n"
6160

6261
@property
63-
def security_issue_entry(self) -> dict[str, str | list[str]]:
62+
def security_issue_entry(self) -> dict[str, str | list[str] | tuple[str, ...]]:
6463
return {
6564
"name": self.package_name,
6665
"version": self.version,
6766
"refs": [self.vulnerability_id, self.cve_id],
6867
"description": self.description,
6968
"coordinates": f"{self.package_name}:{self.version}",
69+
"references": (
70+
f"https://github.com/advisories/{self.vulnerability_id}",
71+
f"https://nvd.nist.gov/vuln/detail/{self.cve_id}",
72+
),
7073
}
7174

7275
@property

test/unit/security_test.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ def test_security_issue_title_template(self, expected, issue):
4747
(
4848
cleandoc(
4949
"""
50-
## Summary
51-
Random Multiline
52-
Description
53-
;)
54-
55-
CVE: CVE-2023-39410
56-
CWE: CWE-XYZ
57-
58-
## References
59-
- https://www.example.com
60-
- https://www.foobar.com
61-
"""
50+
## Summary
51+
Random Multiline
52+
Description
53+
;)
54+
55+
CVE: CVE-2023-39410
56+
CWE: CWE-XYZ
57+
58+
## References
59+
- https://www.example.com
60+
- https://www.foobar.com
61+
"""
6262
),
6363
security.Issue(
6464
cve="CVE-2023-39410",
@@ -336,38 +336,28 @@ def test_from_json(json_input, expected):
336336
[
337337
pytest.param(
338338
"CVE-2025-27516",
339-
(
340-
["CVE-2025-27516"],
341-
[],
342-
["https://nvd.nist.gov/vuln/detail/CVE-2025-27516"],
343-
),
339+
(["CVE-2025-27516"], []),
344340
id="CVE_identified_with_link",
345341
),
346342
pytest.param(
347343
"CWE-611",
348-
([], ["CWE-611"], ["https://cwe.mitre.org/data/definitions/611.html"]),
344+
([], ["CWE-611"]),
349345
id="CWE_identified_with_link",
350346
),
351347
pytest.param(
352348
"GHSA-cpwx-vrp4-4pq7",
353-
([], [], ["https://github.com/advisories/GHSA-cpwx-vrp4-4pq7"]),
349+
([], []),
354350
id="GHSA_link",
355351
),
356352
pytest.param(
357353
"PYSEC-2025-9",
358-
(
359-
[],
360-
[],
361-
[
362-
"https://github.com/pypa/advisory-database/blob/main/vulns/dummy/PYSEC-2025-9.yaml"
363-
],
364-
),
354+
([], []),
365355
id="PYSEC_link",
366356
),
367357
],
368358
)
369359
def test_identify_pypi_references(reference: str, expected):
370-
actual = security.identify_pypi_references([reference], package_name="dummy")
360+
actual = security.identify_pypi_references([reference])
371361
assert actual == expected
372362

373363

@@ -379,7 +369,7 @@ def test_no_vulnerability_returns_empty_list():
379369

380370
@staticmethod
381371
def test_convert_vulnerability_to_issue(sample_vulnerability):
382-
actual = set(
372+
actual = next(
383373
security.from_pip_audit(sample_vulnerability.nox_dependencies_audit)
384374
)
385-
assert actual == {sample_vulnerability.security_issue}
375+
assert actual == sample_vulnerability.security_issue

test/unit/util/dependencies/audit_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,44 @@ def test_security_issue_entry(sample_vulnerability):
4747
== sample_vulnerability.security_issue_entry
4848
)
4949

50+
@staticmethod
51+
@pytest.mark.parametrize(
52+
"reference, expected",
53+
[
54+
pytest.param(
55+
"CVE-2025-27516",
56+
"https://nvd.nist.gov/vuln/detail/CVE-2025-27516",
57+
id="CVE",
58+
),
59+
pytest.param(
60+
"CWE-611",
61+
"https://cwe.mitre.org/data/definitions/611.html",
62+
id="CWE",
63+
),
64+
pytest.param(
65+
"GHSA-cpwx-vrp4-4pq7",
66+
"https://github.com/advisories/GHSA-cpwx-vrp4-4pq7",
67+
id="GHSA",
68+
),
69+
pytest.param(
70+
"PYSEC-2025-9",
71+
"https://github.com/pypa/advisory-database/blob/main/vulns/jinja2/PYSEC-2025-9.yaml",
72+
id="PYSEC",
73+
),
74+
],
75+
)
76+
def test_reference_links(sample_vulnerability, reference: str, expected: list[str]):
77+
result = Vulnerability(
78+
name=sample_vulnerability.package_name,
79+
version=sample_vulnerability.version,
80+
id=reference,
81+
aliases=[],
82+
fix_versions=[sample_vulnerability.fix_version],
83+
description=sample_vulnerability.description,
84+
)
85+
86+
assert result.reference_links == (expected,)
87+
5088

5189
class TestAuditPoetryFiles:
5290
@staticmethod

0 commit comments

Comments
 (0)