T09 · Insecure Skill Coding Practices
- Location
scripts/fetch_growth_rank.py:121- Finding
Unescaped Remote Data Rendered as Trusted Markdown
- Content
View full analysis
Vulnerability Details
File Location:
scripts/fetch_growth_rank.py, lines 121–124 and 196–210
Vulnerability Type: Markdown content and link injection
Risk Level: MediumVulnerable Code
python def make_link(title: str, url: str) -> str: """生成Markdown链接""" t, u = safe_str(title), safe_str(url) return f'[{t}]({u})' if t != "-" and u != "-" else tpython for rank_num, (acc, score) in enumerate(scored_data, 1): max_w = acc.get("maxWork") or {} user = safe_str(acc.get("userName")) lines.append( f"| {rank_num} | {user} | {make_link(max_w.get('title'), max_w.get('oriUrl'))} | " f"{format_count(max_w.get('watchCount'))} | {format_count(max_w.get('likeCount'))} | " f"{format_count(max_w.get('shareCount'))} | {safe_str(max_w.get('clicksCount'))} | " f"{safe_str(max_w.get('publicTime'))} | {score:.2f} |" )Technical Analysis
The script obtains ranking and article fields from the remote RedFox API and inserts
userName,maxWork.title, andmaxWork.oriUrldirectly into a Markdown table. Thesafe_strfunction only converts values to strings and does not escape Markdown metacharacters, table delimiters, line breaks, or control characters.The
make_linkfunction also accepts the API-provided URL without parsing it or restricting its scheme. Consequently, crafted remote values can terminate the intended table cell or link syntax and introduce additional Markdown elements. This conflicts with the Skill instructions requiring the script's standard output to be displayed verbatim, because the Agent is explicitly instructed not to sanitize or reformat the generated output after execution.Attack Path
- A remote ranking record contains a crafted account name, article title, or original-article URL.
fetch_dataretrieves the record from the configured RedFox API endpoint.render_tablepasses the remote t ...[truncated 1083 chars]
- Remediation
View remediation
Remediation Suggestions
- Escape Markdown control characters in every API-derived text field, including backslashes, pipes, brackets, parentheses, carriage returns, and line feeds.
- Normalize each value to a single line before inserting it into the table.
- Parse
oriUrlwith a standard URL parser and allow only expected schemes, preferablyhttps. - Reject malformed URLs and render their titles as escaped plain text rather than clickable links.
- Consider restricting links to expected article hosts if that restriction is compatible with the service.
- Add tests covering table delimiters, nested links, image syntax, multiline values, control characters, and disallowed URL schemes.
- Revise the verbatim-output instruction so it applies only after remote fields have been validated and safely encoded by the script.
