Skip to content

Commit 6978806

Browse files
MaffoochMaffooch
andauthored
Fix endpoint_status bug for ad-hoc findings (#3147)
* Fix endpoint_status bug for ad-hoc findings * Fix Flake8 Co-authored-by: Maffooch <[email protected]>
1 parent b779a74 commit 6978806

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

dojo/filters.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ class ComponentFilter(ProductComponentFilter):
297297
queryset=Product_Type.objects.all().order_by('name'),
298298
label="Product Type")
299299

300+
300301
class EngagementFilter(DojoFilter):
301302
engagement__lead = ModelChoiceFilter(
302303
queryset=User.objects.filter(
@@ -536,7 +537,7 @@ class ApiFindingFilter(DojoFilter):
536537
class Meta:
537538
model = Finding
538539
exclude = ['url', 'is_template', 'thread_id', 'notes', 'images',
539-
'sourcefile', 'line']
540+
'sourcefile', 'line', 'endpoint_status']
540541

541542

542543
class OpenFindingFilter(DojoFilter):
@@ -589,7 +590,7 @@ class Meta:
589590
'endpoint', 'references', 'test', 'is_template',
590591
'thread_id', 'notes', 'scanner_confidence', 'mitigated',
591592
'numerical_severity', 'reporter', 'last_reviewed', 'line',
592-
'duplicate_finding', 'hash_code', 'images',
593+
'duplicate_finding', 'hash_code', 'images', 'endpoint_status',
593594
'line_number', 'reviewers', 'mitigated_by', 'sourcefile', 'jira_creation', 'jira_change', 'created']
594595

595596
def __init__(self, *args, **kwargs):
@@ -687,7 +688,7 @@ class Meta:
687688
'endpoint', 'references', 'test', 'is_template',
688689
'active', 'verified', 'out_of_scope', 'false_p',
689690
'duplicate', 'thread_id', 'date', 'notes',
690-
'numerical_severity', 'reporter', 'endpoints',
691+
'numerical_severity', 'reporter', 'endpoints', 'endpoint_status',
691692
'last_reviewed', 'review_requested_by', 'defect_review_requested_by',
692693
'last_reviewed_by', 'created', 'jira_creation', 'jira_change']
693694

@@ -754,7 +755,7 @@ class Meta:
754755
'endpoint', 'references', 'test', 'is_template',
755756
'active', 'verified', 'out_of_scope', 'false_p',
756757
'duplicate', 'thread_id', 'mitigated', 'notes',
757-
'numerical_severity', 'reporter', 'endpoints',
758+
'numerical_severity', 'reporter', 'endpoints', 'endpoint_status',
758759
'last_reviewed', 'o', 'jira_creation', 'jira_change']
759760

760761
def __init__(self, *args, **kwargs):
@@ -815,7 +816,7 @@ class Meta:
815816
'endpoint', 'references', 'test', 'is_template',
816817
'active', 'verified', 'out_of_scope', 'false_p',
817818
'duplicate_finding', 'thread_id', 'mitigated', 'notes',
818-
'numerical_severity', 'reporter', 'endpoints',
819+
'numerical_severity', 'reporter', 'endpoints', 'endpoint_status',
819820
'last_reviewed', 'jira_creation', 'jira_change']
820821

821822
def __init__(self, *args, **kwargs):
@@ -1052,6 +1053,7 @@ class Meta:
10521053
'last_reviewed_by',
10531054
'images',
10541055
'endpoints',
1056+
'endpoint_status',
10551057
'is_template',
10561058
'jira_creation',
10571059
'jira_change']
@@ -1123,6 +1125,7 @@ class Meta:
11231125
'last_reviewed_by',
11241126
'images',
11251127
'endpoints',
1128+
'endpoint_status',
11261129
'is_template',
11271130
'jira_creation',
11281131
'jira_change']
@@ -1215,7 +1218,7 @@ class Meta:
12151218
model = Finding
12161219
exclude = ['date', 'cwe', 'url', 'description', 'mitigation', 'impact',
12171220
'endpoint', 'references', 'test', 'is_template',
1218-
'thread_id', 'notes', 'endpoints',
1221+
'thread_id', 'notes', 'endpoints', 'endpoint_status',
12191222
'numerical_severity', 'reporter', 'last_reviewed', 'images', 'jira_creation', 'jira_change']
12201223

12211224

@@ -1264,7 +1267,7 @@ class Meta:
12641267
model = Finding
12651268
exclude = ['date', 'cwe', 'url', 'description', 'mitigation', 'impact',
12661269
'endpoint', 'references', 'test', 'is_template',
1267-
'thread_id', 'notes', 'endpoints',
1270+
'thread_id', 'notes', 'endpoints', 'endpoint_status',
12681271
'numerical_severity', 'reporter', 'last_reviewed', 'jira_creation', 'jira_change']
12691272

12701273

dojo/test/views.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,14 @@ def add_findings(request, tid):
360360
# always false now since this will be deprecated soon in favor of new Finding_Template model
361361
new_finding.is_template = False
362362
new_finding.save(dedupe_option=False, push_to_jira=False)
363-
new_finding.endpoints.set(form.cleaned_data['endpoints'])
363+
for ep in form.cleaned_data['endpoints']:
364+
eps, created = Endpoint_Status.objects.get_or_create(
365+
finding=new_finding,
366+
endpoint=ep)
367+
ep.endpoint_status.add(eps)
368+
369+
new_finding.endpoints.add(ep)
370+
new_finding.endpoint_status.add(eps)
364371

365372
# Push to jira?
366373
push_to_jira = False
@@ -514,7 +521,14 @@ def add_temp_finding(request, tid, fid):
514521
# no further action needed here since this is already adding from template.
515522
new_finding.is_template = False
516523
new_finding.save(dedupe_option=False, false_history=False)
517-
new_finding.endpoints.set(form.cleaned_data['endpoints'])
524+
for ep in form.cleaned_data['endpoints']:
525+
eps, created = Endpoint_Status.objects.get_or_create(
526+
finding=new_finding,
527+
endpoint=ep)
528+
ep.endpoint_status.add(eps)
529+
530+
new_finding.endpoints.add(ep)
531+
new_finding.endpoint_status.add(eps)
518532
new_finding.save(false_history=True)
519533
tags = request.POST.getlist('tags')
520534
t = ", ".join('"{0}"'.format(w) for w in tags)

0 commit comments

Comments
 (0)