Summary
PolarVista xcode-mcp-server 1.0.0 contains an OS command injection vulnerability in the MCP Interface's build_project/run_tests functionality, where user-controlled request data is incorporated into system commands.
A remote attacker who can send crafted requests to this interface may execute arbitrary commands on the underlying server with the permissions of the xcode-mcp-server process.
Affected context
The vulnerability resides in the MCP Interface implementation in src/index.ts, specifically in logic associated with the build_project and run_tests operations.
It appears when request parameters are used to construct shell commands without robust validation, escaping, or use of safe execution primitives.
Any deployment that exposes the MCP Interface over a network (directly or via an intermediary service) and accepts untrusted or partially trusted requests can be affected, especially when the server process has access to build tools, file system resources, or other internal services.
Exploit preconditions
- Attack surface: Network-accessible MCP Interface endpoints that handle
build_projectand/orrun_testsrequests. - Required access: Ability to send crafted requests to the vulnerable server (e.g., via HTTP/WebSocket/JSON-RPC depending on deployment).
- Trigger point: Invocation of the
build_project/run_testslogic that concatenates or interpolates request data into an OS command string. - Why exploitation is possible: Request fields are treated as trusted and are passed directly or indirectly into shell commands without adequate sanitization, argument separation, or command whitelisting, allowing injection of additional command tokens or payloads.
Why this happens
The root cause aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), and is closely related to CWE-77: Command Injection.
In the MCP Interface, request parameters (for example, project paths, test targets, or build/test options) are likely concatenated into command strings that are executed by the operating system shell.
When application code assembles a string command with untrusted input and executes it through generic process APIs (e.g., exec, execSync, or equivalents), the shell interprets metacharacters such as ;, &&, |, or backticks as additional commands or arguments.
This insecure pattern treats user-provided data as part of the command structure rather than as opaque data, enabling attackers to inject arbitrary OS-level instructions.
Potential impact
- Remote execution of arbitrary OS commands with the privileges of the xcode-mcp-server process.
- Reading, modifying, or deleting files accessible to the service account, including project artifacts, logs, or configuration files.
- Pivoting to other internal services or hosts reachable from the vulnerable server.
- Exfiltration of secrets such as API keys, tokens, or environment variables present on the system.
- Disruption of build and test pipelines, including denial of service by resource exhaustion or process crashes.
- Potential foundation for broader infrastructure compromise if run with elevated privileges or in a sensitive environment.
General mitigation guidance
Effective mitigation emphasizes removing direct shell mediation and strictly controlling how external commands are invoked:
- Prefer high-level language APIs or libraries that implement the required build/test functionality without invoking a shell (e.g., direct tool APIs instead of shelling out).
- When external tools must be used, call them through process execution APIs that accept argument arrays (e.g.,
spawn/execFilepatterns) rather than shell-interpretive string commands. - Implement strict allowlists for commands and arguments: predefine valid tools and constrained option sets instead of letting the client supply arbitrary flags or paths.
- Normalize and validate all user-controlled input before use (e.g., restrict to expected character sets, limit length, and constrain path values to known directories).
- Run the xcode-mcp-server service under a least-privilege account with minimal file system and network access to reduce blast radius if exploitation occurs.
- Isolate build/test execution in sandboxes or containers with constrained permissions and no direct access to sensitive host resources.
How teams detect issues like this
Detection typically combines code-level analysis with runtime monitoring:
- Static analysis: Configure linters or SAST tools to flag concatenation of request-derived variables into command strings, especially in calls to process execution APIs. Look for patterns like
exec(request.param)or string interpolation into shell commands. - Code review: During manual review, identify any code paths where external commands are constructed from user input (paths, flags, environment values) and check that argument arrays, allowlists, and strict validation are used.
- Security policy enforcement: Establish development guidelines that prohibit direct shell execution with untrusted input and require approvals for new use of command execution APIs.
- Runtime monitoring: Use telemetry and logging to detect anomalous command patterns, unusual arguments, or commands not normally associated with build/test workflows; integrate with intrusion detection systems to alert on suspicious process trees.

