nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Chat webview renders Markdown into innerHTML without sanitization, permitting layout injection and external image tracking

Open akramcodez opened this issue 1 month ago • 3 comments

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

  1. Have the model return raw HTML formatting tags or <img src="https://example.com/tracking.png">.
  2. 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, 3449
    • plugins/vscode/media/chat-panel.html:9
  • Bundle DOMPurify into the webview and sanitize all marked.parse() outputs before writing to innerHTML.
  • Tighten the CSP image policy or restrict external images.

akramcodez avatar Oct 12 '26 11:10 akramcodez

@akramcodez i'll fix this

Dhirenderchoudhary avatar Oct 12 '26 14:10 Dhirenderchoudhary

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?

Mahdi-Hasan avatar Nov 02 '26 11:11 Mahdi-Hasan

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 !

addyCooks avatar Nov 06 '26 11:11 addyCooks