T09 · Insecure Skill Coding Practices
- Location
md_to_pdf_v4.py:804- Finding
Untrusted Markdown and document titles can execute active HTML in the rendering browser
- Content
View full analysis
str: with open(md_path, "r", encoding="utf-8", errors="replace") as f: for line in f: line = line.strip() if line.startswith("# "): return sanitize_title(line[2:].strip()) return pathlib.Path(md_path).stem ``` The extracted title is inserted directly into HTML: ```python cover_html_content = f''' @page {{ size: A4; margin: 0; }} * {{ margin: 0; padding: 0; box-sizing: border-box; }} body {{ font-family: "Microsoft YaHei", "PingFang SC", sans-serif; height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #111827; background: #ffffff; margin: 0; padding: 0; }} .cover-title {{ font-size: 28pt; font-weight: 700; margin-bottom: 80px; line-height: 1.4; }} .cover-date {{ font-size: 14pt; color: #6b7280; border-top: 2px solid #e5e7eb; padding-top: 20px; width: 200px; line-height: 1.5; }}{title}{today}''' ``` The Markdown body is converted using a Pandoc reader configuration that does not explicitly disable raw HTML: ```python cmd = [ PANDOC, md_path, "-o", html_path, "--standalone", "--from", "markdown-fancy_lists", "--mathml", "--highlight-style", "pygments", "--metadata", "lang=zh-CN", ] ``` The resulting HTML is then loaded in a CDP-connected browser: ```python with sync_playwright() as p: browser = p.chromium.connect_over_cdp("http://127.0.0.1:9222") page = browser.new_page(viewport={ ...[truncated 2948 chars]- Remediation
View remediation
