T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/dispatch.py:196
- Finding
- Arbitrary File Overwrite Through Batch Output Path## Vulnerability Details **File Location**: `scripts/dispatch.py:196-198` **Vulnerability Type**: Unrestricted file write **Risk Level**: Medium ```python if args.output: with open(args.output, "w") as f: json.dump(results, f, indent=2) ``` ### Technical Analysis The `batch` command opens the user-supplied `--output` path in truncating write mode without calling `_validate_output_path()`. This differs from `cmd_task()`, which attempts to validate its output destination before writing. Consequently, batch mode can overwrite any file writable by the process. The written content is JSON containing model responses, but an attacker may influence those responses through supplied prompts. Even without precise content control, opening an existing file with mode `"w"` immediately truncates it. ### Attack Path 1. An attacker influences a Skill invocation or convinces the user or agent to run the `batch` command. 2. The attacker supplies an existing user-writable configuration, source, or shell initialization file as `--output`. 3. The batch tasks are sent to OpenRouter. 4. The script opens the chosen file in truncating mode without validating its location. 5. The original file is replaced with batch-result JSON, causing corruption or potentially introducing attacker-influenced content. ### Impact Assessment The vulnerability grants write and overwrite capability within the permissions of the user running the Skill. It does not directly elevate operating-system privileges, but it may: - Destroy or corrupt user-owned files. - Cause denial of service by overwriting required configuration or project files. - Modify application behavior if a writable configuration file is targeted. - Contribute to later code execution if an executable or automatically loaded file can be replaced with usable attacker-controlled content. The scope is limited to paths writable by the current process account.
- Remediation
- ## Remediation Suggestions - Call `_validate_output_path(args.output)` before opening the batch output file. - Replace the existing string-prefix containment check with `os.path.commonpath()` to enforce directory boundaries reliably. - Resolve and validate the parent directory and reject unsafe symbolic-link destinations where appropriate. - Restrict output to an explicitly designated output directory rather than the entire home directory. - Use atomic writes through a temporary file in the validated destination directory followed by `os.replace()`. - Consider requiring explicit confirmation before overwriting an existing file.
