Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(API): update version matching for NuGet, PyPI and RubyGems #2971

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
46 changes: 46 additions & 0 deletions gcp/api/integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,52 @@ def test_query_comparing_version(self):
timeout=_TIMEOUT)
self.assertEqual(0, len(response.json()))

def test_malicious_package_matching(self):
""""Test malicious package query"""
# Test matching by affected ranges
mal_2022_7426 = self._get('MAL-2022-7426')

expected_vulns = [
mal_2022_7426,
]

package = 'pymocks'
ecosystem = 'PyPI'

response = requests.post(
_api() + _BASE_QUERY,
data=json.dumps({
'version': '0.0.1',
'package': {
'name': package,
'ecosystem': ecosystem,
}
}),
timeout=_TIMEOUT)
self.assert_results_equal({'vulns': expected_vulns}, response.json())

# Test matching by affected versions
mal_2024_4618 = self._get('MAL-2024-4618')

expected_vulns = [
mal_2024_4618,
]

package = 'psbuiId'
ecosystem = 'NuGet'

response = requests.post(
_api() + _BASE_QUERY,
data=json.dumps({
'version': '1.1.1-beta',
'package': {
'name': package,
'ecosystem': ecosystem,
}
}),
timeout=_TIMEOUT)
self.assert_results_equal({'vulns': expected_vulns}, response.json())

def test_query_invalid_ecosystem(self):
"""Test a query with an invalid ecosystem fails validation."""
response = requests.post(
Expand Down
4 changes: 4 additions & 0 deletions osv/ecosystems/nuget.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,7 @@ def enumerate_versions(self,
self.sort_versions(versions)
return self._get_affected_versions(versions, introduced, fixed,
last_affected, limits)

@property
def supports_comparing(self):
return True
4 changes: 4 additions & 0 deletions osv/ecosystems/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ def enumerate_versions(self,

return self._get_affected_versions(versions, introduced, fixed,
last_affected, limits)

@property
def supports_comparing(self):
return True
4 changes: 4 additions & 0 deletions osv/ecosystems/rubygems.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ def enumerate_versions(self,
self.sort_versions(versions)
return self._get_affected_versions(versions, introduced, fixed,
last_affected, limits)

@property
def supports_comparing(self):
return True
Loading