T09 · Insecure Skill Coding Practices
- Location
scripts/transcribe.py:62- Finding
Predictable Shared Temporary Audio File Enables Symlink and Race Attacks
- Content
View full analysis
Vulnerability Details
File Location:
scripts/transcribe.py, lines 62-74; usage and cleanup at lines 209 and 226-230
Vulnerability Type: Predictable and insecure temporary-file handling
Risk Level: MediumVulnerable Code
python def extract_audio(input_file, temp_audio="/tmp/audio_extract.wav"): """从视频文件中提取音频""" try: subprocess.run([ "ffmpeg", "-i", input_file, "-vn", "-acodec", "pcm_s16le", "-ar", "16000", "-ac", "1", "-y", temp_audio ], check=True, capture_output=True) return temp_audio except subprocess.CalledProcessError as e: print(f"音频提取失败:{e.stderr.decode()}") sys.exit(1)The predictable path is used and later removed as follows:
python audio_file = extract_audio(args.input)python finally: # 清理临时文件 if audio_file != args.input and not args.keep_audio: try: os.remove(audio_file) except: passTechnical Analysis
Every video transcription writes extracted audio to the fixed path
/tmp/audio_extract.wav. Shared temporary directories are writable by other local users, and a predictable filename provides no isolation between processes.The
-yoption instructs FFmpeg to overwrite the destination without prompting. The script does not securely create the file, verify its ownership, reject symbolic links, or ensure that it belongs to the current invocation. This creates the following security conditions:- A local attacker can pre-create the path as a symbolic link to another file writable by the victim.
- Concurrent invocations can overwrite, transcribe, or remove each other's temporary audio.
- An attacker can race file creation or replacement between extraction, transcription, and cleanup.
- When
--keep-audiois used, sensitive speech remains at a known path that may be accessible to ...[truncated 1969 chars]
- Remediation
View remediation
Remediation Suggestions
- Use
tempfile.TemporaryDirectory()to create a private, uniquely named directory for each invocation. - Generate the extracted-audio path inside that directory rather than using a fixed global path.
- Ensure the temporary directory and files are accessible only to the current user.
- Manage cleanup through a context manager so it executes reliably on success and failure.
- Do not suppress cleanup exceptions indiscriminately; report failures without exposing sensitive paths unnecessarily.
- If retained audio is required, require an explicit destination rather than retaining it under a predictable shared path.
- Consider verifying that any destination is a regular file owned by the current user and is not a symbolic link.
Example hardening pattern:
python import tempfile from pathlib import Path with tempfile.TemporaryDirectory(prefix="transcribe-") as temp_dir: audio_file = str(Path(temp_dir) / "audio.wav") extract_audio(args.input, audio_file) result = transcribe( audio_file, model_name=args.model, language=args.language, device=args.device ) format_output(result, args.output_format, output_file)If
--keep-audiomust be supported, copy the completed audio to a user-selected path only after transcription and apply restrictive permissions.- Use
