Summary
Local File System Validation Bypass Leading to File Overwrite, Sensitive File Access, and Potential Code Execution
A vulnerability in CraftCMS allows an attacker to bypass local file system validation by utilizing a double file:// scheme (e.g., file://file:////). This enables the attacker to specify sensitive folders as the file system, leading to potential file overwriting through malicious uploads, unauthorized access to sensitive files, and, under certain conditions, remote code execution (RCE) via Server-Side Template Injection (SSTI) payloads.
Note that this will only work if you have an authenticated administrator account with allowAdminChanges enabled.
https://craftcms.com/knowledge-base/securing-craft#set-allowAdminChanges-to-false-in-production
Details
The issue lies in line 57 of cms/src/helpers/FileHelper.php, it only removes file:// on the most left. It is trivial to bypass this sanitization by adding 2 file://, e.g. file://file:////.
public static function normalizePath($path, $ds = DIRECTORY_SEPARATOR): string
{
// Remove any file protocol wrappers
$path = StringHelper::removeLeft($path, 'file://');
// Is this a UNC network share path?
$isUnc = (str_starts_with($path, '//') || str_starts_with($path, '\\\\'));
// Normalize the path
$path = parent::normalizePath($path, $ds);
// If it is UNC, add those slashes back in front
if ($isUnc) {
$path = $ds . $ds . ltrim($path, $ds);
}
return $path;
}
PoC
- Sign in with an admin account and navigate to
Settings → Assets, then create a new volume. - n the Asset Filesystem section, create a new file system and set the Base Path to
file://file:////vendor.
Without the prefix, the selection fails.
With the doublefile://prefix, the selection succeeds.
- Access Assets from the left navigation bar, then upload a file into this volume.
- The file is successfully uploaded and stored in the sensitive folder specified (e.g.,
/vendor).
- SSTI payloads can be uploaded to
/templatesfolder, though full code execution was not achieved during testing, some payloads were still successful, leading to sensitive information disclosure, among other potential impacts.
Impact
Attackers who compromise an admin account(The admin user is not equal to the server owner) can exploit this flaw to assign sensitive folders as the base path of the filesystem. For instance, if the path /templates is specified (e.g., file://file:////var/www/html/templates), the attacker could upload SSTI payloads. While CraftCMS includes strict SSTI input sanitization, RCE may still be possible if the attacker can craft a valid payload, as seen in similar vulnerabilities (e.g., GHSA-44wr-rmwq-3phw).
Additionally, attackers can upload tampered files to overwrite critical web application files. By enabling public URLs for files in the specified filesystem, they can also retrieve sensitive files (e.g., configuration files from the local file system).
Although the vulnerability is exploitable only in the authenticated users, configuration with ALLOW_ADMIN_CHANGES=true, there is still a potential security threat.
Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files. Typical impact: unauthorized file read or write outside the intended directory.
CVE-2024-52291 has a CVSS score of 8.4 (High). The vector is network-reachable, high privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (5.4.6, 4.12.5); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
craftcms/cms to 5.4.6 or later; craftcms/cms to 4.12.5 or later
Kodem Kai can prioritize this vulnerability in your dependency tree and generate a fix recommendation.
Frequently Asked Questions
- What is CVE-2024-52291? CVE-2024-52291 is a high-severity path traversal vulnerability in craftcms/cms (composer), affecting versions >= 5.0.0-RC1, <= 5.4.5.1. It is fixed in 5.4.6, 4.12.5. Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files.
- How severe is CVE-2024-52291? CVE-2024-52291 has a CVSS score of 8.4 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of craftcms/cms are affected by CVE-2024-52291? craftcms/cms (composer) versions >= 5.0.0-RC1, <= 5.4.5.1 is affected.
- Is there a fix for CVE-2024-52291? Yes. CVE-2024-52291 is fixed in 5.4.6, 4.12.5. Upgrade to this version or later.
- Is CVE-2024-52291 exploitable, and should I be worried? Whether CVE-2024-52291 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2024-52291 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2024-52291?
- Upgrade
craftcms/cmsto 5.4.6 or later - Upgrade
craftcms/cmsto 4.12.5 or later
- Upgrade