Skip to content

Commit 3457f62

Browse files
authored
Merge pull request #285 from CybercentreCanada/hotfix/ingest_classification
Validate file classification during ingest
2 parents e0b7025 + 07c9b44 commit 3457f62

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

assemblyline_ui/api/v4/ingest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from assemblyline.common.dict_utils import flatten
99
from assemblyline.common.str_utils import safe_str
1010
from assemblyline_ui.api.base import api_login, make_api_response, make_subapi_blueprint
11-
from assemblyline_ui.config import TEMP_SUBMIT_DIR, STORAGE, config
11+
from assemblyline_ui.config import CLASSIFICATION, TEMP_SUBMIT_DIR, STORAGE, config
1212
from assemblyline_ui.helper.service import ui_to_submission_params
1313
from assemblyline_ui.helper.submission import safe_download, FileTooBigException, InvalidUrlException, \
1414
ForbiddenLocation, submission_received
@@ -243,7 +243,7 @@ def ingest_single_file(**kwargs):
243243
binary.save(out_file)
244244

245245
if os.path.getsize(out_file) == 0:
246-
return make_api_response("", err="File empty. Ingestion failed", status_code=400)
246+
return make_api_response({}, err="File empty. Ingestion failed", status_code=400)
247247

248248
# Load default user params
249249
s_params = ui_to_submission_params(load_user_settings(user))
@@ -284,9 +284,9 @@ def ingest_single_file(**kwargs):
284284
# Validate file size
285285
if fileinfo['size'] > MAX_SIZE and not s_params.get('ignore_size', False):
286286
msg = f"File too large ({fileinfo['size']} > {MAX_SIZE}). Ingestion failed"
287-
return make_api_response("", err=msg, status_code=413)
287+
return make_api_response({}, err=msg, status_code=413)
288288
elif fileinfo['size'] == 0:
289-
return make_api_response("", err="File empty. Ingestion failed", status_code=400)
289+
return make_api_response({}, err="File empty. Ingestion failed", status_code=400)
290290

291291
# Decode cart if needed
292292
extracted_path, fileinfo, al_meta = decode_file(out_file, fileinfo)
@@ -297,6 +297,11 @@ def ingest_single_file(**kwargs):
297297
s_params['classification'] = al_meta.pop('classification', s_params['classification'])
298298
name = al_meta.pop('name', name)
299299

300+
# Validate ingest classification
301+
if not CLASSIFICATION.is_accessible(user['classification'], s_params['classification']):
302+
return make_api_response({}, "You cannot start a submission with higher "
303+
"classification then you're allowed to see", 400)
304+
300305
# Save the file to the filestore if needs be
301306
sha256 = fileinfo['sha256']
302307
if not f_transport.exists(sha256):
@@ -338,7 +343,7 @@ def ingest_single_file(**kwargs):
338343
"params": s_params
339344
})
340345
except (ValueError, KeyError) as e:
341-
return make_api_response("", err=str(e), status_code=400)
346+
return make_api_response({}, err=str(e), status_code=400)
342347

343348
# Send submission object for processing
344349
ingest.push(submission_obj.as_primitives())

0 commit comments

Comments
 (0)