fix(vscode): sanitize and lock down Dependencies webview to prevent XSS - #8029
fix(vscode): sanitize and lock down Dependencies webview to prevent XSS#8029Peter Ombwa (peombwa) wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the Kiota VS Code extension “Dependencies” webview against XSS by HTML-escaping dynamic values and introducing a restrictive Content Security Policy, plus regression tests to prevent reintroduction.
Changes:
- Added shared HTML utilities for escaping and CSP nonce generation.
- Escaped all dependency- and localization-derived strings before interpolating into the webview HTML.
- Added regression tests asserting malicious payloads are escaped and a CSP is present.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| vscode/packages/microsoft-kiota/src/utilities/html.ts | Adds escapeHtml and getNonce helpers used by webviews. |
| vscode/packages/microsoft-kiota/src/providers/dependenciesViewProvider.ts | Applies escaping to all dynamic webview HTML values and adds a CSP meta tag. |
| vscode/packages/microsoft-kiota/src/test/suite/providers/dependenciesViewProvider.test.ts | Adds regression tests covering escaping behavior and CSP presence. |
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in commit a62d951 in the Show a code coverage summary of the most covered files.
Updated |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
vscode/packages/microsoft-kiota/src/providers/dependenciesViewProvider.ts:8
- The webview HTML produced here doesn’t include any <script> tags or message handlers, but
resolveWebviewViewstill setsenableScripts: true. Even with a CSP, disabling scripts entirely is a stronger mitigation and reduces future XSS blast radius if any unescaped HTML slips in later.
import { escapeHtml, getNonce } from '../utilities/html';
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
vscode/packages/microsoft-kiota/src/providers/dependenciesViewProvider.ts:63
- The PR description mentions adding a
getNonce()helper and using a nonce-scopedscript-src, but the implemented CSP disables scripts entirely (script-src 'none') and there is no nonce helper. Please update the PR description to match the implemented approach (or adjust the implementation if you intended to allow scripts with a nonce).
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src ${webview.cspSource}; img-src ${webview.cspSource}; script-src 'none';">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
This PR fixes an XSS vulnerability in the Kiota VS Code extension's dependencies webview.
DependenciesViewProvider._getHtmlForWebview()interpolated dependencyName/Version, dependency type, and language strings directly into the webview's HTML (table rows and the "install commands"<pre>block) without any escaping. The webview also hadenableScripts: truewith no Content-Security-Policy. Any HTML/script content in a dependency name or version would render/execute unescaped, allowing an attacker to spoof the install commands shown to the user.Changes
escapeHtml()helper (src/utilities/html.ts).dependenciesViewProvider.ts(dependency name/version/type, language name, localized labels).Content-Security-Policymeta tag (default-src 'none', nonce-scopedscript-src, scopedstyle-src/img-src) - none existed previously.webview.html =patterns; this was the only instance.dependenciesViewProvider.test.ts) that feed malicious dependency name/version payloads and assert the output is escaped and includes a CSP.