T09 · Insecure Skill Coding Practices
- Location
bin/agentsource.py:115- Finding
Predictable and Insecure Temporary Files Expose Sensitive Prospect Data
- Content
View full analysis
pathlib.Path: ts = int(time.time()) return TEMP_DIR / f"agentsource_{ts}_{command}.json" def write_result(command: str, data: dict) -> pathlib.Path: path = make_temp_path(command) path.write_text(json.dumps(data, indent=2, default=str)) print(str(path)) return path def write_error(command: str, error_msg: str, error_code: str = None, http_status: int = None) -> pathlib.Path: ``` The same predictable path construction and unrestricted `write_text()` operation are also used when error files are written. ### Technical Analysis The CLI stores API responses and imported CSV content directly in the shared `/tmp` directory. A filename consists only of the current timestamp in seconds and a predictable command name, such as: ```text /tmp/agentsource_1750000000_fetch.json ``` This construction has several security weaknesses: 1. **Predictable filenames:** A local attacker can calculate likely paths from the current time and known command names. 2. **Non-atomic creation:** `Path.write_text()` opens an existing pathname rather than securely creating a new, exclusive file. 3. **Symbolic-link following:** If an attacker creates the expected pathname as a symbolic link, the CLI follows it and overwrites the link target, provided the victim account can write to that target. 4. **No explicit restrictive permissions:** The resulting mode depends on the process umask. Under a common `022` umask, files are created as `0644` and may be readable by other local users. 5. **Filename collisions:** Two invocations of the same command during the same second use the same path and can overwrite or corrupt each other's results. 6. **No explicit cleanup: ...[truncated 1809 chars]- Remediation
View remediation
