Skip to content

Commit 2356f9a

Browse files
committed
Move references_links to Vulnerability
1 parent 28afd03 commit 2356f9a

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",
@@ -354,38 +354,28 @@ def test_from_prefix(prefix: str, expected):
354354
[
355355
pytest.param(
356356
"CVE-2025-27516",
357-
(
358-
["CVE-2025-27516"],
359-
[],
360-
["https://nvd.nist.gov/vuln/detail/CVE-2025-27516"],
361-
),
357+
(["CVE-2025-27516"], []),
362358
id="CVE_identified_with_link",
363359
),
364360
pytest.param(
365361
"CWE-611",
366-
([], ["CWE-611"], ["https://cwe.mitre.org/data/definitions/611.html"]),
362+
([], ["CWE-611"]),
367363
id="CWE_identified_with_link",
368364
),
369365
pytest.param(
370366
"GHSA-cpwx-vrp4-4pq7",
371-
([], [], ["https://github.com/advisories/GHSA-cpwx-vrp4-4pq7"]),
367+
([], []),
372368
id="GHSA_link",
373369
),
374370
pytest.param(
375371
"PYSEC-2025-9",
376-
(
377-
[],
378-
[],
379-
[
380-
"https://github.com/pypa/advisory-database/blob/main/vulns/dummy/PYSEC-2025-9.yaml"
381-
],
382-
),
372+
([], []),
383373
id="PYSEC_link",
384374
),
385375
],
386376
)
387377
def test_identify_pypi_references(reference: str, expected):
388-
actual = security.identify_pypi_references([reference], package_name="dummy")
378+
actual = security.identify_pypi_references([reference])
389379
assert actual == expected
390380

391381

@@ -397,7 +387,7 @@ def test_no_vulnerability_returns_empty_list():
397387

398388
@staticmethod
399389
def test_convert_vulnerability_to_issue(sample_vulnerability):
400-
actual = set(
390+
actual = next(
401391
security.from_pip_audit(sample_vulnerability.nox_dependencies_audit)
402392
)
403-
assert actual == {sample_vulnerability.security_issue}
393+
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
@@ -46,6 +46,44 @@ def test_security_issue_entry(sample_vulnerability):
4646
== sample_vulnerability.security_issue_entry
4747
)
4848

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

5088
class TestAuditPoetryFiles:
5189
@staticmethod

0 commit comments

Comments
 (0)