Skip to content

Commit b8f5e53

Browse files
🐛 Remove unselected parsers from filters and test types (#13767)
* squashed commits * remove unittest * update * update * add unittest * update
1 parent 176d5e8 commit b8f5e53

File tree

7 files changed

+51
-16
lines changed

7 files changed

+51
-16
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
---
22
title: 'Upgrading to DefectDojo Version 2.54.x'
33
toc_hide: true
4-
weight: -20251201
5-
description: No special instructions.
4+
weight: -20250804
5+
description: Dropped support for DD_PARSER_EXCLUDE
66
---
7-
There are no special instructions for upgrading to 2.54.x. Check the [Release Notes](https://github.com/DefectDojo/django-DefectDojo/releases/tag/2.54.0) for the contents of the release.
7+
8+
To simplify the management of the DefectDojo application, parser exclusions are no longer controlled via the environment variable DD_PARSER_EXCLUDE or application settings. This variable is now unsupported.
9+
From now on, you should use the active flag in the Test_Type model to enable or disable parsers. Only parsers associated with active Test_Type entries will be available for use.
10+
11+
There are other instructions for upgrading to 2.54.x. Check the Release Notes for the contents of the release.

dojo/filters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
from dojo.risk_acceptance.queries import get_authorized_risk_acceptances
9494
from dojo.test.queries import get_authorized_tests
9595
from dojo.user.queries import get_authorized_users
96-
from dojo.utils import get_system_setting, is_finding_groups_enabled, truncate_timezone_aware
96+
from dojo.utils import get_system_setting, get_visible_scan_types, is_finding_groups_enabled, truncate_timezone_aware
9797

9898
logger = logging.getLogger(__name__)
9999

@@ -2030,6 +2030,9 @@ def __init__(self, *args, **kwargs):
20302030
# Don't show the product filter on the product finding view
20312031
self.set_related_object_fields(*args, **kwargs)
20322032

2033+
if "test__test_type" in self.form.fields:
2034+
self.form.fields["test__test_type"].queryset = get_visible_scan_types()
2035+
20332036
def set_related_object_fields(self, *args: list, **kwargs: dict):
20342037
finding_group_query = Finding_Group.objects.all()
20352038
if self.pid is not None:

dojo/finding/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
get_page_items_and_count,
119119
get_return_url,
120120
get_system_setting,
121+
get_visible_scan_types,
121122
get_words_for_field,
122123
match_finding_to_existing_findings,
123124
process_tag_notifications,
@@ -302,6 +303,7 @@ def get_initial_context(self, request: HttpRequest):
302303
"enable_table_filtering": get_system_setting("enable_ui_table_based_searching"),
303304
"title_words": get_words_for_field(Finding, "title"),
304305
"component_words": get_words_for_field(Finding, "component_name"),
306+
"visible_test_types": get_visible_scan_types(),
305307
}
306308
# Look to see if the product was used
307309
if product_id := self.get_product_id():

dojo/settings/settings.dist.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@
275275
# regular expression to exclude one or more parsers
276276
# could be usefull to limit parser allowed
277277
# AWS Scout2 Scan Parser is deprecated (see https://github.com/DefectDojo/django-DefectDojo/pull/5268)
278-
DD_PARSER_EXCLUDE=(str, ""),
279278
# when enabled in sytem settings, every minute a job run to delete excess duplicates
280279
# we limit the amount of duplicates that can be deleted in a single run of that job
281280
# to prevent overlapping runs of that job from occurrring
@@ -1853,9 +1852,6 @@ def saml2_attrib_map_format(din):
18531852
# If using this, lines for Qualys WAS deduplication functions must be un-commented
18541853
QUALYS_WAS_UNIQUE_ID = False
18551854

1856-
# exclusion list for parsers
1857-
PARSER_EXCLUDE = env("DD_PARSER_EXCLUDE")
1858-
18591855
SERIALIZATION_MODULES = {
18601856
"xml": "tagulous.serializers.xml_serializer",
18611857
"json": "tagulous.serializers.json",

dojo/tools/factory.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from inspect import isclass
77
from pathlib import Path
88

9-
from django.conf import settings
10-
119
from dojo.models import Test_Type, Tool_Configuration, Tool_Type
1210

1311
PARSERS = {}
@@ -37,12 +35,12 @@ def get_parser(scan_type):
3735
if scan_type not in PARSERS:
3836
msg = f"Parser '{scan_type}' does not exist"
3937
raise ValueError(msg)
40-
rg = re.compile(settings.PARSER_EXCLUDE)
41-
if not rg.match(scan_type) or not settings.PARSER_EXCLUDE.strip():
42-
# update DB dynamically
43-
test_type, _ = Test_Type.objects.get_or_create(name=scan_type)
44-
if test_type.active:
45-
return PARSERS[scan_type]
38+
39+
# update DB dynamically
40+
test_type, _ = Test_Type.objects.get_or_create(name=scan_type)
41+
if test_type.active:
42+
return PARSERS[scan_type]
43+
4644
msg = f"Parser {scan_type} is not active"
4745
raise ValueError(msg)
4846

dojo/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
Product,
6969
System_Settings,
7070
Test,
71+
Test_Type,
7172
User,
7273
)
7374
from dojo.notifications.helper import create_notification
@@ -83,6 +84,11 @@
8384
"""
8485

8586

87+
def get_visible_scan_types():
88+
"""Returns a QuerySet of active Test_Type objects."""
89+
return Test_Type.objects.filter(active=True)
90+
91+
8692
def do_false_positive_history(finding, *args, **kwargs):
8793
"""
8894
Replicate false positives across product.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
from django.test import TestCase
3+
4+
from dojo.filters import FindingFilter
5+
from dojo.models import Test_Type
6+
from dojo.utils import get_visible_scan_types
7+
8+
9+
class TestFindingFilterActiveInactiveTestTypes(TestCase):
10+
def setUp(self):
11+
self.active_type = Test_Type.objects.create(name="Nessus Scan", active=True)
12+
self.inactive_type = Test_Type.objects.create(name="Burp Scan", active=False)
13+
14+
def test_only_active_types_in_filter(self):
15+
filter_instance = FindingFilter(data={})
16+
self.assertIn("test__test_type", filter_instance.form.fields)
17+
queryset = filter_instance.form.fields["test__test_type"].queryset
18+
actual_names = set(queryset.values_list("name", flat=True))
19+
self.assertIn(self.active_type.name, actual_names)
20+
self.assertNotIn(self.inactive_type.name, actual_names)
21+
22+
def test_helper_function_returns_only_active(self):
23+
visible = get_visible_scan_types()
24+
names = set(visible.values_list("name", flat=True))
25+
self.assertIn(self.active_type.name, names)
26+
self.assertNotIn(self.inactive_type.name, names)

0 commit comments

Comments
 (0)