Back to skill

Security audit

智慧播放列表 DJ

Security checks for vulnerabilities and agentic risk

Overview

This appears to be a real macOS Music DJ skill, but it contains an unsafe AppleScript search path that can turn a crafted song title or search query into local command execution.

Review before installing. Only use this on macOS if you are comfortable granting Music.app automation, sending the configured city to wttr.in, and storing Music metadata in ~/.smart-playlist-dj. The AppleScript injection issue should be fixed before normal use, especially if track names or search terms may contain untrusted text.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Error
Location
scripts/music_player.py:198
Finding

AppleScript Injection in Music Library Search

Content
View full analysis

Vulnerability Details

File Location: scripts/music_player.py:198-211
Vulnerability Type: AppleScript command injection
Risk Level: High

Vulnerable Code

python
def play_search(query: str) -> str:
    """在 Music.app 中搜尋並播放"""
    script = f'''
tell application "Music"
    set searchResults to search library playlist 1 for "{query}"
    if (count of searchResults) > 0 then
        play track 1 of searchResults
        return "▶️  播放:「{query}」"
    else
        return "❌ 找不到:「{query}」"
    end if
end tell
'''
    return _run(script)

The generated script is subsequently executed by the following helper:

python
def _run(script: str, timeout: int = 10) -> str:
    try:
        r = subprocess.run(["osascript", "-e", script],
                          capture_output=True, text=True, timeout=timeout)
        return r.stdout.strip()
    except Exception as e:
        return f"ERROR:{e}"

Technical Analysis

The play_search() function inserts the untrusted query value directly into an AppleScript source string. It performs no quoting, escaping, or structural separation between user-controlled data and executable AppleScript.

An attacker can include quotation marks, statement delimiters, newlines, or other AppleScript syntax in the query. This can terminate the intended string literal and inject additional AppleScript statements. AppleScript can invoke operating-system commands through facilities such as do shell script, so successful injection can cross from Music.app automation into arbitrary local command execution.

The query has two identified input paths:

  1. The positional query argument of the play-search CLI command in scripts/music_player.py.
  2. A Music-library track title selected by scripts/dj_main.py:133-138, which passes the title to play_search().

Using an argument-array subprocess call prevents shell injection into the Python process itself, but it does not prevent injection into the AppleScript in ...[truncated 1693 chars]

Remediation
View remediation

Remediation Suggestions

Do not interpolate the search query into executable AppleScript source. Pass it as a separate osascript argument and retrieve it from argv:

python
def play_search(query: str) -> str:
    script = r'''
on run argv
    set searchQuery to item 1 of argv
    tell application "Music"
        set searchResults to search library playlist 1 for searchQuery
        if (count of searchResults) > 0 then
            play track 1 of searchResults
            return "Playback started"
        else
            return "Track not found"
        end if
    end tell
end run
'''
    try:
        result = subprocess.run(
            ["osascript", "-e", script, query],
            capture_output=True,
            text=True,
            timeout=10,
            check=False,
        )
        if result.returncode != 0:
            return f"ERROR:{result.stderr.strip()}"
        return result.stdout.strip()
    except Exception as exc:
        return f"ERROR:{exc}"

Additional hardening measures:

  1. Treat Music metadata as untrusted input, even when read from the local library.
  2. Keep all dynamic values outside AppleScript source code and transfer them only through argv.
  3. Avoid inserting the query into AppleScript-generated status messages; format user-facing messages safely in Python after execution.
  4. Check the subprocess return code and handle stderr rather than relying only on standard output.
  5. Add regression tests using queries containing double quotes, backslashes, newlines, Unicode characters, and AppleScript keywords.
  6. Review every future osascript call and prohibit dynamic source construction through f-strings, concatenation, or % formatting.
  7. Run the Skill with only the macOS Automation and privacy permissions required to control Music.app.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
Findings (20)

Tp4

High
Category
MCP Tool Poisoning
Confidence
94% confidence
Finding

The described mismatch includes undeclared access to the local Music.app library and writing cache/history files despite no declared permissions. Hidden local data access and persistence are security-relevant because they can expose user media metadata, create unexpected artifacts, and exceed the trust implied by the public description.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The described mismatch includes undeclared access to the local Music.app library and writing cache/history files despite no declared permissions. Hidden local data access and persistence are security-relevant because they can expose user media metadata, create unexpected artifacts, and exceed the trust implied by the public description.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
91% confidence
Finding

The described mismatch includes undeclared access to the local Music.app library and writing cache/history files despite no declared permissions. Hidden local data access and persistence are security-relevant because they can expose user media metadata, create unexpected artifacts, and exceed the trust implied by the public description.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The primary descriptive text is written in Chinese and the file does not indicate that users can choose another language or opt in to this locale. This can violate language/locale policy when a skill effectively forces one language without user choice or documented justification.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
92% confidence
Finding

