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

CVE scan on cve-bin-tool's requirements and HTML report dependencies #1113

Merged
merged 38 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
563095f
CSV file for CVE input
BreadGenie Mar 24, 2021
3f16c28
Add github workflow for scanning requirements of cve-bin-tool
BreadGenie Mar 25, 2021
5076b95
Remove zstandard
BreadGenie Mar 29, 2021
48f3445
Add script to find versions of packages
BreadGenie Mar 31, 2021
24da964
Refactor code and black fix
BreadGenie Mar 31, 2021
307a675
Add CSV for docs
BreadGenie Apr 1, 2021
d985fee
Swap pkg_resources module for importlib
BreadGenie Apr 14, 2021
311249d
Fix ModuleNotFound Error
BreadGenie Apr 14, 2021
27b72a3
Add html dependencies and reportlab module
BreadGenie Apr 16, 2021
a9435cb
Add get-date step and new lines in every file
BreadGenie Apr 16, 2021
1cf198c
Add newline
BreadGenie Apr 17, 2021
40e4214
Update script to find HTML dependecies' versions
BreadGenie Apr 21, 2021
d925d79
Remove seperate scanning html dependencies
BreadGenie Apr 21, 2021
50bdcc9
Update requirements_csv.py
BreadGenie Apr 21, 2021
a9eefb5
Refactor code
BreadGenie Apr 21, 2021
d9abc33
Move requirements_csv.py to test folder
BreadGenie Apr 28, 2021
98e0973
Add allowable list of packages
BreadGenie Apr 29, 2021
b518167
Fix workflow
BreadGenie Apr 29, 2021
d181e53
Run CVE scan inside the test
BreadGenie Apr 29, 2021
a0825d0
Change command and add comment
BreadGenie Apr 29, 2021
eb00e33
Remove nested function
BreadGenie Apr 30, 2021
bbdd4d1
Rerun CI
BreadGenie Apr 30, 2021
68f6fbd
Remove jQuery from allowed list
BreadGenie May 4, 2021
758b227
Add test to check if requirements.csv and requirements.txt files are …
BreadGenie May 14, 2021
8a7c53a
Capitalize sphinx to match in requirements.txt
BreadGenie May 14, 2021
ec6bfe4
Create cache folder if it doesn't exist
BreadGenie May 14, 2021
8ddf147
Refactor Code
BreadGenie May 15, 2021
e567d81
Improve test case
BreadGenie May 15, 2021
524ad19
Add single run of cve-bin-tool
BreadGenie May 15, 2021
33ad437
Format assert message
BreadGenie May 15, 2021
d1a9cbe
Install cabextract before scan
BreadGenie May 15, 2021
9a58ea5
Correct the error message and variables
BreadGenie May 15, 2021
af9f6a6
Remove redundant aiohttp entry
BreadGenie May 15, 2021
d7bd5fe
Remove caching of the .csv file
BreadGenie May 15, 2021
fa142d8
Format with black
BreadGenie May 15, 2021
960cca8
Add the .csv file used for scan in .gitignore
BreadGenie May 15, 2021
bd04c17
Refactor code
BreadGenie May 15, 2021
f0cec4f
Combine pip install command
BreadGenie May 15, 2021
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
39 changes: 39 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,42 @@ jobs:
pytest -v
test/test_cvedb.py
test/test_cli.py

cve_scan:
name: CVE Scan on dependencies
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Get Date
id: get-date
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
with:
python-version: 3.8
- name: get cached python packages
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: get cached database
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/cache@v2
with:
path: ~/.cache/cve-bin-tool
key: ${{ runner.os }}-cve-bin-tool-${{ steps.get-date.outputs.date }}
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r doc/requirements.txt
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
- name: Create cache requirements.csv with versions
run: |
python requirements_csv.py
- name: Run CVE Binary tool against requirements.csv and HTML report dependencies
run: |
python -m cve_bin_tool.cli --input-file ~/.cache/cve-bin-tool/requirements.csv
4 changes: 4 additions & 0 deletions cve_bin_tool/output_engine/html_reports/js/dependencies.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor,product
getbootstrap,bootstrap
jquery,jquery
plotly,plotly.js
4 changes: 4 additions & 0 deletions doc/requirements.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor,product
rtfd_not_in_db,recommonmark
sphinx-doc_not_in_db,sphinx
ryanfox_not_in_db,sphinx_markdown_tables
19 changes: 19 additions & 0 deletions requirements.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
vendor,product

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these files risk getting out of sync with the .txt versions, we should either have a lookup where we map the .txt to the vendor package pair, and make sure that there is a mapping for each, or else raise an exception that we need to update the mapping. OR we should have a test which checks that all the entries in the .txt file also appear in the .csv file (for each file respectively).

plot,plotly
pocoo,jinja2
aiohttp_project,aiohttp
pyyaml,pyyaml
reportlab,reportlab
pytest_not_in_db,pytest
pytest_not_in_db,pytest-xdist
pytest_not_in_db,pytest-cov
pytest_not_in_db,pytest-asyncio
pycqa_not_in_db,isort
willmcgugan_not_in_db,rich
crummy_not_in_db,beautifulsoup4
aio-libs_not_in_db,aiohttp
uiri_not_in_db,toml
jsonschema_not_in_db,jsonschema
python_not_in_db,py
srossross_not_in_db,rpmfile
indygreg_not_in_db,zstandard
63 changes: 63 additions & 0 deletions requirements_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: GPL-3.0-or-later

# Script to add versions to requirements.csv

import csv
import os
import re
from importlib.metadata import version

REQ_CSV = os.path.abspath(os.path.join(os.path.dirname(__file__), "requirements.csv"))
DOC_CSV = os.path.abspath(
os.path.join(os.path.dirname(__file__), "doc", "requirements.csv")
)
CACHE_CSV = os.path.join(
os.path.expanduser("~"), ".cache", "cve-bin-tool", "requirements.csv"
)
HTML_DEP_PATH = os.path.abspath(
os.path.join(
os.path.dirname(__file__), "cve_bin_tool", "output_engine", "html_reports", "js"
)
)
HTML_DEP_CSV = os.path.join(HTML_DEP_PATH, "dependencies.csv")


def get_cache_csv_data(file):
data = []
with open(file, "r") as f:
r = csv.reader(f)
next(r)
for row in r:
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
if file is HTML_DEP_CSV:
file_name = (
"{}/{}".format(HTML_DEP_PATH, row[1])
if ".js" in row[1]
else "{}/{}.js".format(HTML_DEP_PATH, row[1])
)
BreadGenie marked this conversation as resolved.
Show resolved Hide resolved
with open(file_name) as f:
file_content = f.read()
html_dep_version = re.search(
r"v([0-9]+\.[0-9]+\.[0-9]+)", file_content
).group(1)
data.append((row[0], row[1], html_dep_version))
else:
if "_not_in_db" not in row[0]:
data.append((row[0], row[1], version(row[1])))
return data


cache_csv_data = (
get_cache_csv_data(REQ_CSV)
+ get_cache_csv_data(DOC_CSV)
+ get_cache_csv_data(HTML_DEP_CSV)
)

# writes a cache CSV file
with open(CACHE_CSV, "w") as f:
writer = csv.writer(f)
fieldnames = ["vendor", "product", "version"]
writer = csv.writer(f)
writer.writerow(fieldnames)
for row in cache_csv_data:
writer.writerow(row)