Back to skill

Security audit

公文格式Word生成

Security checks for vulnerabilities and agentic risk

Overview

This skill coherently generates Chinese official-format Word documents, with normal file-writing risks but no evidence of hidden, deceptive, persistent, or data-stealing behavior.

Install only if you need Chinese GB/T 9704-style Word document generation. Choose an explicit .docx output path in a safe workspace, avoid pointing it at existing files, and prefer installing `python-docx` in a dedicated virtual environment with a pinned version if reproducibility matters.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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
Findings (2)

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/generate_gongwen.py:166
Finding

Unrestricted File Overwrite Through User-Controlled Output Path

Content
View full analysis

Vulnerability Details

File Location: scripts/generate_gongwen.py, lines 166-168
Vulnerability Type: Arbitrary file overwrite through an unvalidated path
Risk Level: Medium

python
output_path = config['output_path']
doc.save(output_path)
return output_path

Technical Analysis

The script reads output_path directly from the caller-supplied JSON configuration and passes it to Document.save() without validating or constraining the destination. There is no canonical path resolution, allowed-directory enforcement, filename sanitization, .docx extension check, or protection against overwriting an existing file.

Both absolute paths and path traversal sequences can therefore target any writable location accessible to the process. Because Document.save() writes a DOCX archive and replaces an existing destination, targeting an unrelated file can corrupt or destroy that file.

Attack Path

  1. An attacker supplies or influences the JSON configuration processed by the script.
  2. The attacker sets output_path to an absolute path or traversal path, such as ../../target-file.
  3. The Agent invokes generate_gongwen.py using that configuration.
  4. The script passes the attacker-controlled path directly to doc.save().
  5. If the process has write permission, the target is created or overwritten with DOCX data.

Impact Assessment

Exploitation is limited to the filesystem privileges of the process running the Skill; it does not independently elevate privileges. Within that boundary, an attacker could overwrite user documents, application data, configuration files, or other writable resources. The result could include data loss, configuration corruption, or denial of service. More serious consequences may be possible if the process can overwrite a security-sensitive file that another component later consumes.

Remediation
View remediation

Remediation Suggestions

  1. Define a dedicated output directory controlled by the application.
  2. Resolve the requested path to its canonical absolute form and verify that it remains beneath the allowed directory.
  3. Reject absolute paths and traversal outside the permitted directory.
  4. Require a .docx extension and sanitize user-controlled filenames.
  5. Refuse to overwrite existing files by default, using exclusive creation or an explicit overwrite authorization.
  6. Generate a safe server-side filename when the destination originates from untrusted input.
  7. Run the generator with minimal filesystem permissions.

Example validation pattern:

python
from pathlib import Path

output_root = Path("/approved/output/directory").resolve()
requested_name = Path(config["output_path"])

if requested_name.is_absolute():
    raise ValueError("Absolute output paths are not permitted")

output_path = (output_root / requested_name).resolve()

if output_root not in output_path.parents:
    raise ValueError("Output path escapes the approved directory")
if output_path.suffix.lower() != ".docx":
    raise ValueError("Output file must use the .docx extension")
if output_path.exists():
    raise FileExistsError("Refusing to overwrite an existing file")

doc.save(str(output_path))

T08 · Insecure Dependencies

Note
Location
SKILL.md:95
Finding

Unpinned Third-Party Dependency Installation

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, line 95
Vulnerability Type: Unpinned runtime dependency
Risk Level: Low

markdown
### scripts/generate_gongwen.py
公文格式Word生成脚本。读取JSON配置,输出符合GB/T 9704标准的.docx文件。依赖 python-docx(需安装到 venv:`pip install python-docx`)。

Technical Analysis

The documented installation command installs python-docx without a fixed version, lock file, or integrity hash. Consequently, the dependency selected during installation can change over time without any modification to this project.

This creates a non-reproducible dependency boundary and increases exposure to a compromised upstream release, an unsafe package index, or a future incompatible version. The package name itself is not shown to be malicious; the issue is the absence of version and integrity controls.

Attack Path

  1. An operator or Agent follows the documented prerequisite and executes pip install python-docx.
  2. pip resolves the package from its configured package index at installation time.
  3. The environment receives whichever version the index currently serves rather than a specifically reviewed artifact.
  4. The installed package is imported when generate_gongwen.py runs.
  5. If the resolved distribution or configured index is compromised, attacker-controlled dependency code executes with the privileges of the Python process.

Impact Assessment

A compromised dependency would execute inside the Python runtime with the same privileges as the Agent or user invoking the generator. This could expose files and environment data available to that process, alter generated documents, or perform other actions permitted by the host environment. Exploitation depends on compromise or substitution of the package source and is not caused by malicious code currently present in the audited project.

Remediation
View remediation

Remediation Suggestions

  1. Pin python-docx to a reviewed version.
  2. Maintain dependencies in a version-controlled requirements or lock file.
  3. Record and enforce distribution hashes, such as with pip install --require-hashes.
  4. Install only from a trusted, explicitly configured package index.
  5. Review and update pinned dependencies through a controlled maintenance process.
  6. Use an isolated virtual environment with minimal host permissions.
  7. Avoid automatically installing dependencies without operator approval.

Example requirements entry:

text
python-docx==REVIEWED_VERSION \
    --hash=sha256:VERIFIED_DISTRIBUTION_HASH

Example installation command:

bash
python -m pip install --require-hashes -r requirements.txt
Vulnerability Patterns
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • 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
Findings (3)

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
88% confidence
Finding

The skill instructs reading local resource files such as references/gongwen_format_spec.md and executing a local script, but it declares no explicit tool scope or permissions. In an agent environment, missing scope declarations can cause the skill to operate with broader-than-expected file access or make its file access behavior opaque to reviewers and users.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

This markdown file is entirely scoped to Chinese government document formatting and presents mandatory Chinese-language conventions such as Chinese fonts, numbering forms, and full-width punctuation. The file does not offer a language or locale choice or state that the constraint is optional, which matches the policy category for forcing a specific language/locale without user opt-in.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

The skill tells the agent to generate and deliver a .docx file to an output path, but it does not clearly warn that this will write to the filesystem. That omission can lead to unexpected file creation or overwriting in user-specified locations, especially in automated agent runs where side effects should be explicit.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.