Skip to content

Commit 8b4034d

Browse files
committed
refactor: moved Vulnerabilities to be nested inside the Component
Signed-off-by: Paul Horton <[email protected]>
1 parent f477bf0 commit 8b4034d

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

cyclonedx/output/xml.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ def output_as_string(self) -> str:
4545
ElementTree.register_namespace('v', Xml.get_vulnerabilities_namespace())
4646

4747
components = ElementTree.SubElement(bom, 'components')
48-
if self.get_bom().has_vulnerabilities():
49-
vulnerabilities = ElementTree.SubElement(bom, 'v:vulnerabilities')
48+
# if self.get_bom().has_vulnerabilities():
49+
# vulnerabilities = ElementTree.SubElement(bom, 'v:vulnerabilities')
5050

5151
for component in self.get_bom().get_components():
52-
components.append(self._get_component_as_xml_element(component=component))
52+
component_element = self._get_component_as_xml_element(component=component)
53+
components.append(component_element)
5354
if component.has_vulnerabilities() and self.component_supports_bom_ref():
5455
# Vulnerabilities are only possible when bom-ref is supported by the main CycloneDX schema version
56+
vulnerabilities = ElementTree.SubElement(component_element, 'v:vulnerabilities')
5557
for vulnerability in component.get_vulnerabilities():
5658
vulnerabilities.append(self._get_vulnerability_as_xml_element(bom_ref=component.get_purl(),
5759
vulnerability=vulnerability))

tests/fixtures/bom_v1.3_setuptools_with_vulnerabilities.xml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,43 @@
88
<name>setuptools</name>
99
<version>50.3.2</version>
1010
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
11+
<v:vulnerabilities>
12+
<v:vulnerability ref="pkg:pypi/[email protected]?extension=tar.gz">
13+
<v:id>CVE-2018-7489</v:id>
14+
<v:source name="NVD">
15+
<v:url>https://nvd.nist.gov/vuln/detail/CVE-2018-7489</v:url>
16+
</v:source>
17+
<v:ratings>
18+
<v:rating>
19+
<v:score>
20+
<v:base>9.8</v:base>
21+
<v:impact>5.9</v:impact>
22+
<v:exploitability>3.0</v:exploitability>
23+
</v:score>
24+
<v:severity>Critical</v:severity>
25+
<v:method>CVSSv3</v:method>
26+
<v:vector>AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H</v:vector>
27+
</v:rating>
28+
<v:rating>
29+
<v:severity>Low</v:severity>
30+
<v:method>OWASP Risk</v:method>
31+
<v:vector>OWASP/K9:M1:O0:Z2/D1:X1:W1:L3/C2:I1:A1:T1/F1:R1:S2:P3/50</v:vector>
32+
</v:rating>
33+
</v:ratings>
34+
<v:cwes>
35+
<v:cwe>123</v:cwe>
36+
<v:cwe>456</v:cwe>
37+
</v:cwes>
38+
<v:description>A description here</v:description>
39+
<v:recommendations>
40+
<v:recommendation>Upgrade</v:recommendation>
41+
</v:recommendations>
42+
<v:advisories>
43+
<v:advisory>http://www.securityfocus.com/bid/103203</v:advisory>
44+
<v:advisory>http://www.securitytracker.com/id/1040693</v:advisory>
45+
</v:advisories>
46+
</v:vulnerability>
47+
</v:vulnerabilities>
1148
</component>
1249
</components>
13-
<v:vulnerabilities>
14-
<v:vulnerability ref="pkg:pypi/[email protected]?extension=tar.gz">
15-
<v:id>CVE-2018-7489</v:id>
16-
<v:source name="NVD">
17-
<v:url>https://nvd.nist.gov/vuln/detail/CVE-2018-7489</v:url>
18-
</v:source>
19-
<v:ratings>
20-
<v:rating>
21-
<v:score>
22-
<v:base>9.8</v:base>
23-
<v:impact>5.9</v:impact>
24-
<v:exploitability>3.0</v:exploitability>
25-
</v:score>
26-
<v:severity>Critical</v:severity>
27-
<v:method>CVSSv3</v:method>
28-
<v:vector>AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H</v:vector>
29-
</v:rating>
30-
<v:rating>
31-
<v:severity>Low</v:severity>
32-
<v:method>OWASP Risk</v:method>
33-
<v:vector>OWASP/K9:M1:O0:Z2/D1:X1:W1:L3/C2:I1:A1:T1/F1:R1:S2:P3/50</v:vector>
34-
</v:rating>
35-
</v:ratings>
36-
<v:cwes>
37-
<v:cwe>123</v:cwe>
38-
<v:cwe>456</v:cwe>
39-
</v:cwes>
40-
<v:description>A description here</v:description>
41-
<v:recommendations>
42-
<v:recommendation>Upgrade</v:recommendation>
43-
</v:recommendations>
44-
<v:advisories>
45-
<v:advisory>http://www.securityfocus.com/bid/103203</v:advisory>
46-
<v:advisory>http://www.securitytracker.com/id/1040693</v:advisory>
47-
</v:advisories>
48-
</v:vulnerability>
49-
</v:vulnerabilities>
5050
</bom>

0 commit comments

Comments
 (0)