Back to skill

Security audit

remove-bg

Security checks for vulnerabilities and agentic risk

Overview

This image background-removal skill mostly does what it says, but it also automatically opens the output file and uses a risky Windows shell call that is not clearly disclosed.

Review before installing. The skill appears intended for local image conversion and does not show network access or persistence, but the helper should be changed so opening the output image is an explicit option and the Windows shell=True call is removed. Use only trusted input and output paths until then.

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
remove_bg.py:34
Finding
Windows Shell Command Injection Through Attacker-Controlled Output Path<![CDATA[ ## Vulnerability Details **File Location**: `remove_bg.py`, lines 34–35 **Vulnerability Type**: OS command injection through `shell=True` **Risk Level**: High on Windows ```python if sys.platform.startswith('win'): subprocess.run(['start', str(out_path)], shell=True, check=False) ``` ### Technical Analysis The output path originates from the command-line argument `sys.argv[2]` and reaches `subprocess.run()` without validation or shell-safe handling. On Windows, the code invokes the command shell because `shell=True` is enabled. The `start` command is a shell built-in, and shell metacharacters contained in the attacker-controlled output path may therefore be interpreted as command separators or other shell syntax rather than as literal filename characters. Although the image must be saved before this branch is reached, Windows permits certain command-shell metacharacters, such as `&`, in filenames. Pillow is also explicitly instructed to save in PNG format, so the output filename does not need a conventional extension for the save operation to succeed. Consequently, an attacker able to control the output argument may select a writable, syntactically valid filename that becomes dangerous when subsequently interpreted by the shell. The automatic viewer launch is not necessary for background removal and is not disclosed in the documented command behavior. On macOS and Linux, the external viewer is launched with `shell=False`, so this specific shell-injection path applies to the Windows branch. ### Attack Path 1. An attacker controls or influences the output-image argument passed to the skill. 2. The attacker supplies a writable Windows path whose filename contains command-shell syntax, such as an `&` command separator followed by another command. 3. `remove_background()` successfully writes PNG data to that path. 4. The same untrusted path is passed to `subprocess.run()` with `shell=True`. 5. The Windows command shell parses the metacharacters ...[truncated 655 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. Remove the automatic image-viewer launch. Saving the processed PNG should be the default and only behavior of this image-processing skill. 2. If opening the result is required, make it an explicit opt-in option rather than an automatic side effect. 3. Never pass user-controlled values through `shell=True`. On Windows, use a platform API such as `os.startfile()` after validation, or invoke a fixed trusted executable with `shell=False`. 4. Validate that the output has a `.png` suffix, as required by the documented interface. 5. Resolve and validate the output path against an approved workspace directory if the skill is intended to write only within that workspace. 6. Reject unexpected control characters and enforce a conservative filename policy as defense in depth. This validation must supplement—not replace—removal of `shell=True`. 7. Report viewer-launch failures separately and avoid treating external application execution as part of the core conversion operation. ]]>
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
Findings (7)

Natural-Language Policy Violations

Medium
Confidence
94% confidence
Finding
The natural-language content describing the skill, usage, examples, and implementation is presented only in Chinese. Under the stated policy, forcing a specific language without user opt-in or a documented regional justification is a language/locale policy violation.

Intent-Code Divergence

Medium
Confidence
95% confidence
Finding
The module documentation describes only background removal and saving a PNG, but the code also launches the generated file in the system viewer. This hidden side effect undermines user trust and makes the script more dangerous because users are not informed that it will execute external viewer commands.

Context-Inappropriate Capability

Medium
Confidence
93% confidence
Finding
Executing system viewer commands is not required to remove an image background and save output. Adding external program launch capability increases attack surface and can be abused in environments where scripts are expected to perform only local file transformation.

Natural-Language Policy Violations

Medium
Confidence
97% confidence
Finding
The script forces automatic opening of the generated image without asking the user. In a skill or automation context, unexpected application launches are particularly risky because they can trigger external handlers, disrupt workflows, and violate least-surprise expectations.

subprocess module call

Medium
Category
Dangerous Code Execution
Content
try:
        import subprocess, sys
        if sys.platform.startswith('win'):
            subprocess.run(['start', str(out_path)], shell=True, check=False)
        elif sys.platform.startswith('darwin'):
            subprocess.run(['open', str(out_path)], check=False)
        else:
Confidence
91% confidence
Finding
On Windows, the script invokes a shell-backed command to open the output file automatically. Although the argument is derived from the output path, using shell=True introduces unnecessary command-execution surface and the auto-launch behavior is unrelated to the documented core function of background removal.

subprocess module call

Medium
Category
Dangerous Code Execution
Content
if sys.platform.startswith('win'):
            subprocess.run(['start', str(out_path)], shell=True, check=False)
        elif sys.platform.startswith('darwin'):
            subprocess.run(['open', str(out_path)], check=False)
        else:
            subprocess.run(['xdg-open', str(out_path)], check=False)
    except Exception as e:
Confidence
83% confidence
Finding
The macOS open command launches an external application based on the generated file without user consent. This is less severe than shell-based execution, but it still causes unexpected execution of external programs and expands the script's behavior beyond simple image processing.

subprocess module call

Medium
Category
Dangerous Code Execution
Content
elif sys.platform.startswith('darwin'):
            subprocess.run(['open', str(out_path)], check=False)
        else:
            subprocess.run(['xdg-open', str(out_path)], check=False)
    except Exception as e:
        print('Failed to open image:', e)
Confidence
83% confidence
Finding
The xdg-open call triggers the desktop's default handler for the saved file, causing external program execution without opt-in. While commonly used for convenience, it is unnecessary for the stated purpose and may trigger risky handler behavior on the host system.

Static analysis

No suspicious patterns detected.