Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
592e846
Sanity Checks for redhat import response
savish28 Mar 18, 2021
1b06423
Make sure vulnerability id is_cve or is_vulcoid
Hritik14 Mar 18, 2021
3d66b4e
Merge pull request #387 from savish28/Issue#384
sbs2001 Mar 19, 2021
4d020a7
Use is_cve helper to validate vulnerablitiy id
Hritik14 Mar 19, 2021
54b7707
Merge branch 'main' into bugfix
Hritik14 Mar 19, 2021
f06e1b2
Bump djangorestframework from 3.11.0 to 3.11.2
dependabot[bot] Mar 19, 2021
c689e9d
Merge pull request #389 from Hritik14/bugfix
sbs2001 Mar 22, 2021
d8d07ab
Fix various importer errors
sbs2001 Mar 15, 2021
bfa005e
Merge pull request #378 from sbs2001/fix-importer-errors
sbs2001 Mar 24, 2021
d440ebd
Merge branch 'main' into dependabot/pip/djangorestframework-3.11.2
sbs2001 Mar 25, 2021
da4325b
Bump pyyaml from 5.3.1 to 5.4
dependabot[bot] Mar 25, 2021
964e0a8
Merge pull request #401 from nexB/dependabot/pip/pyyaml-5.4
sbs2001 Mar 26, 2021
fdd029b
Update to django 3.0.13
sbs2001 Mar 26, 2021
ec3e800
Merge pull request #392 from nexB/dependabot/pip/djangorestframework-…
sbs2001 Mar 26, 2021
4aab987
Bump lxml from 4.6.2 to 4.6.3
dependabot[bot] Mar 26, 2021
adf86fd
Collect more data at NugetVersionApi
sbs2001 Mar 26, 2021
27ceb23
Add me to AUTHORS
Hritik14 Mar 26, 2021
383e87c
Update nix deps.
rolfschr Mar 27, 2021
bdd7adb
Merge branch 'main' into add_me
sbs2001 Mar 29, 2021
3688d89
Merge pull request #405 from Hritik14/add_me
sbs2001 Mar 29, 2021
8c22bee
enable configuration of allowed host
tardyp Mar 26, 2021
e1b6ab9
import: continue upon failure
tardyp Mar 29, 2021
b78cd91
DEBUG_PROPAGATE_EXCEPTIONS = True
tardyp Mar 29, 2021
c2e1b23
Enforce static collection in dockerfile
tardyp Mar 29, 2021
ca32550
enable aiohttp client to trust environement for proxy
tardyp Mar 29, 2021
d96fe5b
Bump pygments from 2.6.1 to 2.7.4
dependabot[bot] Mar 29, 2021
3f1f493
Merge pull request #414 from nexB/dependabot/pip/pygments-2.7.4
sbs2001 Mar 30, 2021
8b6aae0
Bump lxml from 4.6.2 to 4.6.3
dependabot[bot] Mar 30, 2021
0b7dc3d
Fix istio (#395)
Hritik14 Mar 30, 2021
ca7bc1f
Merge pull request #406 from ngi-nix/dependabot/pip/lxml-4.6.3
sbs2001 Mar 30, 2021
86eef3b
Merge pull request #411 from tardyp/aiohttpclient
sbs2001 Mar 30, 2021
97d4da5
Merge pull request #412 from tardyp/continue
sbs2001 Mar 30, 2021
0af5389
Merge pull request #413 from tardyp/dockerfile
sbs2001 Mar 31, 2021
dfb1ab5
Merge pull request #404 from tardyp/allowed_hosts
sbs2001 Mar 31, 2021
35f36a7
Merge pull request #402 from nexB/dependabot/pip/lxml-4.6.3
sbs2001 Apr 1, 2021
eb52414
Fix bulk api in case purl does not exist
sbs2001 Apr 1, 2021
2684f05
requests_with_5xx_retry: Retry on 5xx errors
Hritik14 Mar 29, 2021
aff0065
Not all RHSA errata have a CVRF document
Hritik14 Mar 31, 2021
b0329fa
Remove debugging symbols and black -l 100
Hritik14 Apr 1, 2021
c90a871
Mock requests_session in redhat importer
Hritik14 Apr 1, 2021
dbb8878
Add unspecified scoring system
Hritik14 Mar 30, 2021
cdaf81e
Rename unspecified to generic system
Hritik14 Apr 2, 2021
9634400
Merge pull request #418 from Hritik14/fix_redhat
sbs2001 Apr 2, 2021
8f9850f
Merge pull request #415 from Hritik14/scoring_system
sbs2001 Apr 2, 2021
e0bd0f0
Add tests for checking upstream data sources
sbs2001 Mar 13, 2021
60370ee
Update travis config
sbs2001 Mar 19, 2021
86424ee
Merge pull request #365 from sbs2001/test_upstream_data
sbs2001 Apr 4, 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
pip install -r requirements.txt

- name: Run tests
run: python -m pytest
run: python -m pytest -v -m "not webtest"
env:
# The hostname, username used to communicate with the PostgreSQL service container
POSTGRES_HOST: localhost
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/upstream_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
workflow_dispatch: # allow manual execution
push:
schedule:
# run on every 9 o'clock
- cron: '0 9 * * *'

jobs:
unit_tests:
runs-on: ubuntu-latest

services:
# Label used to access the service container
postgres:
image: postgres
env:
POSTGRES_PASSWORD: vulnerablecode
POSTGRES_DB: vulnerablecode
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
sudo apt install python3-dev postgresql libpq-dev build-essential libxml2-dev libxslt1-dev
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests
run: pytest -v -m webtest
env:
# The hostname, username used to communicate with the PostgreSQL service container
POSTGRES_HOST: localhost
VC_DB_USER: postgres
POSTGRES_PORT: 5432
DJANGO_DEV: 1
GH_TOKEN: 1
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ before_script:

script:
- ./manage.py collectstatic
- python -m pytest
- python -m pytest -v -m "not webtest"

notifications:
email: false
Expand Down
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ The following organizations or individuals have contributed to this repo:
- Islam Elhakmi @EslamHiko
- Edoardo Lanzini @elanzini
- Navonil Das @NavonilDas
- Tushar Upadhyay @tushar912
- Tushar Upadhyay @tushar912
- Hritik Vijay @hritik14
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ ENV PYTHONUNBUFFERED 1
RUN mkdir /vulnerablecode
WORKDIR /vulnerablecode
ADD . /vulnerablecode/
RUN pip install -r requirements.txt
RUN pip install -r requirements.txt && \
DJANGO_DEV=1 python manage.py collectstatic

LABEL "base_image": "pkg:docker/python@sha256%3Ae9b7e3b4e9569808066c5901b8a9ad315a9f14ae8d3949ece22ae339fff2cad0"
LABEL "dockerfile_url": "https://github.com/nexB/vulnerablecode/blob/develop/Dockerfile"
Expand Down
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ On Debian-based distros, these can be installed with::

**Application dependencies**

Create a virtualenv, install dependencies, and run the database migrations::
Create a virtualenv, install dependencies, generate static files and run the database migrations::

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
DJANGO_DEV=1 python manage.py collectstatic
DJANGO_DEV=1 python manage.py migrate

The environment variable ``DJANGO_DEV`` is used to load settings suitable for
Expand All @@ -160,6 +161,11 @@ for this purpose::

SECRET_KEY=$(python -c "from django.core.management import utils; print(utils.get_random_secret_key())")

You will also need to setup the VC_ALLOWED_HOSTS environment variable to match the hostname where the app is deployed::

VC_ALLOWED_HOSTS=vulnerablecode.your.domain.example.com

You can specify several host by separating them with a colon `:`

Using Nix
~~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions etc/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
# mach-nix release) is usually insufficient. Use
# ./get-latest-pypi-deps-db.sh to obtain the data rev & hash.
pypiDataRev =
"499750266bb4b2840cbe856c2cc0e3297685e362"; # 2021-03-06T08:13:08Z
"e9b0fc6b92cd6efbca7ba3b3d4a551bcc13a73c5"; # 2021-03-27T08:13:04Z
pypiDataSha256 =
"188g24k8pk4lgqybywimkvwjwh8014v6l2mrkvzv309882i9p5gc";
"1ssa48l2iz8kncby1gfrbds79mg114dkhpxrridwcq6q2c37p62s";
});

