Back to skill

Security audit

wechat article formatter pro

Security checks for vulnerabilities and agentic risk

Overview

This is a plausible WeChat article formatter, but it needs review because crafted theme inputs can expose local files and generated previews can preserve active HTML content.

Install only if you are comfortable with local draft and HTML files being written. Use only the documented theme filenames, avoid processing sensitive drafts, and inspect generated HTML before opening, sharing, or publishing content from untrusted sources.

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 (2)

T09 · Insecure Skill Coding Practices

Warning
Location
wechat_template_generator.py:7
Finding

Unrestricted Theme Path Allows Arbitrary Local File Disclosure

Content
View full analysis

Vulnerability Details

File Location: skill_entry.py:37-44; wechat_template_generator.py:7-14
Vulnerability Type: Path traversal and unrestricted local file read
Risk Level: Medium

Complete Code Snippet

python
# skill_entry.py
if __name__ == "__main__":
    input_file = sys.argv[1] if len(sys.argv) > 1 else "article.md"
    theme_choice = sys.argv[2] if len(sys.argv) > 2 else "theme_orange.css"
    
    if os.path.exists(input_file):
        with open(input_file, 'r', encoding='utf-8') as f:
            content = f.read()
        
        result = generate_wechat_article(
            content,
            title="悟空极度舒适",
            theme=theme_choice
        )
python
# wechat_template_generator.py
class WeChatTemplate:
    def __init__(self, theme_css='theme_orange.css'):
        current_dir = os.path.dirname(os.path.abspath(__file__))
        full_css_path = os.path.join(current_dir, 'themes', theme_css)
        
        if os.path.exists(full_css_path):
            with open(full_css_path, 'r', encoding='utf-8') as f:
                self.css_content = f.read()
        else:
            self.css_content = "/* 默认样式 */ body { font-family: sans-serif; }"

Technical Analysis

The second command-line argument is accepted as a theme path and passed unchanged to WeChatTemplate. The code joins that value to the themes directory but does not validate the resulting canonical path or restrict it to the ten documented CSS files.

A path containing ../ segments can escape the intended directory. In addition, Python's os.path.join discards earlier components when the final component is an absolute path. Therefore, an attacker who can control the theme argument can select an arbitrary readable local file.

The selected file is loaded into self.css_content and later embedded in the generated HTML document's <style> element. This converts the generat ...[truncated 1271 chars]

Remediation
View remediation

Remediation Suggestions

  1. Define an explicit allowlist containing only the ten supported theme filenames.
  2. Reject absolute paths, directory separators, traversal components, and unknown filenames.
  3. Resolve both the theme directory and candidate file with pathlib.Path.resolve().
  4. Verify that the candidate is a direct child of the theme directory before opening it.
  5. Verify that the candidate is a regular .css file rather than a directory or unexpected special file.
  6. Return a clear error instead of silently accepting unsafe values.

Example hardening:

python
from pathlib import Path

ALLOWED_THEMES = {
    "theme_orange.css",
    "theme_blue.css",
    "theme_green.css",
    "theme_purple.css",
    "theme_gray.css",
    "theme_pink.css",
    "theme_brown.css",
    "theme_gold.css",
    "theme_cyan.css",
    "theme_navy.css",
}

theme_dir = (Path(__file__).resolve().parent / "themes").resolve()

if theme_css not in ALLOWED_THEMES:
    raise ValueError("Unsupported theme")

candidate = (theme_dir / theme_css).resolve()

if candidate.parent != theme_dir or not candidate.is_file():
    raise ValueError("Invalid theme path")

self.css_content = candidate.read_text(encoding="utf-8")

T09 · Insecure Skill Coding Practices

Warning
Location
wechat_template_generator.py:17
Finding

Unsanitized Raw HTML Produces Active-Content Preview Files

Content
View full analysis

Vulnerability Details

File Location: wechat_template_generator.py:17-38
Vulnerability Type: Stored HTML and script injection in generated documents
Risk Level: Medium

Complete Code Snippet

