T09 · Insecure Skill Coding Practices
- Location
scripts/find_icon.py:8- Finding
Predictable Temporary and Output Files Permit Symlink-Based File Clobbering
- Content
View full analysis
Vulnerability Details
File Location:
scripts/find_icon.py:8-12,scripts/find_icon.py:23-24, andscripts/find_icon.py:128-131
Vulnerability Type: Unsafe temporary files and predictable output paths
Risk Level: MediumVulnerable Code
python def screenshot(path='_temp_screen.png'): """Capture the full screen and save it.""" img = pyautogui.screenshot() img.save(path) return pathpython if big_path is None: big_path = screenshot()python if results: big_path = '_temp_screen.png' if big is None else big mark_icons(results, big_path, '_result.png') print(f'Annotated image saved: _result.png')The final write is performed by
mark_icons:python def mark_icons(results, big_path, output_path, color=(0, 255, 0)): """Mark all matching positions on the image with sequence numbers.""" img = cv2.imread(big_path) font = cv2.FONT_HERSHEY_SIMPLEX for i, r in enumerate(results): x, y, score, cx, cy, scale, w, h = r cv2.rectangle(img, (x, y), (x + w, y + h), color, 3) cv2.putText(img, f'{i+1}', (x + w // 2 - 10, y - 10), font, 1.5, (0, 0, 255), 3) cv2.putText(img, f'{score:.2f}', (x + w // 2 - 20, y + h + 25), font, 0.6, color, 1) cv2.imwrite(output_path, img)Technical Analysis
The script stores automatically captured screenshots in
_temp_screen.pngand annotated results in_result.png. Both are fixed relative paths resolved against the process's current working directory. The script does not create these files atomically, verify ownership, reject symbolic links, or prevent replacement of existing files.If an attacker can write to the working directory, the attacker can create either predictable filename as a symbolic link to another file writable by the user running the Skill. Calls to
img.save()orcv2.imwrite()can then follow that link and over ...[truncated 1852 chars]- Remediation
View remediation
Remediation Suggestions
-
Use Python's
tempfilefacilities for screenshots rather than a fixed relative filename:python import os import tempfile def screenshot(): fd, path = tempfile.mkstemp(prefix='screen-icon-', suffix='.png') os.close(fd) img = pyautogui.screenshot() img.save(path) return path -
Prefer a private
TemporaryDirectorywith permissions restricted to the current user, and remove temporary screenshots in afinallyblock after processing. -
Generate result files in a trusted output directory using randomized names. If a stable destination must be supported, require it as an explicit user parameter rather than silently overwriting
_result.png. -
Refuse unintended overwrites. Where supported, open output files using exclusive creation semantics such as
os.openwithO_CREAT | O_EXCL, and write through the securely opened file descriptor. -
Do not rely only on
os.path.islink()followed by a separate write, because that introduces a race condition. Use descriptor-based, atomic filesystem operations and platform-appropriate no-follow protections such asO_NOFOLLOWwhere available. -
Validate that output paths reside beneath an approved directory and document the lifecycle and sensitivity of captured screenshots.
-
