From d08fce5296c063b666b45f3cc6b0aff8c37cf32f Mon Sep 17 00:00:00 2001 From: Sanchit Date: Tue, 24 Nov 2026 05:43:54 +0000 Subject: [PATCH 1/2] fix(elixir): skip entries with no usable version range An advisory with no patched or unaffected versions listed produced a HexVersionRange with no constraints, which serializes as 'vers:hex/'. VersionRange.from_string rejects that string, so the affected package was dropped on round-trip. Skip the entry instead, mirroring the gentoo/apache_httpd fix for #2387. Signed-off-by: Sanchit --- .../v2_importers/elixir_security_importer.py | 19 +++-- .../test_elixir_security_importer_v2.py | 80 +++++++++++++++++++ 2 files changed, 94 insertions(+), 5 deletions(-) diff --git a/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py b/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py index 211743a93..3bf3cc684 100644 --- a/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py +++ b/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py @@ -120,12 +120,21 @@ def process_file(self, file, base_path) -> Iterable[AdvisoryDataV2]: affected_packages = [] if pkg_name: - affected_packages.append( - AffectedPackageV2( - package=PackageURL(type="hex", name=pkg_name), - affected_version_range=HexVersionRange(constraints=constraints), + # Do not build a version range with empty constraints: its + # string form ("vers:hex/") is rejected by + # VersionRange.from_string and the affected package is then + # dropped on round-trip. Skip the entry instead, mirroring + # the gentoo/apache_httpd fix for #2387. + version_range = HexVersionRange(constraints=constraints) if constraints else None + if version_range is None: + self.log(f"Skipping package {pkg_name} with no usable version range") + else: + affected_packages.append( + AffectedPackageV2( + package=PackageURL(type="hex", name=pkg_name), + affected_version_range=version_range, + ) ) - ) date_published = None if yaml_file.get("disclosure_date"): diff --git a/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py b/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py index e47d11623..3d95a380e 100644 --- a/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py +++ b/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py @@ -106,3 +106,83 @@ def test_collect_advisories_skips_invalid_cve(mock_fetch_via_vcs, tmp_path): importer.clone() advisories = list(importer.collect_advisories()) assert len(advisories) == 0 + + +@pytest.fixture +def mock_vcs_response_no_versions(tmp_path): + repo_dir = tmp_path / "repo" + repo_dir.mkdir() + packages_dir = repo_dir / "packages" / "some_package" + packages_dir.mkdir(parents=True) + + advisory_file = packages_dir / "CVE-2022-9999.yml" + advisory_file.write_text( + """ + cve: "2022-9999" + package: "plug" + description: "Vulnerability with no patched or unaffected versions listed" + disclosure_date: "2022-12-01" + link: "https://example.com/advisory" + """ + ) + + mock = MagicMock() + mock.dest_dir = str(repo_dir) + mock.delete = MagicMock() + return mock + + +def test_collect_advisories_skips_empty_version_range( + mock_vcs_response_no_versions, +): + """An advisory with no patched/unaffected versions must not mint an + empty range: 'vers:hex/' is rejected by VersionRange.from_string and + the affected package would be dropped on round-trip.""" + with patch( + "vulnerabilities.pipelines.v2_importers.elixir_security_importer.fetch_via_vcs" + ) as mock: + mock.return_value = mock_vcs_response_no_versions + importer = ElixirSecurityImporterPipeline() + importer.clone() + advisories = list(importer.collect_advisories()) + + assert len(advisories) == 1 + assert advisories[0].affected_packages == [] + # The advisory itself is still recorded, with no invalid range string + assert "vers:hex/" not in str(advisories[0].to_dict()) + + +def test_collect_advisories_keeps_one_sided_versions(tmp_path): + """Only one version list present still builds a usable range.""" + repo_dir = tmp_path / "repo" + packages_dir = repo_dir / "packages" / "some_package" + packages_dir.mkdir(parents=True) + + advisory_file = packages_dir / "CVE-2022-9999.yml" + advisory_file.write_text( + """ + cve: "2022-9999" + package: "plug" + description: "Vulnerability with only a patched version listed" + patched_versions: + - ">= 1.11.1" + disclosure_date: "2022-12-01" + link: "https://example.com/advisory" + """ + ) + + mock_response = MagicMock() + mock_response.dest_dir = str(repo_dir) + mock_response.delete = MagicMock() + + with patch( + "vulnerabilities.pipelines.v2_importers.elixir_security_importer.fetch_via_vcs" + ) as mock: + mock.return_value = mock_response + importer = ElixirSecurityImporterPipeline() + importer.clone() + advisories = list(importer.collect_advisories()) + + assert len(advisories) == 1 + assert len(advisories[0].affected_packages) == 1 + assert str(advisories[0].affected_packages[0].affected_version_range) != "vers:hex/" From 5b99f101d065229c456a88174469637277bfbef3 Mon Sep 17 00:00:00 2001 From: Sanchit Date: Mon, 30 Nov 2026 16:38:31 +0000 Subject: [PATCH 2/2] fix(elixir): keep package with vers:hex/* when no versions listed An advisory with no patched or unaffected versions means no fix is known and no version is known unaffected, so every version is affected. Use the wildcard range instead of dropping the package. Signed-off-by: Sanchit --- .../v2_importers/elixir_security_importer.py | 31 ++++++++++--------- .../test_elixir_security_importer_v2.py | 20 +++++++----- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py b/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py index 3bf3cc684..1bc41b305 100644 --- a/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py +++ b/vulnerabilities/pipelines/v2_importers/elixir_security_importer.py @@ -120,21 +120,24 @@ def process_file(self, file, base_path) -> Iterable[AdvisoryDataV2]: affected_packages = [] if pkg_name: - # Do not build a version range with empty constraints: its - # string form ("vers:hex/") is rejected by - # VersionRange.from_string and the affected package is then - # dropped on round-trip. Skip the entry instead, mirroring - # the gentoo/apache_httpd fix for #2387. - version_range = HexVersionRange(constraints=constraints) if constraints else None - if version_range is None: - self.log(f"Skipping package {pkg_name} with no usable version range") - else: - affected_packages.append( - AffectedPackageV2( - package=PackageURL(type="hex", name=pkg_name), - affected_version_range=version_range, - ) + if not constraints: + # No patched or unaffected versions listed means no fix is + # known and no version is known unaffected, so every version + # is affected. An empty range string ("vers:hex/") is + # rejected by VersionRange.from_string and the package would + # be dropped on round-trip, so use the wildcard range + # ("vers:hex/*") instead. + self.log( + f"No patched or unaffected versions listed for {pkg_name}; " + "treating all versions as affected" ) + constraints = [VersionConstraint.from_string(version_class=vrc, string="*")] + affected_packages.append( + AffectedPackageV2( + package=PackageURL(type="hex", name=pkg_name), + affected_version_range=HexVersionRange(constraints=constraints), + ) + ) date_published = None if yaml_file.get("disclosure_date"): diff --git a/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py b/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py index 3d95a380e..2c075ff35 100644 --- a/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py +++ b/vulnerabilities/tests/pipelines/v2_importers/test_elixir_security_importer_v2.py @@ -132,12 +132,14 @@ def mock_vcs_response_no_versions(tmp_path): return mock -def test_collect_advisories_skips_empty_version_range( +def test_collect_advisories_keeps_package_with_wildcard_range( mock_vcs_response_no_versions, ): - """An advisory with no patched/unaffected versions must not mint an - empty range: 'vers:hex/' is rejected by VersionRange.from_string and - the affected package would be dropped on round-trip.""" + """An advisory with no patched/unaffected versions means no fix is + known and no version is known unaffected, so every version is affected: + keep the package with the wildcard range 'vers:hex/*'. An empty range + ('vers:hex/') is rejected by VersionRange.from_string and the affected + package would be dropped on round-trip.""" with patch( "vulnerabilities.pipelines.v2_importers.elixir_security_importer.fetch_via_vcs" ) as mock: @@ -147,9 +149,13 @@ def test_collect_advisories_skips_empty_version_range( advisories = list(importer.collect_advisories()) assert len(advisories) == 1 - assert advisories[0].affected_packages == [] - # The advisory itself is still recorded, with no invalid range string - assert "vers:hex/" not in str(advisories[0].to_dict()) + assert len(advisories[0].affected_packages) == 1 + assert str(advisories[0].affected_packages[0].affected_version_range) == "vers:hex/*" + # No bare empty range string anywhere in the serialised advisory + assert "'vers:hex/'" not in str(advisories[0].to_dict()) + round_tripped = AdvisoryDataV2.from_dict(advisories[0].to_dict()) + assert len(round_tripped.affected_packages) == 1 + assert str(round_tripped.affected_packages[0].affected_version_range) == "vers:hex/*" def test_collect_advisories_keeps_one_sided_versions(tmp_path):