File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -346,15 +346,18 @@ def download(dir):
346346 abort (400 , description = "Directory traversal attempt detected" )
347347
348348 dirname = secure_filename (dir ) + "/" + secure_filename (sub_folder )
349- directory_name = os .path .abspath (os .path .join (concore_path , dirname ))
349+ concore_real = os .path .realpath (concore_path )
350+ directory_name = os .path .realpath (os .path .join (concore_real , dirname ))
351+ if not directory_name .startswith (concore_real + os .sep ):
352+ abort (403 , description = "Access denied" )
350353 if not os .path .exists (directory_name ):
351354 resp = jsonify ({'message' : 'Directory not found' })
352355 resp .status_code = 400
353356 return resp
354357
355- # Ensure final resolved path is within the intended directory
356- full_path = os .path .abspath (os .path .join (directory_name , safe_path ))
357- if not full_path .startswith (os . path . abspath ( directory_name ) + os .sep ):
358+ # Ensure final resolved path is within the intended directory, resolving symlinks
359+ full_path = os .path .realpath (os .path .join (directory_name , safe_path ))
360+ if not full_path .startswith (directory_name + os .sep ):
358361 abort (403 , description = "Access denied" )
359362
360363 try :
You can’t perform that action at this time.
0 commit comments