Skip to content

Commit eb238c2

Browse files
committed
Add more tests.
Use parse_advisory_data_v3 for GitHub OSV. Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent db0e601 commit eb238c2

File tree

9 files changed

+503
-76
lines changed

9 files changed

+503
-76
lines changed

vulnerabilities/importers/osv_v2.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from cvss.exceptions import CVSS3MalformedError
1818
from cvss.exceptions import CVSS4MalformedError
1919
from packageurl import PackageURL
20-
from univers.version_constraint import VersionConstraint
20+
from univers.version_constraint import VersionConstraint, validate_comparators
2121
from univers.version_range import RANGE_CLASS_BY_SCHEMES
2222
from univers.versions import InvalidVersion
2323
from univers.versions import SemverVersion
@@ -152,36 +152,41 @@ def parse_advisory_data_v3(
152152
or fixed_by_commit_patches
153153
or introduced_by_commit_patches
154154
):
155-
affected_packages.append(
156-
AffectedPackageV2(
157-
package=purl,
158-
affected_version_range=affected_version_range,
159-
fixed_version_range=fixed_version_range,
160-
fixed_by_commit_patches=fixed_by_commit_patches,
161-
introduced_by_commit_patches=introduced_by_commit_patches,
155+
try:
156+
affected_packages.append(
157+
AffectedPackageV2(
158+
package=purl,
159+
affected_version_range=affected_version_range,
160+
fixed_version_range=fixed_version_range,
161+
fixed_by_commit_patches=fixed_by_commit_patches,
162+
introduced_by_commit_patches=introduced_by_commit_patches,
163+
)
162164
)
163-
)
165+
except Exception as e:
166+
logger.error(f"Invalid AffectedPackageV2 {e} for {advisory_id}")
164167

165168
database_specific = raw_data.get("database_specific") or {}
166169
cwe_ids = database_specific.get("cwe_ids") or []
167170
weaknesses = list(map(get_cwe_id, cwe_ids))
168171

169172
if advisory_id in aliases:
170173
aliases.remove(advisory_id)
171-
172-
return AdvisoryData(
173-
advisory_id=advisory_id,
174-
aliases=aliases,
175-
summary=summary,
176-
references_v2=references,
177-
severities=severities,
178-
affected_packages=affected_packages,
179-
date_published=date_published,
180-
weaknesses=weaknesses,
181-
patches=patches,
182-
url=advisory_url,
183-
original_advisory_text=advisory_text or json.dumps(raw_data, indent=2, ensure_ascii=False),
184-
)
174+
try:
175+
return AdvisoryData(
176+
advisory_id=advisory_id,
177+
aliases=aliases,
178+
summary=summary,
179+
references_v2=references,
180+
severities=severities,
181+
affected_packages=affected_packages,
182+
date_published=date_published,
183+
weaknesses=weaknesses,
184+
patches=patches,
185+
url=advisory_url,
186+
original_advisory_text=advisory_text or json.dumps(raw_data, indent=2, ensure_ascii=False),
187+
)
188+
except Exception as e:
189+
logger.error(f"Invalid AdvisoryData for {advisory_id}: {e}")
185190

186191

187192
def extract_events(range_data) -> Iterable[str]:
@@ -335,12 +340,18 @@ def get_explicit_affected_constraints(affected_pkg, raw_id, supported_ecosystem)
335340
version_obj = version_range_class.version_class(version)
336341
constraint = VersionConstraint(comparator="=", version=version_obj)
337342
constraints.append(constraint)
343+
validate_comparators(constraints)
338344
except Exception as e:
339345
logger.error(
340-
f"Invalid VersionRange for affected_pkg: {affected_pkg} "
341-
f"for OSV id: {raw_id!r}: error:{e!r}"
346+
f"Invalid VersionConstraint: {version} " f"for OSV id: {raw_id!r}: error:{e!r}"
342347
)
343348

349+
try:
350+
validate_comparators(constraints)
351+
except Exception as e:
352+
logger.error(
353+
f"InvalidConstraint: {version} " f"for OSV id: {raw_id!r}: error:{e!r}"
354+
)
344355
return constraints
345356

346357

vulnerabilities/pipelines/v2_importers/github_osv_importer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ def advisories_count(self):
4848
return sum(1 for _ in advisory_dir.rglob("*.json"))
4949

5050
def collect_advisories(self) -> Iterable[AdvisoryData]:
51-
from vulnerabilities.importers.osv import parse_advisory_data_v2
52-
5351
supported_ecosystems = [
5452
"pypi",
5553
"npm",

vulnerabilities/pipelines/v2_importers/oss_fuzz.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ def advisories_count(self):
4444
return sum(1 for _ in vulns_directory.rglob("*.yaml"))
4545

4646
def collect_advisories(self) -> Iterable[AdvisoryData]:
47-
from vulnerabilities.importers.osv import parse_advisory_data_v2
48-
4947
base_directory = Path(self.vcs_response.dest_dir)
5048
vulns_directory = base_directory / "vulns"
5149

vulnerabilities/pipelines/v2_importers/pysec_importer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import requests
1616

1717
from vulnerabilities.importer import AdvisoryData
18+
from vulnerabilities.importers.osv_v2 import parse_advisory_data_v3
1819
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
1920

2021

@@ -47,7 +48,6 @@ def advisories_count(self) -> int:
4748

4849
def collect_advisories(self) -> Iterable[AdvisoryData]:
4950
"""Yield AdvisoryData using a zipped data dump of OSV data"""
50-
from vulnerabilities.importers.osv import parse_advisory_data_v2
5151

5252
with ZipFile(BytesIO(self.advisory_zip)) as zip_file:
5353
for file_name in zip_file.namelist():
@@ -60,7 +60,7 @@ def collect_advisories(self) -> Iterable[AdvisoryData]:
6060
with zip_file.open(file_name) as f:
6161
vul_info = json.load(f)
6262
advisory_text = f.read()
63-
yield parse_advisory_data_v2(
63+
yield parse_advisory_data_v3(
6464
raw_data=vul_info,
6565
supported_ecosystems=["pypi"],
6666
advisory_url=self.url,
Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
1-
id: PYSEC-2021-796
2-
details: TensorFlow is an end-to-end open source platform for machine learning. In
3-
affected versions TFLite's [`expand_dims.cc`](https://github.com/tensorflow/tensorflow/blob/149562d49faa709ea80df1d99fc41d005b81082a/tensorflow/lite/kernels/expand_dims.cc#L36-L50)
4-
contains a vulnerability which allows reading one element outside of bounds of heap
5-
allocated data. If `axis` is a large negative value (e.g., `-100000`), then after
6-
the first `if` it would still be negative. The check following the `if` statement
7-
will pass and the `for` loop would read one element before the start of `input_dims.data`
8-
(when `i = 0`). We have patched the issue in GitHub commit d94ffe08a65400f898241c0374e9edc6fa8ed257.
9-
The fix will be included in TensorFlow 2.6.0. We will also cherrypick this commit
10-
on TensorFlow 2.5.1, TensorFlow 2.4.3, and TensorFlow 2.3.4, as these are also affected
11-
and still in supported range.
1+
id: PYSEC-2017-94
2+
details: Heap-based buffer overflow in the ALGnew function in block_templace.c in
3+
Python Cryptography Toolkit (aka pycrypto) allows remote attackers to execute arbitrary
4+
code as demonstrated by a crafted iv parameter to cryptmsg.py.
125
affected:
136
- package:
14-
name: tensorflow-gpu
7+
name: pycrypto
158
ecosystem: PyPI
16-
purl: pkg:pypi/tensorflow-gpu
9+
purl: pkg:pypi/pycrypto
1710
ranges:
1811
- type: GIT
19-
repo: https://github.com/tensorflow/tensorflow
12+
repo: https://github.com/dlitz/pycrypto
2013
events:
21-
- introduced: "0"
22-
- fixed: d94ffe08a65400f898241c0374e9edc6fa8ed257
14+
- introduced: '0'
15+
- fixed: 8dbe0dc3eea5c689d4f76b37b93fe216cf1f00d4
2316
- type: ECOSYSTEM
2417
events:
25-
- introduced: 2.3.0
26-
- fixed: 2.3.4
27-
- introduced: 2.4.0
28-
- fixed: 2.4.3
18+
- introduced: '0'
2919
versions:
30-
- 2.3.0
31-
- 2.3.1
32-
- 2.3.2
33-
- 2.3.3
34-
- 2.4.0
20+
- 1.9a2
21+
- 1.9a5
22+
- 1.9a6
23+
- '2.0'
24+
- 2.0.1
25+
- 2.1.0
26+
- '2.2'
27+
- '2.3'
28+
- '2.4'
3529
- 2.4.1
36-
- 2.4.2
30+
- '2.5'
31+
- '2.6'
32+
- 2.6.1
3733
references:
34+
- type: WEB
35+
url: https://pony7.fr/ctf:public:32c3:cryptmsg
36+
- type: WEB
37+
url: https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/RJ37R2YLX56YZABFNAOWV4VTHTGYREAE/
38+
- type: WEB
39+
url: https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/C6BWNADPLKDBBQBUT3P75W7HAJCE7M3B/
40+
- type: REPORT
41+
url: https://github.com/dlitz/pycrypto/issues/176
3842
- type: FIX
39-
url: https://github.com/tensorflow/tensorflow/commit/d94ffe08a65400f898241c0374e9edc6fa8ed257
43+
url: https://github.com/dlitz/pycrypto/commit/8dbe0dc3eea5c689d4f76b37b93fe216cf1f00d4
44+
- type: REPORT
45+
url: https://bugzilla.redhat.com/show_bug.cgi?id=1409754
46+
- type: WEB
47+
url: http://www.securityfocus.com/bid/95122
48+
- type: WEB
49+
url: http://www.openwall.com/lists/oss-security/2016/12/27/8
4050
- type: ADVISORY
41-
url: https://github.com/tensorflow/tensorflow/security/advisories/GHSA-c545-c4f9-rf6v
51+
url: https://security.gentoo.org/glsa/201702-14
52+
- type: ADVISORY
53+
url: https://github.com/advisories/GHSA-cq27-v7xp-c356
4254
aliases:
43-
- CVE-2021-37685
44-
- GHSA-c545-c4f9-rf6v
45-
modified: "2021-12-09T06:35:39.778016Z"
46-
published: "2021-08-12T23:15:00Z"
55+
- CVE-2013-7459
56+
- GHSA-cq27-v7xp-c356
57+
modified: '2021-08-27T03:22:16.665546Z'
58+
published: '2017-02-15T15:59:00Z'

0 commit comments

Comments
 (0)