T09 · Insecure Skill Coding Practices
- Location
scripts/gen_dashboard.py:289- Finding
Stored HTML and JavaScript Injection in Generated Dashboard
- Content
View full analysis
0) {{ usageHtml = c.usage.map(u => '📎 ' + u.section + ' [' + u.start + 's→' + u.end + 's] ' + u.note + '' ).join(''); }} else {{ usageHtml = '未在成品中使用'; }} let speechHtml = ''; if (c.speech.length > 0) {{ speechHtml = c.speech.map(s => '💬 ' + s + '').join(''); }} detail.innerHTML = '📹 ' + c.file + '
' + '' + ''; ``` ### Technical Analysis The dashboard embeds data derived from analysis and edit-plan JSON files directly into an executable `' + '' + thumbs + '' + '' + '时长:' + c.dur.toFixed(1) + '秒' + '画面:' + c.visual + '' + (speechHtml ? '语音内容:' + speechHtml + '' : '') + '使用情况:' + '' + usageHtml + '- Remediation
View remediation
... ``` Before embedding it, escape at least `<`, `>`, `&`, U+2028, and U+2029. Parse it through the element's `textContent`. 2. Replace dynamic `innerHTML` construction with safe DOM APIs: ```javascript const name = document.createElement('h3'); name.textContent = c.file; detail.replaceChildren(name); ``` 3. Use `textContent` for filenames, transcripts, notes, descriptions, and section names. Only use `innerHTML` for fixed, developer-controlled markup. 4. If HTML templates remain necessary, apply a well-reviewed context-aware sanitizer and keep untrusted values separate from markup. 5. Validate filenames and generated relative paths. Reject control characters, traversal sequences, and characters that are unnecessary for supported media filenames. 6. Add regression tests containing payloads such as closing script sequences, image error handlers, quotes, angle brackets, and multiline transcript content. Verify that they are displayed as text and never executed. ]]>
