Skip to content

fix(vscode): sanitize and lock down Dependencies webview to prevent XSS - #8029

Open
Peter Ombwa (peombwa) wants to merge 3 commits into
mainfrom
fix/dependencies-webview-xss-msrc-131309
Open

fix(vscode): sanitize and lock down Dependencies webview to prevent XSS#8029
Peter Ombwa (peombwa) wants to merge 3 commits into
mainfrom
fix/dependencies-webview-xss-msrc-131309

Conversation

@peombwa

@peombwa Peter Ombwa (peombwa) commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes an XSS vulnerability in the Kiota VS Code extension's dependencies webview.

DependenciesViewProvider._getHtmlForWebview() interpolated dependency Name/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 had enableScripts: true with 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

  • Added escapeHtml() helper (src/utilities/html.ts).
  • Escaped all dynamic values before HTML interpolation in dependenciesViewProvider.ts (dependency name/version/type, language name, localized labels).
  • Added a strict Content-Security-Policy meta tag (default-src 'none', nonce-scoped script-src, scoped style-src/img-src) - none existed previously.
  • Audited the rest of the extension for similar webview.html = patterns; this was the only instance.
  • Added regression tests (dependenciesViewProvider.test.ts) that feed malicious dependency name/version payloads and assert the output is escaped and includes a CSP.

Copilot AI lite review requested due to automatic review settings August 5, 2026 23:13
@msgraph-bot msgraph-bot Bot added this to Kiota Aug 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment thread vscode/packages/microsoft-kiota/src/utilities/html.ts Outdated
@github-code-quality

github-code-quality Bot commented Aug 5, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: C#

C# / code-coverage/dotnet

The overall coverage in commit a62d951 in the fix/dependencies-web... branch is 72%. Coverage data for the main branch is not yet available.

Show a code coverage summary of the most covered files.
File main fix/dependencies-web... a62d951 +/-
/home/runner/wo...guageRefiner.cs 98%
/home/runner/wo...criptRefiner.cs 98%
/home/runner/wo...MethodWriter.cs 97%
/home/runner/wo...MethodWriter.cs 96%
/home/runner/wo...MethodWriter.cs 96%
/home/runner/wo...MethodWriter.cs 95%
/home/runner/wo...rs/GoRefiner.cs 94%
/home/runner/wo...KiotaBuilder.cs 90%
/home/runner/wo...ationService.cs 89%
/home/runner/wo...xGenerator.g.cs 75%

Updated August 05, 2026 23:55 UTC

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 5, 2026 23:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 resolveWebviewView still sets enableScripts: 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';

Copilot AI review requested due to automatic review settings August 5, 2026 23:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-scoped script-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">

@peombwa
Peter Ombwa (peombwa) marked this pull request as ready for review August 6, 2026 00:13
@peombwa
Peter Ombwa (peombwa) requested a review from a team as a code owner August 6, 2026 00:13
@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Aug 6, 2026
@gavinbarron
Gavin Barron (gavinbarron) added this pull request to the merge queue Aug 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress 🚧

Development

Successfully merging this pull request may close these issues.

3 participants