T09 · Insecure Skill Coding Practices
- Location
src/process_earnings_call.py:38- Finding
Predictable Shared Temporary Directory Enables File Manipulation
- Content
View full analysis
Vulnerability Details
File Location:
src/process_earnings_call.py, lines 38–47 and 245–276
Vulnerability Type: Unsafe temporary-file and output-path handling
Risk Level: MediumVulnerable Code
python # Whisper writes <basename>.txt next to the audio or in output_dir audio_stem = Path(audio_path).stem transcript_file = out_path / f"{audio_stem}.txt" if not transcript_file.exists(): # fallback: look for any .txt in output_dir txts = list(out_path.glob("*.txt")) if txts: transcript_file = txts[0] else: raise FileNotFoundError(f"No transcript file found in {out_path}") transcript = transcript_file.read_text(encoding="utf-8").strip() # also save a canonical copy canonical = out_path / "transcript.txt" canonical.write_text(transcript, encoding="utf-8")python parser.add_argument("--output-dir", default="/tmp/earnings_output", help="Output directory") args = parser.parse_args() output_dir = Path(args.output_dir) output_dir.mkdir(parents=True, exist_ok=True)python indicators_path = output_dir / "financial_indicators.json" indicators_path.write_text( json.dumps(indicators, indent=2, ensure_ascii=False), encoding="utf-8" ) feishu_path = output_dir / "feishu_content.md" feishu_path.write_text(feishu_md, encoding="utf-8")Technical Analysis
The application uses the fixed, predictable path
/tmp/earnings_outputas its default output directory. It does not verify that this directory is owned by the current user, has restrictive permissions, or is not controlled by another local account. It also writes predictable filenames without rejecting symbolic links or confirming that their destinations are regular files.The transcript fallback compounds this weakness. If Whisper does not create the exact expected transcript filename, the application selects the first existing
*.txtentry in the output directory without proving that Whisper created it during the current run. An at ...[truncated 1890 chars]- Remediation
View remediation
Remediation Suggestions
- When no output directory is supplied, create a unique private directory with
tempfile.mkdtemp()ortempfile.TemporaryDirectory()rather than using a fixed shared path. - Create directories with permissions restricted to the current user, such as mode
0700, and verify ownership and permissions before use. - Remove the unrestricted
glob("*.txt")fallback. Accept only the exact transcript path expected for the current audio file and invocation. - Record directory contents before invoking Whisper and only accept an output created by that invocation if fallback discovery is unavoidable.
- Reject symbolic links and non-regular files before reading or writing. Use
lstat()or equivalent checks and validate the resolved destination remains inside the intended output directory. - Create output files securely and exclusively using low-level flags such as
O_CREAT | O_EXCL | O_NOFOLLOWwhere supported. - Write to securely created temporary files in the same trusted directory, flush them, and atomically replace final outputs after validating the destination.
- Fail safely if the selected output directory already exists with unexpected ownership, permissions, or contents.
- When no output directory is supplied, create a unique private directory with
