T09 · Insecure Skill Coding Practices
- Location
scripts/inventory_store.py:347- Finding
Arbitrary File Overwrite Through an Unrestricted Export Destination
- Content
View full analysis
Vulnerability Details
File Location:
scripts/inventory_store.py:347-369
Vulnerability Type: Arbitrary file write and overwrite
Risk Level: Highpython data = read_json_input(args) output_path = None if data and data.get("output"): output_path = data["output"] elif args.file: output_path = args.file if not output_path: output_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), "..", "output", f"inventory_export_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv", ) os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True) fieldnames = [ "sku_id", "name", "category", "quantity", "unit_cost", "selling_price", "safety_stock", "warehouse", "expiry_date", "last_inbound_date", "last_outbound_date", "created_at", "updated_at", ] with open(output_path, "w", encoding="utf-8-sig", newline="") as f:Technical Analysis
The export destination is obtained directly from the user-controlled JSON
outputproperty or the--filecommand-line argument. The path is not canonicalized or restricted toIE_DATA_DIRor another dedicated export directory.The code creates missing parent directories and opens the destination in
wmode. Consequently, an existing file is truncated before CSV data is written. Absolute paths, relative traversal paths such as../../target, and paths traversing writable symbolic links are not rejected.This behavior also conflicts with the security declaration at
SKILL.md:268, which states that file operations are limited to the directory specified byIE_DATA_DIR.Attack Path
- An attacker supplies or induces an export request containing a chosen destination, for example through the
outputJSON property or--file. - The Agent invokes the export action with that attacker-controlled path.
- The script resolves no security boundary and creates the destination's pare ...[truncated 682 chars]
- An attacker supplies or induces an export request containing a chosen destination, for example through the
- Remediation
View remediation
Remediation Suggestions
- Place all exports in a dedicated directory under
IE_DATA_DIR. - Canonicalize both the permitted base directory and requested destination with
os.path.realpath(). - Use
os.path.commonpath()to verify that the canonical destination remains inside the permitted export directory. - Reject absolute paths, traversal components, symbolic-link destinations, and non-regular existing files.
- Do not overwrite existing files by default. Use exclusive creation mode or require explicit, trusted confirmation.
- Write to a securely created temporary file in the same directory and atomically rename it after a successful export.
- Apply restrictive directory and file permissions appropriate for inventory data.
- Add tests covering absolute paths,
..traversal, symbolic links, pre-existing files, and paths outsideIE_DATA_DIR.
- Place all exports in a dedicated directory under
