Skip to content

Commit 32e7929

Browse files
authored
feat: support for CycloneDX schema 1.4.2 - adds vulnerability.properties to the schema
2 parents d720a5f + db7445c commit 32e7929

File tree

9 files changed

+1678
-1433
lines changed

9 files changed

+1678
-1433
lines changed

cyclonedx/model/vulnerability.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from sortedcontainers import SortedSet
2828

2929
from ..exception.model import MutuallyExclusivePropertiesException, NoPropertiesProvidedException
30-
from . import ComparableTuple, OrganizationalContact, OrganizationalEntity, Tool, XsUri
30+
from . import ComparableTuple, OrganizationalContact, OrganizationalEntity, Property, Tool, XsUri
3131
from .bom_ref import BomRef
3232
from .impact_analysis import (
3333
ImpactAnalysisAffectedStatus,
@@ -788,6 +788,7 @@ def __init__(self, *, bom_ref: Optional[str] = None, id: Optional[str] = None,
788788
credits: Optional[VulnerabilityCredits] = None,
789789
tools: Optional[Iterable[Tool]] = None, analysis: Optional[VulnerabilityAnalysis] = None,
790790
affects_targets: Optional[Iterable[BomTarget]] = None,
791+
properties: Optional[Iterable[Property]] = None,
791792
# Deprecated Parameters kept for backwards compatibility
792793
source_name: Optional[str] = None, source_url: Optional[str] = None,
793794
recommendations: Optional[Iterable[str]] = None) -> None:
@@ -808,6 +809,7 @@ def __init__(self, *, bom_ref: Optional[str] = None, id: Optional[str] = None,
808809
self.tools = tools or [] # type: ignore
809810
self.analysis = analysis
810811
self.affects = affects_targets or [] # type: ignore
812+
self.properties = properties or [] # type: ignore
811813

812814
if source_name or source_url:
813815
warnings.warn('`source_name` and `source_url` are deprecated - use `source`', DeprecationWarning)
@@ -1062,6 +1064,21 @@ def affects(self) -> "SortedSet[BomTarget]":
10621064
def affects(self, affects_targets: Iterable[BomTarget]) -> None:
10631065
self._affects = SortedSet(affects_targets)
10641066

1067+
@property
1068+
def properties(self) -> "SortedSet[Property]":
1069+
"""
1070+
Provides the ability to document properties in a key/value store. This provides flexibility to include data not
1071+
officially supported in the standard without having to use additional namespaces or create extensions.
1072+
1073+
Return:
1074+
Set of `Property`
1075+
"""
1076+
return self._properties
1077+
1078+
@properties.setter
1079+
def properties(self, properties: Iterable[Property]) -> None:
1080+
self._properties = SortedSet(properties)
1081+
10651082
def __eq__(self, other: object) -> bool:
10661083
if isinstance(other, Vulnerability):
10671084
return hash(other) == hash(self)
@@ -1079,7 +1096,7 @@ def __hash__(self) -> int:
10791096
return hash((
10801097
self.id, self.source, tuple(self.references), tuple(self.ratings), tuple(self.cwes), self.description,
10811098
self.detail, self.recommendation, tuple(self.advisories), self.created, self.published, self.updated,
1082-
self.credits, tuple(self.tools), self.analysis, tuple(self.affects)
1099+
self.credits, tuple(self.tools), self.analysis, tuple(self.affects), tuple(self.properties)
10831100
))
10841101

10851102
def __repr__(self) -> str:

cyclonedx/output/xml.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ def _get_vulnerability_as_xml_element_post_1_4(self, vulnerability: Vulnerabilit
688688
for version in target.versions:
689689
Xml._add_bom_target_version_range(parent_element=v_target_versions_element, version=version)
690690

691+
# properties
692+
if vulnerability.properties:
693+
Xml._add_properties_element(properties=vulnerability.properties, parent_element=vulnerability_element)
694+
691695
return vulnerability_element
692696

693697
@staticmethod

cyclonedx/schema/bom-1.4.xsd

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ limitations under the License.
2222
targetNamespace="http://cyclonedx.org/schema/bom/1.4"
2323
vc:minVersion="1.0"
2424
vc:maxVersion="1.1"
25-
version="1.4.1">
25+
version="1.4.2">
2626

2727
<xs:import namespace="http://cyclonedx.org/schema/spdx" schemaLocation="spdx.xsd"/>
2828

@@ -2014,6 +2014,16 @@ limitations under the License.
20142014
</xs:sequence>
20152015
</xs:complexType>
20162016
</xs:element>
2017+
<xs:element name="properties" type="bom:propertiesType" minOccurs="0" maxOccurs="1">
2018+
<xs:annotation>
2019+
<xs:documentation>Provides the ability to document properties in a key/value store.
2020+
This provides flexibility to include data not officially supported in the standard
2021+
without having to use additional namespaces or create extensions. Property names
2022+
of interest to the general public are encouraged to be registered in the
2023+
CycloneDX Property Taxonomy - https://github.com/CycloneDX/cyclonedx-property-taxonomy.
2024+
Formal registration is OPTIONAL.</xs:documentation>
2025+
</xs:annotation>
2026+
</xs:element>
20172027
</xs:sequence>
20182028
<xs:attribute name="bom-ref" type="bom:refType">
20192029
<xs:annotation>

0 commit comments

Comments
 (0)