Back to skill

Security audit

Gmail Draft Email

Security checks for vulnerabilities and agentic risk

Overview

The skill has a clear Gmail draft purpose, but its command-string template can mishandle attacker-controlled email fields if executed through a shell.

Review before installing. The skill should be changed to invoke gog with separate argv arguments, validate recipient addresses, treat subject/body as opaque data, and avoid shell-based execution or blind retries that could create duplicate drafts.

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
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: High

Complete 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

  1. An attacker supplies or influences an email recipient, subject, or body that the agent is asked to place in a Gmail draft.
  2. The supplied content includes shell syntax that escapes the surrounding ...[truncated 966 chars]
Remediation
View remediation

Remediation Suggestions

  • Invoke gog directly 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 with shell=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.

Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep