T09 · Insecure Skill Coding Practices
- Location
scripts/score_papers.py:284- Finding
Untrusted Paper Metadata Is Emitted Without Safe Markdown or HTML Escaping
- Content
View full analysis
Vulnerability Details
File Location:
scripts/score_papers.py:284-318
Vulnerability Type: Improper neutralization of externally controlled content in generated Markdown
Risk Level: MediumVulnerable Code
python def markdown_link(value): value = str(value or "").strip() if not value: return "" label = "PDF" if ".pdf" in value.lower() else "Link" if value.startswith("http"): return f"[{label}]({value})" return value def write_markdown(rows, path): headers = ["Tier", "Source", "Title", "Authors", "Year", "Venue", "IF", "Rank/Tags", "Citations", "Access", "Why keep"] lines = [ "| " + " | ".join(headers) + " |", "|---|---|---|---:|---:|---|---:|---|---:|---|---|", ] rows = sorted(rows, key=ranking_key) for row in rows: values = [ row.get("tier", ""), row.get("source", ""), row.get("title", ""), row.get("authors", ""), row.get("year", ""), row.get("venue", ""), row.get("impact_factor", ""), row.get("rank_tags", ""), row.get("citations", ""), markdown_link(row.get("access_link", "")), row.get("why_keep", ""), ] clean = [str(v).replace("\n", " ").replace("|", "\\|") for v in values] lines.append("| " + " | ".join(clean) + " |")Technical Analysis
Candidate records are loaded from user-supplied JSON or CSV files and may also originate from externally retrieved Google Scholar or MCP metadata. Fields such as titles, authors, venues, reasons, and access links are therefore not inherently trusted.
The Markdown generator only removes newline characters and escapes table separators. It does not neutralize raw HTML or Markdown control characters. Consequently, values containing raw HTML are written unchanged into the generated re ...[truncated 2161 chars]
- Remediation
View remediation
Remediation Suggestions
- Treat every field from candidate JSON, CSV, Scholar, and MCP results as untrusted.
- Escape Markdown metacharacters contextually in all table cells, including backslashes, brackets, parentheses, angle brackets, backticks, and other formatting controls.
- Strip or encode raw HTML before writing metadata to Markdown. Do not rely solely on downstream renderers to sanitize generated reports.
- Parse access links with a standard URL parser and allow only exact
httpandhttpsschemes. - Reject URLs containing control characters, malformed authority components, or unsafe syntax.
- Safely encode characters that can terminate Markdown link destinations, particularly parentheses.
- Prefer a maintained Markdown-generation library that provides contextual escaping rather than constructing Markdown through direct string interpolation.
- Document that generated reports must be viewed with raw HTML disabled or through a renderer using a strict HTML sanitizer and content security policy.
- Add regression tests using hostile titles, authors, reasons, and URLs to verify that injected HTML and Markdown are rendered only as inert text.
