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.

