T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/wx_ocr_reply.py:12
- Finding
- Full-Screen Capture Stored in a Predictable Temporary File<![CDATA[ ## Vulnerability Details **File Location**: `scripts/wx_ocr_reply.py`, lines 12-15 and 57-61 **Vulnerability Type**: Insecure temporary-file handling and excessive sensitive-data collection **Risk Level**: Medium ### Vulnerable Code ```python def take_screenshot(): """截图当前屏幕""" screenshot_path = "/tmp/wechat_screenshot.png" subprocess.run(["screencapture", "-x", screenshot_path]) return screenshot_path ``` ```python # 截图识别聊天内容 print("截图识别聊天内容...") screenshot = take_screenshot() chat_content = ocr_screenshot(screenshot) print("识别到的内容:") print(chat_content) ``` ### Technical Analysis The OCR workflow captures the entire screen rather than limiting capture to the intended WeChat window or conversation region. The screenshot is written to the fixed, predictable path `/tmp/wechat_screenshot.png`. The file is not securely created, its ownership and type are not validated, and it is never removed after OCR processing. Reusing a shared temporary-file name can expose the workflow to interference from another local process. Depending on operating-system behavior and permissions, another process may monitor, replace, or pre-create the path. Independently of such interference, the screenshot remains on disk and may contain unrelated sensitive information visible elsewhere on the screen. The recognized screen text is also printed to standard output, which can expose conversation content through terminal history, captured task logs, or automation logs. ### Attack Path 1. A user invokes `wx_ocr_reply.py` while WeChat and other sensitive applications or notifications are visible. 2. The script captures the entire display, including information outside the requested conversation. 3. The image is stored at the known path `/tmp/wechat_screenshot.png`. 4. A local process that monitors the predictable path, or another user with sufficient local access, retrieves or interferes with the screenshot. 5. The file remains available after OCR completes be ...[truncated 822 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Capture only the WeChat window or the smallest required conversation region instead of the full display. 2. Create the screenshot with a securely generated, user-private temporary path, such as through Python's `tempfile` module. 3. Open or create temporary files with restrictive permissions and validate that the destination is a regular file owned by the current user. 4. Place screenshot creation and OCR processing inside a `try`/`finally` block and delete the file in the `finally` block. 5. Avoid printing complete OCR output by default. Provide an explicit debug option and redact sensitive content before logging. 6. Check the return codes from `screencapture` and OCR subprocesses and fail closed if capture or processing fails. 7. Consider processing the image in memory where supported, eliminating persistent screenshot storage entirely. ]]>
