T09 · Insecure Skill Coding Practices
- Location
subtitle-extractor.py:425- Finding
Predictable and Persistent Temporary Files
- Content
View full analysis
Vulnerability Details
File Location:
subtitle-extractor.py:425-450,subtitle-extractor.py:479-480, andsubtitle-extractor.py:540-541
Vulnerability Type: Predictable temporary-file creation and sensitive-data retention
Risk Level: MediumVulnerable Code
python pid = os.getpid() audio_template = str(Path(tempfile.gettempdir()) / f'video-summary-audio-{pid}.%(ext)s') cmd = ['yt-dlp'] if cookie_file: cmd += ['--cookies', cookie_file] cmd += ['-x', '--audio-format', 'mp3', '-o', audio_template, url] result = subprocess.run( cmd, stdout=subprocess.PIPE, stderr=sys.stderr, encoding='utf-8', errors='replace' ) audio_files = list(Path(tempfile.gettempdir()).glob(f'video-summary-audio-{pid}.*'))python sub_path = Path(tempfile.gettempdir()) / f'video-summary-{os.getpid()}.srt' sub_path.write_text(srt, encoding='utf-8')python sub_path = Path(tempfile.gettempdir()) / f'video-summary-{os.getpid()}.{sub_ext}' sub_path.write_text(transcript, encoding='utf-8')Technical Analysis
The Skill places downloaded audio and generated subtitles directly in the system-wide temporary directory. Filenames depend only on the process ID, which is generally predictable and has limited entropy.
Subtitle files are opened through
Path.write_text()without exclusive creation or a prior check that the destination is a regular file owned by the current process. If an attacker can create a matching symbolic link before the write occurs, the write may follow that link and overwrite another file writable by the victim.The audio download path has the same predictable process-ID naming pattern and is passed to an external downloader. The precise overwrite behavior can depend on
yt-dlpand the existing destination, but the Skill itself does not establish a private directory, create the target securely, or validate the resulting file against symbol ...[truncated 1589 chars]- Remediation
View remediation
Remediation Suggestions
- Create a private, randomly named per-run directory with
tempfile.TemporaryDirectory()rather than writing directly into the global temporary directory. - Keep downloaded audio and generated subtitle files inside that private directory.
- Where a persistent intermediate file is necessary, use
tempfile.NamedTemporaryFile(delete=False)ortempfile.mkstemp()so the file is created atomically with a random name and restrictive permissions. - Do not reopen a predictable pathname after secure creation. Pass the securely created path or file descriptor through the pipeline.
- Validate that generated files are regular files and not symbolic links before reading or moving them.
- Copy only the final requested output to the designated output directory.
- Remove intermediate audio and subtitle files in a
finallyblock after successful or failed processing. - Apply owner-only permissions to temporary artifacts where supported.
- Create a private, randomly named per-run directory with
