T09 · Insecure Skill Coding Practices
Warning
- Location
- src/newsletter-kit.js:39
- Finding
- Unescaped Markdown Content Allows Newsletter Markup Injection## Vulnerability Details **File Location**: `src/newsletter-kit.js`, lines 39-49 **Vulnerability Type**: Markdown content injection **Risk Level**: Medium ### Vulnerable Code ```javascript _generateMarkdown(intro) { let md = `# ${this.name}\n*${new Date().toLocaleDateString()}*\n\n`; if (intro) md += intro + '\n\n'; for (const [section, items] of Object.entries(this.sections)) { md += `## ${section}\n\n`; for (const item of items) { md += item.url ? `- [${item.title}](${item.url})` : `- ${item.title}`; if (item.note) md += ` — ${item.note}`; md += '\n'; } md += '\n'; } return md; } ``` ### Technical Analysis The Markdown generator directly interpolates the newsletter name, introduction, section name, item title, URL, and note into the output without escaping Markdown metacharacters or validating URL schemes. An attacker who can influence newsletter items can inject arbitrary Markdown structures such as headings, images, deceptive links, or raw HTML. Unlike the HTML generator, which escapes text and restricts links to HTTP or HTTPS, the Markdown generator applies no equivalent controls. The exact consequences depend on the downstream Markdown renderer. If it permits raw HTML or unsafe URI schemes, the injection could become HTML injection or client-side script execution. Even with a restrictive renderer, an attacker can manipulate newsletter presentation and introduce phishing links. ### Attack Path 1. An attacker supplies content to `addItem()` through an application or workflow that accepts externally curated newsletter content. 2. The attacker places Markdown syntax or raw HTML in `section`, `title`, `note`, or `url`. For example, a title could contain a forged link or an HTML element. 3. The application calls `generate({ format: "markdown" })`. 4. `_generateMarkdown()` inserts the malicious value into the document without escaping or validation. 5. ...[truncated 673 chars]
- Remediation
- ## Remediation Suggestions 1. Escape Markdown control characters in all untrusted text fields, including the newsletter name, introduction, section names, titles, and notes. 2. Parse URLs with the standard `URL` class and explicitly allow only required schemes, preferably `https:` and, if necessary, `http:`. 3. Reject URLs containing control characters, malformed encoding, or unsupported schemes. 4. Decide whether raw HTML is a supported feature. If it is not, escape or remove HTML tags before generating Markdown. 5. Apply validation when items are added rather than relying exclusively on output-time sanitization. 6. Add tests covering injected headings, images, nested links, raw HTML, `javascript:` URLs, `data:` URLs, and newline-based document-structure injection. 7. Document that downstream publishing platforms should use a Markdown renderer configured to disable raw HTML and unsafe links.
