CVE-2021-34551 is a high-severity (CVSS 8.1) Unrestricted File Upload vulnerability in phpmailer/phpmailer. A fix is available for phpmailer/phpmailer — see the affected versions and patch details below.
Remote Code Execution vulnerability in PHPMailer 6.4.1 running on Windows
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
CVE-2021-34551 by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.
Where this sits among everything scored
Of 395,249 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Counts from FIRST.org, log-scaled.
Real-World Exposure
phpmailer/phpmailerReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects Packagist packages — download data is not available via public APIs for these ecosystems.
Description
PHPMailer 6.4.1 contains a possible remote code execution vulnerability through the $lang_path parameter of the setLanguage() method. If the $lang_path parameter is passed unfiltered from user input, it can be set to a UNC path, and if an attacker is also able to create a remote mount on the server that the UNC path points to, a script file under their control may be executed.
Impact
Arbitrary code may be run by a remote attacker under the web server or PHP process running on Window hosts.
Patches
Mitigated in PHPMailer 6.5.0 by no longer treating translation files as PHP code, but by parsing their text content directly. This approach avoids the possibility of executing unknown code while retaining backward compatibility. This isn't ideal, so the current translation format is deprecated and will be replaced in the next major release.
Workarounds
Any of:
- Ensure that calling code does not pass unfiltered user-supplied data to the
$lang_pathparameter of thesetLanguage()method. - Block or filter the use of unknown UNC paths in this parameter (or altogether).
- Ensure that unauthorised users do not have the ability to read from unknown remote servers via UNC paths.
- Run on an OS that does not support UNC paths
References
Reported by listensec.com via Tidelift.
For more information
If you have any questions or comments about this advisory:
- Open an issue in PHPMailer
- Email the maintainers
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐘Packagist | phpmailer/phpmailer | all versions | 6.5.0composer require phpmailer/phpmailer:^6.5.0 |
Affected Products
fedorafedoraprojectphpmailerphpmailer_projectDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for phpmailer/phpmailer, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update phpmailer/phpmailer to 6.5.0 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms CVE-2021-34551 is resolved across your whole dependency graph.
Workarounds
Treat uploaded files as untrusted until proven otherwise: validate the actual content type rather than the supplied extension, store uploads outside the web root on a volume mounted without execute permission, and rename them to server-generated identifiers so an attacker cannot choose the path a request will later resolve.
Frequently Asked Questions
Is CVE-2021-34551 in your dependencies?
Find it across Packagist, including transitive dependencies.