T09 · Insecure Skill Coding Practices
- Location
- scripts/get-window-bounds.sh:24
- Finding
- AppleScript Injection Through an Untrusted Application Name<![CDATA[ ## Vulnerability Details **File Location**: `scripts/get-window-bounds.sh:24-33` **Vulnerability Type**: AppleScript injection leading to arbitrary local command execution **Risk Level**: High ### Vulnerable Code ```bash osascript -e " tell application \"System Events\" tell process \"$APP_NAME\" set win to front window set {x, y} to position of win set {w, h} to size of win end tell end tell return \"x:\" & x & \" y:\" & y & \" width:\" & w & \" height:\" & h " ``` ### Technical Analysis The script directly interpolates the first command-line argument, stored in `APP_NAME`, into dynamically generated AppleScript source. Shell double-quote escaping only preserves the surrounding shell string; it does not escape the value for the AppleScript language. An application name containing quotation marks and additional AppleScript statements can terminate the intended `tell process` string and alter the program parsed by `osascript`. An injected statement could invoke AppleScript capabilities such as `do shell script`, resulting in arbitrary command execution. The vulnerability becomes exploitable whenever an untrusted user, external task, or manipulated Agent instruction can influence the application-name argument passed to this script. ### Attack Path 1. An attacker supplies or influences the application name requested by an automation task. 2. The Agent invokes `scripts/get-window-bounds.sh` with the attacker-controlled value as its first argument. 3. The script inserts that value directly into the AppleScript source at line 26. 4. Embedded quotation marks terminate the intended process-name string. 5. Additional attacker-controlled AppleScript statements are parsed by `osascript`. 6. The injected statements execute with the privileges and macOS permissions of the process running the Skill. ### Impact Assessment Successful exploitation permits arbitrary local command execution under the account running the Agent. T ...[truncated 474 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Do not construct AppleScript source by interpolating command-line values. Pass the application name as an argument to `osascript` and retrieve it from an `on run argv` handler: ```bash osascript - "$APP_NAME" <<'APPLESCRIPT' on run argv set appName to item 1 of argv tell application "System Events" tell process appName set win to front window set {x, y} to position of win set {w, h} to size of win end tell end tell return "x:" & x & " y:" & y & " width:" & w & " height:" & h end run APPLESCRIPT ``` Additional hardening should include: 1. Reject empty values and values containing control characters. 2. Compare the requested name against the names of currently running application processes. 3. If the expected applications are known, enforce a strict allowlist. 4. Return an error when the application does not exist rather than attempting to reinterpret the input. 5. Add regression tests using names containing quotes, backslashes, line breaks, and AppleScript keywords. ]]>
