Skip to content

🔀 Merge v0.6.4.1 patches#702

Merged
nevans merged 13 commits into
masterfrom
v0.6.4-patches
Jun 9, 2026
Merged

🔀 Merge v0.6.4.1 patches#702
nevans merged 13 commits into
masterfrom
v0.6.4-patches

Conversation

@nevans

@nevans nevans commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

nevans added 13 commits June 8, 2026 11:33
Also update internal RawText docs.
It's bad behavior to send a non-synchronizing literal that's too large.
This forces the server to choose between reading but ignoring the bytes
or closing the connection.

But, for servers that _don't_ support non-synchronizing literals, this
could be another CRLF/command injection attack vector.  If a server sees
the `}\r\n` but can't parse the literal bytesize, it may decide to close
the connection, and all is fine.  But, a server _might_ respond to any
unparseable command line (ending in `CRLF`) with `BAD`, then interpret
the literal as the next command.  In that case, a CRLF/command injection
could succeed.

Fortunately, `LITERAL-` is supported by most IMAP servers.  So this
is not expected to be widely exploitable.
This shares most of the validation implementation with RawText, via an
extracted shared superclass.

Please note: in currently released `net-imap`, QuotedString is _not_
used to quote regular string arguments.  It's currently only used by
`Net::IMAP#id` (the `ID` extension).

Without this patch, `Net::IMAP#id` is vulnerable to the same CRLF
injection issues in GHSA-75xq-5h9v-w6px and GHSA-hm49-wcqc-g2xg.  The
string will be quoted, which may limit the ability to inject some
commands.  Presumably, `Net::IMAP#id` is unlikely to be called with
user-provided input, making this less likely to be exploitable.
Nevertheless, CRLF injection should be prevented!
This still allows the argument to be a single string with multiple
space-delimited arguments.  It splits the string first, and validates
the substrings.
Zero-length literals are explicitly allowed by the RFCs and this did not
catch text that ends with `{0}` or `{0+}`.  This leaves RawData able to
absorb the `CRLF` that ends the command, and thus absorb the following
command into itself.

Ultimately, we don't care if the `number64` is encoded correctly nor
whether it claims to be a binary literal.  So I've simplified the regexp
by dropping `~?` and using `\d+` for the number.
This removes the duplicated string quoting implementation.  It also
introduces stricter enforcement of `quoted` string validation..
🥅 Validate `ID` values contain only valid bytes
🥅 Validate `#enable` arguments are all atoms
…teral-marker-validation

🐛 Prevent trailing `{0}` in RawData validation
These tests can raise `Errno::ECONNREST, "Connection reset"` in the
server thread.  I've only seen it in TruffleRuby (semi-reliably) and
MacOS (flaky), but probably it's a timing issue and can happen elsewhere
too?
…l-support

🥅 Validate non-synchronizing literals support
@nevans nevans added bug Something isn't working backport-0.5 This ticket needs to be backported to the v0.5-stable branch. security vulnerability patch Pull requests that address security vulnerabilities labels Jun 9, 2026
@nevans nevans merged commit 36f0329 into master Jun 9, 2026
57 checks passed
@nevans nevans deleted the v0.6.4-patches branch June 9, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-0.5 This ticket needs to be backported to the v0.5-stable branch. bug Something isn't working security vulnerability patch Pull requests that address security vulnerabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant