T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/generate_report.cjs:81
- Finding
- Unsanitized Remote Content Written to Generated Markdown Reports<![CDATA[ ## Vulnerability Details **File Location**: `scripts/generate_report.cjs:81-89, 107-110, 146-190, 217` **Vulnerability Type**: Stored Markdown/HTML content injection **Risk Level**: Medium ### Vulnerable Code Remote document fields are extracted without validation or sanitization: ```js // 也提取 docData 中的文档标题和摘要 const docs = []; const docGroups = parsed?.data?.docData?.docRecall || []; for (const g of docGroups) { for (const doc of (g.docList || []).slice(0, 3)) { docs.push({ type: 'doc', title: doc.title || '', summary: (doc.summary || '').slice(0, 300) }); } } resolve([...recalls, ...docs]); ``` The formatter only removes carriage returns, reduces repeated newlines, and truncates the value: ```js function fmt(content, maxLen = 1000) { if (!content) return '暂无数据'; return content.replace(/\r/g, '').replace(/\n{3,}/g, '\n\n').trim().slice(0, maxLen); } ``` Remote fields are then inserted directly into Markdown: ```js if (results.cn_overview?.length > 0) { md += `## 📈 A股大盘\n\n`; for (const b of results.cn_overview.slice(0, 2)) { if (b.content) md += fmt(b.content) + '\n\n'; } } if (!quick && results.cn_sectors?.length > 0) { md += `## 🔥 板块轮动\n\n`; md += fmt(results.cn_sectors[0]?.content || '', 1500) + '\n\n'; } if (!quick && results.cn_flow?.length > 0) { md += `## 💰 资金流向\n\n`; md += fmt(results.cn_flow[0]?.content || '', 1200) + '\n\n'; } if (!quick && results.cn_stocks?.length > 0) { md += `## 🚨 个股异动\n\n`; md += fmt(results.cn_stocks[0]?.content || '', 1200) + '\n\n'; } if (!quick && results.events?.length > 0) { md += `## 📢 重要公告\n\n`; for (const b of results.events.slice(0, 3)) { if (b.title || b.summary) md += `- **${b.title || ''}** ${b.summary || ''}\n`; else if (b.content) md += fmt(b.content, 300) + '\n'; } md += '\n'; } if (results.hk_overview?.length > 0) { md += `## 🇭🇰 港股大盘\n\n`; md += fmt(results.hk_overview[0]?.content || '', 1000) + '\n\n'; } if (results.us_overview?.len ...[truncated 2959 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Treat every gateway response field as untrusted data and validate the complete response against an explicit schema before use. 2. Escape Markdown metacharacters in plain-text fields such as titles and summaries. 3. Remove or encode raw HTML unless HTML output is an explicit and securely handled requirement. 4. Parse links and images, permit only approved schemes such as `https`, and reject dangerous or unexpected schemes. 5. Consider disabling external images and links entirely in generated reports, or render them as inert text. 6. Use a Markdown sanitizer designed for the capabilities of the eventual renderer rather than relying on truncation or regular-expression cleanup. 7. Authenticate the local gateway or verify responses using a trusted application-level mechanism where the gateway supports one. 8. Add security tests containing malicious Markdown, raw HTML, external images, malformed links, and dangerous URI schemes. 9. Document that generated reports contain externally sourced data and should be opened only in Markdown viewers that disable unsafe HTML and active content. ]]>
