T09 · Insecure Skill Coding Practices
- Location
scripts/notes_new.sh:10- Finding
AppleScript Injection Through an Unescaped Folder Name
- Content
View full analysis
&2 exit 1 fi # Notes body is HTML-ish: escape + convert newlines to
export TITLE BODY BODY_HTML=$(python3 - <<'PY' import html, os s = os.environ.get('BODY','') print(html.escape(s).replace('\n','
')) PY ) # Escape for AppleScript string literal export BODY_HTML BODY_AS=$(python3 - <<'PY' import os s=os.environ['BODY_HTML'] print(s.replace('\\','\\\\').replace('"','\\"')) PY ) TITLE_AS=$(python3 - <<'PY' import os s=os.environ['TITLE'] print(s.replace('\\','\\\\').replace('"','\\"')) PY ) osascript -e "tell application \"Notes\" to make new note at folder \"$FOLDER\" with properties {name:\"$TITLE_AS\", body:\"$BODY_AS\"}" ``` The vulnerable argument can also originate from JSON input: ```bash FOLDER=$(python3 - <<'PY' import json, os obj=json.loads(os.environ.get('NOTES_PAYLOAD','') or '{}') print(obj.get('folder','Notes')) PY ) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" "$SCRIPT_DIR/notes_new.sh" "$TITLE" "$BODY" "$FOLDER" >/dev/null ``` ### Technical Analysis The script dynamically constructs AppleScript source inside a shell string. Although the title and body undergo limited escaping for AppleScript string literals, `FOLDER` is interpolated directly into the source without escaping or validation: ```bash folder \"$FOLDER\" ``` Shell quoting prevents the folder value from becoming a separate shell command, but it does not prevent the value from altering the AppleScript program passed to `osascript`. An attacker-controlled folder name can contain quotation marks, AppleScript statement separators or line breaks, additional statements, and ...[truncated 2193 chars]- Remediation
View remediation
