T09 · Insecure Skill Coding Practices
- Location
scripts/generate_report.py:63- Finding
Unescaped User-Controlled Content Injection into Markdown Reports
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_report.py, lines 63-67
Vulnerability Type: Markdown content injection
Risk Level: MediumVulnerable Code
python if files: report += "| 序号 | 文件编号 | 文件名称 | 版本 | 文件类型 | 关键要素 |\n" report += "|------|---------|---------|------|---------|--------|\n" for idx, f in enumerate(files, 1): report += f"| {idx} | {f.get('code', '-')} | {f.get('name', '-')} | {f.get('version', '-')} | {f.get('type', '-')} | {f.get('summary', '-')} |\n" else: report += "*未提供文件清单*\n"The same unsafe interpolation pattern also occurs in other report sections, including gap entries, risk entries, compliance clauses, suggestions, and conclusions.
Technical Analysis
Values parsed from the
--filesand--analysisJSON arguments are inserted directly into Markdown without contextual escaping or validation. Table delimiters, newline characters, headings, links, and image syntax are therefore interpreted as report markup rather than inert text.For example, an attacker-controlled
summaryvalue could contain newline characters followed by a forged heading, deceptive audit conclusion, phishing link, or remote image. This content would become part of the generated report. If the Markdown viewer automatically retrieves remote images, opening the report could initiate a request to an attacker-controlled server.This is a content-injection vulnerability rather than direct operating-system command execution. The script does not execute injected Markdown, but the resulting report can misrepresent audit findings or expose the report viewer to unsafe external content.
Attack Path
- An attacker supplies a document or metadata containing crafted Markdown syntax.
- The crafted value is preserved in a file-list or analysis JSON field such as
summary,description,suggestion, oroverall. generate_report.pyparses the JSON and interpo ...[truncated 932 chars]
- Remediation
View remediation
Remediation Suggestions
- Implement context-specific escaping before inserting untrusted values:
- Escape pipe characters in table cells.
- Replace embedded carriage returns and newlines with safe text or HTML line breaks.
- Escape Markdown control characters used for headings, links, images, and emphasis.
- Create separate sanitization functions for table cells, headings, paragraphs, and list items rather than applying one generic transformation.
- Reject or neutralize remote image syntax and unsafe URI schemes. If links are permitted, allow only explicitly approved schemes such as
https. - Validate parsed JSON against a strict schema, including expected object types, field types, lengths, and nesting depth.
- Consider generating a structured intermediate representation and rendering it through a Markdown library configured to disable raw HTML and unsafe links.
- Add regression tests using payloads containing pipes, newlines, forged headings, raw HTML, links, and remote images.
- Apply the remediation consistently to every interpolated field in the file list, architecture analysis, responsibility analysis, process analysis, gaps, risks, compliance clauses, suggestions, and conclusions.
- Implement context-specific escaping before inserting untrusted values:
