T09 · Insecure Skill Coding Practices
- Location
SKILL.md:22- Finding
Command Injection Through Unsafe User Input Interpolation
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 22-31
Vulnerability Type: Command injection through dynamically constructed Python and shell code
Risk Level: HighVulnerable Code:
markdown ## Execution Instructions When the user requests a QR code, execute a Python one-liner to perform the generation. ### Implementation Template: ```bash python3 -c "import qrcode; img = qrcode.QRCode(version=1, box_size=10, border=5); img.add_data('USER_TEXT_HERE'); img.make(fit=True); img.make_image(fill_color='black', back_color='white').save('FILE_NAME.png')"text ### Technical Analysis The implementation template places user-controlled QR content and the requested output filename directly inside Python string literals embedded in a shell command. No escaping, parameterization, or validation is specified. An attacker can provide input containing quote characters and Python syntax that terminates the intended string and introduces additional statements. For example, QR content shaped like: ```text '); __import__('os').system('ATTACKER_COMMAND'); #can transform the generated one-liner so that
os.system()is evaluated when the agent executespython3 -c. A filename containing shell metacharacters or double quotes could also escape the outer shell quoting if interpolated verbatim.This flaw is conditional on the agent following the documented placeholder-substitution approach, but that is the explicit implementation mechanism supplied by the skill.
Attack Path
- An attacker asks the agent to generate a QR code using maliciously crafted text or a crafted output filename.
- The agent replaces
USER_TEXT_HEREorFILE_NAME.pngin the documented command with the supplied value. - The crafted value terminates the intended Python string or outer shell context.
- The agent invokes the resulting
python3 -ccommand. - The injected Python or shell command executes with the s ...[truncated 586 chars]
- Remediation
View remediation
Remediation Suggestions
-
Replace the dynamically constructed one-liner with a fixed Python script.
-
Pass QR content and output paths as ordinary process arguments or through standard input rather than embedding them in Python source code.
-
Invoke Python through a structured process API without a shell, such as an argument array equivalent to:
text ["python3", "generate_qr.py", "--text", user_text, "--output", validated_path] -
Parse arguments with
argparseand treat all supplied content strictly as data. -
Restrict output to an approved workspace directory.
-
Resolve and normalize the destination path before writing, reject traversal outside the approved directory, and enforce an expected
.pngextension. -
Define overwrite behavior explicitly and reject symbolic-link destinations where appropriate.
-
Add tests covering single quotes, double quotes, semicolons, command substitutions, newlines, path traversal sequences, and absolute paths.
-
