Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions vulnerabilities/pipes/osv_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions vulnerabilities/tests/pipes/test_osv_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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