T09 · Insecure Skill Coding Practices
- Location
SKILL.md:392- Finding
Stored HTML Injection in Browser-Rendered Diagnosis Reports
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 392–394, 423–433, and 469
Vulnerability Type: Stored HTML/script injection through insufficient output encoding
Risk Level: MediumVulnerable Snippets
html <tr><td>1</td><td>{query_id}</td><td>{username}</td><td>{pct}%</td><td>{start_time_beijing}</td><td class="sql-text">{query_text}</td></tr> <tr><td>2</td><td>{query_id}</td><td>{username}</td><td>{pct}%</td><td>{start_time_beijing}</td><td class="sql-text">{query_text}</td></tr> <tr><td>3</td><td>{query_id}</td><td>{username}</td><td>{pct}%</td><td>{start_time_beijing}</td><td class="sql-text">{query_text}</td></tr>The diagnosis summary also embeds the username without an encoding requirement:
html <div class="loc-row"><span class="loc-key">用户名</span><span class="loc-val">{username}</span></div>The general output rule only mandates escaping SQL text:
text Output is a complete HTML document that can be rendered directly in a browser; `<` `>` `&` in SQL text must be escaped as `<` `>` `&`.Technical Analysis
The Skill retrieves database usernames and related diagnostic fields from
cpu_io_diagnose_detail, places those values into an HTML report, saves the report to the workspace, and expects it to be rendered in a browser. The report template inserts{username}directly into HTML element content.Although the instructions explicitly require escaping
<,>, and&in SQL text, they do not impose equivalent contextual HTML encoding on usernames. A database principal capable of selecting a specially crafted quoted username can therefore cause markup to enter the monitoring results and subsequently the generated report.For example, a username containing an HTML element with an event handler would be interpreted as markup rather than displayed as text if inserted without encoding. This is an exploitable output-encoding flaw rather than evidence that the Skill author deliberately intended t ...[truncated 1753 chars]
- Remediation
View remediation
Remediation Suggestions
-
Apply contextual HTML encoding to every dynamic value before inserting it into the report, including:
- Database and operating-system usernames
- Cluster and node names
- Resource, query, and project identifiers
- SQL text and summaries
- Process and command names
- Tool-returned error messages and metric values
-
Use a template engine with automatic HTML escaping rather than direct string substitution. Permit raw HTML only for fixed markup generated internally by trusted report logic.
-
Encode at least
&,<,>,", and'for values inserted into HTML text or attributes. Use context-specific encoders for URLs, CSS, or attributes if dynamic values are ever introduced into those contexts. -
Keep
diagnosis_summarystructured internally as data rather than preformatted HTML. Render its fields through the same escaping template layer. -
Add regression tests using values such as:
text <img src=x onerror=alert(1)> "><svg onload=alert(1)> <script>alert(1)</script>The resulting report must display these values as literal text and must not create executable DOM elements.
- Consider adding a restrictive Content Security Policy to the generated report as defense in depth, for example by disallowing scripts and limiting network destinations. This does not replace correct output encoding.
-