The skill advertises and invokes local scripts that imply shell execution, Music.app control, and likely file/network access, but it declares no explicit permissions or allowed tools. This breaks least-privilege expectations and can let an agent invoke more capability than a user or platform reviewer would reasonably infer from the manifest.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger phrases are broad enough to match ordinary conversation like 'play music' or 'what should I listen to,' which can cause unintended activation of a skill that may execute scripts and control Music.app. In this context, broad activation increases risk because the skill is not just informational; it may perform local actions automatically.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The module description and all user-facing text are written in Traditional Chinese, and the default city is hard-coded to Taipei, implying a Taiwan-specific locale. The file does not offer a language or locale choice before presenting output, which conflicts with the policy against forcing a specific language/locale without opt-in.

Content

No source excerpt is available for this finding.

Dynamic import via __import__()

Medium
Category
Dangerous Code Execution
Confidence
75% confidence
Finding

Dynamic import() can load arbitrary modules at runtime, bypassing static analysis and potentially importing malicious code.

Content

Scanner excerpt · scripts/dj_main.py (reported line 101)May include surrounding context.

python
# Auto-select based on context
        activity = ctx.get("activity", "")
        mood     = ctx.get("mood", "")
        time_hr  = __import__("datetime").datetime.now().hour

        if activity == "morning" or (time_hr >= 5 and time_hr < 9):
            preset = "morning"

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill's natural-language interface, prompts, and descriptions are written entirely in Traditional Chinese, and the CLI does not offer any language selection or opt-in. This can violate language/locale policy when a skill implicitly forces one language for all users without documenting a justified regional constraint.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/music_player.py (reported line 23)May include surrounding context.

python
def _run(script: str, timeout: int = 10) -> str:
    try:
        r = subprocess.run(["osascript", "-e", script],
                          capture_output=True, text=True, timeout=timeout)
        return r.stdout.strip()
    except Exception as e:

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill claims to generate context-aware playlists, but this script exposes broad direct Music.app control primitives such as play, pause, next, previous, stop, queue inspection, search-play, repeat, shuffle, seek, and queue clearing. This capability mismatch increases risk because an agent or caller expecting a narrow playlist-generation tool could instead manipulate local media playback and state in ways the user did not intend.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

Stopping playback, changing system Music volume, seeking within tracks, and clearing the queue are broader device-control actions than necessary for generating or selecting a context-appropriate playlist. In an agent setting, these functions can disrupt the user's environment or media session and represent over-privileged behavior relative to the declared purpose.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

The queue-clear command performs an immediate destructive action with no confirmation, preview, or undo. In an automated agent workflow, an accidental or prompt-induced invocation could irreversibly remove the user's pending playback queue and degrade trust or usability.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

This code file contains natural-language descriptions and CLI messages entirely in Traditional Chinese, starting with the module docstring. Under the policy, forcing a specific language without user opt-in is a natural-language policy violation because users are not offered any locale or language selection.

Content

No source excerpt is available for this finding.

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/playlist_generator.py (reported line 27)May include surrounding context.

python
def _run_music(script: str) -> str:
    """透過 osascript 與 Music.app 溝通"""
    try:
        result = subprocess.run(
            ["osascript", "-e", script],
            capture_output=True, text=True, timeout=20
        )

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
83% confidence
Finding

This markdown file states that the skill uses real-time weather data from wttr.in and integrates with macOS Music.app, but it does not disclose any privacy or system-impact implications of those behaviors. For markdown files, user-facing descriptions should warn when the skill may access external services or affect local media playback/library context.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
77% confidence
Finding

The manifest description and user-facing instructions are entirely in Traditional Chinese, with no indication that the skill can operate in other languages or that the language choice is intentional and opt-in. Under the policy, a fixed language or locale should be offered as a user choice unless clearly justified as region-specific.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Low
Category
Not specified by scanner
Confidence
81% confidence
Finding

The manifest describes a situational DJ that detects context and plays playlists, but this file additionally creates a hidden application directory and reads/writes a config file under the user's home directory. Local config persistence is not mentioned in the description and expands behavior beyond pure detection/generation/playback.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

This code makes an outbound HTTP request to wttr.in using the provided city value, which transmits user-selected location context to a third-party service. In the code path shown, there is no user-facing warning, confirmation, log, or comment/docstring explaining that external network access occurs.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
84% confidence
Finding

The module description and all user-facing help/output strings are written in Traditional Chinese, with no indication that users may choose another language. Per the policy, fixed language behavior without user opt-in can be a natural-language policy concern unless the locale restriction is explicitly documented and justified.

Content

No source excerpt is available for this finding.