Skip to content

Commit ab3bac0

Browse files
committed
fix: source vulnerability version ranges from Socket field names
1 parent dd935ed commit ab3bac0

2 files changed

Lines changed: 50 additions & 13 deletions

File tree

socketsecurity/fossa_compat.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,19 @@ def _extract_string_list(*values: Any) -> list[str]:
132132

133133

134134
def _build_remediation(props: dict[str, Any]) -> dict[str, Any]:
135-
partial_fix = _first_non_empty(
135+
fix = _first_non_empty(
136+
props.get("firstPatchedVersionIdentifier"),
136137
props.get("partialFix"),
137-
props.get("fixedVersion"),
138-
props.get("fixed_version"),
139-
props.get("patchedVersion"),
140-
props.get("patched_version"),
141-
props.get("range"),
142-
)
143-
complete_fix = _first_non_empty(
144138
props.get("completeFix"),
145139
props.get("fixedVersion"),
146140
props.get("fixed_version"),
147141
props.get("patchedVersion"),
148142
props.get("patched_version"),
149-
props.get("range"),
150143
)
151144
return {
152-
"partialFix": partial_fix,
145+
"partialFix": fix,
153146
"partialFixDistance": props.get("partialFixDistance"),
154-
"completeFix": complete_fix,
147+
"completeFix": fix,
155148
"completeFixDistance": props.get("completeFixDistance"),
156149
}
157150

@@ -230,8 +223,16 @@ def _build_vulnerability_entry(
230223
"cveStatus": props.get("cveStatus"),
231224
"cwes": _extract_string_list(props.get("cwes"), props.get("cwe")),
232225
"published": props.get("published"),
233-
"affectedVersionRanges": _extract_string_list(props.get("affectedVersionRanges"), props.get("affected_versions")),
234-
"patchedVersionRanges": _extract_string_list(props.get("patchedVersionRanges"), props.get("patched_versions")),
226+
"affectedVersionRanges": _extract_string_list(
227+
props.get("affectedVersionRanges"),
228+
props.get("vulnerableVersionRange"),
229+
props.get("affected_versions"),
230+
),
231+
"patchedVersionRanges": _extract_string_list(
232+
props.get("patchedVersionRanges"),
233+
props.get("firstPatchedVersionIdentifier"),
234+
props.get("patched_versions"),
235+
),
235236
"references": _extract_references(issue, props),
236237
"cvssVector": props.get("cvssVector"),
237238
"exploitability": props.get("exploitability"),

tests/unit/test_fossa_compat.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,39 @@ def test_analyze_payload_empty_diff_yields_empty_arrays():
235235
assert payload["vulnerability"] == []
236236
assert payload["licensing"] == []
237237
assert payload["quality"] == []
238+
239+
240+
def test_vulnerability_version_ranges_sourced_from_socket_fields():
241+
"""affectedVersionRanges/patchedVersionRanges come from Socket's singular fields, wrapped."""
242+
from socketsecurity.fossa_compat import _build_vulnerability_entry
243+
issue = Issue(
244+
type="criticalCVE",
245+
severity="high",
246+
key="CVE-2024-12345_pip+requests",
247+
pkg_type="pypi",
248+
pkg_name="requests",
249+
pkg_version="2.30.0",
250+
props={
251+
"ghsaId": "GHSA-aaaa-bbbb-cccc",
252+
"cveId": "CVE-2024-12345",
253+
"cvss": 7.5,
254+
"vulnerableVersionRange": ">=2.0.0,<2.31.1",
255+
"firstPatchedVersionIdentifier": "2.31.1",
256+
"cwes": ["CWE-200"],
257+
},
258+
)
259+
package = Package(
260+
type="pypi",
261+
name="requests",
262+
version="2.30.0",
263+
id="pip+requests$2.30.0",
264+
score={},
265+
alerts=[],
266+
direct=True,
267+
)
268+
project = {"branch": "main", "id": "acme$x", "project": "acme", "projectId": "acme", "revision": "x", "url": "u"}
269+
entry = _build_vulnerability_entry(issue, package, project, index=1)
270+
assert entry["affectedVersionRanges"] == [">=2.0.0,<2.31.1"]
271+
assert entry["patchedVersionRanges"] == ["2.31.1"]
272+
assert entry["remediation"]["partialFix"] == "2.31.1"
273+
assert entry["remediation"]["completeFix"] == "2.31.1"

0 commit comments

Comments
 (0)