Back to skill

Security audit

Patent Writer

Security checks for vulnerabilities and agentic risk

Overview

This patent-writing skill is mostly purpose-aligned, but its DOCX conversion script can execute unintended shell commands if given a crafted filename or output path.

Review this before installing. The patent-writing instructions are coherent, but avoid using scripts/md2docx.sh with untrusted filenames or output paths unless the eval-based pandoc call is fixed. Expect the skill to perform literature/web searches and create local patent documents in Chinese.

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
scripts/md2docx.sh:27
Finding

Arbitrary Command Execution Through Unsafe Shell Evaluation

Content
View full analysis

Vulnerability Details

File Location: scripts/md2docx.sh, lines 27-39
Vulnerability Type: Shell command injection
Risk Level: High

Vulnerable Code

bash
# Build pandoc command
PANDOC_CMD="pandoc \"$INPUT_MD\" -o \"$OUTPUT_DOCX\""

# Add reference template if exists
TEMPLATE="$REFERENCES_DIR/template.docx"
if [ -f "$TEMPLATE" ]; then
    PANDOC_CMD="$PANDOC_CMD --reference-doc=\"$TEMPLATE\""
fi

# Add TOC
PANDOC_CMD="$PANDOC_CMD --toc --toc-depth=3"

# Execute
echo "📄 Converting: $INPUT_MD → $OUTPUT_DOCX"
eval $PANDOC_CMD

Technical Analysis

The script builds a shell command by interpolating the user-controlled INPUT_MD and OUTPUT_DOCX arguments into a string, then executes that string with eval.

Although literal quotation marks are added around the path values, eval causes the fully constructed string to be parsed by the shell again. An argument containing quotation marks and shell metacharacters can therefore terminate the intended quoted value and introduce an additional command.

The input file existence check does not prevent exploitation through the optional output argument because OUTPUT_DOCX is neither validated nor required to exist. Input-path injection may also be possible when an attacker can create a file whose crafted name passes the existence check.

Attack Path

  1. An attacker causes the conversion script to be invoked with a normal Markdown input file and a maliciously constructed output path.
  2. The output path contains a quotation mark that terminates the intended argument, followed by shell syntax and an attacker-selected command.
  3. The script inserts that value into PANDOC_CMD.
  4. At line 39, eval reparses the constructed text as shell code.
  5. The injected command executes with the privileges and environment of the user or service running the Skill.

A representative malicious output-argument structure is:

text
output.docx"; <attacker-selected-command>; #

This structure is suffi ...[truncated 852 chars]

Remediation
View remediation

Remediation Suggestions

Remove eval and construct the Pandoc invocation as a Bash array. Arrays preserve argument boundaries without reparsing user-controlled values as shell syntax:

bash
PANDOC_CMD=(pandoc "$INPUT_MD" -o "$OUTPUT_DOCX")

TEMPLATE="$REFERENCES_DIR/template.docx"
if [ -f "$TEMPLATE" ]; then
    PANDOC_CMD+=(--reference-doc="$TEMPLATE")
fi

PANDOC_CMD+=(--toc --toc-depth=3)

echo "📄 Converting: $INPUT_MD → $OUTPUT_DOCX"
"${PANDOC_CMD[@]}"

Additional hardening should include:

  1. Validate that input and output paths contain no control characters.
  2. Restrict output files to an explicitly approved workspace directory when the script is exposed through an automated service.
  3. Resolve and verify paths before execution to prevent writes outside the intended workspace.
  4. Run document conversion with least privilege and without unnecessary secrets in the process environment.
  5. Add regression tests using filenames containing spaces, quotation marks, semicolons, command substitutions, and newline characters to verify that they remain literal arguments.
  6. Where supported by the invoked utility, use an end-of-options marker or otherwise ensure path values cannot be interpreted as command-line options.
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • Behavioral ASTexec() Call, eval() Call, Dynamic Import
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (10)

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

声明描述的是一个面向专利写作的智能助手,核心能力应包括理解技术方向、生成或推荐发明点、以及撰写专利交底书内容。但提供的代码仅执行文件格式转换:检查输入 Markdown 文件、构造 pandoc 命令、可选应用 reference template、添加目录并输出 DOCX。它没有任何与专利分析、创新点检索/推荐、内容生成、对话流程分支或中文专利撰写相关的逻辑。因此代码的主要目的与声明明显不一致,属于实质性能力不匹配。

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The listed trigger phrases include "帮我写个专利", which is broad natural language that can overlap with ordinary conversational requests rather than a narrowly scoped invocation pattern. The description also presents a mixed list of triggers without clear boundaries or exclusion conditions, increasing the chance of unintended activation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The description and title repeatedly define the skill as a Chinese patent-writing assistant and imply Chinese-only operation, but do not offer the user a language choice or explicit opt-in. This is a natural-language locale restriction that may violate language-choice policy unless justified as region-specific or made optional.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The description states that this is a "中文专利交底书撰写助手," which specifies Chinese-language behavior as an inherent requirement. There is no indication that users can choose another language or explicitly opt into this locale constraint, which creates a natural-language policy concern under the language/locale rule.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The entire guide is written in Chinese and presents the skill instructions solely in that language, with no indication that users may choose another language or that the skill is intentionally limited to a Chinese-speaking context. The policy scope includes language or locale constraints in natural-language content, so a monolingual instruction file without opt-in or justification is a policy concern.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The file is entirely written in Chinese and provides no indication that users may choose another language or that the template is restricted to a China-specific or Chinese-language workflow. Under the policy, forcing a specific language without user opt-in is a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The file title and content are entirely in Chinese, and the template sets global writing requirements such as total word count and style without indicating that language selection is optional. Under the policy rule, forcing a specific language or locale without user opt-in can be a natural-language policy violation unless the regional constraint is explicitly documented and justified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The document is entirely framed as a required Chinese writing standard for patent drafting, including line L217 stating character-count rules based on Chinese characters and multiple prescriptive language requirements. This imposes a specific language/locale on the skill's output without any user opt-in or explanation that the skill is limited to a China-specific legal context.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
98% confidence
Finding

This is a real command-injection risk because the script constructs a shell command string using user-controlled filenames and then executes it with eval. Even though the variables are wrapped in quotes inside the string, eval performs a second round of shell parsing, so crafted input containing quotes or shell metacharacters can break out of the intended argument context and execute arbitrary commands.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

The entire skill file is written in Chinese and presents a fixed-language example without any indication that users may choose another language or that the file is intentionally limited to a Chinese-speaking or region-specific context. Under the language/locale policy rule, a fixed language can be a policy concern when no opt-in or justification is provided.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.