T09 · Insecure Skill Coding Practices
- Location
scripts/generate_html.py:109- Finding
Stored HTML and Script Injection Through Unescaped Skill Metadata
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_html.py, lines 109, 179, 299, 542, and 641–653
Vulnerability Type: Stored HTML injection / cross-site scripting in generated documentation
Risk Level: MediumRelevant Code
python # Line 109: attacker-controlled frontmatter value name = fm.get("name", skill_dir.name)python # Lines 172–180: regex renderer emits text and link destinations without # first applying HTML or attribute-context escaping def md2html(text: str) -> str: if not text: return "" text = re.sub(r'```[\w]*\n(.*?)```', lambda m: f'<pre class="mini-code">{esc(m.group(1).strip())}</pre>', text, flags=re.DOTALL) text = re.sub(r'`([^`]+)`', r'<code>\1</code>', text) text = re.sub(r'\*\*(.+?)\*\*', r'<strong>\1</strong>', text) text = re.sub(r'\*(.+?)\*', r'<em>\1</em>', text) text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'<a href="\2" target="_blank">\1</a>', text) return textpython # Line 299: section titles are inserted directly into markup cards.append(f' <div class="card"><div class="card-icon">{em_actual}</div><div class="card-title">{sec["title"]}</div><div class="card-desc">{desc}</div></div>')python # Line 542: author metadata is inserted directly into markup author_html = f'维护者 <strong>{author}</strong> · ' if author else ""python # Lines 641–653: unescaped metadata reaches the generated HTML document <title>{name} · Skill 使用说明</title> ... <a class="fab-install" href="{install_url}" target="_blank" rel="noopener"> <div class="fab-circle">📦</div> <span class="fab-label">点我安装</span> </a> ... <section id="hero" class="fade-in"> <div class="badge"><span class="badge-dot"></span>OpenClaw Skill · {name}</div> <h1><span class="gradient-text">{name}</span></h1>Technical Analysis
The tool is designed to process
USAGE.mdorSKILL.mdfrom another skill directory and produce a deployable HTML page. The target skill's author co ...[truncated 3009 chars]- Remediation
View remediation
Remediation Suggestions
-
Apply HTML escaping to every plain-text value at its final output boundary, including:
- Skill name and description.
- Author and update metadata.
- Section and card titles.
- Trigger labels and list-derived summaries.
-
Use attribute-context escaping for every value inserted into
href,src, or other HTML attributes. Python'shtml.escape(value, quote=True)is suitable for escaping but should be combined with URL validation. -
Validate link schemes against an explicit allowlist such as
https,http, and optionally relative fragment links. Reject dangerous schemes such asjavascript:,data:, andvbscript:where they are not explicitly required. -
Replace the regex-based
md2html()implementation with the consistently configured Markdown renderer, or escape the complete input before applying safe Markdown transformations. -
Consider applying a maintained HTML sanitizer to all generated Markdown fragments before inserting them into the final template.
-
Use a template engine with automatic HTML escaping instead of constructing the document with large formatted strings.
-
Add regression tests covering:
</title><script>...</script>in frontmatter names.- Event-handler attributes in headings and list items.
- Quotes and angle brackets in author metadata.
javascript:anddata:Markdown links.- Behavior when Mistune is unavailable and the fallback renderer is used.
-
