/

CVE-2026-28783

Severity:

CRITICAL RISK

(9.1)

Code Injection in Craft CMS Twig Arrow Functions

CVE-2026-28783

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94, CWE-184, CWE-1336

Impact:

Remote Code Execution and Sensitive Data Exposure

Severity:

CRITICAL RISK

(9.1)

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

Craft CMS uses a blocklist-based filter to prevent dangerous PHP functions from being invoked through Twig non-Closure arrow functions, but several risky functions are not covered.

With sufficient backend permissions or misconfiguration, an attacker can leverage these unblocked functions to execute arbitrary code or access sensitive resources via template execution.

Affected context

This vulnerability affects Craft CMS installations where Twig templates can be influenced by users who:

  • Have administrative or near-administrative capabilities, or
  • Have access to the System Messages utility, or
  • Operate in environments where allowAdminChanges is enabled in production.

It manifests specifically in contexts where Twig non-Closure arrow functions can end up invoking PHP functions, and where the blocklist is relied upon as the primary safeguard against dangerous function calls. The issue is more impactful in production environments where templates are processed with high-privilege application context.

Exploit preconditions

  • Attack surface: Server-side template rendering within Craft CMS (Twig engine).
  • Required access:
  • A compromised or malicious admin account, or
  • An account with access to the System Messages utility, or
  • A production environment with allowAdminChanges enabled and reachable by the attacker.
  • Trigger point: Rendering of Twig templates that can execute non-Closure arrow functions which internally call PHP functions.
  • Why exploitation is possible: The protection mechanism relies on a PHP function blocklist that is incomplete. Several dangerous functions remain callable, enabling attackers with sufficient template influence to chain them into payloads that can perform code execution, file operations, outbound network calls, or further template-based injection.

Why this happens

The core issue is a reliance on an incomplete blocklist to constrain what PHP functions can be invoked from Twig non-Closure arrow functions.

This design aligns with CWE-94: Improper Control of Generation of Code, because user-influenced template content can effectively trigger execution of dynamically constructed code paths via PHP functions that should have been considered unsafe.

Supporting issues include:

  • CWE-184: Incomplete Blacklist, where not all high-risk functions are enumerated or consistently blocked.
  • CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine, since the template execution environment is not fully constrained, allowing template constructs to act as a bridge from templating logic into lower-level PHP functionality.

Abstractly, the insecure pattern is: "Restrict powerful execution primitives with a hand-maintained denylist inside a templating context that processes attacker-influenced data," rather than enforcing a strict allowlist or isolating template execution from sensitive APIs.

Potential impact

  • Remote code execution (RCE) in the context of the web server process.
  • Arbitrary file reads from the server's filesystem, potentially including configuration files and secrets.
  • Server-side request forgery (SSRF), allowing outbound requests to internal services or cloud metadata endpoints.
  • Server-side template injection (SSTI) chains that escalate from template control to full code execution.
  • Unauthorized access to sensitive application data or credentials.
  • Lateral movement within the hosting environment if the compromised process has broader network or file privileges.

General mitigation guidance

Effective mitigation focuses on reducing the power of the template execution environment and shrinking the attack surface of callable functions, rather than attempting to maintain ever-growing blocklists.

Recommended defensive patterns include:

  • Use allowlists instead of blocklists: Define a minimal, explicit set of PHP functions that templates are allowed to call, and deny all others by default.
  • Harden template execution contexts: Separate untrusted or semi-trusted template content into a restricted sandbox that does not expose powerful APIs, filesystem access, or network functions.
  • Limit administrative capabilities in production:
  • Disable allowAdminChanges in production where possible.
  • Restrict access to powerful utilities such as System Messages to a minimal set of accounts.
  • Apply least-privilege principles: Run the web server and PHP-FPM processes with the least privileges required (limited filesystem access, constrained network egress, and minimal OS permissions) to reduce blast radius if code execution occurs.
  • Reduce template mutability: Avoid giving non-operations staff the ability to directly modify high-privilege templates or system messages that are executed with full application context.
  • Centralize security-sensitive functionality: Encapsulate file access, network calls, and command execution behind vetted service layers, and never expose such primitives directly to template logic.

How teams detect issues like this

Detection should combine code-centric and configuration-centric approaches:

  • Static analysis and code review:
  • Search template-related code for use of Twig non-Closure arrow functions that can invoke PHP functions.
  • Flag any template-exposed APIs that map directly to filesystem operations, network calls, or dynamic code execution.
  • Look for denylist/blocklist implementations controlling function access and verify whether the pattern is inverted to an allowlist.
  • Policy-based checks:
  • Enforce organizational policies that disallow powerful PHP functions from being accessible in templating environments by default.
  • Guardrails in CI to reject changes that introduce new template-callable functions without security review.
  • Runtime monitoring:
  • Log and monitor template rendering paths used by privileged panels (like System Messages) and watch for unusual patterns or spikes in error logs related to templates.
  • Track use of sensitive PHP functions and correlate invocation contexts to template execution where feasible.
  • Automated tooling:
  • Employ SAST tools or custom rulesets that understand Twig/Craft CMS integration to surface templating contexts where user-influenced content is combined with powerful PHP primitives.
  • Periodically run security tests that attempt benign template payloads to validate that sandbox and function restrictions are enforced.

Sources

SourceLink
github.comgithub.com/craftcms/cms/pull/18208
github.comgithub.com/craftcms/cms/security/advisories/GHSA-5fvc-7894-ghp4

Frequently asked

questions

Yes, but only if an attacker can reach interfaces where Twig templates are processed with sufficient privilege and can control the template content or parameters. In practice, this typically requires access to administrative or semi-administrative features such as System Messages or other high-privilege template-editing capabilities.

The attacker generally needs one of the following: a compromised admin account, an account with access to the System Messages utility, or a production instance where allowAdminChanges is enabled and reachable. Anonymous users without such access cannot typically exploit this vulnerability directly.

Move away from blocklist-based function restrictions toward a strict allowlist of safe functions that templates are allowed to call, and ensure that templates executing with high privilege do not expose powerful primitives such as file I/O, network requests, or dynamic code execution.

Design template systems so that:

  • Templates operate in a constrained sandbox with no direct access to dangerous PHP APIs.
  • Only a carefully curated allowlist of harmless helpers is exposed.
  • Administrative interfaces that modify templates are tightly access-controlled and not enabled in production by default.
  • Security reviews explicitly consider template injection and function exposure before new template features are released.
Find out what's already
exploitable in your codebase.