in {
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ contextlib2==0.5.5
decorator==4.4.2
dephell-specifier==0.2.1
dj-database-url==0.4.2
Django==3.0.7
Django==3.0.13
django-filter==2.2.0
djangorestframework==3.11.0
djangorestframework==3.11.2
django-widget-tweaks==1.4.8
drf-spectacular==0.13.0
gunicorn==19.7.1
importlib-metadata==1.3.0
ipython==7.13.0
ipython-genutils==0.2.0
jedi==0.17.0
lxml==4.6.2
lxml==4.6.3
more-itertools==8.0.2
packageurl-python==0.9.3
packaging==19.2
Expand All @@ -34,7 +34,7 @@ ptyprocess==0.6.0
py==1.8.0
pycparser==2.20
pygit2==1.5.0
Pygments==2.6.1
Pygments==2.7.4
pyparsing==2.4.5
pytest==5.3.2
django-widget-tweaks==1.4.8
Expand All @@ -54,5 +54,5 @@ whitenoise==5.0.1
zipp==0.6.0
requests==2.23.0
toml==0.10.2
PyYAML==5.3.1
PyYAML==5.4
freezegun==1.1.0
2 changes: 2 additions & 0 deletions vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def bulk_search(self, request):
)
for purl in request.data["purls"]:
try:
purl_string = purl
purl = PackageURL.from_string(purl).to_dict()
except ValueError as ve:
return Response(status=400, data={"Error": f"Invalid Package URL: {purl}"})
Expand All @@ -165,6 +166,7 @@ def bulk_search(self, request):
purl_response = purl
purl_response["unresolved_vulnerabilities"] = []
purl_response["resolved_vulnerabilities"] = []
purl_response["purl"] = purl_string
response.append(purl_response)

