Summary
FastlyMCP's fastly_cli tool contains an OS command injection issue in fastly-mcp.mjs, where a user-controlled command argument is passed into system-level execution without adequate sanitization.
A remote attacker who can influence this argument may execute arbitrary commands on the host running the CLI, depending on how and where the tool is invoked.
Affected context
The vulnerability exists within the FastlyMCP fastly_cli tool, specifically in the fastly-mcp.mjs module where external commands are constructed and executed.
It is relevant in environments where:
- The CLI is exposed via services (e.g., wrappers, automation jobs, CI/CD tasks, or web hooks) that accept remote input, and
- User-supplied or remotely influenced data can flow into the
commandargument.
The risk is higher when the CLI process runs with elevated permissions or has access to sensitive configuration, credentials, or deployment pipelines.
Exploit preconditions
- Attack surface: Any workflow, service, or automation that accepts external input and passes it to the fastly_cli tool (directly or indirectly).
- Required access: Ability to supply or influence the
commandargument, such as via API parameters, configuration values, environment variables, or script arguments. - Trigger point: Execution of fastly-mcp.mjs where the untrusted
commandvalue is interpolated into a shell/system command and executed. - Why exploitation is possible: The implementation constructs OS-level commands by concatenating or interpolating untrusted input into shell command strings, instead of using safe parameterized process execution APIs, enabling injection of additional commands or arguments.
Why this happens
This issue stems from constructing shell commands using untrusted input and executing them through generic OS command facilities (e.g., child_process.exec, shell invocation, or equivalent).
Instead of treating the input as data-only arguments, the code appears to embed the command parameter directly in a command string that is interpreted by a shell, allowing metacharacters, separators, or subshell syntax to alter control flow.
Conceptually, this maps to:
- CWE-78: Improper Neutralization of Special Elements used in an OS Command, where attacker-controlled data can inject or modify executed commands.
- Related CWE-77 patterns where shell metacharacters are not properly sanitized or where shell interpretation is unnecessarily invoked.
Potential impact
- Execution of arbitrary OS commands with the privileges of the fastly_cli process
- Reading, modifying, or deleting files accessible to the CLI's runtime user
- Theft of API tokens, credentials, or configuration used by FastlyMCP or adjacent tooling
- Tampering with Fastly configurations, deployments, or traffic policies via compromised automation
- Lateral movement into CI/CD runners or build agents if the tool is used in pipelines
- Use of the compromised host as a pivot point for further network attacks
General mitigation guidance
Mitigations focus on eliminating direct shell interpretation of untrusted input and constraining what commands can be executed:
- Prefer parameterized process execution APIs (e.g., spawning a process with an argument array) instead of passing concatenated strings to a shell.
- Implement strict allowlists for permissible commands and arguments, rejecting or ignoring anything outside expected patterns.
- Normalize and validate input at the boundary, rejecting values containing shell metacharacters, control operators, or unexpected whitespace patterns.
- Introduce privilege separation, running the CLI with the least necessary system permissions and restricted filesystem access.
- Isolate automation that invokes the CLI (e.g., in containers or dedicated service accounts) to limit blast radius if command execution is compromised.
- Treat all remotely influenced configuration as untrusted and avoid feeding it directly into command construction logic.
How teams detect issues like this
Detection is typically achieved through a combination of code-centric and operational controls:
- Static analysis: Enable rules that flag usage of shell-executing APIs (
exec,spawnwithshell: true, or similar) where untrusted variables flow into the command string. - Code review: Look for string concatenation or template literals used to build commands, especially where parameters named
command,cmd,args, or user input are included. - Secure coding policies: Enforce guidelines that prohibit shell invocation with untrusted data and require parameterized process calls and allowlists.
- Runtime monitoring: Use OS-level logging or EDR solutions to monitor unusual child process trees, suspicious shell invocations, or anomalous command patterns originating from fastly_cli processes.
- CI integration: Integrate automated code scanning tools into pull requests, focusing on command construction logic and data flow from external inputs.

