CVE-2026-42257: Net imap Net-imap Vulnerable To Command Injection Vulnerability

MODERATE
Advisory Identifier: GHSA-hm49-wcqc-g2xg
CWE-93 CWE-77
Published
Advisory Summary

CVE-2026-42257 is a MODERATE net-imap vulnerable to command injection vulnerability (CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')) affecting Net imap libraries in the RubyGems ecosystem. The issue involves net-imap vulnerable to command injection via "raw" arguments to multiple commands. Remediation is available by upgrading affected packages to version 0.6.4, 0.5.14, 0.4.24.

CVE-2026-42257 at a Glance

CVE Identifier CVE-2026-42257
GHSA Identifier GHSA-hm49-wcqc-g2xg
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')
Affected Product Net imap
Package Ecosystem RubyGems
Published Date
Last Updated

How to Fix CVE-2026-42257

To remediate this vulnerability, upgrade all affected Net imap dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

net-imap fixed: 0.6.4
Upgrade net-imap to 0.6.4
net-imap fixed: 0.5.14
Upgrade net-imap to 0.5.14
net-imap fixed: 0.4.24
Upgrade net-imap to 0.4.24
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for net-imap

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-42257, inspect your project dependencies for Net imap:

inspect dependencies for net-imap

Analyze the terminal output to locate any version of Net imap in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.6.4), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection'), where the product uses crlf (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes crlf sequences from inputs. In Net imap, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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: * `#uid_search`, `#search`, `#uid_sort`, `#sort`, `#uid_thread`, `#thread` * when `criteria` is a String, it is sent raw * `#uid_fetch`, `#fetch * when `attr` is a String, it is sent raw * when `attr` is an Array, each String in `attr` is sent raw * `#uid_store`, `#store` * when `attr` is a String, it is sent raw * `#setquota`: * `limit` is interpolated with `#to_s` 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 `#uid_store`, `#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 `#uid_fetch` 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. The SORT and THREAD commands and their UID variants also handle their search criteria argument similarly to SEARCH and are subject to the same 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`, `#uid_store`, 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.

CVE-2026-42257 Affected Net imap Versions

3 component(s)
Fixed Versions:
0.6.40.5.140.4.24
Product / Package Ecosystem Affected Versions Fixed Version
net-imap
RubyGems
≥ 0.6.0
< 0.6.4
0.6.4
net-imap
RubyGems
≥ 0.5.0
< 0.5.14
0.5.14
net-imap
RubyGems
< 0.4.24
0.4.24

References

Frequently Asked Questions

What is CVE-2026-42257?
CVE-2026-42257 is a security vulnerability in Net imap involving net-imap vulnerable to command Injection via "raw" arguments to multiple commands under CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection').
Which Net imap versions are affected?
Affected versions include releases prior to 0.6.4, 0.5.14, 0.4.24 across affected packages: net-imap.
What version fixes CVE-2026-42257?
Upgrading to 0.6.4, 0.5.14, 0.4.24 (or the latest patched release for your respective branch) resolves the vulnerability.
Is net-imap affected?
Yes, net-imap is affected in releases prior to 0.6.4, 0.5.14, 0.4.24. Upgrade your dependency to 0.6.4, 0.5.14, 0.4.24 or later.
What CWE is associated with CVE-2026-42257?
CVE-2026-42257 is classified under CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection') (The product uses CRLF (carriage return line feeds) as a special element, e.g. to separate lines or records, but it does not neutralize or incorrectly neutralizes CRLF sequences from inputs.).
How can I check RubyGems dependencies for CVE-2026-42257?
Run the dependency tree command: 'inspect dependencies for net-imap'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-hm49-wcqc-g2xg",
  "modified" : "2026-06-17T19:45:30Z",
  "published" : "2026-05-04T22:04:41Z",
  "aliases" : [ "CVE-2026-42257" ],
  "summary" : "net-imap vulnerable to command Injection via \"raw\" arguments to multiple commands",
  "details" : "### Summary\nSeveral `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.\n\n### Details\n\n`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.\n\nBut 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:\n* `#uid_search`, `#search`, `#uid_sort`, `#sort`, `#uid_thread`, `#thread`\n  * when `criteria` is a String, it is sent raw\n* `#uid_fetch`, `#fetch\n  * when `attr` is a String, it is sent raw\n  * when `attr` is an Array, each String in `attr` is sent raw\n* `#uid_store`, `#store`\n  * when `attr` is a String, it is sent raw\n* `#setquota`:\n  * `limit` is interpolated with `#to_s` and that string is sent raw\n\nBecause 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.\n\nUsing \\\"raw data\\\" arguments for  `#uid_store`, `#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.\n\nThe 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.\n\nAlthough 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 `#uid_fetch` is sent as \\\"raw data\\\".\n\n### Impact\n\nIf 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.\n\nThe 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.\n\nThe SORT and THREAD commands and their UID variants also handle their search criteria argument similarly to SEARCH and are subject to the same risk.\n\nExpected 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.\n\n### Mitigation\n - Update to a patched version of `net-imap` which:\n   - validates that `Net::IMAP::RawData` is composed of well-formed IMAP `text`, `literal`, and `literal8` values, with no unescaped `NULL`, `CR`, or `LF` bytes.\n   - does not use `Net::IMAP::RawData` for `#store`, `#uid_store`, or `#setquota`.\n - Prefer to send search criteria as an array of key value pairs.  Avoid sending it as an interpolated string.\n - If an immediate upgrade is not possible:\n   - String inputs to search criteria and fetch attributes can be validated against command injection by checking for `\\r` and `\\n` characters.\n   - 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.\n   - Use `Kernel#Integer` to coerce and validate user controlled inputs to `#setquota` limit.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:P/VC:N/VI:H/VA:L/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "net-imap"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.6.0"
      }, {
        "fixed" : "0.6.4"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.6.3"
    }
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "net-imap"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.5.0"
      }, {
        "fixed" : "0.5.14"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.5.13"
    }
  }, {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "net-imap"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.24"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.4.23"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/security/advisories/GHSA-hm49-wcqc-g2xg"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-42257"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/commit/0ec4fd351263e8b9a4f683713427827b7b1ad974"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/commit/47c72186d272441878ca73c9499f66013829ca2f"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/commit/6bf02aef7e0b5931010c36e377f79a71636b306b"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/commit/a4f7649c3da77dec7631f03a037a478eb4330048"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/commit/aec06996eb87a7e1bbcef1f9f8926e8add2b8c71"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ruby/net-imap"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/releases/tag/v0.4.24"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/releases/tag/v0.5.14"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ruby/net-imap/releases/tag/v0.6.4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/net-imap/CVE-2026-42257.yml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77", "CWE-93" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-05-04T22:04:41Z",
    "nvd_published_at" : "2026-05-09T20:16:28Z"
  }
}