T09 · Insecure Skill Coding Practices
- Location
video_editor_auto_v4.6.py:569- Finding
User-Controlled Recursive Directory Deletion During Batch Cleanup
- Content
View full analysis
Vulnerability Details
File Location:
video_editor_auto_v4.6.py:569andvideo_editor_auto_v4.6.py:606-611
Vulnerability Type: Unrestricted recursive deletion of a user-controlled path
Risk Level: HighVulnerable Code
python # Phase 4: Clean intermediate files (individual clips + temp audio) for c in clips: if os.path.exists(c.clip_path): os.remove(c.clip_path) if os.path.exists(work_dir): shutil.rmtree(work_dir, ignore_errors=True)The directory is obtained directly from a command-line argument:
python if len(sys.argv) >= 2 and os.path.isdir(sys.argv[1]): input_dir = sys.argv[1] output_dir = sys.argv[2] if len(sys.argv) > 2 else "./output" work_dir = sys.argv[3] if len(sys.argv) > 3 else "./video_work" os.makedirs(output_dir, exist_ok=True) os.makedirs(work_dir, exist_ok=True) process_batch(input_dir, output_dir, work_dir)Technical Analysis
In batch mode, the third command-line argument directly determines
work_dir. After successful processing and concatenation, the application passes this path toshutil.rmtree()without verifying that it is a temporary directory created by the application.The code does not canonicalize the path, check whether it is the input or output directory, reject sensitive locations, verify directory ownership, detect symlink-based redirection, or require an application-specific marker. The initial
os.makedirs(work_dir, exist_ok=True)does not establish that the directory is safe to delete because an existing arbitrary directory is accepted.This is particularly dangerous because
shutil.rmtree()recursively removes the directory and its contents. The use ofignore_errors=Truealso suppresses cleanup errors, reducing visibility into partial destructive operations.Attack Path
- An attacker provides or recommends a batch-processing command with a sensitive writable directory as t ...[truncated 1093 chars]
- Remediation
View remediation
Remediation Suggestions
- Create the working directory internally with
tempfile.mkdtemp()ortempfile.TemporaryDirectory()rather than accepting an arbitrary cleanup target. - Retain the canonical path returned by the temporary-directory API and delete only that exact generated directory.
- Resolve paths with
os.path.realpath()orpathlib.Path.resolve()before validation and deletion. - Explicitly reject the filesystem root, user home directory, current working directory, input directory, output directory, and their parent directories.
- Ensure the cleanup target is located beneath a dedicated application-controlled temporary root.
- Refuse symlink cleanup targets and check that no path component redirects outside the expected temporary root.
- Consider deleting only the known files generated during the current run instead of recursively deleting an entire caller-selected directory.
- Remove
ignore_errors=True, handle expected errors explicitly, and report cleanup failures to the user. - If a custom work directory remains supported, create a unique child directory inside it and delete only that child directory.
- Create the working directory internally with
