diff --git a/vulnerabilities/pipes/osv_v2.py b/vulnerabilities/pipes/osv_v2.py index 4b8ce47c7..c79279b2f 100644 --- a/vulnerabilities/pipes/osv_v2.py +++ b/vulnerabilities/pipes/osv_v2.py @@ -486,6 +486,7 @@ def get_version_ranges_constraints( affected_constraints = [] fixed_constraints = [] + zero_intro_v_obj = None version_range_class = RANGE_CLASS_BY_SCHEMES.get(supported_ecosystem) for event_type, event_value in extract_events(ranges): @@ -520,6 +521,7 @@ def get_version_ranges_constraints( if event_type == "introduced": if event_value == "0": + zero_intro_v_obj = v_obj continue constraint = VersionConstraint(comparator=">=", version=v_obj) affected_constraints.append(constraint) @@ -550,6 +552,9 @@ def get_version_ranges_constraints( f"Unsupported version constraint type: {event_type}:{event_value!r} for OSV id: {raw_id!r}" ) + if not affected_constraints and zero_intro_v_obj is not None: + affected_constraints.append(VersionConstraint(comparator=">=", version=zero_intro_v_obj)) + return ( affected_constraints, fixed_constraints, diff --git a/vulnerabilities/tests/pipes/test_osv_v2.py b/vulnerabilities/tests/pipes/test_osv_v2.py index 2fb276fd3..508ead60d 100644 --- a/vulnerabilities/tests/pipes/test_osv_v2.py +++ b/vulnerabilities/tests/pipes/test_osv_v2.py @@ -324,3 +324,24 @@ def test_to_advisories_pypa8_cvss_v3_0_parsing(self): ) result = imported_data.to_dict() util_tests.check_results_against_json(result, expected_file, regen=True) + + def test_parse_advisory_data_v3_introduced_zero_only(self): + raw_data = { + "id": "GHSA-wj6h-64fc-37mp", + "summary": "ECDSA vulnerability", + "affected": [ + { + "package": {"ecosystem": "PyPI", "name": "ecdsa"}, + "ranges": [{"type": "ECOSYSTEM", "events": [{"introduced": "0"}]}], + } + ], + } + imported_data = parse_advisory_data_v3( + raw_data, ["pypi"], advisory_url="https://test.com", advisory_text="" + ) + assert imported_data is not None + assert len(imported_data.affected_packages) == 1 + affected = imported_data.affected_packages[0] + assert str(affected.package) == "pkg:pypi/ecdsa" + assert str(affected.affected_version_range) == "vers:pypi/>=0" + assert affected.fixed_version_range is None