Skip to content

Commit

Permalink
initial files but likely to change
Browse files Browse the repository at this point in the history
  • Loading branch information
hblankenship committed Nov 1, 2024
1 parent abb7735 commit c575dee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dojo/importers/base_importer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import logging
from pathlib import Path
from typing import List, Tuple

from django.conf import settings
Expand Down Expand Up @@ -686,6 +687,21 @@ def process_files(
for unsaved_file in finding.unsaved_files:
data = base64.b64decode(unsaved_file.get("data"))
title = unsaved_file.get("title", "<No title>")
valid_extensions = settings.FILE_UPLOAD_TYPES

if Path(title).suffix not in valid_extensions:
if accepted_extensions := f"{', '.join(valid_extensions)}":
msg = (
"Unsupported extension. Supported extensions are as "
f"follows: {accepted_extensions}"
)
else:
msg = (
"File uploads are prohibited due to the list of acceptable "
"file extensions being empty"
)
raise ValidationError(msg)

file_upload, _ = FileUpload.objects.get_or_create(title=title)
file_upload.file.save(title, ContentFile(data))
file_upload.save()
Expand Down
16 changes: 16 additions & 0 deletions unittests/scans/generic/test_with_image_no_ext.json

Large diffs are not rendered by default.

0 comments on commit c575dee

Please sign in to comment.