Skip to content

Commit 0756c7a

Browse files
authored
feat(form-import): DRY File Extension (#13066)
1 parent 90efc0f commit 0756c7a

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

dojo/forms.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,7 @@ class ImportScanForm(forms.Form):
549549
tags = TagField(required=False, help_text="Add tags that help describe this scan. "
550550
"Choose from the list or add new tags. Press Enter key to add.")
551551
file = forms.FileField(
552-
widget=forms.widgets.FileInput(
553-
attrs={"accept": ".xml, .csv, .nessus, .json, .jsonl, .html, .js, .zip, .xlsx, .txt, .sarif"},
554-
),
552+
widget=forms.widgets.FileInput(attrs={"accept": ", ".join(settings.FILE_IMPORT_TYPES)}),
555553
label="Choose report file",
556554
allow_empty_file=True,
557555
required=False,
@@ -674,9 +672,7 @@ class ReImportScanForm(forms.Form):
674672
tags = TagField(required=False, help_text="Modify existing tags that help describe this scan. "
675673
"Choose from the list or add new tags. Press Enter key to add.")
676674
file = forms.FileField(
677-
widget=forms.widgets.FileInput(
678-
attrs={"accept": ".xml, .csv, .nessus, .json, .jsonl, .html, .js, .zip, .xlsx, .txt, .sarif, .fpr, .md, .log, .fvdl"},
679-
),
675+
widget=forms.widgets.FileInput(attrs={"accept": ", ".join(settings.FILE_IMPORT_TYPES)}),
680676
label="Choose report file",
681677
allow_empty_file=True,
682678
required=False,

dojo/settings/settings.dist.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@
286286
# List of acceptable file types that can be uploaded to a given object via arbitrary file upload
287287
DD_FILE_UPLOAD_TYPES=(list, [".txt", ".pdf", ".json", ".xml", ".csv", ".yml", ".png", ".jpeg",
288288
".sarif", ".xlsx", ".doc", ".html", ".js", ".nessus", ".zip", ".fpr"]),
289+
# List of acceptable file types that can be (re)imported
290+
DD_FILE_IMPORT_TYPES=(list, [".xml", ".csv", ".nessus", ".json", ".jsonl", ".html", ".js", ".zip",
291+
".xlsx", ".txt", ".sarif", ".fpr", ".md", ".log", ".fvdl"]),
289292
# Max file size for scan added via API in MB
290293
DD_SCAN_FILE_MAX_SIZE=(int, 100),
291294
# When disabled, existing user tokens will not be removed but it will not be
@@ -1877,6 +1880,8 @@ def saml2_attrib_map_format(din):
18771880
}
18781881
# List of acceptable file types that can be uploaded to a given object via arbitrary file upload
18791882
FILE_UPLOAD_TYPES = env("DD_FILE_UPLOAD_TYPES")
1883+
# List of acceptable file types that can be (re)imported
1884+
FILE_IMPORT_TYPES = env("DD_FILE_IMPORT_TYPES")
18801885
# Fixes error
18811886
# AttributeError: Problem installing fixture '/app/dojo/fixtures/defect_dojo_sample_data.json': 'Settings' object has no attribute 'AUDITLOG_DISABLE_ON_RAW_SAVE'
18821887
AUDITLOG_DISABLE_ON_RAW_SAVE = False

dojo/validators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from collections.abc import Callable
44

55
from cvss import CVSS2, CVSS3, CVSS4
6+
from django.conf import settings
67
from django.core.exceptions import ValidationError
78
from django.core.validators import FileExtensionValidator
89

@@ -102,7 +103,7 @@ def cvss4_validator(value: str | list[str], exception_class: Callable = Validati
102103

103104

104105
class ImporterFileExtensionValidator(FileExtensionValidator):
105-
default_allowed_extensions = ["xml", "csv", "nessus", "json", "jsonl", "html", "js", "zip", "xlsx", "txt", "sarif", "fpr", "md", "log", "fvdl"]
106+
default_allowed_extensions = [ext[1:] for ext in settings.FILE_IMPORT_TYPES]
106107

107108
def __init__(self, *args: list, **kwargs: dict):
108109
if "allowed_extensions" not in kwargs:

0 commit comments

Comments
 (0)