Try adopting native sanitizer instead of dompurify in copilot#320026
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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() }); | ||
| } |
DonJayamanne
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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