mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-12 18:03:35 +08:00
Merge a476e4c5e524d3f2a99e697f08d114c0794ea84f into 532938b16b544e4492ba0ffbe18b201b1a7bc55f
This commit is contained in:
commit
9854a5d1a6
@ -65,7 +65,7 @@ class UserManager():
|
||||
|
||||
return user
|
||||
|
||||
def get_request_user_filepath(self, request, file, type="userdata", create_dir=True):
|
||||
def get_request_user_filepath(self, request, target, type="userdata", create_dir=True, target_is_file=True):
|
||||
user_directory = folder_paths.get_user_directory()
|
||||
|
||||
if type == "userdata":
|
||||
@ -80,20 +80,23 @@ class UserManager():
|
||||
if os.path.commonpath((root_dir, user_root)) != root_dir:
|
||||
return None
|
||||
|
||||
if file is not None:
|
||||
if target is not None:
|
||||
# Check if filename is url encoded
|
||||
if "%" in file:
|
||||
file = parse.unquote(file)
|
||||
if "%" in target:
|
||||
target = parse.unquote(target)
|
||||
|
||||
# prevent leaving /{type}/{user}
|
||||
path = os.path.abspath(os.path.join(user_root, file))
|
||||
path = os.path.abspath(os.path.join(user_root, target))
|
||||
if os.path.commonpath((user_root, path)) != user_root:
|
||||
return None
|
||||
|
||||
parent = os.path.split(path)[0]
|
||||
if target_is_file:
|
||||
dir_path = os.path.dirname(path)
|
||||
else:
|
||||
dir_path = path
|
||||
|
||||
if create_dir and not os.path.exists(parent):
|
||||
os.makedirs(parent, exist_ok=True)
|
||||
if create_dir and not os.path.exists(dir_path):
|
||||
os.makedirs(dir_path, exist_ok=True)
|
||||
|
||||
return path
|
||||
|
||||
@ -164,7 +167,7 @@ class UserManager():
|
||||
if not directory:
|
||||
return web.Response(status=400, text="Directory not provided")
|
||||
|
||||
path = self.get_request_user_filepath(request, directory)
|
||||
path = self.get_request_user_filepath(request, directory, target_is_file=False)
|
||||
if not path:
|
||||
return web.Response(status=403, text="Invalid directory")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user