@@ -1519,7 +1519,9 @@ def public_upload_videoChunked():
15191519 blob = request .files .get ('blob' )
15201520 chunkPart = int (request .form .get ('chunkPart' ))
15211521 totalChunks = int (request .form .get ('totalChunks' ))
1522- checkSum = request .form .get ('checkSum' )
1522+ checkSum = re .sub (r'[^a-zA-Z0-9_-]' , '' , request .form .get ('checkSum' ))
1523+ if not checkSum :
1524+ return Response (status = 400 )
15231525 if not blob .filename or blob .filename .strip () == '' or blob .filename == 'blob' :
15241526 return Response (status = 400 )
15251527 filename = secure_filename (blob .filename )
@@ -1528,11 +1530,14 @@ def public_upload_videoChunked():
15281530 filetype = filename .split ('.' )[- 1 ] # TODO, probe filetype with fmpeg instead and remux to supporrted
15291531 if not filetype in SUPPORTED_FILE_TYPES :
15301532 return Response (status = 400 )
1531-
1533+
15321534 upload_directory = paths ['video' ] / upload_folder
15331535 if not os .path .exists (upload_directory ):
1534- os .makedirs (upload_directory )
1536+ os .makedirs (upload_directory )
15351537 tempPath = os .path .join (upload_directory , f"{ checkSum } .{ filetype } " )
1538+ # Guard against path traversal: ensure the resolved path stays within upload_directory
1539+ if not os .path .realpath (tempPath ).startswith (os .path .realpath (upload_directory ) + os .sep ):
1540+ return Response (status = 400 )
15361541 with open (tempPath , 'ab' ) as f :
15371542 f .write (blob .read ())
15381543 if chunkPart < totalChunks :
0 commit comments