T09 · Insecure Skill Coding Practices
- Location
scripts/generate_invoice.py:46- Finding
Unescaped JSON Data Allows HTML and Script Injection
- Content
View full analysis
Invoice {data['invoice_num']} ``` ```pythonInvoice #{data['invoice_num']}
Date: {data['date']} | Due: {data['due_date']}
Bill To:
{data['client']['name']}
``` ### Technical Analysis Values loaded from the supplied JSON file are interpolated directly into an HTML document without contextual output encoding. The affected fields include the invoice number, invoice and due dates, and client identity and contact fields. Because HTML metacharacters are not escaped, a value can terminate its intended text context and introduce arbitrary HTML elements. Depending on how the generated document is opened or converted, the injected markup may include scripts, event handlers, forms, misleading invoice content, or references to attacker-controlled remote resources. For example, a client name containing an image element with an error event handler would be embedded directly into the invoice: ```json { "client": { "name": "
{data['client']['address']}
{data['client']['email']}", "address": "Example Address", "email": "billing@example.com" } } ``` The source currently has a syntax error at line 99, so the vulnerable generation path cannot execute as provided. The vulnerability becomes reachable if that syntax error is corrected without also implementing output encoding. ### Attack Path 1. An attacker supplies or modifies an invoice JSON file. 2. The attacker places an HTML or JavaScript payload in an affected field such as `client.name`, `client.address`, `client.email`, or `invoice_num`. 3. The user invokes the invoice generator after the line 99 syntax error has been repaired. 4. The script inserts the payload into ...[truncated 925 chars]
- Remediation
View remediation
