T09 · Insecure Skill Coding Practices
- Location
scripts/render_text_image.py:480- Finding
SVG Attribute Injection Through Unvalidated Style Fields
- Content
View full analysis
', f'', ] for index, line in enumerate(lines): y = start_y + index * font_size * line_height current_x = line_start_x(align, width, padding, line_pixel_width(line, font_size)) svg_lines.append( f'' ) for item in line: color = escape(str(item["color"])) text = escape(item["text"]) svg_lines.append( f'{text}' ) current_x += text_width(item["text"], font_size) svg_lines.append("") ``` ### Technical Analysis The `background`, `font_family`, and segment or highlight `color` fields are controlled by the input specification and are interpolated into double-quoted SVG attributes. The code applies `xml.sax.saxutils.escape()` without providing an entity mapping for quotation marks. By default, this function escapes `&`, `<`, and `>`, but it does not escape `"`. An attacker can therefore insert a double quote to terminate the intended attribute and inject additional SVG attributes ...[truncated 2084 chars]- Remediation
View remediation
str: return escape( str(value), { '"': """, "'": "'", }, ) ``` 4. Prefer constructing the SVG with a standards-compliant XML library that serializes attribute values safely instead of assembling XML through string interpolation. 5. Consider sanitizing the completed SVG with a policy that rejects scripts, event-handler attributes, external references, foreign objects, and unsafe URL schemes. 6. Add regression tests containing quotation marks and attempted SVG payloads in every attribute-bearing input field. Verify that the resulting SVG parses only as the intended elements and attributes. ]]>
