T09 · Insecure Skill Coding Practices
- Location
scripts/bundle.py:267- Finding
Unsafe Markdown Link Schemes Allow JavaScript Execution
- Content
View full analysis
$1"); t=t.replace(/\*\*([^*]+)\*\*/g,"$1"); t=t.replace(/\*([^*\n]+)\*/g,"$1"); t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g,""); t=t.replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+["']([^"']*)["'])?\)/g,"$1"); return t; } function renderLinks(el){ el.querySelectorAll("a[data-href]").forEach(a=>{ let h=a.getAttribute("data-href"); if(/^\.md$|^[\w\-/.]+(?:\.md)(?:#.*)?$/.test(h)||h.endsWith(".md")){ a.addEventListener("click",()=>openMd(h)); a.title="内部文档链接"; }else if(/^https?:\/\//.test(h)){ a.href=h;a.target="_blank"; }else{a.href=h;} }); } ``` ### Technical Analysis Markdown content is treated as untrusted input and embedded in the generated HTML. The custom Markdown renderer converts every Markdown link destination into a `data-href` attribute. The `renderLinks` function subsequently assigns that value to the link element's `href` property. Only HTTP and HTTPS URLs receive special handling. All other non-Markdown destinations are assigned directly through the following branch: ```javascript else{a.href=h;} ``` There is no allowlist that rejects active or dangerous schemes such as `javascript:`, `data:`, or `vbscript:`. Consequently, Markdown such as: ```markdown [Open document](javascript:alert(document.domain)) ``` is converted into a clickable link with a `javascript:` URL. Clicking it executes attacker-controlled JavaScript in the context of the generated document. The escaping function used before link conversion only escapes ampersands and angle brackets. It does not escape quotation marks, making string-based HTML a ...[truncated 1719 chars]
- Remediation
View remediation
