T09 · Insecure Skill Coding Practices
- Location
images_to_video.py:25- Finding
Predictable Temporary File Allows Symlink-Based File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
images_to_video.py, lines 25–30 and 54–56
Vulnerability Type: Unsafe predictable temporary file
Risk Level: Mediumpython # Create temporary file list file_list_path = Path('filelist.txt') with open(file_list_path, 'w') as f: for img in image_files: duration = 1.0 / fps f.write(f"file '{Path(img).absolute()}'\n") f.write(f"duration {duration}\n")python finally: # Clean up temp file if file_list_path.exists(): file_list_path.unlink()Technical Analysis
The script uses the fixed filename
filelist.txtin its current working directory and opens it using write-and-truncate semantics. It does not create the file atomically, verify that it is a regular file, reject symbolic links, or assign a unique name.A local attacker with write access to the working directory can pre-create
filelist.txtas a symbolic link to another file writable by the victim process. When the Skill runs,open(..., 'w')follows the link and truncates the linked target before writing the FFmpeg manifest. The cleanup operation may then unlink the symbolic link.Concurrent executions also use the same path. One process can overwrite or remove another process's manifest, causing unintended inputs, corrupted output, or failures.
Attack Path
- The attacker identifies a directory in which a more privileged user or service will execute the script.
- The attacker creates
filelist.txtas a symbolic link to a file writable by the victim process. - The victim invokes
images_to_video.pyfrom that directory. - The script follows the symbolic link when opening
filelist.txtwith truncation enabled. - The target file is truncated and replaced with FFmpeg manifest content.
- The script subsequently attempts to remove the predictable path during cleanup.
Impact Assessment
The vulnerability can overwrite ...[truncated 441 chars]
- Remediation
View remediation
Remediation Suggestions
- Create the manifest using
tempfile.NamedTemporaryFileortempfile.mkstempwith a unique, securely generated filename. - Place temporary files in a private temporary directory with restrictive permissions.
- Create files atomically and do not follow symbolic links where the platform supports
O_NOFOLLOW. - Verify that any existing path is a regular file owned by the current process before using or deleting it.
- Keep cleanup in a
finallyblock, but only remove the exact unique file created by the current invocation. - Avoid running the media conversion process with elevated privileges.
Example hardening pattern:
python import os import tempfile fd, manifest_path = tempfile.mkstemp( prefix="ffmpeg_concat_", suffix=".txt", text=True ) try: with os.fdopen(fd, "w", encoding="utf-8") as manifest: # Write validated entries. pass finally: Path(manifest_path).unlink(missing_ok=True)- Create the manifest using
