T07 · Tool Hijacking and Spoofing
Error
- Location
- scripts/transcribe.py:19
- Finding
- Python Import-Path Hijacking Through a Shared Temporary Directory<![CDATA[ ## Vulnerability Details **File Location**: `scripts/transcribe.py:19-31` **Vulnerability Type**: Untrusted Python module search path **Risk Level**: High ### Vulnerable Code ```python # Ensure whisper venv is in path (fallback for different Python versions) _VENV_PATHS = [ '/tmp/whisper-venv/lib/python3.12/site-packages', '/tmp/whisper-venv/lib/python3.11/site-packages', '/tmp/whisper-venv/lib/python3.10/site-packages', ] for p in _VENV_PATHS: if os.path.exists(p): sys.path.insert(0, p) break import whisper import soundfile as sf import numpy as np ``` ### Technical Analysis The script conditionally inserts a predictable path under the shared `/tmp` directory at the beginning of `sys.path`. It verifies only that the path exists; it does not verify the directory's owner, permissions, canonical path, or integrity. Because the selected directory is placed at index zero, modules found there take precedence over packages installed in the legitimate Python environment. An attacker who creates `/tmp/whisper-venv` before the victim, or otherwise controls that directory, can provide malicious `whisper`, `soundfile`, or `numpy` modules. Python executes top-level module code immediately during import, before the transcription logic begins. The sticky-bit protection commonly applied to `/tmp` does not prevent this attack when the attacker creates the predictable directory first. It only restricts deletion or replacement of entries owned by other users. ### Attack Path 1. A local attacker anticipates that a victim or automated Agent will run `scripts/transcribe.py`. 2. The attacker creates one of the expected directory structures, such as: `/tmp/whisper-venv/lib/python3.12/site-packages/`. 3. The attacker places a malicious module or package at that location, such as `whisper.py` or `whisper/__init__.py`. 4. The victim executes `scripts/transcribe.py`. 5. The script detects the attacker-controlled directory and prepend ...[truncated 791 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove the shared `/tmp/whisper-venv` fallback and do not modify `sys.path` using predictable globally writable locations. 2. Invoke the project virtual environment's interpreter directly, for example: ```bash .venv/bin/python scripts/transcribe.py input.ogg ``` 3. If runtime path modification is unavoidable, use a project-owned directory and validate it before use: - Resolve the canonical path with `os.path.realpath()`. - Confirm that it is located inside the expected project directory. - Confirm that the current trusted user owns it. - Reject group-writable or world-writable directories. - Reject symbolic links and unexpected path components. 4. Create temporary directories with `tempfile.TemporaryDirectory()` when temporary storage is necessary. Do not reuse a fixed name under `/tmp`. 5. Run the Skill with least privilege and isolate it from sensitive credentials and unrelated files. ]]>
