Summary
Roslyn CodeLens MCP Server automatically loads and executes all DiagnosticAnalyzer assemblies referenced by a target .NET solution when running the get_diagnostics tool.
If an attacker can get a victim to open a malicious .csproj that references an attacker-controlled analyzer DLL, they may achieve arbitrary code execution within the MCP server process under the server's OS privileges.
Affected context
This vulnerability affects environments where Roslyn CodeLens MCP Server is used to provide semantic code intelligence over .NET solutions.
The issue arises specifically in the get_diagnostics MCP tool, which by default (includeAnalyzers=true) loads all DiagnosticAnalyzer assemblies referenced by the opened solution.
Installations are at risk when users open or analyze .csproj or solution files from locations that might be attacker-controlled or untrusted, such as cloned repositories, shared folders, or downloaded sample projects.
Exploit preconditions
- Attack surface: The MCP server process that hosts Roslyn CodeLens and runs get_diagnostics against user-specified .NET solutions or projects.
- Required access: Ability to supply or modify a .csproj or solution file that the victim will open in the MCP server context, plus the ability to host or provide the referenced analyzer DLL.
- Trigger point: Invocation of the get_diagnostics tool against the malicious solution or project, with the default includeAnalyzers setting (true) or any configuration that permits analyzer loading.
- Why exploitation is possible: The server implicitly trusts and loads all referenced DiagnosticAnalyzer assemblies without an allowlist, signature validation, sandboxing, or interactive user confirmation, allowing arbitrary managed code to run.
Why this happens
The core issue is untrusted plugin loading: DiagnosticAnalyzer assemblies referenced by the target solution are treated as benign extensions and executed with full privileges of the MCP server process.
This maps to CWE-94 (Improper Control of Generation of Code) because untrusted, attacker-supplied code is effectively loaded and executed without constraints, turning a diagnostics feature into a code execution channel.
The get_diagnostics tool conflates "project configuration" with "trusted execution environment," failing to enforce a trust boundary or apply validation around dynamically loaded analyzer assemblies.
Potential impact
- Attackers may execute arbitrary .NET code within the MCP server process.
- Compromise of the developer's workstation or server account running the MCP server.
- Access to source code, configuration files, and sensitive data reachable by the MCP server process.
- Installation of persistent backdoors or further tooling under the server's OS privileges.
- Lateral movement within the development or CI environment using the MCP server as an initial foothold.
General mitigation guidance
Effective mitigation focuses on treating analyzer assemblies as untrusted code unless explicitly validated:
- Introduce an explicit allowlist or policy that restricts which DiagnosticAnalyzer assemblies can be loaded, based on origin, path, or publisher identity.
- Add strong validation of analyzers, such as code signing enforcement or trusted repository checks, before loading them into the MCP server process.
- Make analyzer loading opt-in rather than default, surfacing clear prompts or configuration flags before executing third-party analyzers.
- Consider process isolation or sandboxing for analyzer execution, limiting available privileges and filesystem or network access.
- Encourage users to only run diagnostics on solutions from trusted sources, especially in shared or multi-tenant environments.
How teams detect issues like this
Detection and assurance can be improved with a combination of static policy checks and runtime monitoring:
- Implement static analysis or build-time rules that flag dynamic assembly loading in the MCP server, especially APIs that load analyzers or plugins without validation.
- During code review, treat any code that loads DiagnosticAnalyzer or other plugin assemblies as a security-sensitive boundary, mandating explicit trust and validation logic.
- Add auditing or logging around analyzer loading: log the paths, hashes, and origins of all loaded analyzer assemblies and alert on unexpected or unapproved entries.
- Use host-based monitoring to detect anomalous behavior from the MCP server process, such as unexpected file access, process creation, or outbound network connections.

