T09 · Insecure Skill Coding Practices
- Location
wechat_sender.py:47- Finding
AppleScript Injection Through the Contact Name
- Content
View full analysis
Vulnerability Details
File Location:
wechat_sender.py, lines 47-73
Vulnerability Type: AppleScript injection through an unescaped command-line argument
Risk Level: HighVulnerable Code
python def search_contact(contact: str): script = f''' tell application "System Events" tell process "WeChat" set frontmost to true end tell end tell delay 0.3 tell application "System Events" tell process "WeChat" keystroke "f" using {{command down, shift down}} end tell end tell delay 0.5 tell application "System Events" keystroke "{contact}" end tell delay 0.8 tell application "System Events" keystroke return end tell delay 1 ''' _run_osascript(script)Technical Analysis
The
contactvalue originates from the--contactcommand-line argument and is inserted directly into an AppleScript string literal using an f-string. It is not encoded or escaped for AppleScript syntax.Although
subprocess.run()uses an argument array and therefore avoids shell parsing, the resulting string is executable AppleScript source. A contact value containing a quotation mark, line break, AppleScript statements, and trailing comment syntax can terminate the intendedkeystrokeargument and inject additional commands.The generated script is passed to
osascript, so injected statements execute with the permissions of the user running the skill.Attack Path
- An attacker gains influence over the value supplied to
--contact, such as through an agent-generated command, automation workflow, or untrusted external input. - The attacker supplies a contact value crafted to close the AppleScript string literal.
- The value appends one or more AppleScript statements and neutralizes the remaining generated syntax.
search_contact()interpolates the v ...[truncated 865 chars]
- An attacker gains influence over the value supplied to
- Remediation
View remediation
Remediation Suggestions
-
Do not interpolate the contact name into AppleScript source.
-
Pass the contact as a positional
osascriptargument and retrieve it through anon run argvhandler:python script = ''' on run argv set contactName to item 1 of argv tell application "System Events" tell process "WeChat" set frontmost to true keystroke "f" using {command down, shift down} end tell delay 0.5 keystroke contactName delay 0.8 keystroke return end tell end run ''' subprocess.run( ["osascript", "-e", script, contact], check=True, capture_output=True, text=True, timeout=30, ) -
Apply reasonable length and control-character validation to contact names as defense in depth.
-
Reject values containing unexpected line breaks or non-printable characters when such characters are not legitimate contact-name content.
-
Check and propagate subprocess failures instead of continuing and reporting success.
-
