T09 · Insecure Skill Coding Practices
- Location
scripts/visual_ref.py:69- Finding
Caller-Controlled Output Directory Enables Destructive File Cleanup
- Content
View full analysis
Vulnerability Details
File Location:
scripts/visual_ref.py, lines 69-85
Vulnerability Type: Arbitrary-directory destructive cleanup
Risk Level: MediumVulnerable Code:
python parser.add_argument("--output", default="/tmp/visual-refs", help="Output folder") parser.add_argument("--orientation", choices=["landscape", "portrait", "square"], help="Orientation (optional)") parser.add_argument("--list-only", action="store_true", help="List URLs only, no download") args = parser.parse_args() if not PEXELS_API_KEY: print("Error: PEXELS_API_KEY not found in environment.", file=sys.stderr) print(" Set it with: export PEXELS_API_KEY=your_api_key", file=sys.stderr) sys.exit(1) output_dir = Path(args.output) # Clean previous references to avoid accumulation across searches if output_dir.exists(): for old_file in output_dir.glob("ref_*"): old_file.unlink() meta = output_dir / "refs_meta.json" if meta.exists(): meta.unlink()Technical Analysis
The
--outputargument accepts an unrestricted filesystem path. Before performing the search or downloading images, the script deletes every entry matchingref_*and the filerefs_meta.jsonfrom the selected directory.The cleanup operation does not verify that the directory is the documented
/tmp/visual-refsdirectory, that it was created by this script, or that the matching files belong to a previous invocation. It also lacks confirmation, canonical-path validation, and a directory ownership marker. AlthoughPath.glob()limits deletion to matching entries directly inside the selected directory, unrelated files with those names can still be removed.The documented mandatory output path reduces accidental exposure when instructions are followed, but the implementation does not enforce that rule. The behavior therefore exceeds the minimum filesystem privileges needed for the declared functionality.
...[truncated 1071 chars]
- Remediation
View remediation
Remediation Suggestions
- Enforce the documented
/tmp/visual-refsdirectory instead of accepting arbitrary output paths. - If custom directories are required, resolve them with
Path.resolve()and require them to be descendants of a dedicated, application-controlled base directory. - Create a marker file when initializing an output directory and refuse cleanup unless the marker proves that the directory is managed by this Skill.
- Track files created by the script and delete only those exact files rather than deleting every entry matching a broad filename pattern.
- Skip all cleanup in
--list-onlymode because that mode does not need an output directory for downloaded images. - Refuse dangerous locations such as filesystem roots, user home directories, and existing directories not created by the Skill.
- Handle directories and symbolic links explicitly so cleanup cannot unexpectedly target or fail against non-regular entries.
- Enforce the documented
