Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workaround property for v1.5 and v1.6 #642

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions cyclonedx/model/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ def __init__(
description: Optional[str] = None,
detail: Optional[str] = None,
recommendation: Optional[str] = None,
workaround: Optional[str] = None,
advisories: Optional[Iterable[VulnerabilityAdvisory]] = None,
created: Optional[datetime] = None,
published: Optional[datetime] = None,
Expand All @@ -964,6 +965,7 @@ def __init__(
self.description = description
self.detail = detail
self.recommendation = recommendation
self.workaround = workaround
self.advisories = advisories or [] # type:ignore[assignment]
self.created = created
self.published = published
Expand Down Expand Up @@ -1120,15 +1122,23 @@ def recommendation(self) -> Optional[str]:
def recommendation(self, recommendation: Optional[str]) -> None:
self._recommendation = recommendation

# @property
# @serializable.view(SchemaVersion1Dot5)
# @serializable.xml_sequence(9)
# def workaround(self) -> ...:
# ... # TODO since CDX 1.5
#
# @workaround.setter
# def workaround(self, ...) -> None:
# ... # TODO since CDX 1.5
@property
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(9)
def workaround(self) -> Optional[str]:
"""
A bypass, usually temporary, of the vulnerability that reduces its likelihood and/or impact.
Workarounds often involve changes to configuration or deployments.

Returns:
`str` if set else `None`
"""
return self._workaround

@workaround.setter
def workaround(self, workaround: Optional[str]) -> None:
self._workaround = workaround

# @property
# @serializable.view(SchemaVersion1Dot5)
Expand Down Expand Up @@ -1310,8 +1320,8 @@ def __lt__(self, other: Any) -> bool:
def __hash__(self) -> int:
return hash((
self.id, self.source, tuple(self.references), tuple(self.ratings), tuple(self.cwes), self.description,
self.detail, self.recommendation, tuple(self.advisories), self.created, self.published, self.updated,
self.credits, tuple(self.tools), self.analysis, tuple(self.affects), tuple(self.properties)
self.detail, self.recommendation, self.workaround, tuple(self.advisories), self.created, self.published,
self.updated, self.credits, tuple(self.tools), self.analysis, tuple(self.affects), tuple(self.properties)
))

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/_data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def get_bom_with_component_setuptools_with_vulnerability() -> Bom:
)
],
cwes=[22, 33], description='A description here', detail='Some detail here',
recommendation='Upgrade',
recommendation='Upgrade', workaround='Describe the workarounds here',
advisories=[
VulnerabilityAdvisory(url=XsUri('https://nvd.nist.gov/vuln/detail/CVE-2018-7489')),
VulnerabilityAdvisory(url=XsUri('http://www.securitytracker.com/id/1040693'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@
"vendor": "CycloneDX"
}
],
"updated": "2021-09-03T10:50:42.051979+00:00"
"updated": "2021-09-03T10:50:42.051979+00:00",
"workaround": "Describe the workarounds here"
}
],
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<description>A description here</description>
<detail>Some detail here</detail>
<recommendation>Upgrade</recommendation>
<workaround>Describe the workarounds here</workaround>
<advisories>
<advisory>
<url>http://www.securitytracker.com/id/1040693</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"vendor": "CycloneDX"
}
],
"updated": "2021-09-03T10:50:42.051979+00:00"
"updated": "2021-09-03T10:50:42.051979+00:00",
"workaround": "Describe the workarounds here"
}
],
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<description>A description here</description>
<detail>Some detail here</detail>
<recommendation>Upgrade</recommendation>
<workaround>Describe the workarounds here</workaround>
<advisories>
<advisory>
<url>http://www.securitytracker.com/id/1040693</url>
Expand Down
1 change: 1 addition & 0 deletions tests/test_model_vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def test_empty_vulnerability(self) -> None:
self.assertIsNone(v.description)
self.assertIsNone(v.detail)
self.assertIsNone(v.recommendation)
self.assertIsNone(v.workaround)
self.assertFalse(v.advisories)
self.assertIsNone(v.created)
self.assertIsNone(v.published)
Expand Down