T09 · Insecure Skill Coding Practices
Warning
- Location
- bin/agentsource.py:116
- Finding
- Predictable and Insufficiently Protected Temporary Files Expose Sensitive Prospect Data<![CDATA[ ## Vulnerability Details **File Location**: `bin/agentsource.py:116-124` **Vulnerability Type**: Predictable temporary-file creation with permissions inherited from the process umask **Risk Level**: Medium ### Vulnerable Code ```python def make_temp_path(command: str) -> 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 ``` The same pattern is used for error files: ```python path = make_temp_path(f"{command}_error") path.write_text(json.dumps(data, indent=2)) ``` ### Technical Analysis The CLI writes imported CSV rows, fetched companies, prospect contact information, enrichment results, and event data directly to the shared `/tmp` directory. Filenames contain only a timestamp with one-second resolution and a known command name. The implementation does not: - Generate a cryptographically random filename. - Atomically reserve the destination before writing. - Explicitly set result-file permissions to `0600`. - Use a private temporary directory with permissions such as `0700`. - Remove result files after use. Consequently, file permissions depend on the invoking process's umask. With a common `022` umask, newly created files may be readable by other local users. Predictable names also permit collisions between invocations of the same command during the same second. Depending on operating-system temporary-file protections, pre-creation or link-based interference may also be possible. The README states that these files are cleaned up automatically by the operating system, but that does not provide timely confidentiality guarantees and does not prevent exposure while the files exist. ### Attack Path 1. An attacker with access to another local account monitors `/tmp` for names matching `agentsource_*_fetch.jso ...[truncated 1153 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create a private per-user temporary directory with mode `0700`. 2. Use `tempfile.NamedTemporaryFile(delete=False)` or `tempfile.mkstemp()` to atomically create unpredictable files. 3. Explicitly create every result file with mode `0600`, independent of the process umask. 4. Avoid second-resolution names and prevent concurrent commands from sharing a destination. 5. Add a cleanup command or configurable retention policy for files containing personal data. 6. Where possible, delete intermediate imported CSV JSON files immediately after matching. 7. Document the retention period and local exposure risk rather than relying solely on eventual operating-system cleanup. A hardened implementation should use an atomic file descriptor returned by `tempfile`, write through that descriptor, flush the data, and return only the resulting randomized path. ]]>
