Can a filename_prefix with .., an absolute path or a symlink make ComfyUI write outside the output directory?
Problem. Prefixes are user or agent text and could carry path-traversal sequences. Conditions. Core get_save_image_path at fb3befd. Method. After normalising the prefix, the code joins output_dir with the subfolder and calls is_within_directory, which resolves both paths with realpath and compares them with commonpath; if the folder is outside, it logs an error and raises, so the save fails and no file is written. Because realpath is used, a symlink inside the output directory that points elsewhere is also rejected at this check. Only the directory part is checked: the stem is the basename, so it cannot contain separators. An absolute prefix or '../' therefore should fail the check (inference from the code; not executed). Failure modes. The error aborts the node, so a pipeline that interpolates untrusted strings into the prefix gets a failed run rather than a rewritten path; sanitise first. The check happens at path computation, not at file open, so a symlink swapped in between chec...
Structured fields
{
"citations": [
{
"url": "https://raw.githubusercontent.com/comfyanonymous/ComfyUI/fb3befd168731438f88bc96e0920a538e8649878/folder_paths.py",
"note": "get_save_image_path; get_save_image_path; is_within_directory docstring; researcher reasoning"
}
]
}Evidence claims
- [sourced_fact] Problem. Prefixes are user or agent text and could carry path-traversal sequences. Conditions. Core get_save_image_path at fb3befd. Method. After normalising the prefix, the code joins output_dir with the subfolder and calls is_within_directory, which resolves both paths with realpath and compares them with commonpath; if the folder is outside, it logs an error and raises, so the save fails and no file is written. Because realpath is used, a symlink inside the output directory that points elsewhere is also rejected at this check. Only the directory part is checked: the stem is the basename, so it cannot contain separators. An absolute prefix or '../' therefore should fail the check (inference from the code; not executed). Failure modes. The error aborts the node, so a pipeline that interpolates untrusted strings into the prefix gets a failed run rather than a rewritten path; sanitise first. The check happens at path computation, not at file open, so a symlink swapped in between check and write is a theoretical race (inference). Limitations. Covers SaveImage and nodes calling the helper; custom nodes may bypass it. Version/date. fb3befd, fetched 2026-10-24. · locator: get_save_image_path; get_save_image_path; is_within_directory docstring; researcher reasoning source
Rights
| component | license | hosting | redistribution | modification | training | Evidence and notes |
|---|---|---|---|---|---|---|
| documentation | unknown | permitted | permitted | unknown | unknown | Applies to this original summary only, not to the cited sources. |