T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/notion_db_weekly_report_generator.py:59
- Finding
- Unescaped Record Data Allows Markdown Content Injection<![CDATA[ ## Vulnerability Details **File Location**: `scripts/notion_db_weekly_report_generator.py`, lines 59–75 **Vulnerability Type**: Markdown content injection **Risk Level**: Medium ```python lines = [ f"# {week_label} 周报", "", "## 数据概览", f"- 总任务数:{total}", f"- 已完成:{done}", f"- 进行中:{in_progress}", f"- 平均进度:{avg_progress}%", "", "## 本周亮点", ] lines.extend([f"- {item}" for item in (highlights or ["暂无高进度事项"])]) lines.append("") lines.append("## 风险与阻塞") lines.extend([f"- {item}" for item in (top_risks or ["暂无明显阻塞"])]) ``` ### Technical Analysis The report generator inserts the untrusted `week_label` and task titles directly into Markdown without escaping Markdown metacharacters, filtering raw HTML, or validating embedded URLs. An attacker can supply titles containing headings, links, images, HTML elements, or other Markdown syntax. Depending on the eventual Markdown renderer, this can alter the apparent structure of the report, introduce phishing content, or load an external resource. For example, a title containing an external Markdown image can cause a compatible renderer to request an attacker-controlled URL when a user opens the generated report. A malicious title is only included in the report when it qualifies as a highlight or risk. The attacker can ensure this by assigning a progress value of at least 80 or below 40. ### Attack Path 1. The attacker supplies an otherwise valid record with a title such as: ```text  ``` 2. The attacker sets `progress` to `100`, causing the title to be included in the highlights section, or to `0`, causing it to be included in the risks section. 3. `validate_payload` preserves the title without Markdown escaping. 4. `_build_report` interpolates the title directly into the generated Markdown. 5. A victim opens the report in a Markdown renderer that per ...[truncated 863 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Escape Markdown metacharacters in every untrusted value before interpolation, including `week_label` and record titles. 2. If only plain text is required, reject or neutralize raw HTML, Markdown links, image syntax, and line breaks. 3. Apply explicit length limits to report fields to reduce content abuse and resource consumption. 4. Configure downstream Markdown renderers to disable raw HTML and block external images or other remote resources. 5. If links must be supported, parse them and allow only approved schemes such as `https`, with optional hostname allowlisting. 6. Add tests covering injected headings, links, images, raw HTML, multiline titles, and dangerous URL schemes. ]]>
