Summary
A path traversal vulnerability in ComfyUI dataset save nodes allows crafted workflows to use attacker-controlled folder names to write files outside the intended output directory. If an attacker can get a victim or exposed instance to load such a workflow, the written files may alter startup components and enable code execution.
Affected context
The issue occurs in ComfyUI deployments that use affected dataset save nodes and accept workflows containing attacker-controlled folder_name values. Risk increases when the process has write access beyond its designated output directory or when startup scripts, package initializers, or other executable application files are writable.
Exploit preconditions
- Attack surface: ComfyUI workflow loading and dataset save nodes
- Required access: Ability to submit, import, or cause a user to load a crafted workflow
- Trigger point: Processing a dataset save node with an untrusted folder_name value
- Why exploitation is possible: The folder name is not sufficiently constrained to the intended output directory, allowing path traversal and attacker-controlled file placement
Why this happens
The vulnerability results from treating a user-controlled folder_name value as a filesystem path without enforcing a trusted directory boundary. This insecure path construction pattern permits traversal sequences or equivalent path representations to escape the intended output location. The behavior maps to CWE-22, Improper Limitation of a Pathname to a Restricted Directory, and may become especially serious when the process can overwrite files that are later executed or imported.
Potential impact
- Attackers may write arbitrary content to accessible filesystem locations.
- Application startup behavior may be altered.
- Python package initializers or related files could be modified and executed.
- The ComfyUI process or host may be compromised.
- Stored data, configuration, or workflows may be tampered with.
General mitigation guidance
Mitigation generally focuses on enforcing a strict filesystem trust boundary
for every dataset output path.
Common defensive patterns include:
- Resolve candidate paths and verify that they remain beneath an approved output directory.
- Reject traversal components, absolute paths, alternate separators, and other ambiguous path forms.
- Prefer generated identifiers or controlled path components over user-supplied directory names.
- Apply allowlists and strict schema validation before performing filesystem operations.
- Run the application with least-privilege filesystem permissions and isolate writable data from executable code.
- Use read-only mounts for application code, startup files, and package metadata where practical.
- Treat imported workflows as untrusted content and require explicit review or approval before execution.
How teams detect issues like this
Detection approaches may include:
- Static analysis for path joins or file writes that incorporate workflow-controlled values without canonicalization and boundary checks.
- Code review of dataset and export nodes for absolute paths, traversal sequences, separator normalization gaps, and symlink handling.
- Runtime logging of resolved output paths, rejected path values, and writes outside approved directories.
- Filesystem monitoring for unexpected changes to startup scripts, package initializers, configuration files, or source code.
- Policy enforcement that restricts application write access to dedicated data directories.
- Automated security review tools can help identify unsafe path construction patterns in pull requests.

