CVE-2023-32679: Remote Code Execution via unrestricted file extension in Craft CMS

Published May 19, 2023
·
Updated

Summary Unrestricted file extension lead to a potential Remote Code Execution (Authenticated, ALLOWADMINCHANGES=true)

Details Vulnerability Cause : If the name parameter value is not empty string('') in the View.php's doesTemplateExist() -> resolveTemplate() -> resolveTemplateInternal() -> resolveTemplate() function, it returns directly without extension verification, so that arbitrary extension files are rendered as twig templates (even if they are not extensions set in defaultTemplateExtensions = ['html', 'twig']) php / Searches for a template files, and returns the first match if there is one. @param string $basePath The base path to be looking in. @param string $name The name of the template to be looking for. @param bool $publicOnly Whether to only look for public templates (template paths that don’t start with the private template trigger). @return string|null The matching file path, or null. / private function resolveTemplate(string $basePath, string $name, bool $publicOnly): ?string { // Normalize the path and name $basePath = FileHelper::normalizePath($basePath); $name = trim(FileHelper::normalizePath($name), '/');

// $name could be an empty string (e.g. to load the homepage template) if ($name !== '') { if ($publicOnly && pregmatch(sprintf('/(^|\/)%s/', pregquote($this->privateTemplateTrigger, '/')), $name)) { return null; }

// Maybe $name is already the full file path $testPath = $basePath . DIRECTORYSEPARATOR . $name;

if (isfile($testPath)) { return $testPath; }

foreach ($this->defaultTemplateExtensions as $extension) { $testPath = $basePath . DIRECTORYSEPARATOR . $name . '.' . $extension;

if (isfile($testPath)) { return $testPath; } } }

foreach ($this->indexTemplateFilenames as $filename) { foreach ($this->defaultTemplateExtensions as $extension) { $testPath = $basePath . ($name !== '' ? DIRECTORYSEPARATOR . $name : '') . DIRECTORYSEPARATOR . $filename . '.' . $extension;

if (isfile($testPath)) { return $testPath; } } }

return null; }

When attacker with admin privileges on the DEV or Misconfigured STG, PROD, they can exploit this vulnerability to remote code execution (ALLOWADMINCHANGES=true)

PoC Step 1) Create a new filesystem. Base Path: /var/www/html/templates !1

Step 2) Create a new asset volume. Asset Filesystem: template !2

Step 3) Upload poc file( .txt , .js , .json , etc ) with twig template rce payload twig {{'<pre>'}} {{13371337}} {{['cat /etc/passwd']|map('passthru')|join}} {{['id;pwd;ls -altr /']|map('passthru')|join}} !7 !5

Step 4) Create a new global set with template layout. The template filename is poc.js !8

Step 5) When access global menu or /admin/global/test, poc.js is rendered as a template file and RCE confirmed !9

Step 6) RCE can be confirmed on other menus(Entries, Categories) where the template file is loaded. !10 !11

Poc Environment) ALLOWADMINCHANGES=true, defaultTemplateExtensions=['html','twig'] !0 !13 !14

Impact Take control of vulnerable systems, Data exfiltrations, Malware execution, Pivoting, etc.

Additionally, there are 371 domains using CraftCMS exposed on Shodan, and among them, 33 servers have "stage" or "dev" included in their hostnames.

although the vulnerability is exploitable only in the authenticated users, configuration with ALLOWADMINCHANGES=true, there is still a potential security threat (Remote Code Execution)

!2023-03-31 10 29 53

Remediation Recommend taking measures by referring to https://github.com/craftcms/cms-ghsa-9f84-5wpf-3vcf/pull/1 php // Maybe $name is already the full file path $testPath = $basePath . DIRECTORYSEPARATOR . $name;

if (isfile($testPath)) { // Remedation: Verify template file extension, before return $fileExt = pathinfo($testPath, PATHINFOEXTENSION); $isDisallowed = false;

if (isset($fileExt)) { $isDisallowed = !inarray($fileExt, $this->defaultTemplateExtensions);

if($isDisallowed) { return null; } else { return $testPath; } } }

!remediation

Other sources

Craft CMS is an open source content management system. In affected versions of Craft CMS an unrestricted file extension may lead to Remote Code Execution. If the name parameter value is not empty string('') in the View.php's doesTemplateExist() -> resolveTemplate() -> resolveTemplateInternal() -> resolveTemplate() function, it returns directly without extension verification, so that arbitrary extension files are rendered as twig templates. When attacker with admin privileges on a DEV or an improperly configured STG or PROD environment, they can exploit this vulnerability to remote code execution. Code execution may grant the attacker access to the host operating system. This issue has been addressed in version 4.4.6. Users are advised to upgrade. There are no known workarounds for this vulnerability.

Affected Software

2 affected componentsFixes available
composer/craftcms/cms>=4.0.0<4.4.6
4.4.6
Craft CMS>=4.0.0<4.4.6

Event History

May 19, 2023
CVE Published
via MITRE·07:40 PM
Data Sourced
via MITRE·07:40 PM
DescriptionSeverityWeakness
May 22, 2023
Advisory Published
08:36 PM
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is CVE-2023-32679?

CVE-2023-32679 is a vulnerability in Craft CMS that allows for unrestricted file extensions, leading to remote code execution.

2

How does CVE-2023-32679 impact Craft CMS?

CVE-2023-32679 allows an attacker to execute arbitrary code remotely by exploiting unrestricted file extensions in Craft CMS.

3

What is the severity of CVE-2023-32679?

CVE-2023-32679 has a severity rating of 7.2 (High).

4

How can I fix CVE-2023-32679 in Craft CMS?

To fix CVE-2023-32679, update Craft CMS to version 4.4.6 or newer.

5

Where can I find more information about CVE-2023-32679?

You can find more information about CVE-2023-32679 in the Craft CMS security advisory at: https://github.com/craftcms/cms/security/advisories/GHSA-vqxf-r9ph-cc9c

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203