python
self.template = """<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{title}</title>
    <style>
{css}
    </style>
</head>
<body>
{content}
</body>
</html>"""

def generate_html(self, markdown_text, title="悟空极度舒适"):
    html_content = markdown.markdown(
        markdown_text,
        extensions=['tables', 'fenced_code', 'nl2br', 'sane_lists']
    )
    return self.template.format(
        title=title,
        css=self.css_content,
        content=html_content
    )

Technical Analysis

The renderer treats the Markdown input as untrusted content but does not escape or sanitize raw HTML. Python-Markdown preserves raw HTML by default. Consequently, HTML elements and attributes supplied in the draft can survive conversion and be inserted directly into the body of a complete HTML document.

Depending on browser behavior and downstream publication handling, malicious input may contain script elements, event-handler attributes, iframes, forms, or remote-resource elements. These can execute code in the preview context, display deceptive interfaces, or initiate network requests when the output is opened.

The issue is stored rather than transient: the payload is written to a timestamped HTML file and remains active whenever that artifact is opened.

Attack Path

  1. An attacker supplies or influences the Markdown draft.
  2. The draft includes active raw HTML, such as a script element, an event-handler attribute, an iframe, or a remote tracking resource.
  3. markdown.markdown() preserves the raw HTML because no safe-mode or sanitization stage is configured.
  4. The result is ...[truncated 1033 chars]
Remediation
View remediation

Remediation Suggestions

  1. Decide whether raw HTML is necessary. If it is not, escape or remove raw HTML before Markdown conversion.
  2. Sanitize the converted HTML with a maintained allowlist-based sanitizer.
  3. Permit only required article elements and attributes, such as headings, paragraphs, lists, tables, blockquotes, and safe links.
  4. Remove script elements, event-handler attributes, iframes, object/embed elements, forms, inline active content, and dangerous URL schemes such as javascript:.
  5. Restrict or remove remote images and other externally loaded resources if offline previews are expected.
  6. Add a restrictive Content Security Policy to preview documents as defense in depth, while recognizing that CSP is not a substitute for sanitization.
  7. Add regression tests using script elements, event attributes, iframes, SVG payloads, and dangerous link schemes.

A typical design is to convert Markdown first and then sanitize the generated HTML:

python
import bleach

html_content = markdown.markdown(
    markdown_text,
    extensions=["tables", "fenced_code", "nl2br", "sane_lists"],
)

html_content = bleach.clean(
    html_content,
    tags={
        "h1", "h2", "h3", "p", "br", "strong", "em",
        "ul", "ol", "li", "blockquote", "pre", "code",
        "table", "thead", "tbody", "tr", "th", "td",
        "a", "hr"
    },
    attributes={
        "a": ["href", "title"],
        "code": ["class"],
    },
    protocols={"http", "https", "mailto"},
    strip=True,
)

If external links are retained, validate them separately and add appropriate rel attributes during output processing.

Vulnerability Patterns
  • 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
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (17)

Tp4

High
Category
MCP Tool Poisoning
Confidence
94% confidence
Finding

The code does implement themed WeChat article formatting/generation from Markdown, which partially aligns with the description. However, the description specifically promises AI-driven polishing and automatic Markdown tag completion, and those capabilities are not present in the supplied code chunk. The actual code simply passes the input content to a template converter, applies a CSS theme, and saves the generated HTML locally. This is a material description-to-behavior mismatch because the advertised intelligent content-enhancement features are absent, and the primary observable behavior is static conversion/output generation rather than AI editing.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
89% confidence
Finding

The declared description emphasizes an intelligent AI formatting engine that can refine prose, complete Markdown markup, and generate formatting according to a user-specified theme color. The actual code is much narrower: it simply reads a CSS file from a local themes directory and converts Markdown to HTML using the markdown library, then wraps it in a static HTML template. While this partially aligns with 'final formatting,' it does not implement the key advertised capabilities of AI polishing or Markdown completion. The WeChat-specific aspect is also not evident beyond the filename/class naming. Therefore, the description materially overstates the code's actual behavior.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
85% confidence
Finding

