Skip to content

Commit f5e7feb

Browse files
authored
Merge pull request #230 from sbs2001/curation_ui
Add UI for VulnerableCode
2 parents 4069abe + 1caad95 commit f5e7feb

38 files changed

Lines changed: 17529 additions & 8 deletions

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dj-database-url==0.4.2
1212
Django==3.0.7
1313
django-filter==2.2.0
1414
djangorestframework==3.11.0
15+
django-widget-tweaks==1.4.8
1516
gunicorn==19.7.1
1617
importlib-metadata==1.3.0
1718
ipython==7.13.0
@@ -35,6 +36,7 @@ pygit2==1.2.0
3536
Pygments==2.6.1
3637
pyparsing==2.4.5
3738
pytest==5.3.2
39+
django-widget-tweaks==1.4.8
3840
pytest-dependency==0.4.0
3941
pytest-django==3.7.0
4042
pytest-mock==1.13.0

vulnerabilities/forms.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) nexB Inc. and others. All rights reserved.
2+
# http://nexb.com and https://github.com/nexB/vulnerablecode/
3+
# The VulnerableCode software is licensed under the Apache License version 2.0.
4+
# Data generated with VulnerableCode require an acknowledgment.
5+
#
6+
# You may not use this software except in compliance with the License.
7+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software distributed
9+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
# specific language governing permissions and limitations under the License.
12+
#
13+
# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode
14+
# derivative work, you must accompany this data with the following acknowledgment:
15+
#
16+
# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
17+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
18+
# VulnerableCode should be considered or used as legal advice. Consult an Attorney
19+
# for any legal advice.
20+
# VulnerableCode is a free software tool from nexB Inc. and others.
21+
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
22+
23+
from django import forms
24+
25+
from vulnerabilities.models import Package, PackageRelatedVulnerability, Vulnerability
26+
27+
28+
def get_package_types():
29+
pkg_types = [(i.type, i.type) for i in Package.objects.distinct("type").all()]
30+
pkg_types.append((None, "package type"))
31+
return pkg_types
32+
33+
34+
def get_package_namespaces():
35+
pkg_namespaces = [
36+
(i.namespace, i.namespace)
37+
for i in Package.objects.distinct("namespace").all()
38+
if i.namespace
39+
]
40+
pkg_namespaces.append((None, "package namespace"))
41+
return pkg_namespaces
42+
43+
44+
class PackageForm(forms.Form):
45+
46+
type = forms.ChoiceField(choices=get_package_types)
47+
namespace = forms.ChoiceField(choices=get_package_namespaces, required=False)
48+
name = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "package name"}))
49+
version = forms.CharField(
50+
widget=forms.TextInput(attrs={"placeholder": "package version"}), required=False
51+
)
52+
53+
54+
class CVEForm(forms.Form):
55+
56+
cve_id = forms.CharField(widget=forms.TextInput(attrs={"placeholder": "vulnerability id"}))

vulnerabilities/lib_oval.py.ABOUT

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
about_resource: lib_oval.py
2+
version: 6aaae0
3+
download_url: https://raw.githubusercontent.com/CISecurity/OVALRepo/6aaae00876ec716927e0ae5b9ccfa12f310427a0/scripts/lib_oval.py
4+
5+
name: OVALRepo - lib_oval
6+
homepage_url: https://github.com/CISecurity/OVALRepo
7+
owner: Center for Internet Security
8+
author: Gunnar Engelbach <Gunnar.Engelbach@ThreatGuard.com>
9+
notes: This a single file extracted from OVALRepo that parses OVAL files.
10+
11+
license: bsd-new
12+
license_file: lib_oval.py.LICENSE
13+
14+
copyright: Copyright (c) 2010 United States Government. All Rights Reserved.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright© 2010 United States Government. All Rights Reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7+
Neither the name of the Center for Internet Security, Inc. (CIS) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER, CIS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, CIS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

vulnerabilities/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ class Vulnerability(models.Model):
4545
help_text='Summary of the vulnerability', blank=True)
4646
cvss = models.FloatField(max_length=100, help_text='CVSS Score', null=True)
4747

48+
@property
49+
def vulnerable_to(self):
50+
return self.packagerelatedvulnerability_set.filter(is_vulnerable=True)
51+
52+
@property
53+
def resolved_to(self):
54+
return self.packagerelatedvulnerability_set.filter(is_vulnerable=False)
55+
4856
def __str__(self):
4957
return self.cve_id or self.summary
5058

@@ -80,6 +88,14 @@ class Package(PackageURLMixin):
8088
vulnerabilities = models.ManyToManyField(
8189
to='Vulnerability', through='PackageRelatedVulnerability')
8290

91+
@property
92+
def vulnerable_to(self):
93+
return self.packagerelatedvulnerability_set.filter(is_vulnerable=True)
94+
95+
@property
96+
def resolved_to(self):
97+
return self.packagerelatedvulnerability_set.filter(is_vulnerable=False)
98+
8399
class Meta:
84100
unique_together = ('name', 'namespace', 'type',
85101
'version', 'qualifiers', 'subpath')

0 commit comments

Comments
 (0)