Skip to content

Commit 68b4d0e

Browse files
authored
Merge branch 'main' into alpine-migrate
2 parents 6578642 + 93888f1 commit 68b4d0e

File tree

10 files changed

+616
-239
lines changed

10 files changed

+616
-239
lines changed

README.rst

Lines changed: 48 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1-
===============
1+
==============
22
VulnerableCode
3+
==============
4+
5+
VulnerableCode is a database of software package vulnerabilities with Web UI and API.
6+
7+
Why Use VulnerableCode?
8+
=======================
9+
10+
VulnerableCode provides a Web UI and API to access a database of known software package
11+
vulnerabilities with comprehensive information from upstream and downstream public
12+
sources including packages affected by a vulnerability and packages that fix a
13+
vulnerability.
14+
15+
There is a `public VulnerableCode database <https://public.vulnerablecode.io/>`_
16+
and the project also provides the tools to build your own instance of the database.
17+
18+
Getting Started
319
===============
420

21+
Instructions to get you up and running on your local machine are at `Getting Started <https://vulnerablecode.readthedocs.io/en/stable/>`_
22+
23+
The VulnerableCode documentation also provides:
24+
25+
- prerequisites for installing the software.
26+
- an introduction to the user interface.
27+
- how to use the API.
28+
- tutorials for adding new pipelines to import and improve advisories.
29+
- extensive reference information about VulnerableCode data.
30+
- guidelines for contributing to code development.
31+
32+
Build and tests status
33+
======================
34+
535
|Build Status| |Code License| |Data License| |Python 3.8+| |stability-wip| |Gitter chat|
636

737

@@ -18,11 +48,12 @@ VulnerableCode
1848
:target: https://gitter.im/aboutcode-org/vulnerablecode
1949

2050

51+
Benefits of VulnerableCode
52+
==========================
53+
2154
VulnerableCode is a free and open database of open source software package
2255
vulnerabilities **because open source software vulnerability data and tools
23-
should be free and open source themselves**:
24-
25-
We are trying to change this and evolve the status quo in a few other areas!
56+
should be free and open source themselves**.
2657

2758
- Vulnerability databases have been **traditionally proprietary** even though they
2859
are mostly about free and open source software.
@@ -37,110 +68,29 @@ We are trying to change this and evolve the status quo in a few other areas!
3768
easier to find a package and whether it is vulnerable.
3869

3970
PURLs were designed initially for ScanCode and VulnerableCode. PURL is
40-
now a de-facto standard for vulnerability management and package references.
41-
See https://github.com/package-url/purl-spec
42-
43-
The VulnerableCode project is a FOSS community resource to help improve the
44-
security of the open source software ecosystem and its users at large.
45-
46-
VulnerableCode consists of a database and the tools to collect, refine and keep
47-
the database current.
48-
49-
50-
.. pull-quote::
51-
**Warning**
52-
VulnerableCode is under active development and may not be ready for production
53-
use depending on your use cases.
54-
55-
Read more about VulnerableCode at https://vulnerablecode.readthedocs.org/
71+
now a `standard <https://github.com/package-url/purl-spec>`_ for vulnerability management
72+
and package references.
5673

5774
The VulnerableCode tech stack is Python, Django, PostgreSQL, nginx and Docker and
5875
several libraries.
5976

60-
Getting started
61-
===============
62-
63-
Run with Docker
64-
---------------
65-
66-
First install docker, then run
67-
68-
.. code:: bash
69-
70-
git clone https://github.com/nexB/vulnerablecode.git && cd vulnerablecode
71-
make envfile
72-
docker compose build
73-
docker compose up -d
74-
docker compose run vulnerablecode ./manage.py import --list
75-
76-
Then run an importer for nginx advisories (which is small)
77+
Support
78+
=======
7779

78-
.. code:: bash
80+
If you have a specific problem, suggestion or bug, please submit a
81+
`GitHub issue <https://github.com/aboutcode-org/vulnerablecode/issues>`_.
7982

