T09 · Insecure Skill Coding Practices
- Location
scripts/cleaning_report.py:78- Finding
Stored HTML and JavaScript Injection in Generated Reports
- Content
View full analysis
0 else f"{mins}分钟" note = e.get("note", "")[:20] or "-" table_rows += f""" {e.get('date', '')} {rooms_display} {dur_display} {note} """ ``` ### Technical Analysis The `date`, `rooms`, and `note` fields are inserted directly into an HTML document without context-appropriate escaping. These values originate from cleaning records supplied through the command-line interface and stored in SQLite. SQL parameterization protects the database from SQL injection, but it does not make retrieved strings safe for insertion into HTML. An attacker-controlled value such as: ```html``` can therefore become an active HTML element when placed in the `rooms` field. The browser executes the event handler when the generated report is opened. Because the malicious value is stored in the database, this is a stored injection vulnerability. The 20-character truncation applied to `note` is not a security control. Other fields, particularly `rooms`, are not truncated, and sufficiently compact payloads may also bypass length-based restrictions. ### Attack Path 1. An attacker or untrusted input source supplies a cleaning record containing an HTML payload in the room, date, or note field. 2. `cleaning_db.py` stores the value unchanged in `cleaning.db`. 3. The user generates a monthly HTML report. 4. `cleaning_report.py` retrieves the record and interpolates the malicious fiel ...[truncated 832 chars]
- Remediation
View remediation
`, event-handler attributes, quotes, and `` sequences. ]]>
