T09 · Insecure Skill Coding Practices
- Location
handler.js:43- Finding
Persistent Markdown Injection Through Unsanitized Connection Fields
- Content
View full analysis
Vulnerability Details
File Location:
handler.js, lines 43–117 and 225–241
Vulnerability Type: Persistent Markdown content injection
Risk Level: MediumVulnerable Code
js function addConnection({ type, platform, action, value = 1, status = '✅' }) { ensureDirs(); const now = new Date(); const timeStr = now.toTimeString().split(' ')[0].slice(0, 5); const todayStr = getTodayStr(); let stars = '⭐'; if (value >= 3) stars = '⭐⭐⭐'; else if (value >= 2) stars = '⭐⭐'; let trackerContent = ''; if (fs.existsSync(TRACKER_FILE)) { trackerContent = fs.readFileSync(TRACKER_FILE, 'utf-8'); } const newRow = `| ${timeStr} | ${type} | ${platform} | ${action} | ${stars} | ${status} |`; // ... fs.writeFileSync(TRACKER_FILE, trackerContent); const dailyFile = path.join(DAILY_DIR, `${todayStr}.md`); appendToDaily(dailyFile, { time: timeStr, type, platform, action, value, stars, status }); return { success: true, message: `已记录:${type}/${platform}/${action}` }; } function appendToDaily(filePath, record) { let content = ''; if (fs.existsSync(filePath)) { content = fs.readFileSync(filePath, 'utf-8'); } else { content = `# 连接日志 ${record.time.split(':')[0]}:00\n\n`; } const line = `- [${record.time}] ${record.type}/${record.platform}: ${record.action} (${record.stars})\n`; content += line; fs.writeFileSync(filePath, content); } // CLI entry point if (require.main === module) { const args = process.argv.slice(2); const command = args[0]; if (command === 'add') { const params = {}; for (let i = 1; i < args.length; i++) { if (args[i].startsWith('--')) { params[args[i].slice(2)] = args[++i]; } } const result = addConnection({ type: params.type || 'unknown', platform: params.platform || 'unknown', ...[truncated 2308 chars]- Remediation
View remediation
Remediation Suggestions
-
Validate every externally supplied field before storage:
- Require strings of bounded length.
- Reject newline, carriage-return, null, and other control characters.
- Define allowlists for
typeandstatus. - Restrict
valueto an explicit numeric range.
-
Apply context-specific Markdown encoding:
- Escape pipe characters and backslashes in table cells.
- Encode or reject raw HTML.
- Neutralize Markdown links and images if those constructs are not required.
- Do not rely solely on generic HTML escaping because Markdown tables have additional delimiters.
-
Store records in a structured format such as JSON with a strict schema, then generate Markdown from validated and escaped values. This separates data storage from presentation and reduces structural corruption.
-
Reject missing option values rather than consuming the next flag or accepting
undefined. -
If rendered in a browser, use a Markdown renderer configured to disable raw HTML and sanitize generated HTML and link protocols.
-
Add tests covering pipes, multiline values, raw HTML, Markdown links, oversized input, Unicode control characters, and malformed CLI argument sequences.
-
