Back to skill

Security audit

Alibabacloud Terraform Code Generation

Security checks for vulnerabilities and agentic risk

Overview

The skill is mostly coherent for Alibaba Cloud Terraform generation, but it should be reviewed because it tells agents to run shell commands with an unquoted user-supplied target directory.

Review before installing or using. The skill is not malicious, but it should be fixed so every target directory is validated and shell-quoted, especially before any terraform or cleanup command runs. Treat terraform plan as an explicit opt-in action because it may use locally configured Alibaba Cloud credentials, even though the skill says it will not read or print secret values.

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:67
Finding

Command Injection Through Unquoted User-Controlled Target Directory

Content
View full analysis
` from the user's request (explicit path like `myshop-infra/` or current working directory if unspecified). All subsequent `fmt` / `init` / `validate` commands run in this directory. Before writing any `.tf` file, **MUST** create the directory: ```bash mkdir -p ``` All file writes MUST prefix paths with `/` — never write to the current working directory directly, never write to a generic `outputs/` parent. After generation completes, verify the structure: ```bash ls -R ``` ``` The same unquoted value is subsequently used in additional shell commands. `SKILL.md:365-368`: ```bash (cd \ && terraform fmt -recursive \ && terraform init -backend=false \ && terraform validate -json) ``` `SKILL.md:451-453`: ```bash (cd && terraform init && terraform plan -out=tfplan) ``` `references/auth-and-network.md:101-102`: ```bash rm -rf /.terraform /.terraform.lock.hcl (cd && terraform init -backend=false) ``` ### Technical Analysis The workflow explicitly derives `` from the user's request and then places it into shell command templates without requiring shell-safe quoting, argument separation, or input validation. Shell metacharacters in a supplied path—such as semicolons, command substitutions, redirections, pipes, or newlines—can change the structure of the resulting command. For example, direct substitution of a value resembling: ```text infra; attacker-command ``` into: ```bash mkdir -p ``` would produce a shell command equivalent to: ```bash mkdir -p infra; a ...[truncated 2251 chars]
Remediation
View remediation
&& terraform ...`. 4. Replace the cleanup example with quoted, constrained operations: ```bash rm -rf -- "$target_dir/.terraform" rm -f -- "$target_dir/.terraform.lock.hcl" ``` Before cleanup, verify that `target_dir` is non-empty, canonical, and located within the approved workspace. Consider requiring explicit user confirmation before destructive cleanup. 5. Update every occurrence consistently, including the generation, validation, planning, content-grep, and network-recovery commands. Fixing only `mkdir` would leave later injection points exploitable. 6. Add negative tests using paths containing spaces, leading hyphens, semicolons, command substitutions, newlines, wildcard characters, and traversal components. Tests should confirm that each value is handled only as a path and never parsed as shell syntax. ]]>
Vulnerability Patterns
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Rogue AgentSelf-Modification, Session Persistence
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (14)

Tp4

High
Category
MCP Tool Poisoning
Confidence
99% confidence
Finding

The declared description says this skill should generate Terraform for Alibaba Cloud resources. The supplied code does not create Terraform, interpret user infrastructure requirements, or emit HCL for VPC/ECS/RDS/etc. Its actual role is offline tooling for scanning the Alicloud provider docs to catalog deprecated fields and suggested replacements, then writing a markdown reference file. While this may support a broader Terraform-related workflow, it is not a supporting implementation detail of HCL generation in this chunk; it is a separate, materially different function. Therefore the description does not accurately represent the code's actual behavior.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
94% confidence
Finding

The skill instructs the agent to read files, write Terraform, and execute shell commands, but it declares no explicit tool scope or permissions boundary. In practice this increases the blast radius of prompt injection or user confusion because the agent may perform filesystem and shell actions that were not transparently constrained by the skill contract.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The skill claims it will never read credentials, but later directs checks of environment variables and credential-file existence. This contradiction is dangerous because it weakens user trust boundaries and normalizes secret-adjacent inspection, making it easier for a future modification or prompt injection to extend that behavior into direct secret access.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
60% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · SKILL.md (reported line 388)May include surrounding context.

md
not a config bug. Point the user at the mirror-source configuration in
`references/auth-and-network.md`, then proceed to Step 7 — the Summary
MUST use `Validation: SKIPPED (init failed — network/unreachable)`.
Do not retry blindly, do not write `~/.terraformrc` yourself.

If `terraform` is absent: SKIP this step and surface that fact in Step 7's
summary (Hard rule §2) with `Validation: SKIPPED (terraform binary not on PATH)`.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
89% confidence
Finding

The optional plan workflow enumerates local credential availability by probing environment variables and credential-file presence. Even without printing secret values, this inspects sensitive local security posture unrelated to pure code generation and can leak whether privileged cloud access paths exist, which is valuable reconnaissance in a compromised or multi-tenant setting.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
60% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · references/auth-and-network.md (reported line 109)May include surrounding context.

(cd && terraform init -backend=false)

text

### SKILL contract: diagnose, don't write

`~/.terraformrc` is a **user-global** configuration file. SKILL's Step 6
failure branch MUST:

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/build_alicloud_providers.py (reported line 54)May include surrounding context.

python
def ensure_repo(clone_dir: Path) -> None:
    if (clone_dir / ".git").exists():
        print(f"[info] refreshing existing clone at {clone_dir}", file=sys.stderr)
        subprocess.run(
            ["git", "-C", str(clone_dir), "pull", "--ff-only"],
            check=False,
            timeout=300,

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/build_deprecated_fields.py (reported line 120)May include surrounding context.

python
def ensure_repo(clone_dir: Path) -> None:
    if (clone_dir / ".git").exists():
        print(f"[info] refreshing existing clone at {clone_dir}", file=sys.stderr)
        subprocess.run(
            ["git", "-C", str(clone_dir), "pull", "--ff-only"],
            check=False,
            timeout=300,

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/build_alicloud_providers.py (reported line 62)May include surrounding context.

python
return
    clone_dir.parent.mkdir(parents=True, exist_ok=True)
    print(f"[info] cloning provider repo to {clone_dir}", file=sys.stderr)
    subprocess.run(
        [
            "git", "clone", "--depth", "1", "--filter=blob:none", "--sparse",
            PROVIDER_REPO, str(clone_dir),

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/build_deprecated_fields.py (reported line 127)May include surrounding context.

python
return
    clone_dir.parent.mkdir(parents=True, exist_ok=True)
    print(f"[info] cloning provider repo to {clone_dir}", file=sys.stderr)
    subprocess.run(
        [
            "git", "clone", "--depth", "1", "--filter=blob:none", "--sparse",
            PROVIDER_REPO, str(clone_dir),

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/build_alicloud_providers.py (reported line 70)May include surrounding context.

python
check=True,
        timeout=600,
    )
    subprocess.run(
        ["git", "-C", str(clone_dir), "sparse-checkout", "set", "website/docs"],
        check=True,
        timeout=60,

subprocess module call

Medium
Category
Dangerous Code Execution
Confidence
70% confidence
Finding

subprocess module calls execute external commands. Without careful input validation, this enables command injection.

Content

Scanner excerpt · scripts/build_deprecated_fields.py (reported line 135)May include surrounding context.

python
check=True,
        timeout=600,
    )
    subprocess.run(
        ["git", "-C", str(clone_dir), "sparse-checkout", "set", "website/docs"],
        check=True,
        timeout=60,

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
95% confidence
Finding

Line L0007 uses Chinese-only status text (⚠️ 弃用) inside an otherwise English catalog. This imposes a specific language for understanding important status information without user opt-in or justification, which is a natural-language locale policy issue.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
94% confidence
Finding

The generated markdown hard-codes the status text as ⚠️ 弃用, which forces a specific language in user-facing output. The file does not offer a language choice or explain a justified region-specific requirement, so this is a natural-language locale policy issue.

Content

No source excerpt is available for this finding.