Skip to content

Try adopting native sanitizer instead of dompurify in copilot#320026

Merged
mjbvz merged 1 commit into
mainfrom
dev/mjbvz/psychiatric-kingfisher
Jun 5, 2026
Merged

Try adopting native sanitizer instead of dompurify in copilot#320026
mjbvz merged 1 commit into
mainfrom
dev/mjbvz/psychiatric-kingfisher

Conversation

@mjbvz
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz commented Jun 5, 2026

Just doing this in this one limited location for now for testing. Should be pretty low impact if it doesn't work

Currently not supported in Safari which blocks wider adoption

Just doing this in this one limited location for now for testing. Should be pretty low impact if it doesn't work

Currently not supported in Safari which blocks wider adoption
@mjbvz mjbvz self-assigned this Jun 5, 2026
Copilot AI review requested due to automatic review settings June 5, 2026 00:13
@mjbvz mjbvz enabled auto-merge June 5, 2026 00:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR experiments with replacing DOMPurify-based HTML sanitization in the Copilot Suggestions Panel webview with the browser-native Sanitizer / Element.setHTML API, while also tightening snippet escaping on the snippet generation side. It also removes the DOMPurify dependency from the Copilot extension package.

Changes:

  • Escapes raw <pre> snippet output when syntax highlighting is unavailable.
  • Reworks the suggestions panel webview rendering to construct DOM nodes and set snippet HTML via native Sanitizer APIs.
  • Removes dompurify (and related lockfile entries) from the extension dependencies.
Show a summary per file
File Description
extensions/copilot/src/extension/completions-core/vscode-node/extension/src/panelShared/highlighter.ts Escapes raw snippet text in the non-highlighted fallback path to prevent HTML injection.
extensions/copilot/src/extension/completions-core/vscode-node/extension/src/copilotPanel/webView/suggestionsPanelWebview.ts Replaces string-based innerHTML construction + DOMPurify with DOM element construction and native setHTML + Sanitizer for snippets.
extensions/copilot/package.json Removes the dompurify direct dependency.
extensions/copilot/package-lock.json Removes dompurify and its optional @types/trusted-types lock entries.

Copilot's findings

Files not reviewed (1)
  • extensions/copilot/package-lock.json: Language not supported
  • Files reviewed: 3/4 changed files
  • Comments generated: 1

Comment on lines +98 to +101
function setSnippetHtml(element: HTMLElement, html: string): void {
const sanitizerElement = element as unknown as SanitizableHTMLElement;
sanitizerElement.setHTML(html, { sanitizer: getSnippetSanitizer() });
}
@mjbvz mjbvz merged commit 841ce52 into main Jun 5, 2026
40 of 41 checks passed
@mjbvz mjbvz deleted the dev/mjbvz/psychiatric-kingfisher branch June 5, 2026 16:53
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants