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

security(vscode): Prototype pollution in WorkflowDesigner, ReDoS in PolicyEngine

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

Finding 1: Prototype Pollution via Object.assign

File: src/webviews/workflowDesigner/WorkflowDesignerPanel.ts:192

The _updateNode handler applies webview-sourced partial updates via Object.assign(node, updates) with no property allowlist. A crafted message from the webview could set constructor.prototype keys.

Fix: Allowlist updatable properties before applying Object.assign.

Finding 2: ReDoS via Custom Policy Regex

File: src/policyEngine.ts:274

User-supplied regex patterns from `.vscode/agent-os.json` are compiled into `RegExp` without complexity validation. A pattern like `(a+)+$` causes catastrophic backtracking, freezing the extension. Since `analyzeCode` runs on every document change, this can make VS Code unresponsive.

Fix: Validate regex against known ReDoS patterns (e.g., `safe-regex` library) or limit to literal string matching.

Finding 3: Dead Code — policyCompletion.ts (361 lines)

File: src/policyCompletion.ts

Exports PolicyCompletionProvider, PolicyHoverProvider, and PolicyDiagnosticsProvider. None are imported anywhere. Functionality is fully superseded by language/completionProvider.ts and language/diagnosticProvider.ts.

Fix: Delete the file.

Severity

  • Prototype pollution: High
  • ReDoS: Medium
  • Dead code: Low

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

🤖 AI Agent: contributor-guide

Hi @first-time-contributor! 👋 Welcome to the microsoft/agent-governance-toolkit project! 🎉 We're thrilled to have you here, and thank you for taking the time to report these issues in such a detailed and well-organized manner. Let's dive into your findings and discuss how we can address them.


🔍 Analysis of Your Issue

Finding 1: Prototype Pollution via Object.assign

  • Relevant Package: This issue seems to pertain to the agent-os package, as it involves the core policy engine and lifecycle management.
  • Code Location: src/webviews/workflowDesigner/WorkflowDesignerPanel.ts:192
  • Suggested Fix: Your proposed solution to allowlist updatable properties before applying Object.assign is spot on. This will prevent malicious updates from the webview.

Finding 2: ReDoS via Custom Policy Regex

  • Relevant Package: This issue also falls under the agent-os package, as it involves the policy engine (policyEngine.ts) and its interaction with user-supplied configurations.
  • Code Location: src/policyEngine.ts:274
  • Suggested Fix: Using a library like safe-regex to validate user-supplied patterns is a great idea. Alternatively, limiting regex usage to simpler patterns or providing a predefined set of safe patterns could also mitigate this issue.

Finding 3: Dead Code in policyCompletion.ts

  • Relevant Package: This appears to be related to agent-os, as the file deals with policy completion and diagnostics, which are core functionalities of the policy engine.
  • Code Location: src/policyCompletion.ts
  • Suggested Fix: If the functionality is indeed superseded by language/completionProvider.ts and language/diagnosticProvider.ts, removing the file is a good cleanup step.

📂 Relevant Code Locations

Here are the directories you might want to explore further:

  • For Finding 1: Check the src/webviews/workflowDesigner/ directory for the WorkflowDesignerPanel.ts file.
  • For Finding 2: Look into src/ for the policyEngine.ts file.
  • For Finding 3: Review the src/ directory for policyCompletion.ts and cross-reference it with language/completionProvider.ts and language/diagnosticProvider.ts.

📚 Helpful Resources

To help you get started, here are some key resources:

  • CONTRIBUTING.md: Guidelines for contributing to the project.
  • QUICKSTART.md: A quick guide to setting up the project locally.
  • Code of Conduct: Our expectations for a respectful and inclusive community.

🚀 Next Steps

Here’s how you can help move this forward:

  1. Prototype Pollution Fix:
    • Implement the allowlist approach in WorkflowDesignerPanel.ts to prevent unsafe property updates.
    • Add a test case to ensure malicious updates are blocked.
  2. ReDoS Fix:
    • Integrate a library like safe-regex or implement a custom validation function in policyEngine.ts.
    • Write tests to verify that unsafe regex patterns are rejected.
  3. Dead Code Cleanup:
    • Confirm that policyCompletion.ts is no longer used by searching for its imports across the codebase.
    • If confirmed, remove the file and update any related documentation or references.

Feel free to open a pull request for any or all of these fixes! If you need help or have questions, don’t hesitate to ask. We're here to support you every step of the way. 😊

Thank you again for your contribution, and we look forward to collaborating with you! 🚀

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