80-
docker compose exec vulnerablecode ./manage.py import nginx_importer
81-
docker compose exec vulnerablecode ./manage.py improve --all
82-
83-
At this point, the VulnerableCode app and API should be up and running with
84-
some data at http://localhost
85-
86-
87-
Populate VulnerableCode database
88-
--------------------------------
89-
90-
VulnerableCode data collection works in two steps: importing data from multiple
91-
sources and then refining and improving how package and software vulnerabilities
92-
are related.
93-
94-
To run all importers and improvers use this
95-
96-
.. code:: bash
97-
98-
./manage.py import --all
99-
100-
.. code:: bash
101-
102-
./manage.py improve --all
103-
104-
105-
Local development installation
106-
------------------------------
107-
108-
On a Debian system, use this
109-
110-
.. code:: bash
111-
112-
sudo apt-get install python3-venv python3-dev postgresql libpq-dev build-essential
113-
git clone https://github.com/nexB/vulnerablecode.git && cd vulnerablecode
114-
make dev envfile postgres
115-
make test
116-
source venv/bin/activate
117-
./manage.py import nginx_importer
118-
./manage.py improve --all
119-
make run
120-
121-
At this point, the VulnerableCode app and API is up at http://127.0.0.1:8001/
83+
For quick questions or socializing, join the AboutCode community discussions on `Slack <https://join.slack.com/t/aboutcode-org/shared_invite/zt-3li3bfs78-mmtKG0Qhv~G2dSlNCZW2pA>`_.
12284

85+
Interested in commercial suppport? Contact the `AboutCode team <mailto:hello@aboutcode.org>`_.
12386

12487
License
125-
========
126-
127-
Copyright (c) nexB Inc. and others. All rights reserved.
128-
129-
VulnerableCode is a trademark of nexB Inc.
130-
131-
SPDX-License-Identifier: Apache-2.0 AND CC-BY-SA-4.0
132-
133-
VulnerableCode software is licensed under the Apache License version 2.0.
134-
135-
VulnerableCode data is licensed collectively under CC-BY-SA-4.0.
136-
137-
See https://www.apache.org/licenses/LICENSE-2.0 for the license text.
138-
139-
See https://creativecommons.org/licenses/by-sa/4.0/legalcode for the license text.
140-
141-
See https://github.com/nexB/vulnerablecode for support or download.
88+
=======
14289

143-
See https://aboutcode.org for more information about nexB OSS projects.
90+
* `Apache-2.0 <apache-2.0.LICENSE>`_ is the overall license.
91+
* `CC-BY-SA-4.0 <cc-by-sa-4.0.LICENSE>`_ applies to reference datasets.
92+
* There are multiple secondary permissive or copyleft licenses (LGPL, MIT,
93+
BSD, GPL 2/3, etc.) for third-party components and test suite code and data.
14494

14595

14696
Acknowledgements, Funding, Support and Sponsoring