return Response(response)
Expand Down
5 changes: 5 additions & 0 deletions vulnerabilities/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

from vulnerabilities.oval_parser import OvalParser
from vulnerabilities.severity_systems import ScoringSystem
from vulnerabilities.helpers import is_cve

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -88,6 +89,10 @@ class Advisory:
resolved_package_urls: Iterable[PackageURL] = dataclasses.field(default_factory=list)
references: List[Reference] = dataclasses.field(default_factory=list)

def __post_init__(self):
if self.vulnerability_id and not is_cve(self.vulnerability_id):
raise ValueError("CVE expected, found: {}".format(self.vulnerability_id))

def normalized(self):
impacted_package_urls = {package_url for package_url in self.impacted_package_urls}
resolved_package_urls = {package_url for package_url in self.resolved_package_urls}
Expand Down
19 changes: 19 additions & 0 deletions vulnerabilities/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import requests
import toml
import urllib3
import yaml

# TODO add logging here
Expand Down Expand Up @@ -79,3 +80,21 @@ def create_etag(data_src, url, etag_key):


is_cve = re.compile(r"CVE-\d+-\d+", re.IGNORECASE).match


def requests_with_5xx_retry(max_retries=5, backoff_factor=0.5):
"""
Returns a requests sessions which retries on 5xx errors with
a backoff_factor
"""
retries = urllib3.util.Retry(
total=max_retries,
backoff_factor=backoff_factor,
raise_on_status=True,
status_forcelist=range(500, 600, 1),
)
adapter = requests.adapters.HTTPAdapter(max_retries=retries)
session = requests.Session()
session.mount("https://", adapter)
session.mount("http://", adapter)
return session
3 changes: 2 additions & 1 deletion vulnerabilities/importers/alpine_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from vulnerabilities.data_source import Advisory
from vulnerabilities.data_source import DataSource
from vulnerabilities.data_source import Reference
from vulnerabilities.helpers import is_cve

BASE_URL = "https://secdb.alpinelinux.org/"

Expand Down Expand Up @@ -193,7 +194,7 @@ def _load_advisories(
impacted_package_urls=[],
resolved_package_urls=resolved_purls,
references=references,
vulnerability_id=vuln_ids[0] if vuln_ids[0] != "CVE-????-?????" else "",
vulnerability_id=vuln_ids[0] if is_cve(vuln_ids[0]) else "",
)
)

Expand Down
1 change: 1 addition & 0 deletions vulnerabilities/importers/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def validate_schema(advisory_dict):

deb_versions = [
"bullseye",
"bullseye-security",
"buster",
"buster-security",
"sid",
Expand Down
6 changes: 3 additions & 3 deletions vulnerabilities/importers/istio.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from vulnerabilities.data_source import Advisory, GitDataSource, Reference
from vulnerabilities.package_managers import GitHubTagsAPI

is_release = re.compile(r"^[\d.]+$", re.IGNORECASE).match


class IstioDataSource(GitDataSource):
def __enter__(self):
Expand All @@ -47,7 +49,7 @@ def set_api(self):
asyncio.run(self.version_api.load_api(["istio/istio"]))

def updated_advisories(self) -> Set[Advisory]:
files = self._updated_files
files = self._added_files.union(self._updated_files)
advisories = []
for f in files:
processed_data = self.process_file(f)
Expand Down Expand Up @@ -195,5 +197,3 @@ def get_data_from_md(self, path):
with open(path) as f:
yaml_lines = self.get_yaml_lines(f)
return self.get_data_from_yaml_lines(yaml_lines)

is_release = re.compile(r"^[\d.]+$", re.IGNORECASE).match
4 changes: 2 additions & 2 deletions vulnerabilities/importers/project_kb_msr2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ProjectKBMSRDataSource(DataSource):

CONFIG_CLASS = ProjectKBDataSourceConfiguration

url = "https://raw.githubusercontent.com/SAP/project-kb/master/MSR2019/dataset/vulas_db_msr2019_release.csv" # nopep8
url = "https://raw.githubusercontent.com/SAP/project-kb/master/MSR2019/dataset/vulas_db_msr2019_release.csv"

def updated_advisories(self):
if create_etag(data_src=self, url=self.url, etag_key="ETag"):
Expand Down Expand Up @@ -82,7 +82,7 @@ def to_advisories(csv_reader):
summary="",
impacted_package_urls=[],
references=[reference],
cve_id=vuln_id,
vulnerability_id=vuln_id,
)
)

Expand Down
Loading