Skip to content

Commit 151044c

Browse files
committed
sbom: work around grype matching unrelated packages with CPEs only
Starting with 0.91.1 grype will match a CVE if the component name matches the ecosystem package, even if the CPE is unrelated. Work around by setting "syft:package:type" for those components, which for some reason makes it stop doing that.
1 parent 75e56b9 commit 151044c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

msys2_devtools/sbom.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def generate_components(value) -> list[Component]:
6565
for cpe in cpes:
6666
name, version = parse_cpe(cpe)[2:4]
6767
assert isinstance(version, str) and isinstance(name, str)
68-
component = Component(name=name, version=version, cpe=cpe, properties=properties)
68+
# https://github.com/anchore/grype/issues/2618
69+
cpe_properties = properties + [Property(name="syft:package:type", value="binary")]
70+
component = Component(name=name, version=version, cpe=cpe, properties=cpe_properties)
6971
components.append(component)
7072

7173
for purl in purls:

tests/test_sbom.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ def test_generate_components():
5858
assert components[0].version == "1.2.3"
5959
assert components[0].purl is None
6060
assert components[0].cpe == "cpe:/a:djangoproject:django:1.2.3"
61+
62+
63+
def test_grype_workaround():
64+
# https://github.com/anchore/grype/issues/2618
65+
srcinfo = {"mingw32": "pkgbase = foo\npkgver = 42"}
66+
components = generate_components({"srcinfo": srcinfo, "extra": {"references": [
67+
"cpe: cpe:/a:djangoproject:django:1.2.3"
68+
]}})
69+
for property in components[0].properties:
70+
if property.name == "syft:package:type":
71+
assert property.value == "binary"
72+
break
73+
else:
74+
assert False, "syft:package:type property not found"
75+
76+
components = generate_components({"srcinfo": srcinfo, "extra": {"references": [
77+
"purl: pkg:pypi/django"
78+
]}})
79+
assert all(
80+
property.name != "syft:package:type" for property in components[0].properties
81+
), "syft:package:type property should not be present"

0 commit comments

Comments
 (0)