T09 · Insecure Skill Coding Practices
- Location
wechat_auto_send.py:43- Finding
Message Automation Continues After WeChat Window Activation Failure
- Content
View full analysis
Vulnerability Details
File Location:
wechat_auto_send.py, lines 43-48; execution continues at lines 145-151
Vulnerability Type: Fail-open error handling for security-sensitive desktop automation
Risk Level: MediumVulnerable Code
python except Exception as e: print(f"[Warning] Window activation failed: {e}") return TrueThe returned value is treated as successful window activation:
python if not focus_wechat(): return 1 success = send_to_contact(args.contact, args.message, args.wait)Technical Analysis
focus_wechat()returnsTruewhen window discovery or activation raises an exception. The caller therefore proceeds with global keyboard shortcuts despite having no assurance that WeChat is the active application.send_to_contact()subsequently writes the contact and message to the system clipboard and issues globalCtrl+F,Ctrl+V, and Enter keystrokes. Because these events are sent to whichever application currently owns focus, an activation failure can paste the intended recipient and message into another application, trigger unintended actions, or disclose message content.The script also reports success after completing the keystroke sequence without verifying the active process, selected contact, or actual delivery result.
Attack Path
- The user or an agent invokes the skill with a contact and message.
- WeChat window activation fails because of an operating-system restriction, stale window handle, focus-stealing prevention, desktop state change, or deliberately induced window-management error.
- The exception handler returns
Trueinstead of failing closed. - Another application remains focused.
- The script copies the recipient and message into the shared clipboard and sends global keyboard shortcuts.
- The focused application receives the pasted values and Enter keystrokes, potentially submitting the message or activating an ...[truncated 601 chars]
- Remediation
View remediation
Remediation Suggestions
- Fail closed on every window-discovery or activation exception by returning
False. - Verify that the active window belongs to the expected WeChat process after activation, rather than relying only on a window title.
- Abort before modifying the clipboard or issuing keyboard events if focus verification fails.
- Verify the selected contact before pasting or sending the message.
- Require explicit user confirmation immediately before the final Enter keystroke for sensitive or externally directed messages.
- Preserve and restore the user's previous clipboard content in a
finallyblock. - Report success only after obtaining reliable confirmation that the expected conversation was selected and the message was submitted.
- Add automated tests proving that activation exceptions stop execution and that
send_to_contact()is never called after such failures.
- Fail closed on every window-discovery or activation exception by returning
