agent-governance-toolkit icon indicating copy to clipboard operation
agent-governance-toolkit copied to clipboard

security(vscode): Missing Content-Security-Policy on 4 legacy webview panels

Open Knapp-Kevin opened this issue 8 months ago • 2 comments

Summary

Four webview panels generate HTML with inline <script> blocks but include no Content-Security-Policy header and no nonce-gated script loading:

  • src/webviews/policyEditor/PolicyEditorPanel.ts (_getHtmlForWebview)
  • src/webviews/workflowDesigner/WorkflowDesignerPanel.ts (_getHtmlForWebview)
  • src/webviews/metricsDashboard/MetricsDashboardPanel.ts (_getHtmlForWebview)
  • src/webviews/onboarding/OnboardingPanel.ts (_getHtmlForWebview)

Without CSP, if any XSS payload reaches the HTML, it executes without restriction.

Recommended Fix

Add CSP meta tags with nonces matching the pattern already used by SidebarProvider.ts:

<meta http-equiv="Content-Security-Policy"
      content="default-src 'none';
               style-src ${webview.cspSource} 'unsafe-inline';
               script-src 'nonce-${nonce}';
               font-src ${webview.cspSource};" />

Move inline scripts to external files loaded via webview.asWebviewUri() with nonce attributes. Set localResourceRoots on createWebviewPanel options.

Additional Findings in Same Area

  1. OnboardingPanel.ts:179-181 — _executeAction executes arbitrary VS Code commands from the webview with no allowlist validation. Should validate command against a known safe set.

  2. extension.ts:841-905 (generateCMVKResultsHTML) — No CSP, no HTML escaping on API-sourced strings (m.model, m.summary, issues, recommendations). A malicious CMVK API response could inject script tags.

Severity

Critical — these are the only webview surfaces in the extension without CSP.

Knapp-Kevin avatar Mar 28 '26 00:03 Knapp-Kevin

Welcome to the Agent Governance Toolkit! Thanks for opening your first issue. A maintainer will review this shortly. Check our Contributing Guide. For security issues, use private vulnerability reporting.

github-actions[bot] avatar Mar 28 '26 00:03 github-actions[bot]

🤖 AI Agent: contributor-guide

Hi @user! 👋

Welcome to the microsoft/agent-governance-toolkit project, and thank you for taking the time to report this detailed issue! 🎉 We’re thrilled to have you here, and your contribution is already making a difference. Let’s dive into your report.


🔍 Issue Analysis

Your report highlights a critical security concern regarding the lack of a Content-Security-Policy (CSP) in several webview panels. This is a significant issue, as webviews are often a target for XSS attacks. Let’s break this down:

Relevant Package(s)

Based on the files and functionality mentioned, this issue seems most relevant to the agent-compliance package. This package likely governs compliance frameworks and audit logging, which aligns with the need for secure webview implementations.

Relevant Code

From your report, the affected files are:

  • src/webviews/policyEditor/PolicyEditorPanel.ts
  • src/webviews/workflowDesigner/WorkflowDesignerPanel.ts
  • src/webviews/metricsDashboard/MetricsDashboardPanel.ts
  • src/webviews/onboarding/OnboardingPanel.ts

Additionally, you’ve pointed out related vulnerabilities in:

  • OnboardingPanel.ts (lines 179-181)
  • extension.ts (lines 841-905)

These files are likely located in the agent-compliance directory. You can start by exploring the src/webviews/ folder and the extension.ts file in the root directory.


📚 Helpful Resources

Here are some resources to guide you as you work on this issue:

  • CONTRIBUTING.md: This document outlines how to contribute to the project, including setting up your development environment and submitting pull requests.
  • QUICKSTART.md: A quick guide to getting the project up and running locally.
  • Code of Conduct: Please ensure all interactions in the community adhere to this code.

✅ Next Steps

Here’s how you can proceed:

  1. Investigate the Code:

    • Review the _getHtmlForWebview methods in the mentioned files to confirm the absence of CSP headers.
    • Check how SidebarProvider.ts implements CSP and nonces for reference.
  2. Implement the Fix:

    • Add CSP meta tags to the webview HTML in the affected files.
    • Refactor inline scripts into external files, loaded via webview.asWebviewUri() with nonce attributes.
    • Set localResourceRoots in the createWebviewPanel options to restrict resource loading.
  3. Address Additional Findings:

    • For OnboardingPanel.ts, implement allowlist validation for the command parameter in _executeAction.
    • For extension.ts, ensure proper HTML escaping for API-sourced strings and add a CSP header.
  4. Test Your Changes:

    • Verify that the webviews function correctly after the changes.
    • Test the CSP implementation to ensure it blocks inline scripts and only allows nonce-gated scripts.
  5. Submit a Pull Request:

    • Once you’ve made the changes, submit a PR with a detailed description of your fixes. Reference this issue in your PR for context.

🌟 Encouragement

Your attention to detail and proactive approach to identifying these vulnerabilities is impressive! Tackling security issues like this is crucial for maintaining the integrity of the project, and your efforts are greatly appreciated. If you have any questions or need guidance along the way, don’t hesitate to ask — we’re here to help!

Looking forward to your contribution! 🚀

github-actions[bot] avatar Mar 28 '26 00:03 github-actions[bot]