Skip to content

Commit 24a919b

Browse files
committed
fix test , remove empty lines
Signed-off-by: ziadhany <ziadhany2016@gmail.com> add CWE for the new UI Signed-off-by: ziadhany <ziadhany2016@gmail.com>
1 parent 377826e commit 24a919b

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ yarl==1.7.2
114114
zipp==3.8.0
115115
dateparser==1.1.1
116116
fetchcode==0.1.0
117+
cwe==1.6

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ install_requires =
7878
defusedxml>=0.7.1
7979
Markdown>=3.3.0
8080
dateparser>=1.1.1
81+
cwe>=1.6
8182

8283
# networking
8384
GitPython>=3.1.17
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 4.0.7 on 2022-09-10 22:10
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('vulnerabilities', '0027_alter_vulnerabilityreference_url'),
10+
]
11+
12+
operations = [
13+
migrations.AlterUniqueTogether(
14+
name='vulnerabilityseverity',
15+
unique_together=set(),
16+
),
17+
migrations.AddField(
18+
model_name='vulnerabilityseverity',
19+
name='cwe_ids',
20+
field=models.JSONField(blank=True, default=list, help_text="Example: ['CWE-327']"),
21+
),
22+
migrations.AlterUniqueTogether(
23+
name='vulnerabilityseverity',
24+
unique_together={('reference', 'scoring_system', 'value', 'cwe_ids')},
25+
),
26+
]

vulnerabilities/models.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import logging
1313
from contextlib import suppress
1414

15+
from cwe import Database
1516
from django.conf import settings
1617
from django.core.exceptions import ValidationError
1718
from django.core.validators import MaxValueValidator
@@ -371,8 +372,20 @@ class VulnerabilitySeverity(models.Model):
371372

372373
value = models.CharField(max_length=50, help_text="Example: 9.0, Important, High")
373374

375+
cwe_ids = models.JSONField(blank=True, default=list, help_text="Example: ['CWE-327']")
376+
377+
@property
378+
def cwe_details(self):
379+
details = []
380+
for cwe_id in self.cwe_ids:
381+
cid = int(cwe_id.split("-")[1])
382+
db = Database()
383+
weakness = db.get(cid)
384+
details.append(weakness.to_dict())
385+
return details
386+
374387
class Meta:
375-
unique_together = ["reference", "scoring_system", "value"]
388+
unique_together = ["reference", "scoring_system", "value", "cwe_ids"]
376389
ordering = ["reference", "scoring_system", "value"]
377390

378391

vulnerabilities/templates/vulnerability_details.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,36 @@
119119
</table>
120120
</div>
121121

122+
<div class="has-text-weight-bold tab-nested-div ml-1 mb-1 mt-6">
123+
Weakness
124+
</div>
125+
<div class="tab-nested-div">
126+
<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth gray-header-border">
127+
<tr>
128+
<th> CWE id </th>
129+
<th> URL </th>
130+
</tr>
131+
{% for severity in severities %}
132+
{% for cwe_detail in severity.cwe_details %}
133+
<tr>
134+
<td>CWE-{{ cwe_detail.cwe_id }}</td>
135+
<td>
136+
<a href="https://cwe.mitre.org/data/definitions/{{ cwe_detail.cwe_id }}.html" target="_blank"
137+
title="CWE-{{ cwe_detail.cwe_id }} : description: {{cwe_detail.description}}">
138+
https://cwe.mitre.org/data/definitions/{{ cwe_detail.cwe_id }}.html<i class="fa fa-external-link fa_link_custom"></i></a>
139+
</td>
140+
</tr>
141+
{% empty %}
142+
<tr>
143+
<td colspan="3">
144+
There are no known CWEs.
145+
</td>
146+
</tr>
147+
{% endfor %}
148+
{% endfor %}
149+
150+
</table>
151+
</div>
122152

123153
<div class="has-text-weight-bold tab-nested-div ml-1 mb-1 mt-6">
124154
Fixed by packages ({{ vulnerability.resolved_to.all|length }})

0 commit comments

Comments
 (0)