CVE-2026-42257: net-imap: Command Injection via "raw" arguments to multiple commands

Published May 4, 2026
·
Updated

Summary Several Net::IMAP commands accept a raw string argument that is sent to the server without validation or escaping. If this string is derived from user-controlled input, it may contain contain CRLF sequences, which an attacker can use to inject arbitrary IMAP commands.

Details

Net::IMAP's generic argument handling, used by most command arguments, interprets string arguments as an IMAP astring. Depending on the string contents and the connection's UTF-8 support, this encodes strings as either a atom, quoted, or literal. These are safe from command or argument injection.

But the following commands transform specific String arguments to Net::IMAP::RawData, which bypasses normal argument validation and encoding and prints the string directly to the socket: #uidsearch, #search when criteria is a String, it is sent raw #uidfetch, #fetch when attr is a String, it is sent raw when attr is an Array, each String in attr is sent raw #uidstore, #store when attr is a String, it is sent raw #setquota: limit is interpolated with #tos and that string is sent raw

Because these string arguments are sent without any neutralization, they serve as a direct vector for command splitting. Any user controlled data interpolated into these strings can be used to break out of the intended command context.

Using "raw data" arguments for #uidstore, #store, and #setquota I both inappropriate and unnecessary. Net::IMAP's generic argument handling is sufficient to safely validate and encode their arguments. Users of the library probably do not expect arguments to these commands to be sent raw and might not be wary of passing unvalidated input.

The API for search criteria and fetch attributes is intentionally low-level and "close to the wire". It allows developers to use some IMAP extensions without requiring explicit support from the library and allows developers to use complex IMAP grammar without complex argument translation. Even so, basic validation is appropriate and could neutralize command injection.

Although this was explicitly documented for search criteria, it was insufficiently documented for fetch attr. So developers may not have realized that the attr argument to #fetch and #uidfetch is sent as "raw data".

Impact

If a developer passes an unvalidated user-controlled input for one of these method arguments, an attacker can append CRLF sequence followed by a new IMAP command (like DELETE mailbox). Although this does not directly enable data exfiltration, it could be combined with other attack vectors or knowledge of the target system's attributes, e.g.: shared mail folders or the application's installed response handlers.

The SEARCH, STORE, and FETCH commands, and their UID variants are some of the most commonly used features of the library. Applications that build search queries or fetch attributes dynamically based on user input (e.g., mail clients or archival tools) may be at significant risk.

Expected use of Net::IMAP#setquota is much more limited: SETQUOTA is often only usable by users with special administrative privileges. Depending on the server, quota administration might be managed through server configuration rather than via the IMAP protocol SETQUOTA command. It is expected to be uncommonly used in system administration scripts or in interactive sessions, it should be completely controlled by trusted users, and should only use trusted inputs. Calling #setquota with untrusted user input is expected to be a very uncommon use case. Please note however this might be combined with other attacks, for example CSRF, which provide unauthorized access to trusted inputs, and may specifically target users or scripts with administrator privileges.

Mitigation - Update to a patched version of net-imap which: - validates that Net::IMAP::RawData is composed of well-formed IMAP text, literal, and literal8 values, with no unescaped NULL, CR, or LF bytes. - does not use Net::IMAP::RawData for #store, #uidstore, or #setquota. - Prefer to send search criteria as an array of key value pairs. Avoid sending it as an interpolated string. - If an immediate upgrade is not possible: - String inputs to search criteria and fetch attributes can be validated against command injection by checking for \r and \n characters. - Hard-coding the store attr argument is often appropriate. Alternatively, user controlled inputs can be restricted to a small enumerated list which is valid for the calling application. - Use Kernel#Integer to coerce and validate user controlled inputs to #setquota limit.

Other sources

Net::IMAP implements Internet Message Access Protocol (IMAP) client functionality in Ruby. Prior to versions 0.4.24, 0.5.14, and 0.6.4, several Net::IMAP commands accept a raw string argument that is sent to the server without validation or escaping. If this string is derived from user-controlled input, it may contain contain CRLF sequences, which an attacker can use to inject arbitrary IMAP commands. This issue has been patched in versions 0.4.24, 0.5.14, and 0.6.4.

MITRE

Affected Software

