CVE-2025-54418: CodeIgniter4's ImageMagick Handler has Command Injection Vulnerability
Impact This vulnerability affects applications that: Use the ImageMagick handler for image processing (imagick as the image library) AND either: Allow file uploads with user-controlled filenames and process uploaded images using the resize() method OR use the text() method with user-controlled text content or options
An attacker can: Upload a file with a malicious filename containing shell metacharacters that get executed when the image is processed OR provide malicious text content or options that get executed when adding text to images
Patches Upgrade to v4.6.2 or later.
Workarounds Switch to the GD image handler (gd, the default handler), which is not affected by either vulnerability For file upload scenarios: Instead of using user-provided filenames, generate random names to eliminate the attack vector with getRandomName() when using the move() method, or use the store() method, which automatically generates safe filenames For text operations: If you must use ImageMagick with user-controlled text, sanitize the input to only allow safe characters: pregreplace('/[^a-zA-Z0-9\s.,!?-]/', '', $text) and validate/restrict text options
References OWASP Command Injection Prevention CWE-78: OS Command Injection
Other sources
CodeIgniter is a PHP full-stack web framework. A command injection vulnerability present in versions prior to 4.6.2 affects applications that use the ImageMagick handler for image processing (imagick as the image library) and either allow file uploads with user-controlled filenames and process uploaded images using the resize() method or use the text() method with user-controlled text content or options. An attacker can upload a file with a malicious filename containing shell metacharacters that get executed when the image is processed or provide malicious text content or options that get executed when adding text to images Users should upgrade to v4.6.2 or later to receive a patch. As a workaround, switch to the GD image handler (gd, the default handler), which is not affected by either vulnerability. For file upload scenarios, instead of using user-provided filenames, generate random names to eliminate the attack vector with getRandomName() when using the move() method, or use the store() method, which automatically generates safe filenames. For text operations, if one must use ImageMagick with user-controlled text, sanitize the input to only allow safe characters and validate/restrict text options.
— MITRE
CodeIgniter4's ImageMagick Handler has Command Injection Vulnerability
— Packagist
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/codeigniter4/frameworkto a version that resolves this vulnerability.Fixed in 4.6.2 - Upgrade
Upgrade
CodeIgniter4 ImageMagick Handlerto a version that resolves this vulnerability.Fixed in 4.6.2 - Configuration
Switch to the GD image handler (`gd`), which is not affected by the vulnerability.
CodeIgniter4 image processing image handler = gd - Compensating control
For file uploads, avoid user-provided filenames: generate random names with `getRandomName()` when using `move()`, or use `store()`, which automatically generates safe filenames.
- Compensating control
For ImageMagick text operations with user-controlled text, sanitize input using `preg_replace('/[^a-zA-Z0-9\s.,!?-]/', '', $text)` and validate or restrict text options.
Event History
Frequently Asked Questions
What is the severity of CVE-2025-54418?
CVE-2025-54418 is considered a high severity vulnerability due to its potential for command injection.
How do I fix CVE-2025-54418?
To fix CVE-2025-54418, upgrade your CodeIgniter framework to version 4.6.2 or later.
What versions are affected by CVE-2025-54418?
CVE-2025-54418 affects all versions of CodeIgniter prior to 4.6.2.
What is the impact of CVE-2025-54418 on my application?
CVE-2025-54418 can allow an attacker to execute arbitrary commands on the server, potentially compromising the entire system.
Does CVE-2025-54418 only affect file uploads?
Yes, CVE-2025-54418 specifically affects applications using the ImageMagick handler with unvalidated user-controlled filenames.