mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-20 15:32:32 +08:00
Use commonpath for path traversal check
Matches the pattern used in folder_paths.py and server.py. The startswith approach is vulnerable to sibling directory bypasses.
This commit is contained in:
parent
8088b347d0
commit
cf43a3a63e
@ -1453,7 +1453,9 @@ class LoadTrainingDataset(io.ComfyNode):
|
|||||||
output_dir = folder_paths.get_output_directory()
|
output_dir = folder_paths.get_output_directory()
|
||||||
dataset_dir = os.path.join(output_dir, folder_name)
|
dataset_dir = os.path.join(output_dir, folder_name)
|
||||||
# Prevent path traversal (e.g. folder_name="../../etc")
|
# Prevent path traversal (e.g. folder_name="../../etc")
|
||||||
if not os.path.realpath(dataset_dir).startswith(os.path.realpath(output_dir)):
|
real_output_dir = os.path.realpath(output_dir)
|
||||||
|
real_dataset_dir = os.path.realpath(dataset_dir)
|
||||||
|
if os.path.commonpath((real_output_dir, real_dataset_dir)) != real_output_dir:
|
||||||
raise ValueError(f"Invalid folder_name: path traversal detected")
|
raise ValueError(f"Invalid folder_name: path traversal detected")
|
||||||
|
|
||||||
if not os.path.exists(dataset_dir):
|
if not os.path.exists(dataset_dir):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user