[Bug] Chat webview renders Markdown into innerHTML without sanitization, permitting layout injection and external image tracking
Description
In plugins/vscode/media/chat-panel.js (lines 1940, 2066, 3449), assistant responses and user inputs are parsed with marked.parse(...) and assigned directly to element.innerHTML without HTML sanitization. In plugins/vscode/media/chat-panel.html:9, the Content Security Policy allows:
img-src 'self' data: https: vscode-webview-resource:;
While script execution is constrained by CSP nonces, unsanitized HTML can alter webview layout or inject unwanted HTML elements. Furthermore, allowing arbitrary HTTPS images allows external image requests (e.g. tracking pixels) that expose the user's IP address.
Environment
- OS: Linux (reviewed); macOS / Windows potentially affected
- Node version: >= 22.0.0
- Nanocoder version: 1.31.0
Steps to Reproduce
- Have the model return raw HTML formatting tags or
<img src="https://example.com/tracking.png">. - Inspect the webview DOM and network activity.
Expected Behavior
All HTML from marked.parse() should pass through a sanitizer (such as DOMPurify) before being assigned to innerHTML. External image loading should adhere to a strict policy.
Actual Behavior
Raw HTML emitted by marked.parse(...) is injected straight into the webview DOM, and external HTTPS images are loaded.
Additional Context
- [x] No matching open issue found in issue search performed on 2026-10-12
- [x] Relevant code paths inspected at commit
d5ff9c37
Implementation Notes (optional)
- Files:
plugins/vscode/media/chat-panel.js:1940, 2066, 3449plugins/vscode/media/chat-panel.html:9
- Bundle
DOMPurifyinto the webview and sanitize allmarked.parse()outputs before writing toinnerHTML. - Tighten the CSP image policy or restrict external images.
@akramcodez i'll fix this
I'd like to pick this up. Plan: run the marked.parse() output through a sanitizer (DOMPurify) before every innerHTML assignment in chat-panel.js, and drop remote https: from img-src in the webview CSP so responses can't trigger external image requests. Code blocks, links and highlighting stay as they are. Could you assign it to me?
Hi @Mahdi-Hasan, thanks so much for your interest in this issue! @Dhirenderchoudhary asked to be assigned first, so I’m assigning it to them. Please feel free to look through the other open issues. Thanks !