security(vscode): Prototype pollution in WorkflowDesigner, ReDoS in PolicyEngine
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
🤖 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-ospackage, 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.assignis 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-ospackage, 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-regexto 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.tsandlanguage/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 theWorkflowDesignerPanel.tsfile. - For Finding 2: Look into
src/for thepolicyEngine.tsfile. - For Finding 3: Review the
src/directory forpolicyCompletion.tsand cross-reference it withlanguage/completionProvider.tsandlanguage/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:
- Prototype Pollution Fix:
- Implement the allowlist approach in
WorkflowDesignerPanel.tsto prevent unsafe property updates. - Add a test case to ensure malicious updates are blocked.
- Implement the allowlist approach in
- ReDoS Fix:
- Integrate a library like
safe-regexor implement a custom validation function inpolicyEngine.ts. - Write tests to verify that unsafe regex patterns are rejected.
- Integrate a library like
- Dead Code Cleanup:
- Confirm that
policyCompletion.tsis no longer used by searching for its imports across the codebase. - If confirmed, remove the file and update any related documentation or references.
- Confirm that
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! 🚀