T09 · Insecure Skill Coding Practices
- Location
scripts/reflector.py:169- Finding
Arbitrary Shell Command Injection in the Refinement Loop
- Content
View full analysis
Vulnerability Details
File Location:
scripts/reflector.py, lines 169–172
Vulnerability Type: OS command injection through unsafe shell interpolation
Risk Level: HighVulnerable Code
python gap_txt = "; ".join(g["rectify"] for g in res["gaps"]) cmd = a.refine_cmd.replace("{artifact}", cur).replace("{gaps}", gap_txt) r = subprocess.run(cmd, shell=True, capture_output=True, text=True) nxt = (r.stdout or "").strip().splitlines()Technical Analysis
The refinement loop constructs a shell command by replacing placeholders in the caller-provided
--refine-cmdstring. It then executes the resulting command withshell=True.The interpolated values are not escaped or validated:
curcontains an artifact path that may be controlled by the caller.gap_txtcontains remediation text derived from rubric criteria loaded from a caller-selected JSON file.- The refinement command itself is supplied directly through a command-line argument.
Shell metacharacters in an artifact path or rubric-derived field are therefore interpreted by the operating system shell. Surrounding a placeholder with quotes in the documented command is insufficient because an attacker can include matching quotes followed by shell operators.
Attack Path
- An attacker supplies a malicious rubric whose failed criterion contains shell metacharacters in its description, or provides a maliciously crafted artifact filename.
- The criterion fails during assessment.
- The attacker-controlled content is copied into the generated
rectifyvalue and then intogap_txt. - The loop replaces
{gaps}or{artifact}in the refinement command with that content. subprocess.run(..., shell=True)passes the complete string to the shell.- The shell interprets the injected operators and executes attacker-selected commands with the privileges of the user running the Skill.
Impact Assessment
Successful explo ...[truncated 410 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
shell=Trueand execute refinement programs withshell=False. - Represent commands as explicit argument arrays rather than shell command strings.
- Pass artifact paths and gap data as separate arguments, through standard input, or through a securely created JSON file.
- Do not perform textual placeholder replacement inside an executable command.
- Validate refinement executables against an allowlist where the environment permits only approved tools.
- Reject unexpected control characters and enforce strict schemas for rubric fields.
- If shell execution is an essential advanced feature, make it an explicit high-risk opt-in and ensure no untrusted values are interpolated into the command.
- Run refinement processes in a restricted sandbox with minimal filesystem, credential, and network access.
- Remove