10 affected componentsFixes available
rubygems/net-imap>=0<=0.4.23
0.4.24
rubygems/net-imap>=0.5.0<=0.5.13
0.5.14
rubygems/net-imap>=0.6.0<=0.6.3
0.6.4
ruby-lang Net\<0.4.24
ruby-lang Net\>=0.5.0<0.5.14
ruby-lang Net\>=0.6.0<0.6.4
debian/ruby2.7<=2.7.4-1+deb11u1, <=2.7.4-1+deb11u5
debian/ruby3.1<=3.1.2-7+deb12u1
debian/ruby3.3<=3.3.8-2, <=3.3.8-2.2
IBM API Connect V12 OnPrem<=All

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade rubygems/net-imap to a version that resolves this vulnerability.

    Fixed in 0.4.24
  2. Upgrade

    Upgrade rubygems/net-imap to a version that resolves this vulnerability.

    Fixed in 0.5.14
  3. Upgrade

    Upgrade rubygems/net-imap to a version that resolves this vulnerability.

    Fixed in 0.6.4
  4. Upgrade

    Upgrade net-imap to a version that resolves this vulnerability.

    Fixed in 0.4.24
  5. Upgrade

    Upgrade net-imap to a version that resolves this vulnerability.

    Fixed in 0.5.14
  6. Upgrade

    Upgrade net-imap to a version that resolves this vulnerability.

    Fixed in 0.6.4
  7. Configuration

    Do not pass untrusted user-controlled input into Net::IMAP#setquota limit/attr arguments as interpolated strings. If immediate upgrade is not possible, validate inputs by rejecting CR and LF characters ("\r" and "\n") and coerce limit using Kernel#Integer semantics (as implemented in patched net-imap).

    Net::IMAP#setquota (attr/limit) usage in application input handling = validate and coerce user-controlled inputs before passing to setquota
  8. Configuration

    Avoid sending search criteria and fetch attributes as interpolated strings. Hard-code the store/fetch attr argument where possible. If immediate upgrade is not possible, validate string inputs to fetch/search criteria by rejecting "\r" and "\n" characters before passing them to Net::IMAP#fetch/#uid_fetch.

    Net::IMAP#fetch / #uid_fetch (attr) usage in application attr argument encoding = use trusted/static attr or validated/neutralized values
  9. Configuration

    If immediate upgrade is not possible, prefer to send search criteria as an array of key value pairs rather than a single String. Validate any String elements used as search criteria by rejecting CR and LF ("\r" and "\n") characters before passing to Net::IMAP#uid_search/#uid_search.

    Net::IMAP#search / #uid_search (criteria) usage in application criteria argument type = array of key/value pairs
  10. Configuration

    Do not build Net::IMAP#store/#uid_store attr values from unvalidated user input. Prefer hard-coding the store attr argument; alternatively restrict user-controlled inputs to a small enumerated list valid for the calling application.

    Net::IMAP#uid_store / #store (attr/commands) usage in application store attr argument handling = avoid raw data arguments; use hard-coded or trusted enumerated values

Event History

May 4, 2026
Advisory Published
via GitHub·10:04 PM
Data Sourced
via GitHub·10:04 PM
DescriptionWeaknessAffected Software
May 9, 2026
CVE Published
via MITRE·07:39 PM
Data Sourced
via MITRE·07:39 PM
DescriptionWeakness
Data Sourced
via NVD·08:16 PM
DescriptionSeverityWeaknessAffected Software
Jun 15, 2026
Data Sourced
via Ubuntu·06:35 PM
RemedyDescriptionSeverityAffected Software
Data Sourced
via Debian·06:36 PM
DescriptionAffected Software
Data Sourced
via Launchpad·06:36 PM
Description
Jul 7, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-42257?

CVE-2026-42257 has a high severity rating due to the potential for command injection vulnerabilities in the `Net::IMAP` commands.

2

How do I fix CVE-2026-42257?

To fix CVE-2026-42257, update the `net-imap` gem to version 0.4.24, 0.5.14, or 0.6.4.

3

What software versions are affected by CVE-2026-42257?

CVE-2026-42257 affects versions of the `net-imap` gem prior to 0.4.24, 0.5.14, and 0.6.4.

4

How can CVE-2026-42257 be exploited?

CVE-2026-42257 can be exploited by an attacker injecting arbitrary IMAP commands through user-controlled input containing CRLF sequences.

5

Is user input safe with CVE-2026-42257?

No, user input is not safe with CVE-2026-42257 as it can lead to command injection vulnerabilities in the `Net::IMAP` commands.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203