CVE-2023-35169 php-imap vulnerable to RCE through a directory traversal vulnerability

Critical 9.1 Published Updated

Unsanitized attachment filenames in php-imap allow attackers to achieve remote code execution via directory traversal when saving emails.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is CVE-2023-35169?

CVE-2023-35169 is a critical path traversal vulnerability in Webklex php-imap, published on 23 Jun 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. Prior to version 5.3.0, an unsanitized attachment filename allows any unauthenticated user to leverage a directory traversal vulnerability, which results in a remote code execution vulnerability. Every application that stores attachments with `Attachment::save()` without providing a `$filename` or passing unsanitized user input is affected by this attack.

An attacker can send an email with a malicious attachment to the inbox, which gets crawled with `webklex/php-imap` or `webklex/laravel-imap`. Prerequisite for the vulnerability is that the script stores the attachments without providing a `$filename`, or providing an unsanitized `$filename`, in `src/Attachment::save(string $path, string $filename = null)`. In this case, where no `$filename` gets passed into the `Attachment::save()` method, the package would use a series of unsanitized and insecure input values from the mail as fallback. Even if a developer passes a `$filename` into the `Attachment::save()` method, e.g. by passing the name or filename of the mail attachment itself (from email headers), the input values never get sanitized by the package. There is also no restriction about the file extension (e.g. ".php") or the contents of a file. This allows an attacker to upload malicious code of any type and content at any location where the underlying user has write permissions. The attacker can also overwrite existing files and inject malicious code into files that, e.g. get executed by the system via cron or requests.

Version 5.3.0 contains a patch for this issue.

Weakness: CWE-22

Which versions are affected by CVE-2023-35169?

4 open source packages ship an affected version, including webklex/php-imap and webklex/laravel-imap. It affects 1 product.

PackageAffectedFixed in
webklex/php-imap PackagistAll versions5.3.0
webklex/php-imap PackagistAll versions5.3.0
webklex/laravel-imap PackagistAll versions5.3.0
webklex/laravel-imap PackagistAll versions5.3.0

Products include Webklex Php-Imap.

How do I fix CVE-2023-35169?

Upgrade webklex/php-imap to 5.3.0 or later.

Upgrade, and resolve every user-supplied path against an allowed base folder before opening it. More about Path traversal.

Is CVE-2023-35169 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2023-35169 exists.

Sources

Also known as GHSA-47p7-xfcc-4pv9, UBUNTU-CVE-2023-35169.

Is CVE-2023-35169 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free