vulnerabilities/importers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from vulnerabilities.pipelines.v2_importers import apache_tomcat_importer as apache_tomcat_v2
4949
from vulnerabilities.pipelines.v2_importers import archlinux_importer as archlinux_importer_v2
5050
from vulnerabilities.pipelines.v2_importers import curl_importer as curl_importer_v2
51+
from vulnerabilities.pipelines.v2_importers import debian_importer as debian_importer_v2
5152
from vulnerabilities.pipelines.v2_importers import (
5253
elixir_security_importer as elixir_security_importer_v2,
5354
)
@@ -104,6 +105,7 @@
104105
ruby_importer_v2.RubyImporterPipeline,
105106
epss_importer_v2.EPSSImporterPipeline,
106107
nginx_importer_v2.NginxImporterPipeline,
108+
debian_importer_v2.DebianImporterPipeline,
107109
mattermost_importer_v2.MattermostImporterPipeline,
108110
apache_tomcat_v2.ApacheTomcatImporterPipeline,
109111
alpine_linux_importer_v2.AlpineLinuxImporterPipeline,
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
10+
import re
11+
from typing import Any
12+
from typing import Iterable
13+
from typing import Mapping
14+
15+
from packageurl import PackageURL
16+
from univers.version_range import DebianVersionRange
17+
18+
from vulnerabilities.importer import AdvisoryData
19+
from vulnerabilities.importer import AffectedPackageV2
20+
from vulnerabilities.importer import ReferenceV2
21+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
22+
from vulnerabilities.utils import create_weaknesses_list
23+
from vulnerabilities.utils import dedupe
24+
from vulnerabilities.utils import fetch_response
25+
from vulnerabilities.utils import get_item
26+
27+
28+
class DebianImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
29+
"""Debian Importer Pipeline"""
30+
31+
pipeline_id = "debian_importer_v2"
32+
spdx_license_expression = "LicenseRef-scancode-other-permissive"
33+
license_url = "https://www.debian.org/license"
34+
notice = """
35+
From: Tushar Goel <tgoel@nexb.com>
36+
Date: Thu, May 12, 2022 at 11:42 PM +00:00
37+
Subject: Usage of Debian Security Data in VulnerableCode
38+
To: <team@security.debian.org>
39+
40+
Hey,
41+
42+
We would like to integrate the debian security data in vulnerablecode
43+
[1][2] which is a FOSS db of FOSS vulnerability data. We were not able
44+
to know under which license the debian security data comes. We would
45+
be grateful to have your acknowledgement over usage of the debian
46+
security data in vulnerablecode and have some kind of licensing
47+
declaration from your side.
48+
49+
[1] - https://github.com/nexB/vulnerablecode
50+
[2] - https://github.com/nexB/vulnerablecode/pull/723
51+
52+
Regards,
53+
54+
From: Moritz Mühlenhoff <jmm@inutil.org>
55+
Date: Wed, May 17, 2022, 19:12 PM +00:00
56+
Subject: Re: Usage of Debian Security Data in VulnerableCode
57+
To: Tushar Goel <tgoel@nexb.com>
58+
Cc: <team@security.debian.org>
59+
60+
61+
Am Thu, May 12, 2022 at 05:12:48PM +0530 schrieb Tushar Goel:
62+
> Hey,
63+
>
64+
> We would like to integrate the debian security data in vulnerablecode
65+
> [1][2] which is a FOSS db of FOSS vulnerability data. We were not able
66+
> to know under which license the debian security data comes. We would
67+
> be grateful to have your acknowledgement over usage of the debian
68+
> security data in vulnerablecode and have some kind of licensing
69+
> declaration from your side.
70+
71+
We don't have a specific license, but you have our endorsemen to
72+
reuse the data by all means :-)
73+
74+
Cheers,
75+
Moritz
76+
"""
77+
78+
api_url = "https://security-tracker.debian.org/tracker/data/json"
79+
response = None
80+
81+
@classmethod
82+
def steps(cls):
83+
return (cls.collect_and_store_advisories,)
84+
85+
def get_response(self):
86+
try:
87+
response = fetch_response(self.api_url)
88+
if response:
89+
return response.json()
90+
return {}
91+
except Exception as e:
92+
self.log(f"Error fetching data from {self.api_url!r}: {e}")
93+
return {}
94+
95+
def advisories_count(self) -> int:
96+
adv_count = 0
97+
if not self.response:
98+
self.response = self.get_response()
99+
for pkg in self.response:
100+
recs = len(self.response[pkg])
101+
adv_count += recs
102+
return adv_count
103+
104+
def collect_advisories(self) -> Iterable[AdvisoryData]:
105+
if not self.response:
106+
self.response = self.get_response()
107+
for pkg_name, records in self.response.items():
108+
yield from self.parse(pkg_name, records)
109+
110+
def parse(self, pkg_name: str, records: Mapping[str, Any]) -> Iterable[AdvisoryData]:
111+
112+
for record_identifier, record in records.items():
113+
affected_versions = []
114+
fixed_versions = []
115+
116+
releases = record["releases"].items()
117+
for release_name, release_record in releases:
118+
version = get_item(release_record, "repositories", release_name)
119+
120+
if not version:
121+
self.log(
122+
f"Version not found for {release_name} in {record} in package {pkg_name}"
123+
)
124+
continue
125+
126+
purl = PackageURL(
127+
name=pkg_name,
128+
type="deb",
129+
namespace="debian",
130+
qualifiers={"distro": release_name},
131+
)
132+
133+
if release_record.get("status", "") == "resolved":
134+
fixed_versions.append(version)
135+
else:
136+
affected_versions.append(version)
137+
138+
if release_record.get("fixed_version"):
139+
fixed_versions.append(release_record["fixed_version"])
140+
141+
references = []
142+
debianbug = record.get("debianbug")
143+
if debianbug:
144+
bug_url = f"https://bugs.debian.org/cgi-bin/bugreport.cgi?bug={debianbug}"
145+
references.append(ReferenceV2(url=bug_url, reference_id=str(debianbug)))
146+
affected_versions = dedupe(affected_versions)
147+
fixed_versions = dedupe(fixed_versions)
148+
if affected_versions:
149+
affected_version_range = DebianVersionRange.from_versions(affected_versions)
150+
else:
151+
affected_version_range = None
152+
affected_packages = []
153+
for fixed_version in fixed_versions:
154+
affected_packages.append(
155+
AffectedPackageV2(
156+
package=purl,
157+
affected_version_range=affected_version_range,
158+
fixed_version_range=DebianVersionRange.from_versions([fixed_version]),
159+
)
160+
)
161+
weaknesses = get_cwe_from_debian_advisory(record)
162+
163+
yield AdvisoryData(
164+
advisory_id=f"{pkg_name}/{record_identifier}",
165+
aliases=[record_identifier],
166+
summary=record.get("description", ""),
167+
affected_packages=affected_packages,
168+
references=references,
169+
weaknesses=weaknesses,
170+
url=f"https://security-tracker.debian.org/tracker/{record_identifier}",
171+
)
172+
173+
174+
def get_cwe_from_debian_advisory(record):
175+
"""
176+
Extracts CWE ID strings from the given raw_data and returns a list of CWE IDs.
177+
178+
>>> get_cwe_from_debian_advisory({"description":"PEAR HTML_QuickForm version 3.2.14 contains an eval injection (CWE-95) vulnerability in HTML_QuickForm's getSubmitValue method, HTML_QuickForm's validate method, HTML_QuickForm_hierselect's _setOptions method, HTML_QuickForm_element's _findValue method, HTML_QuickForm_element's _prepareValue method. that can result in Possible information disclosure, possible impact on data integrity and execution of arbitrary code. This attack appear to be exploitable via A specially crafted query string could be utilised, e.g. http://www.example.com/admin/add_practice_type_id[1]=fubar%27])%20OR%20die(%27OOK!%27);%20//&mode=live. This vulnerability appears to have been fixed in 3.2.15."})
179+
[95]
180+
>>> get_cwe_from_debian_advisory({"description":"There is no WEAKNESS DATA"})
181+
[]
182+
"""
183+
description = record.get("description") or ""
184+
pattern = r"CWE-\d+"
185+
cwe_strings = re.findall(pattern, description)
186+
weaknesses = create_weaknesses_list(cwe_strings)
187+
return weaknesses

vulnerabilities/pipes/osv_v2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from cvss.exceptions import CVSS3MalformedError
1818
from cvss.exceptions import CVSS4MalformedError
1919
from packageurl import PackageURL
20-
from univers.version_constraint import InvalidConstraintsError
2120
from univers.version_constraint import VersionConstraint
2221
from univers.version_constraint import validate_comparators
2322
from univers.version_range import RANGE_CLASS_BY_SCHEMES
@@ -49,7 +48,7 @@
4948
"rubygems": "gem",
5049
"go": "golang",
5150
"hex": "hex",
52-
"cargo": "cargo",
51+
"crates.io": "cargo",
5352
}
5453

5554

0 commit comments

Comments
 (0)