Skip to content
Open
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
14 changes: 10 additions & 4 deletions cyclonedx/model/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
from .tool import Tool, ToolRepository, _ToolRepositoryHelper


_VSS_VECTOR_RE_CVSS_V4 = re.compile(r'^CVSS:4\.\d/?')
_VSS_VECTOR_RE_CVSS_V3 = re.compile(r'^CVSS:3\.\d/?')
_VSS_VECTOR_RE_CVSS_V2 = re.compile(r'^CVSS:2\.\d/?')
_VSS_VECTOR_RE_OWASP = re.compile(r'^OWASP/?')


@serializable.serializable_class(ignore_unknown_during_deserialization=True)
class BomTargetVersionRange:
"""
Expand Down Expand Up @@ -643,15 +649,15 @@ def get_localised_vector(self, vector: str) -> str:
The vector without any scheme prefix as a `str`.
"""
if self is VulnerabilityScoreSource.CVSS_V4 and vector.startswith('CVSS:4.'):
return re.sub(r'^CVSS:4\.\d/?', '', vector)
return _VSS_VECTOR_RE_CVSS_V4.sub('', vector)
if (
self in (VulnerabilityScoreSource.CVSS_V3_1, VulnerabilityScoreSource.CVSS_V3)
) and vector.startswith('CVSS:3.'):
return re.sub(r'^CVSS:3\.\d/?', '', vector)
return _VSS_VECTOR.sub('', vector)
if self is VulnerabilityScoreSource.CVSS_V2 and vector.startswith('CVSS:2.'):
return re.sub(r'^CVSS:2\.\d/?', '', vector)
return _VSS_VECTOR_RE_CVSS_V2.sub('', vector)
if self is VulnerabilityScoreSource.OWASP and vector.startswith('OWASP'):
return re.sub(r'^OWASP/?', '', vector)
return _VSS_VECTOR_RE_OWASP.sub('', vector)
return vector

def get_value_pre_1_4(self) -> str:
Expand Down
Loading