T09 · Insecure Skill Coding Practices
- Location
scripts/secret-rotation-plan.py:16- Finding
Unrestricted Output Path Allows Destructive Local File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
scripts/secret-rotation-plan.py, lines 16 and 35
Vulnerability Type: Unrestricted file overwrite
Risk Level: MediumVulnerable Code
python parser.add_argument("--output", default="secret-rotation-plan.json")python Path(args.output).write_text( json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8" )Technical Analysis
The
--outputargument accepts an unrestricted filesystem path. The supplied path is passed directly toPath.write_text(), which truncates and replaces an existing file without confirmation.The implementation does not:
- Restrict output to a designated artifact directory.
- Reject absolute paths or parent-directory traversal.
- Refuse to overwrite existing files.
- Detect or reject symbolic links.
- Use exclusive or atomic file creation.
The skill only needs to generate a local JSON rotation plan. Permission to overwrite any file writable by the process exceeds that minimum functional requirement. Exploitation requires an attacker, untrusted automation, or prompt-derived workflow to influence the command-line argument; the script does not independently obtain elevated privileges.
Attack Path
- An attacker or untrusted workflow influences the value passed to
--output. - The attacker selects an existing sensitive file writable by the skill process, such as an application configuration file or user shell configuration.
- The script resolves the supplied path without validation.
Path.write_text()truncates the selected file and replaces its contents with the generated JSON plan.- The overwritten file causes configuration corruption, application failure, or user-level denial of service.
Example invocation demonstrating the unsafe primitive:
bash python3 scripts/secret-rotation-plan.py \ --output /path/to/existing/writable/configuration-fileImpact Assessment
The impact is limited to files writable by th ...[truncated 508 chars]
- Remediation
View remediation
Remediation Suggestions
- Resolve generated plans beneath a dedicated output directory and verify that the resolved path remains inside it.
- Reject absolute paths,
..traversal components, and non-JSON filenames unless broader path support is essential. - Refuse existing files by default using exclusive creation:
python output_dir = Path("generated-plans").resolve() output_dir.mkdir(mode=0o700, exist_ok=True) requested = Path(args.output) if requested.is_absolute() or ".." in requested.parts: parser.error("--output must be a relative path without parent traversal") destination = (output_dir / requested).resolve() if output_dir not in destination.parents: parser.error("--output resolves outside the approved directory") with destination.open("x", encoding="utf-8") as handle: json.dump(payload, handle, ensure_ascii=False, indent=2) handle.write("\n")- Reject symbolic-link destinations and inspect parent path components where the directory may be writable by untrusted users.
- If replacement is genuinely required, add an explicit
--forceoption and clearly warn before overwriting. - For reliable updates, write to a securely created temporary file in the same directory and atomically rename it after validation.
