/

CVE-2026-40520

Severity:

HIGH RISK

(7.2)

OS Command Injection in FreePBX API GraphQL Mutation

CVE-2026-40520

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution (as web server user)

Severity:

HIGH RISK

(7.2)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

FreePBX's API module up to version 17.0.8 contains an OS command injection flaw where GraphQL mutation input is passed directly into shell_exec() without sanitization.

An authenticated user with a valid bearer token can craft a moduleOperations mutation that injects backtick-wrapped commands, resulting in arbitrary command execution on the FreePBX host as the web server user.

Affected context

This vulnerability appears in FreePBX deployments that:

  • Enable and expose the API module (GraphQL endpoint),
  • Allow authenticated users or integrations to invoke moduleOperations mutations, and
  • Execute backend shell commands via PHP's shell_exec() in initiateGqlAPIProcess().

It becomes relevant when API authentication tokens are issued to users, services, or integrations that may be compromised or malicious, and when the underlying web server account has access to sensitive files or system utilities.

Exploit preconditions

  • Attack surface: FreePBX GraphQL API endpoint provided by the API module.
  • Required access: Valid authenticated context with a bearer token capable of calling moduleOperations mutations.
  • Trigger point: Submission of a GraphQL moduleOperations mutation whose module field (or related input) contains backtick-wrapped shell commands.
  • Why exploitation is possible: The initiateGqlAPIProcess() function passes GraphQL input directly into shell_exec() without escaping, validation, or a strict command allowlist, causing user-controlled data to be interpreted by the shell.

Why this happens

The defect stems from constructing shell commands directly from untrusted application-layer input and executing them with shell_exec() in PHP.

This is a classic CWE-78: OS Command Injection pattern, where user data is concatenated or interpolated into a shell command without proper validation, encoding, or strict command selection.

Instead of routing operations through parameterized APIs or bounded helpers, the code delegates behavior to a shell, allowing special characters (such as backticks) to break out of the intended command context and execute arbitrary commands.

Potential impact

  • Arbitrary command execution on the FreePBX host as the web server user.
  • Reading or modifying configuration files accessible to the web server account.
  • Establishing persistence or pivoting to other services on the same host.
  • Interference with telephony services, including call routing or logging.
  • Use of the FreePBX server as a foothold for lateral movement in the network.

General mitigation guidance

Mitigations generally focus on removing or strictly constraining shell execution and tightening the API trust boundaries:

  • Replace shell_exec() and similar APIs with dedicated internal functions or libraries that perform the required actions without invoking a shell.
  • If external commands are unavoidable, select them from a fixed allowlist and provide only validated, non-interpreted parameters (e.g., using escapeshellarg()/escapeshellcmd() as a defense-in-depth measure, not as the primary control).
  • Validate and normalize GraphQL input against strict schemas, rejecting unexpected fields, metacharacters, or command-like content.
  • Ensure the web server user adheres to least privilege principles, limiting file system and OS capabilities if command execution is compromised.
  • Restrict API token issuance and scope, and segregate high-privilege API operations to hardened roles or separate services where feasible.

How teams detect issues like this

Detection can be approached at code, configuration, and runtime levels:

  • Static analysis: Flag any use of shell_exec(), exec(), system(), passthru(), or backtick operators where arguments incorporate request, GraphQL, or other user-controlled data.
  • Code review: Look for functions such as initiateGqlAPIProcess() that transform API/GraphQL inputs into shell commands; pay attention to string concatenation, interpolation, or lack of validation around command construction.
  • Policy enforcement: Introduce coding standards that prohibit direct shell invocation in web handlers or API resolvers, enforced via pre-commit hooks or CI linting.
  • Runtime monitoring: Review web server logs, application logs, and OS audit logs for unusual command executions originating from the web server user, especially commands embedded in backticks or atypical shell utilities.

Sources

SourceLink
github.comgithub.com/FreePBX/api/blob/5f194e39a47e5481e8947f9694304d32724175f6/Api.class.php#L546C1-L554C3
github.comgithub.com/FreePBX/api/blob/5f194e39a47e5481e8947f9694304d32724175f6/ApiGqlHelper.class.php#L34C1-L36C136
github.comgithub.com/FreePBX/api/commit/5f194e39a47e5481e8947f9694304d32724175f6
vulncheck.comvulncheck.com/advisories/freepbx-api-module-command-injection-via-graphql

Frequently asked

questions

Yes, if the FreePBX API endpoint is accessible over the network and an attacker can obtain or abuse a valid bearer token, they can issue crafted GraphQL mutations remotely.

Yes. Exploitation requires an authenticated API context, typically a valid bearer token able to invoke the GraphQL moduleOperations mutation. Compromised integration tokens or overly privileged API accounts increase the risk.

The most robust fix is to remove direct shell execution from the request path and instead call internal PHP functions or well-defined libraries. If OS-level calls are truly necessary, they should use a fixed command set with strongly validated, non-interpreted parameters and no user-controlled fragments passed to a generic shell.

Establish a rule that API and GraphQL resolvers must never build shell commands from user input, enforce this via code review and static checks, and validate all inputs against strict schemas. Combine this with least-privilege execution for service accounts and regular security testing focused on injection patterns.

Find out what's already
exploitable in your codebase.