Skip to content

Commit 5d837c6

Browse files
OSV to vers conversion was missing the min including version (#220)
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com> Signed-off-by: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com> Co-authored-by: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com>
1 parent 65c82ba commit 5d837c6

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

test/data/osv-pypi-django.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"GHSA-2gwj-7jmv-h26r","summary":"SQL Injection in Django","details":"An issue was discovered in Django 2.2 before 2.2.28, 3.2 before 3.2.13, and 4.0 before 4.0.4. `QuerySet.annotate()`, `aggregate()`, and `extra()` methods are subject to SQL injection in column aliases via a crafted dictionary (with dictionary expansion) as the passed `**kwargs`.","aliases":["BIT-django-2022-28346","CVE-2022-28346","PYSEC-2022-190"],"modified":"2025-02-21T05:41:10.759178Z","published":"2022-04-13T00:00:33Z","database_specific":{"github_reviewed_at":"2022-04-22T20:33:03Z","github_reviewed":true,"severity":"CRITICAL","cwe_ids":["CWE-89"],"nvd_published_at":"2022-04-12T05:15:00Z"},"references":[{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2022-28346"},{"type":"WEB","url":"https://github.com/django/django/commit/2044dac5c6968441be6f534c4139bcf48c5c7e48"},{"type":"WEB","url":"https://github.com/django/django/commit/2c09e68ec911919360d5f8502cefc312f9e03c5d"},{"type":"WEB","url":"https://github.com/django/django/commit/800828887a0509ad1162d6d407e94d8de7eafc60"},{"type":"WEB","url":"https://github.com/django/django/commit/93cae5cb2f9a4ef1514cf1a41f714fef08005200"},{"type":"WEB","url":"https://docs.djangoproject.com/en/4.0/releases/security"},{"type":"ADVISORY","url":"https://github.com/advisories/GHSA-2gwj-7jmv-h26r"},{"type":"PACKAGE","url":"https://github.com/django/django"},{"type":"WEB","url":"https://github.com/pypa/advisory-database/tree/main/vulns/django/PYSEC-2022-190.yaml"},{"type":"WEB","url":"https://groups.google.com/forum/#!forum/django-announce"},{"type":"WEB","url":"https://lists.debian.org/debian-lts-announce/2022/04/msg00013.html"},{"type":"WEB","url":"https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/HWY6DQWRVBALV73BPUVBXC3QIYUM24IK"},{"type":"WEB","url":"https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/LTZVAKU5ALQWOKFTPISE257VCVIYGFQI"},{"type":"WEB","url":"https://security.netapp.com/advisory/ntap-20220609-0002"},{"type":"WEB","url":"https://www.debian.org/security/2022/dsa-5254"},{"type":"WEB","url":"https://www.djangoproject.com/weblog/2022/apr/11/security-releases"},{"type":"WEB","url":"http://www.openwall.com/lists/oss-security/2022/04/11/1"}],"affected":[{"package":{"name":"django","ecosystem":"PyPI","purl":"pkg:pypi/django"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"2.2"},{"fixed":"2.2.28"}]}],"versions":["2.2","2.2.1","2.2.10","2.2.11","2.2.12","2.2.13","2.2.14","2.2.15","2.2.16","2.2.17","2.2.18","2.2.19","2.2.2","2.2.20","2.2.21","2.2.22","2.2.23","2.2.24","2.2.25","2.2.26","2.2.27","2.2.3","2.2.4","2.2.5","2.2.6","2.2.7","2.2.8","2.2.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/04/GHSA-2gwj-7jmv-h26r/GHSA-2gwj-7jmv-h26r.json"}},{"package":{"name":"django","ecosystem":"PyPI","purl":"pkg:pypi/django"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"3.2"},{"fixed":"3.2.13"}]}],"versions":["3.2","3.2.1","3.2.10","3.2.11","3.2.12","3.2.2","3.2.3","3.2.4","3.2.5","3.2.6","3.2.7","3.2.8","3.2.9"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/04/GHSA-2gwj-7jmv-h26r/GHSA-2gwj-7jmv-h26r.json"}},{"package":{"name":"django","ecosystem":"PyPI","purl":"pkg:pypi/django"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"4.0"},{"fixed":"4.0.4"}]}],"versions":["4.0","4.0.1","4.0.2","4.0.3"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/04/GHSA-2gwj-7jmv-h26r/GHSA-2gwj-7jmv-h26r.json"}}],"schema_version":"1.6.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"},{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"}]}

test/test_source.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ def test_osv_mvn_single_json():
298298
return json.loads(fp.read())
299299

300300

301+
@pytest.fixture
302+
def test_osv_pypi_django_json():
303+
test_cve_data = os.path.join(
304+
os.path.dirname(os.path.realpath(__file__)), "data", "osv-pypi-django.json"
305+
)
306+
with open(test_cve_data, mode="r", encoding="utf-8") as fp:
307+
return json.loads(fp.read())
308+
301309
@pytest.fixture
302310
def test_aqua_alsa_json():
303311
test_cve_data = os.path.join(
@@ -875,12 +883,12 @@ def test_osv_convert(
875883
db6.clear_all()
876884
osvlatest.store(cve_data)
877885
cve_data_count, cve_index_count = db6.stats()
878-
assert cve_data_count == 4
879-
assert cve_index_count == 4
886+
assert cve_data_count == 5
887+
assert cve_index_count == 5
880888
results_count = len(list(search.search_by_any("CVE-2020-8022")))
881889
assert results_count == 0
882890
results_count = len(list(search.search_by_any("CVE-2019-0647")))
883-
assert results_count == 4
891+
assert results_count == 5
884892
results_count = len(
885893
list(search.search_by_any("pkg:maven/org.springframework/spring-web"))
886894
)
@@ -1112,6 +1120,22 @@ def test_osv_mal_convert(test_osv_mal_json, test_osv_mal2_json):
11121120
assert len(cve_data) == 1
11131121

11141122

1123+
def test_osv_pypi_django_convert(test_osv_pypi_django_json):
1124+
osvlatest = OSVSource()
1125+
cve_data = osvlatest.convert(test_osv_pypi_django_json)
1126+
assert len(cve_data) == 3
1127+
db6.clear_all()
1128+
osvlatest.store(cve_data)
1129+
cve_data_count, cve_index_count = db6.stats()
1130+
assert cve_data_count == 3
1131+
assert cve_index_count == 3
1132+
results = list(search.search_by_any("CVE-2022-28346"))
1133+
assert len(results) == 3
1134+
for r in results:
1135+
assert "vers:pypi/>=" in r.get("vers", "")
1136+
db6.clear_all()
1137+
1138+
11151139
def test_aqua_convert(
11161140
test_aqua_alsa_json,
11171141
test_aqua_alas_json,

test/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,23 @@ def test_purl_vers_convert():
947947
],
948948
"vers:deb/<2.36.1-8+deb11u1|!=2.36.1-8+deb11u1",
949949
),
950+
(
951+
"pypi",
952+
[
953+
{
954+
"status": "affected",
955+
"versionType": "pypi",
956+
"version": "2.2",
957+
"lessThan": r"2.2.28",
958+
},
959+
{
960+
"version": r"2.2.28",
961+
"status": "unaffected",
962+
"versionType": "pypi",
963+
}
964+
],
965+
"vers:pypi/>=2.2|<2.2.28|!=2.2.28",
966+
),
950967
]
951968
for tt in test_tuples:
952969
assert utils.to_purl_vers(tt[0], tt[1]) == tt[2]

vdb/lib/cve.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,7 @@ def to_product_versions(vendor, adetail: VulnerabilityDetail) -> list[Versions]:
121121
status=Status.affected,
122122
)
123123
)
124-
if adetail.mae and adetail.mae not in ("*", "-"):
125-
versions.append(
126-
Versions(
127-
version=Version(adetail.mae),
128-
versionType=version_type,
129-
status=Status.unaffected,
130-
)
131-
)
132-
elif adetail.mae:
124+
if adetail.mae:
133125
versions.append(
134126
Versions(
135127
version=Version(adetail.mii),
@@ -138,6 +130,14 @@ def to_product_versions(vendor, adetail: VulnerabilityDetail) -> list[Versions]:
138130
status=Status.affected,
139131
)
140132
)
133+
if adetail.mae not in ("*", "-"):
134+
versions.append(
135+
Versions(
136+
version=Version(adetail.mae),
137+
versionType=version_type,
138+
status=Status.unaffected,
139+
)
140+
)
141141
lt_captured = True
142142
else:
143143
versions.append(

0 commit comments

Comments
 (0)