/

CVE-2026-54133

Severity:

CRITICAL RISK

(9.8)

Code Injection (CWE-94) in jmespath.php CompilerRuntime

CVE-2026-54133

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-20, CWE-94, CWE-116

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

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

jmespath.php prior to 2.9.1 can generate and execute attacker-controlled PHP code when the JmesPath\CompilerRuntime is used with untrusted JMESPath expressions.

The compiler embeds function names from the expression directly into generated PHP source, enabling a crafted expression to inject arbitrary PHP into cached files and achieve remote code execution.

Affected context

This vulnerability arises in PHP applications that embed jmespath.php and enable the compiled runtime (JmesPath\CompilerRuntime) for evaluating JMESPath expressions.

It becomes relevant when expressions originate from users or other untrusted sources, and when the compilation feature (JP_PHP_COMPILE or equivalent configuration) is active so that expressions are turned into cached PHP files and then loaded at runtime.

Deployments using only the default AstRuntime for untrusted expressions are generally outside the primary risk path because they do not generate executable PHP code from user-provided query text.

Exploit preconditions

  • Attack surface: Any API endpoint, CLI entry point, or background job that accepts JMESPath expressions which are processed by JmesPath\CompilerRuntime.
  • Required access: Ability to supply or influence the JMESPath expression evaluated by the PHP application (e.g., request parameters, configuration, templates, or rules).
  • Trigger point: Evaluation of an attacker-controlled expression by the compiler runtime, causing generation and inclusion of a cached PHP file derived from that expression.
  • Why exploitation is possible: Parsed function names from the JMESPath expression are inserted into generated PHP source code without adequate escaping or validation, allowing an attacker to break out of the intended syntax and inject arbitrary PHP code into the compiled cache file which is then executed.

Why this happens

The core issue is an input validation and output encoding failure in the code generation path of jmespath.php's CompilerRuntime.

Instead of treating parsed function names as untrusted content requiring strict validation and escaping, the compiler directly interpolates them into PHP source code templates that are written to cache files and later required or included.

This pattern maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), and is supported by CWE-20: Improper Input Validation and CWE-116: Improper Encoding or Escaping of Output, because untrusted expression components are not constrained to safe identifiers nor correctly encoded before being embedded into executable PHP.

Potential impact

  • Execution of arbitrary PHP code within the web server or PHP process context.
  • Full compromise of the affected application, including reading or modifying sensitive data.
  • Lateral movement by using the compromised application to attack connected services or databases.
  • Planting of persistent backdoors in application code or cache directories.
  • Abuse of the server to perform further attacks, such as sending malicious responses or hosting rogue content.

General mitigation guidance

Effective mitigation typically focuses on avoiding or strictly constraining dynamic code generation paths and treating JMESPath expressions as untrusted input by default.

Security-oriented patterns include:

  • Prefer interpreted execution (e.g., the default AstRuntime) for any expression that can be influenced by users, external systems, or configuration that is not tightly controlled.
  • If compiled execution is required, apply strict allowlists for function names and other expression components, ensuring only known-safe identifiers are ever passed into code generation.
  • Apply robust validation to JMESPath expressions before evaluation, rejecting or sanitizing constructs that do not conform to an expected grammar profile.
  • Separate storage and permissions for cache directories, using least privilege file system permissions so that compromise of one area is less likely to cascade.
  • Adopt a secure-by-default configuration that disables compilation for untrusted contexts, only enabling the compiler runtime explicitly for trusted, internal expressions.

How teams detect issues like this

Detection efforts can focus both on code-level patterns and runtime behavior:

  • Static analysis: Flag any use of JmesPath\CompilerRuntime where the expression argument is derived from request parameters, user input, or other untrusted sources. Rules can also search for dynamic code-generation patterns that concatenate unvalidated strings into PHP source.
  • Code review: During manual reviews, highlight locations that enable JMESPath compilation, and verify that those call sites are restricted to constant or strictly controlled expressions rather than user-supplied data.
  • Configuration and policy checks: Enforce policies that disallow enabling JP_PHP_COMPILE (or equivalent settings) in environments that process untrusted expressions, using CI checks or deployment-time configuration audits.
  • Runtime monitoring: Monitor for unexpected or frequently changing PHP cache files in jmespath-related cache directories, and alert on unusual file contents or modification patterns that may indicate injected code.

Sources

SourceLink
github.comgithub.com/jmespath/jmespath.php/security/advisories/GHSA-pcw8-m77r-2528

Frequently asked

questions

Yes, if an attacker can supply or influence JMESPath expressions that the application evaluates using JmesPath\CompilerRuntime, they can potentially achieve remote code execution without needing file system or shell access.

The attacker needs the ability to control or significantly influence the JMESPath expression evaluated by the vulnerable PHP application. This can occur via HTTP request parameters, configuration fields, rule editors, or any other feature that accepts expressions which are then compiled.

The safest pattern is to avoid using the compiler-based runtime for any untrusted expressions and instead rely on the interpreted AstRuntime or equivalent non-compiling execution engine. Where compilation is unavoidable, enforce strict validation and allowlists around expression components before they reach the code generation layer.

Avoid designs that embed unvalidated user-controlled strings directly into dynamically generated code, templates, or eval-like mechanisms. Treat all expression languages and query DSLs as untrusted input, apply strong validation and encoding, separate trusted from untrusted execution modes, and incorporate static analysis and security code review practices that specifically target dynamic code generation.

Find out what's already
exploitable in your codebase.