The skill directs file read/write style behavior but does not declare any explicit tool scope or permissions. This creates a transparency and governance gap: an agent may perform local file operations that users or platform controls did not clearly authorize, increasing the chance of unexpected data handling.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The workflow instructs saving user-provided content to a local file without clearly warning the user that persistence will occur. This can expose sensitive draft content to unintended retention, later reuse, or access by other local processes, especially in shared or semi-persistent environments.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill instructs silent subprocess execution without notifying the user, which reduces visibility into code execution and can mask unexpected side effects such as additional file access or environment interaction. In agent contexts, undisclosed command execution materially increases risk because users cannot make an informed trust decision.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

This Python skill contains user-facing strings and a default title entirely in Chinese, including the default title at L09 and status/output messages at L25, L32, L45, and L47. Under the policy rule, forcing a specific language without user opt-in is a natural-language policy concern because the skill does not offer any locale or language selection.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

This file includes natural-language text that assumes a Chinese-language context ('微信公众号自动化排版' and related branding) without indicating that the skill is region-specific or offering a language choice. Under the policy rule, forcing a specific language or locale without opt-in can be a natural-language policy issue.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
80% confidence
Finding

This file includes natural-language comments identifying the theme as intended for WeChat public account formatting, and the typography stack prioritizes Chinese fonts. That suggests a locale-specific constraint, but the file does not provide any visible user choice or justification for enforcing a Chinese-oriented presentation context.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
84% confidence
Finding

The file header text is entirely in Chinese and explicitly describes the theme as being for WeChat public-account formatting. This suggests a language/locale-specific skill context without any visible opt-in or documented justification in the file itself, which can conflict with policies against forcing a specific language or locale.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
84% confidence
Finding

The file labels the theme specifically for '微信公众号自动化排版' and includes Chinese-only channel branding in comments. This indicates a fixed Chinese-language/WeChat-publication context without any visible opt-in or documented justification, which can conflict with language/locale neutrality policies.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
78% confidence
Finding

This CSS file includes Chinese-language branding/comments and uses Chinese-specific font families such as PingFang SC, Hiragino Sans GB, and Microsoft YaHei in the heading styles. Under the policy rule for natural-language locale constraints, this suggests a Chinese locale preference without any visible opt-in or justification in the file.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
83% confidence
Finding

The file header text is entirely Chinese and specifically references a WeChat public-account formatting theme, which suggests the skill or asset is oriented to a single language/locale context. Because there is no nearby indication of user opt-in or an offered language choice, this may conflict with a policy requiring optional language selection rather than forcing one locale.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
76% confidence
Finding

The file labels the theme specifically for a WeChat public account workflow in Chinese and prioritizes Chinese system fonts, which suggests a locale-specific presentation choice. Because SQP-3 applies to natural-language policy concerns across all file types, this can be flagged when a specific language/locale is effectively imposed without opt-in or justification in the file.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
81% confidence
Finding

This CSS file contains natural-language comments describing the skill as '微信公众号自动化排版', which signals a China/WeChat-specific locale context. Under the policy rule, locale-specific behavior should either offer user choice or clearly document a justified regional constraint; this file provides neither in its natural-language text.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
76% confidence
Finding

The file labels the theme for a WeChat public-account formatting use case in Chinese and prioritizes Chinese system fonts, which suggests a locale-specific design assumption. Because SQP-3 covers language/locale policy in natural-language content, this may be a mild policy concern if the broader skill forces this locale without explicit opt-in or documented regional scope.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

This CSS file includes natural-language text in Chinese identifying the theme for WeChat public-account publishing and a Chinese account name. Under the policy for natural-language violations, locale-specific language is present without any indication of optionality, user choice, or justification in the file itself.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
88% confidence
Finding

The default title value is hard-coded in Chinese ("悟空极度舒适"), which imposes a specific language choice in generated output. This can violate language/locale policy expectations when the skill is used in broader contexts without explicit user selection or documentation.

Content

No source excerpt is available for this finding.