T09 · Insecure Skill Coding Practices
- Location
scripts/process_video.py:29- Finding
Predictable Shared Temporary Paths Allow Local Symlink-Based File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/process_video.py:29-36, 62-63, 89
Vulnerability Type: Predictable temporary paths and unsafe file creation
Risk Level: MediumThe processor derives its temporary directory from the input video's basename and creates predictable segment and manifest filenames inside that directory.
python def process_multi_segment(input_video, output_video, segments, temp_dir): """ Process video with multiple delogo regions across different time segments. segments: list of (start_time, end_time, x, y, w, h) """ temp_dir = Path(temp_dir) temp_dir.mkdir(parents=True, exist_ok=True) # Process each segment seg_files = [] for i, (s, e, x, y, w, h) in enumerate(segments): seg_file = temp_dir / f'seg_{i+1}.mp4'The predictable concatenation manifest is written without checking whether it is a symbolic link:
python concat_file = temp_dir / 'concat.txt' concat_file.write_text('\n'.join(f"file '{f}'" for f in seg_files))The temporary directory itself is deterministically generated under globally shared
/tmp:python temp_dir = f"/tmp/watermark_proc_{Path(input_video).stem}"SKILL.md:19-21also documents predictable frame names in/tmp:bash for t in 1 2 3 4 5; do ffmpeg -y -ss 00:00:0$t -i "$INPUT" -frames:v 1 "/tmp/wm_frame_$t.jpg" 2>/dev/null doneTechnical Analysis
Temporary resources in a globally writable directory must be created with unpredictable names and exclusive ownership. Here, an attacker can determine the processing directory from the public input basename. The code accepts an already-existing directory through
mkdir(..., exist_ok=True)and does not verify its owner, permissions, or contents.Path.write_text()follows symbolic links when openingconcat.txt. The segment files are also passed to FFmpeg with-y, which aut ...[truncated 2242 chars]- Remediation
View remediation
Remediation Suggestions
-
Create a unique, private temporary directory using
tempfile.TemporaryDirectory()rather than deriving its name from user-controlled input:python import tempfile with tempfile.TemporaryDirectory(prefix="watermark_proc_") as temp_dir: ok = process_multi_segment( input_video, output_video, segments, temp_dir, ) -
Do not reuse an existing temporary directory. Ensure the directory is created atomically with permissions restricted to the current user.
-
Avoid predictable standalone files in
/tmp. Update the commands inSKILL.mdto create a private directory first, for example withmktemp -d, and place all frames inside it. -
Where files are created directly by Python, use exclusive creation and reject symbolic links. On supported platforms, use secure open flags such as
O_CREAT | O_EXCL | O_NOFOLLOW, then verify that the resulting file is a regular file owned by the current user. -
Before invoking FFmpeg, ensure each output path is inside the newly created private directory and does not already exist. Since only the current process can access a correctly permissioned private directory, this prevents another local user from pre-positioning links.
-
Remove temporary resources reliably after both successful and failed processing.
TemporaryDirectory()provides automatic cleanup when used as a context manager. -
Run video processing under a dedicated, unprivileged operating-system account with access limited to the required input, output, and private temporary locations. This limits impact if another file-handling defect is discovered.
-
