T09 · Insecure Skill Coding Practices
Error
- Location
- assets/invoice-template.html:10
- Finding
- Unescaped Template Substitution Allows HTML and Script Injection<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:34-36`; `assets/invoice-template.html:10-27, 42-88` **Vulnerability Type**: Unescaped user-controlled data inserted into HTML and CSS contexts **Risk Level**: High ### Vulnerable Code `SKILL.md:34-36`: ```markdown 2. Read the template at `assets/invoice-template.html` 3. Replace placeholders with actual data, calculate totals 4. Save as `.html` file — user can open in browser and Print → PDF ``` `assets/invoice-template.html:10-27`: ```html .header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 48px; padding-bottom: 24px; border-bottom: 3px solid {{PRIMARY_COLOR}}; } .brand { font-size: 1.8rem; font-weight: 800; color: {{PRIMARY_COLOR}}; } thead th { background: {{PRIMARY_COLOR}}; color: #fff; padding: 12px 16px; text-align: left; font-size: .85rem; text-transform: uppercase; letter-spacing: .5px; } .totals-row.total { border-bottom: none; border-top: 2px solid {{PRIMARY_COLOR}}; font-weight: 800; font-size: 1.2rem; color: {{PRIMARY_COLOR}}; padding-top: 12px; } ``` `assets/invoice-template.html:42-88`: ```html <div class="header"> <div> <div class="brand">{{SENDER_NAME}}</div> <div class="party-detail">{{SENDER_ADDRESS}}<br>{{SENDER_EMAIL}}<br>{{SENDER_PHONE}}</div> </div> <div class="invoice-meta"> <h2>Invoice</h2> <p><strong>#{{INVOICE_NUMBER}}</strong></p> <p>Date: {{INVOICE_DATE}}</p> <p>Due: {{DUE_DATE}}</p> </div> </div> <div class="parties"> <div> <div class="party-label">Bill To</div> <div class="party-name">{{CLIENT_NAME}}</div> <div class="party-detail">{{CLIENT_ADDRESS}}<br>{{CLIENT_EMAIL}}</div> </div> </div> <table> <thead> <tr> <th>Description</th> <th>Qty</th> <th>Unit Price</th> <th>Amount</th> </tr> </thead> <tbody> {{LINE_ITEMS}} </tbody> </table> <div class="totals"> <div class="totals-table"> <div class="totals-row"><span>Subtotal< ...[truncated 2972 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Apply context-sensitive HTML escaping to every text value, including sender details, client details, invoice identifiers, dates, payment terms, notes, and line-item descriptions. At minimum, encode `&`, `<`, `>`, `"`, and `'`. 2. Do not accept preformatted `LINE_ITEMS` or `NOTES_SECTION` HTML from user input. Represent these values as structured data and generate the necessary elements through a trusted renderer. 3. Validate `PRIMARY_COLOR` against a strict allowlist, such as: - Six-digit hexadecimal colors matching `^#[0-9A-Fa-f]{6}$`. - A small predefined set of approved color names. 4. Parse quantities, prices, tax rates, and totals as bounded numeric values. Format them only after performing calculations with an appropriate decimal currency type. 5. Validate dates and invoice numbers against documented schemas and length limits. 6. Add a restrictive Content Security Policy, preferably through a `<meta http-equiv="Content-Security-Policy">` element for the standalone file. Disallow scripts and external resources unless explicitly required. 7. Add security tests containing payloads such as closing tags, event-handler attributes, `</style>` sequences, SVG markup, and malformed line-item data. Verify that they are displayed as inert text. 8. Update `SKILL.md` to explicitly require escaping, structured rendering, and validation rather than generic placeholder replacement. ]]>
