T09 · Insecure Skill Coding Practices
- Location
scripts/check_svg.py:38- Finding
Incomplete Detection of External SVG Resources
- Content
View full analysis
Vulnerability Details
File Location:
scripts/check_svg.py, lines 38–49
Vulnerability Type: Incomplete validation of externally referenced SVG resources
Risk Level: MediumVulnerable Code
python for element in root.iter(): name = local_name(element.tag) if name in DISALLOWED_TAGS: errors.append(f"Disallowed tag found: <{name}>") if name == "image": href = element.attrib.get("href") or element.attrib.get("{http://www.w3.org/1999/xlink}href") if href and (href.startswith("http://") or href.startswith("https://")): errors.append("Remote image reference found in <image>.") if name == "text" and (element.text or "").strip(): text_nodes += 1Technical Analysis
The validator checks remote
hrefvalues only when the current element is an<image>. SVG documents can reference external resources through other constructs, including<use>and<feImage>elements, as well as CSS or presentation attributes containingurl(...).Consequently, an SVG can contain a remote reference while satisfying every implemented validation requirement. This conflicts with the skill's stated guarantee that generated artwork has no external asset references and is self-contained.
The URL comparison is also narrowly limited to literal lowercase
http://andhttps://prefixes. It does not account for protocol-relative URLs, case variations, leading whitespace, or external references expressed through CSS.Attack Path
-
An attacker or untrusted generation source supplies an SVG with the required root element, dimensions,
viewBox, and a non-empty<text>node. -
The SVG embeds an external reference outside an
<image>element, for example:svg <use href="https://attacker.example/remote.svg#object"/> -
validate_svg()does not inspect thishrefbecause the element name isuse. -
The validator returns no error and reports the SVG as structurally valid.
-
A ...[truncated 890 chars]
-
- Remediation
View remediation
Remediation Suggestions
- Inspect
hrefand namespacedxlink:hrefattributes on every SVG element rather than only<image>. - Adopt an allowlist that permits only local fragment references such as
#local-idwhere external resources are unnecessary. - Reject absolute URLs, protocol-relative URLs, and unsupported URI schemes after trimming whitespace and normalizing the scheme.
- Inspect all presentation attributes and
<style>content for externalurl(...)references. - Cover relevant resource-bearing elements, including
<use>,<feImage>, and any other supported SVG elements capable of resolving URLs. - Add regression tests for:
- Remote references in
<use>and<feImage>. - External CSS
url(...)values. - Protocol-relative URLs.
- Mixed-case schemes.
- Leading whitespace and encoded URL variants.
- Valid local fragment references.
- Remote references in
- Consider processing untrusted SVG files in a renderer configured to deny network access, providing defense in depth if validation is bypassed.
- Inspect
