/

CVE-2026-45697

Severity:

CRITICAL RISK

(9.8)

Template Injection / Code Injection in Formie Craft CMS

CVE-2026-45697

Deferred

Vulnerability type

Category:

Template Injection / Code Injection

CWE:

CWE-94, CWE-693, CWE-1336

Impact:

Remote Code Execution / Full Site Compromise

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

Formie, a Craft CMS form-building plugin, evaluated user-submitted data from Hidden fields as Twig templates during form submission handling.

An unauthenticated attacker could submit crafted values that are interpreted as Twig code, potentially leading to full compromise of the Craft site depending on the template context and sandbox configuration.

Affected context

This vulnerability arises in Craft CMS sites that use the Formie plugin with Hidden fields whose "Default value" is configured as "Custom."

During submission handling, Formie treated the submitted value for these Hidden fields as Twig and evaluated it, rather than treating it as plain data.

Installations where Twig evaluation occurs in powerful contexts (e.g., with access to application services, environment variables, or filesystem APIs) are particularly exposed, but even restricted contexts may allow sensitive data access or privilege escalation.

Exploit preconditions

  • Attack surface: Public-facing forms powered by Formie that include one or more Hidden fields with "Default value → Custom" configuration.
  • Required access: No authentication required; the attacker only needs the ability to submit the affected form.
  • Trigger point: Form submission containing crafted payloads in the Hidden field value.
  • Why exploitation is possible: The server-side submission handler evaluates user-supplied Hidden field values as Twig templates instead of treating them as untrusted data, enabling execution of arbitrary Twig expressions within the application's template context.

Why this happens

The core issue is the conflation of user-controlled input with server-side template logic.

Formie's handling of Hidden fields with a custom default value allowed the submitted value to be passed into Twig for evaluation, effectively granting the client the ability to inject template code.

This maps directly to CWE-94: Improper Control of Generation of Code ('Code Injection'), because attacker-controlled data is turned into executable template instructions, and is also related to CWE-693: Protection Mechanism Failure and CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine.

In abstract terms, any design that lets untrusted request parameters influence template source code or expressions at render time, without strict separation or encoding, creates a template injection channel that can escalate to remote code execution depending on the template engine's capabilities.

Potential impact

  • Execution of arbitrary Twig expressions within the Craft CMS runtime context.
  • Theft of sensitive data rendered or accessible in templates (user data, configuration, environment variables).
  • Escalation to remote code execution if the Twig context or extensions expose filesystem or command execution capabilities.
  • Creation or modification of Craft content, templates, or configuration through template-accessible APIs.
  • Persistent compromise of the site, including installation of backdoors or malicious templates.

General mitigation guidance

Effective mitigation focuses on separating untrusted data from template logic and disabling runtime evaluation of user-controlled input:

  • Treat all form field values, including Hidden fields, as data only; ensure they are never passed directly into Twig for evaluation.
  • Avoid designs where "default value" or similar configuration causes runtime template evaluation of submitted values; restrict template rendering to developer-controlled sources.
  • Where template-based defaults are required, render them on the server before exposing them to the client, and do not re-interpret client-submitted values as templates.
  • Enforce strict template sandboxing for Twig to limit filesystem, environment, and API access, reducing blast radius if any template injection occurs.
  • Apply least-privilege principles to the Craft CMS runtime (file permissions, database accounts, API keys) so that template-level compromise has constrained impact.

How teams detect issues like this

To detect similar issues, organizations can combine review, testing, and automation:

  • Static analysis / code review:
  • Search for patterns where request parameters or form field values are passed into Twig's render, templateFromString, or equivalent evaluation functions.
  • Flag any dynamic template compilation that originates from configuration fields that can be influenced via the admin UI and then re-used with user-submitted values.
  • Review plugin and module code paths that build templates from strings or evaluate arbitrary Twig expressions.
  • Configuration and policy checks:
  • Enforce policies that prohibit evaluation of user-controlled strings as templates or code.
  • Audit CMS plugins and custom integrations for "Custom" default-value mechanisms that rely on templating, especially in Hidden or system fields.
  • Dynamic testing:
  • Include template injection checks in application security testing, sending benign Twig expressions in form fields and monitoring server behavior and responses.
  • Tooling:
  • Use SAST/IAST tools that understand template engines and can flag user-to-template-data flows, complemented by manual security review of high-risk input handling logic.

Sources

SourceLink
github.comgithub.com/verbb/formie/commit/f690d5623163ce2a95da305238d6367575486ee3
github.comgithub.com/verbb/formie/releases/tag/2.2.20
github.comgithub.com/verbb/formie/releases/tag/3.1.24
github.comgithub.com/verbb/formie/security/advisories/GHSA-x7m9-mwc2-g6w2

Frequently asked

questions

Yes. Any internet-accessible Craft CMS site using a vulnerable Formie configuration can be targeted remotely by submitting crafted form data, without prior access to the system.

No. The issue affects public form endpoints; an unauthenticated attacker can exploit the vulnerability by sending a specially crafted Hidden field value in a form submission.

The safest pattern is to ensure that user-controlled values are never treated as templates or code.

Hidden field values and other user-submitted inputs should be processed as plain data, with any templating limited to developer-controlled sources and pre-rendered before reaching the client.

Adopt a design rule that strictly separates data from template logic: do not evaluate client-supplied strings as Twig, avoid dynamic template construction from untrusted sources, enforce template sandboxing by default, and include template injection checks in code review and security testing processes.

Find out what's already
exploitable in your codebase.