T09 · Insecure Skill Coding Practices
- Location
scripts/chart.py:107- Finding
Unescaped External Token Metadata Injected into Generated SVG
- Content
View full analysis
Vulnerability Details
File Location:
scripts/chart.py:43-47, 57-62, 107-110, 150-155
Vulnerability Type: SVG/XML injection through unescaped external metadata
Risk Level: MediumComplete Code Snippet
python # Lines 43-47: Solana search results supply the symbol. best = max(rows, key=lambda t: (t.get("symbol", "").lower() == query.lower(), t.get("liquidityUsd") or 0)) return best["token"], best.get("symbol") # Lines 57-62: EVM search results supply the symbol. best = max(hits, key=lambda t: (bool(t.get("verified")), t.get("liquidityUsd") or 0)) return best["address"].lower(), best.get("symbol") # Lines 107-110: The title is inserted directly into SVG markup. out = [f'<svg xmlns="http://www.w3.org/2000/svg" width="{W}" height="{H}" viewBox="0 0 {W} {H}" font-family="ui-monospace,Menlo,Consolas,monospace">', f'<rect width="{W}" height="{H}" fill="#0b0f0e"/>', f'<text x="{L}" y="30" fill="#e8ecea" font-size="20" font-family="system-ui,sans-serif" font-weight="700">{title}</text>', f'<text x="{L}" y="50" fill="#8a9590" font-size="12">{subtitle}</text>'] # Lines 150-155: The external symbol is placed in the title and written # to the generated SVG file. sym = sym or a.token[:10] first, last = rows[0]["o"], rows[-1]["c"] chg = (last / first - 1) * 100 if first else 0.0 vol = sum(r["v"] for r in rows) trades = sum(r.get("n") or 0 for r in rows) span = f'{dt.datetime.fromtimestamp(rows[0]["t"], dt.timezone.utc):%Y-%m-%d %H:%M} to {dt.datetime.fromtimestamp(rows[-1]["t"], dt.timezone.utc):%Y-%m-%d %H:%M} UTC' title = f"{sym} · {a.chain} · {a.tf} ${fmt_price(last)} {chg:+.2f}%"Technical Analysis
When a token is selected by symbol or name rather than by address,
resolve()obtains its display symbol from the external Chord API. That value is assigned tosym, incorporated intotitle, and interpolated directly into an ...[truncated 1995 chars]- Remediation
View remediation
Remediation Suggestions
- XML-escape every externally derived string before inserting it into SVG markup. For example, apply
html.escape(value, quote=True)totitle,subtitle, and any future textual metadata. - Prefer constructing the SVG with a structured XML API such as
xml.etree.ElementTree, which serializes text nodes safely instead of relying on string interpolation. - Apply a conservative display-character policy to token symbols, allowing only characters required for legitimate symbols and replacing or rejecting control characters and XML syntax.
- Keep validation and output encoding separate: validation reduces unexpected content, while context-appropriate XML escaping remains mandatory.
- Add regression tests using symbols containing
&,<,>, quotes, closingtexttags, and SVG event-handler payloads. Verify that these values remain literal text in the generated document. - Where practical, serve or open generated SVGs with restrictive sandboxing and Content Security Policy. This is defense in depth and must not replace output encoding.
- XML-escape every externally derived string before inserting it into SVG markup. For example, apply
