T09 · Insecure Skill Coding Practices
- Location
scripts/transcribe.py:87- Finding
Wildcard-Based Cleanup Can Delete Unrelated User Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/transcribe.py, lines 87–96 and 406–414
Vulnerability Type: Unsafe file discovery and deletion
Risk Level: HighVulnerable Code:
python def split_audio_ffmpeg(audio_path: Path, chunk_sec: int = 600) -> list[Path]: """Split audio into chunks of chunk_sec seconds. Returns list of chunk paths.""" chunk_pattern = audio_path.parent / f"chunk_%03d{audio_path.suffix}" cmd = [ "ffmpeg", "-y", "-i", str(audio_path), "-f", "segment", "-segment_time", str(chunk_sec), "-c", "copy", str(chunk_pattern) ] try: subprocess.run(cmd, check=True, capture_output=True) # collect generated chunks chunks = sorted(audio_path.parent.glob("chunk_*" + audio_path.suffix)) print(f"Split into {len(chunks)} chunks") return chunkspython if args.split and len(chunks) > 1: # remove chunk files (they are in same dir as original or temp) for chunk in chunks: try: chunk.unlink() except: passTechnical Analysis
Audio chunks are created directly in the input file's parent directory using a predictable
chunk_NNNnaming pattern. Afterffmpegfinishes, the script does not record which files were actually created during the current operation. Instead, it uses the broad wildcardchunk_*with the input suffix and assumes every matching file is one of its temporary artifacts.Cleanup subsequently calls
unlink()on every discovered match. Consequently, pre-existing files such aschunk_archive.mp3or chunks produced by another concurrent process can be included and deleted. The bareexceptsuppresses deletion errors and makes the resulting data loss less visible.Attack Path
- An attacker or another user places two or more files named
chunk_*.mp3in a directory containing an MP3 input file. - The victi ...[truncated 711 chars]
- An attacker or another user places two or more files named
- Remediation
View remediation
Remediation Suggestions
- Create a unique temporary directory for each split operation using
tempfile.TemporaryDirectory(). - Direct
ffmpegoutput exclusively into that isolated directory. - Capture and retain an explicit list of files created by the current operation.
- Delete only files inside the dedicated temporary directory instead of globbing in the user's input directory.
- Verify resolved paths remain beneath the expected temporary root before deleting them.
- Replace the bare
exceptwith a specific exception such asOSErrorand report cleanup failures. - Use a
try/finallyblock or a temporary-directory context manager so cleanup occurs safely even if transcription fails.
- Create a unique temporary directory for each split operation using
