T09 · Insecure Skill Coding Practices
- Location
scripts/search_tweets.py:139- Finding
Arbitrary File Overwrite Through Unrestricted Save Path in Tweet Search
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_tweets.py, lines 139-142
Vulnerability Type: Unrestricted file write / arbitrary file overwrite
Risk Level: MediumVulnerable 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.saveis accepted directly from the--savecommand-line argument and passed toopen()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
- An attacker supplies content that causes the agent to invoke
search_tweets.pywith a malicious--savepath. - The path identifies an existing writable configuration, workspace, script, or other sensitive file.
- The script makes the expected request to X and receives a JSON response.
open(args.save, 'w', ...)truncates the targeted file.- 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.
- An attacker supplies content that causes the agent to invoke
- Remediation
View 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
xunless 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.
