Severity:

HIGH RISK

(7.6)

Injection in directorytree/imapengine id() Function

CVE-2026-2469

Deferred

Vulnerability type

Category:

Injection

CWE:

CWE-74

Impact:

Arbitrary IMAP Command Execution on Victim Mailboxes

Severity:

HIGH RISK

(7.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

directorytree/imapengine versions before 1.22.3 are vulnerable to IMAP command injection because user-controlled data is inserted into IMAP ID commands without proper escaping or quoting.

An attacker who can influence the value passed to the id() function can inject additional IMAP syntax, allowing them to execute arbitrary IMAP commands against a victim's mailbox, including reading or deleting emails and terminating sessions.

Affected context

The vulnerability appears in PHP applications that use directorytree/imapengine (pre-1.22.3) to communicate with IMAP servers and pass externally influenced values into the ImapConnection::id() function.

It becomes relevant when:

  • The application builds IMAP ID metadata using user-controlled or indirectly user-controlled values (e.g., headers, client info, request parameters), and
  • Those values are sent directly to the IMAP server as part of an ID command without strict encoding or a safe formatting routine.

In such scenarios, quote characters and CRLF sequences inside the value can prematurely terminate fields and append attacker-chosen IMAP commands.

Exploit preconditions

  • Attack surface: Application features that call the id() function or otherwise construct IMAP ID commands using data derived from HTTP requests, session attributes, device identifiers, or other user-controllable inputs.
  • Required access: Ability to submit or influence the data passed into the ID command (e.g., via web forms, headers, query parameters, or API payloads) in the same logical context as the victim's session.
  • Trigger point: Invocation of ImapConnection::id() (or equivalent wrapper) during IMAP session setup or capability negotiation, where the crafted value is included in the ID command string.
  • Why exploitation is possible: The implementation concatenates raw, unescaped user input into an IMAP command, trusting that it will remain a single value. Special characters such as double quotes and CRLF sequences are not neutralized, allowing the injected data to break out of the intended parameter and introduce new IMAP directives.

Why this happens

This issue stems from improper neutralization of special elements used in a downstream IMAP command context, corresponding to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection').

Instead of treating user input as opaque data, the vulnerable code interpolates it directly into an IMAP ID command string:

  • The ID command expects well-formed, quoted fields.
  • User input containing double quotes or CRLF (\r\n) characters can prematurely terminate a field and inject arbitrary protocol elements.

The underlying bug class is command/protocol injection: a data value is handled as if it were trusted IMAP syntax, with no consistent encoding, quoting, or validation to keep it within its intended field.

Potential impact

  • Attackers could execute arbitrary IMAP commands within the context of the victim's authenticated session.
  • Attackers may read messages from the victim's mailbox, including sensitive content.
  • Attackers may delete or move emails, affecting integrity and availability of mailbox data.
  • Attackers could terminate the victim's IMAP session, causing denial of service to legitimate users.
  • Attackers may alter mailbox state (flags, folders, subscriptions) through injected commands.

General mitigation guidance

Effective mitigation focuses on preventing untrusted data from being interpreted as IMAP syntax:

  • Constrain the data used in IMAP ID commands to a fixed, server-side–controlled set of values (e.g., static product name/version, whitelisted fields), avoiding direct reliance on user-provided input.
  • Apply strict encoding or escaping routines when interpolating dynamic values into IMAP commands so that special characters are always treated as literal data, not protocol delimiters.
  • Validate input before use: enforce conservative character sets (e.g., alphanumeric plus a small set of safe punctuation) for any value that might flow into IMAP protocol fields.
  • Centralize IMAP command construction behind a small, audited API that builds commands from tokens and data values rather than string concatenation.
  • Run mail access components with least privilege, limiting the blast radius of a compromised mailbox or abused IMAP session.

How teams detect issues like this

Potential detection approaches include:

  • Static analysis: Scan for string concatenation or interpolation that builds IMAP commands from untrusted sources, especially around the id() method or related IMAP APIs. Flag any use of user-controlled data that is not passed through a dedicated encoder or validator.
  • Code review: Examine IMAP integration code for:
  • Direct construction of protocol lines using variables derived from HTTP requests, cookies, or headers.
  • Lack of a shared, well-documented escaping function for IMAP fields.
  • Broader patterns where user input influences low-level protocol commands.
  • Logging and monitoring: Instrument IMAP access layers to log abnormal or malformed ID command payloads, including unexpected CRLFs or quoting patterns, and alert on suspicious sequences.
  • Policy enforcement: Use pre-commit hooks, CI pipelines, or automated review tools to enforce rules that forbid raw user input in protocol-level command strings and require approved encoding wrappers.

Sources

SourceLink
gist.github.comgist.github.com/wanamirulhakim/74b41589cdea3c07c3375e5946960778
github.comgithub.com/DirectoryTree/ImapEngine/commit/87fca56affd9527e6907a705e6d600c5174d9a5a
github.comgithub.com/DirectoryTree/ImapEngine/pull/150
security.snyk.iosecurity.snyk.io/vuln/SNYK-PHP-DIRECTORYTREEIMAPENGINE-15274300

Frequently asked

questions

Exploitability depends on whether user-controllable data flows into the IMAP ID command in your application. If end users can influence fields that the application passes to id(), an attacker may be able to inject IMAP commands whenever that code path runs in the context of a victim's mailbox.

Typically, yes. The injected commands execute within an authenticated IMAP session, so the attacker must either control or influence data in a context that is bound to a victim's session (for example, through a feature that reflects user input into IMAP metadata). The package itself does not enforce authentication; that is managed by the surrounding application.

Treat all dynamic data used in IMAP commands as untrusted by default, and either eliminate such dependencies or route them through a strict encoder that renders them safe literals within the protocol. Avoid constructing IMAP commands via string concatenation; instead, use helper routines that take structured parameters and apply correct quoting and character filtering.

Adopt a development policy that forbids direct interpolation of user input into protocol or command strings. Use well-defined encoding/escaping APIs for each downstream component (SQL, HTTP, IMAP, LDAP, etc.), limit allowed characters for any data that influences protocol messages, and integrate secure coding checks into code review and automated tooling.

Find out what's already
exploitable in your codebase.