T09 · Insecure Skill Coding Practices
- Location
SKILL.md:20- Finding
Shell Command Injection Through Unescaped Email Fields
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 20-22
Vulnerability Type: Shell command injection caused by unsafe command-string construction
Risk Level: HighComplete Code Snippet:
markdown 1. **Execute Node:** Execute the native terminal command `gog gmail drafts create --to "..." --subject "..." --body "..." --json`. 2. **Verification Step (Jidoka):** Verify the command returns a valid JSON confirmation. IF it fails or returns an error message, wait 3 seconds and retry (max 3 times). IF it still fails, report the error to the user and STOP.The associated command schema at lines 25-29 reinforces the use of a single interpolated command string:
json { "command": "gog gmail drafts create --to \"example@gmail.com\" --subject \"Invoice\" --body \"Please review the attached invoice.\" --json" }Technical Analysis
The skill directs the agent to insert recipient, subject, and body values into a single terminal command string. It does not require structured argument-array execution, define a shell-escaping procedure, or validate potentially attacker-controlled email content.
Quoting values with double quotes is insufficient when those values can themselves contain quotation marks, command substitutions, or other shell metacharacters. If the generated string is passed to a shell, a malicious field can terminate the intended quoted argument and append an arbitrary command.
For example, a crafted subject conceptually shaped like:
text " ; attacker_command ; #can close the subject argument, introduce a second shell command, and comment out the remainder of the intended command. The exact payload depends on the host shell and operating system.
Attack Path
- An attacker supplies or influences an email recipient, subject, or body that the agent is asked to place in a Gmail draft.
- The supplied content includes shell syntax that escapes the surrounding ...[truncated 966 chars]
- Remediation
View remediation
Remediation Suggestions
-
Invoke
gogdirectly without a shell and pass every parameter as a separate argument. The invocation should be structurally equivalent to:text ["gog", "gmail", "drafts", "create", "--to", recipient, "--subject", subject, "--body", body, "--json"] -
Explicitly prohibit shell-based execution mechanisms such as
sh -c,bash -c, command-string evaluation, and APIs configured withshell=true. -
Validate recipient fields as email addresses and enforce reasonable length limits on recipient, subject, and body values.
-
Treat subjects and bodies as opaque data rather than executable command fragments.
-
If direct process execution is unavailable, apply robust escaping designed specifically for the active shell and operating system; simple quote replacement is not sufficient.
-
Prefer passing long message bodies through a supported standard-input or file-based interface, using a securely created file, if the CLI provides such an option.
-
Add tests containing embedded quotes, semicolons, command substitutions, newlines, and platform-specific shell metacharacters to verify that these values remain single literal arguments.
-
Avoid blind retries after ambiguous failures. Confirm that no draft was created, or use an idempotency mechanism, before retrying to prevent duplicate drafts.
-
