NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · PyPI

CVE-2026-115774: Twisted: Denial of Service in the Twisted IMAP4 Server via a Negative Literal Size in SEARCH

mediumCVSS 3.1 4.9GHSA-2qrf-pqgx-qh9v

Twisted's IMAP4 server (twisted.mail.imap4.IMAP4Server) in 26.4.0 and earlier hangs forever when a logged-in client sends a SEARCH command with a negative literal size such as {-100}. The loop runs on the reactor, so one command stops every service in the process. The patched version is 26.10.0rc1.

Published Oct 23, 2026 · Analysis Nov 2, 2026

What an attacker can do

parseNestedParens reads an inline literal size with int() and never checks the sign. With {-100}, the cursor i goes negative. A negative Python index wraps around the end of the string instead of raising, so the condition i < len(s) stays true and the loop never ends. The _literalStringLimit guard covers only the synchronizing-literal path, not this inline branch.

The code is reached from select_SEARCH through arg_searchkeys. That handler works only in the selected state, so the attacker needs a valid login and a selected mailbox. Any low-privilege account will do. The loop runs synchronously on the single-threaded reactor, so the connection timeout cannot fire either.

The proof of concept is three IMAP lines ending in t3 SEARCH {-100}zzzzzzzzzz. The server never replies and one core sits at 100 percent. In the reporter's test, a health service on the same reactor stopped answering at once. Under twistd mail, SMTP and POP3 stop too. Only a process restart recovers. There is no confidentiality or integrity impact and no code execution. The vector requires high privileges (PR:H) because the sender needs an account.

Who is affected

Twisted <= 26.4.0 when you run twisted.mail.imap4.IMAP4Server, for example through twistd mail or your own IMAP service built on it. Applications that use Twisted without the mail IMAP server are not exposed through this flaw. Check the installed version:

pip show twisted

Search your code and service configs for imap4 or twistd mail.

Twisted

Ecosystem
PyPI
Affected
<= 26.4.0
Fixed in
26.10.0rc1
Check
pip show Twisted

How to fix it

The patched version is 26.10.0rc1, a release candidate:

pip install --pre "twisted>=26.10.0rc1"

The fix (PR 12764, "Reject a negative IMAP literal size") makes the IMAP code refuse negative sizes. The sources do not name a stable release or give a workaround. Until you can upgrade, limit IMAP access to trusted accounts and networks, and run IMAP in its own process so a hang does not take down SMTP or POP3. Those two steps are general hardening, not advice from the advisory. Restart a frozen process to recover.

How to tell if you were hit

A hit looks like an IMAP process pinned at 100 percent of one core that stops answering all connections, including health checks on the same reactor. Check IMAP logs or a packet capture for a SEARCH command with a literal whose size starts with a minus sign, such as {-100}, from an authenticated session. The last log line before the hang is usually a successful login and SELECT from the same client. Watchdog restarts of the Twisted service are another sign.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Summary

An infinite-loop vulnerability (CWE-835) in the Twisted IMAP4 server lets an authenticated client freeze the whole process with one small command. twisted.mail.imap4.parseNestedParens reads an IMAP literal size with int() and never rejects a negative value. A negative size such as {-100} drives the parser cursor negative, and because a negative Python index wraps around the end of the string instead of raising, the scanning loop never terminates. It runs synchronously on the single-threaded reactor, so one SEARCH command holds the reactor at full CPU forever and every other connection stops being served.

Details

Meeting an inline literal, parseNestedParens reads the size between the braces and advances the cursor past the body:

# twisted/mail/imap4.py  parseNestedParens
literalSize = int(s[i + 1 : end])          # no sign check
contentStack[-1].append((s[end + 3 : end + 3 + literalSize],))
i = end + 3 + literalSize                    # negative size -> i goes negative

int(b"-100") is -100, so i goes negative; the loop condition i < len(s) stays true and s[i : i + 1] on a negative index never raises, so the cursor cycles forever. The _literalStringLimit guard only covers the synchronizing-literal continuation path, not this inline branch. The call is reached from select_SEARCH through arg_searchkeys, dispatched only in the selected state, so a valid login and a selected mailbox (any low-privilege account) suffice. It runs in the reactor thread, and the connection timeout cannot fire because the reactor itself is frozen.

Affected product: Twisted (twisted.mail), the IMAP4 server twisted.mail.imap4.IMAP4Server Affected versions: 26.4.0 and earlier

PoC

Log in, select a mailbox, and send a SEARCH whose literal size is negative:

C: t1 LOGIN testuser password-test
C: t2 SELECT INBOX
C: t3 SEARCH {-100}zzzzzzzzzz

The server never responds and one core stays at 100 percent. In a measured run a health service co-hosted on the same reactor stopped answering the instant the command arrived, showing the freeze hits the whole process and not just the attacking connection. A valid {5}zzzzz completes normally and a non-numeric {abc} is rejected with a parse error, which isolates the cause to the missing negative-size check.

Impact

A remote denial of service. One command of about ten bytes freezes the single-threaded reactor, so it stops serving not only every other IMAP connection but every other service co-hosted in the same process (for example SMTP and POP3 under twistd mail), and no timeout can recover it until the process is restarted. It requires an authenticated session, so any account holder can trigger it; there is no confidentiality or integrity impact and no code execution.

Credited to arkmarta.

Questions

Does the attacker need to log in to freeze the Twisted IMAP server?

Yes. SEARCH works only in the selected state, so a valid login and a selected mailbox are required. Any account holder can do it, including low-privilege ones.

Does the connection timeout stop the hang?

No. The loop runs on the reactor thread itself, so the timeout cannot fire. Only restarting the process recovers it.

Is CVE-2026-115774 exploited in the wild?

No source reports exploitation, and it is not in CISA's KEV catalog.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More PyPI vulnerabilities

All PyPI entries