- Location
- scripts/pdd_analyzer.py:889
- Finding
- Unsanitized Remote HTML Is Written to Locally Opened Reports<![CDATA[
## Vulnerability Details
**File Location**: `scripts/pdd_analyzer.py:889-923`, with the resulting document written at `scripts/pdd_analyzer.py:1097-1106`
**Vulnerability Type**: Improper neutralization of remotely supplied active HTML
**Risk Level**: High
### Vulnerable Code
```python
if not report_html:
return ""
chart_data = (sections or {}).get("chart_data") or {}
html = report_html
```
```python
warnings_html = _render_api_warnings(api_warnings)
return _wrap_html_document(warnings_html + html)
```
```python
def _save_html_report(html: str) -> str:
"""将完整 HTML 报告写到本地文件,返回路径(供 stdout 指引)
token 优化:stdout 不回传 HTML+SVG(SVG 对 LLM 无意义,~7-13K token 纯浪费),
改回传 report markdown(~2K token);HTML 写文件供浏览器/IDE 渲染查看。
"""
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
ts = pd.Timestamp.now().strftime("%Y%m%d_%H%M%S")
path = CONFIG_DIR / f"report_{ts}.html"
path.write_text(html, encoding="utf-8")
return str(path)
```
### Technical Analysis
The `report_html` value originates from the remote paid API response. The renderer assigns this value directly to `html`, combines it with warning markup, and places it into a complete HTML document without applying an HTML allowlist sanitizer.
The generated report is saved under `~/.pdd_skill/`, and the user is explicitly instructed to open it in a browser or IDE. If the analysis service, its infrastructure, or the response-generation pipeline is compromised, the response can contain active content such as:
- `<script>` elements.
- Inline event handlers such as `onerror` or `onclick`.
- External images or other resources that create tracking requests.
- Iframes, forms, redirects, or deceptive payment interfaces.
- Unsafe URL schemes or browser-specific active content.
The same output boundary also affects API warning messages, which are interpolated into HTML without escaping in `_render_api_warnings`.
No Content Security Policy is added to the generated document. Consequently, th
...[truncated 1971 chars]
- Remediation
- <![CDATA[
## Remediation Suggestions
1. Do not accept server-generated HTML as trusted presentation content. Prefer returning structured JSON fields and constructing all markup locally.
2. If HTML support is required, sanitize it with a maintained allowlist sanitizer before document composition.
3. Allow only the minimum necessary elements, such as static headings, paragraphs, lists, and tables.
4. Remove at least:
- `script`, `iframe`, `object`, `embed`, `form`, `input`, `button`, `meta`, `base`, and `link` elements.
- All inline event-handler attributes.
- `srcdoc`, unsafe `style` content, and dangerous URL schemes.
- External resource URLs unless they are strictly required and validated.
5. HTML-escape API and local warning messages before interpolation.
6. Add a restrictive Content Security Policy to generated reports, such as:
```html
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src 'none'; connect-src 'none'; frame-src 'none'; form-action 'none'; base-uri 'none'">
```
7. Add automated security tests containing scripts, event handlers, iframes, external images, unsafe links, and malformed markup. Verify that generated reports contain no active content.
8. Consider rendering reports as Markdown or plain text by default and making HTML generation an explicit option.
]]>