T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/search_tweets.py:139
- Finding
- Arbitrary File Overwrite Through Unrestricted Save Path in Tweet Search## Vulnerability Details **File Location**: `scripts/search_tweets.py`, lines 139-142 **Vulnerability Type**: Unrestricted file write / arbitrary file overwrite **Risk Level**: Medium **Vulnerable Code:** ```python # Save to file if args.save: with open(args.save, 'w', encoding='utf-8') as f: json.dump(result, f, indent=2, ensure_ascii=False) ``` ### Technical Analysis The value of `args.save` is accepted directly from the `--save` command-line argument and passed to `open()` in truncating write mode. No restriction confines output to an intended directory, and there are no checks for absolute paths, parent-directory traversal, symbolic links, or existing sensitive files. This permits the script to overwrite any file writable by its operating-system user. The vulnerability becomes exploitable when an attacker can influence the arguments used by an agent or automation system to invoke the Skill. ### Attack Path 1. An attacker supplies content that causes the agent to invoke `search_tweets.py` with a malicious `--save` path. 2. The path identifies an existing writable configuration, workspace, script, or other sensitive file. 3. The script makes the expected request to X and receives a JSON response. 4. `open(args.save, 'w', ...)` truncates the targeted file. 5. The API response is written over the original contents. ### Impact Assessment The attacker does not gain permissions beyond those of the process running the Skill, but can affect any file writable by that account. Likely consequences include workspace corruption, destruction of configuration, denial of service, and manipulation of files consumed by other applications. Further impact may occur if the overwritten content is subsequently interpreted by a security-sensitive component.
- Remediation
- ## Remediation Suggestions - Write only beneath a dedicated output directory controlled by the Skill. - Resolve the requested path with `pathlib.Path.resolve()` and verify that it remains beneath the approved directory. - Reject absolute paths, traversal outside the output directory, symbolic links, and special files. - Prefer exclusive creation with mode `x` unless overwriting is explicitly requested and confirmed. - Apply restrictive permissions to newly created output files. - If arbitrary destinations are genuinely required, require explicit trusted-user approval before replacing an existing file.
