T09 · Insecure Skill Coding Practices
- Location
assets/application-tracker.html:305- Finding
Persistent DOM-Based Cross-Site Scripting Through Imported Record IDs
- Content
View full analysis
` ${escapeHtml(formatDate(item.date))} ${escapeHtml(item.company)} ${escapeHtml(item.position || '-')} ${escapeHtml(item.status)} ${escapeHtml(item.next || '-')} ${escapeHtml(item.note || '-')}编辑删除`).join(''); ``` The corresponding import validation is: ```javascript let id = item.id; if (id == null || id === '') { do { id = makeId(); } while (seenIds.has(id)); } else if (typeof id !== 'string' || !id.trim() || id !== id.trim()) fail('ID 格式无效'); if (seenIds.has(id)) fail('ID 重复'); seenIds.add(id); ``` ### Technical Analysis The application renders records by assigning an HTML string to `body.innerHTML`. Most displayed record properties are passed through `escapeHtml`, but `item.id` is inserted directly into the quoted `data-edit` and `data-delete` attributes. Imported IDs are only checked for type, surrounding whitespace, emptiness, and duplication. Quotes, angle brackets, and event-handler syntax are accepted. An attacker can therefore terminate the `data-edit` attribute and inject another attribute or element. For example, an imported ID similar to the following can create an executable event handler: ```text " onmouseover="alert(document.domain) ``` Because imported records are saved in `localStorage`, the injected markup is persistent and is rendered again wheneve ...[truncated 1399 chars]- Remediation
View remediation
