//nefariousplan

CVE-2026-123007: NGINX's HTTP/2 Validator Subtracted From a Counter That Could Legally Exceed Its Maximum. The Fix Is the Ledger Column That Would Have Kept It Legal.

vendor

patterns

cve

proof of concept

NGINX's HTTP/2 connection-level send window is a size_t named send_window. Through version 1.31.8, the connection WINDOW_UPDATE validator checked every client grant with window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window. That subtraction is correct only while send_window is at or below NGX_HTTP_V2_MAX_WINDOW. Every path that wrote the counter maintained that invariant except one. When a stream was reset, the cleanup path refunded the credit that had been reserved for queued-but-not-yet-sent DATA frames. If the client had raised the window between queueing and reset, the refund crossed the ceiling. From that moment the validator was subtracting a larger unsigned value from a smaller one. It wrapped. The next WINDOW_UPDATE was accepted. Rapid7 walked that wrap into unauthenticated RCE against unmodified NGINX 1.31.8 in 190 seconds and 119 GiB of plaintext.

The validator subtracts unsigned from a counter it trusts to stay below MAX

The relevant code is ngx_http_v2_state_window_update in src/http/v2/ngx_http_v2.c. The connection-wide branch takes a window increment off the wire and runs one check before applying it:

if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) {
    ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
                  "client violated connection flow control: ...");
    return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR);
}

h2c->send_window += window;

NGX_HTTP_V2_MAX_WINDOW is 0x7fffffff. The field h2c->send_window is a size_t: unsigned 64-bit on every platform NGINX Plus ships to. The subtraction NGX_HTTP_V2_MAX_WINDOW - h2c->send_window is unsigned 64-bit arithmetic.

The check is correct exactly while send_window <= NGX_HTTP_V2_MAX_WINDOW. In that regime the subtraction returns the signed distance to the ceiling, and the comparison does what the HTTP/2 spec requires: reject any increment that would push the per-connection total above 0x7fffffff. The regime the check depends on is an invariant on send_window. Nothing in this function enforces that invariant. The function reads it.

When send_window is already above 0x7fffffff, the subtraction underflows. size_t arithmetic wraps modulo 2^64, so the expression returns a number close to 2^64. Every legal window on the wire is a 31-bit integer less than 0x80000000. Every such window is less than 2^64 - 0x80000000. The check passes for any input. The branch below runs. h2c->send_window += window adds it in.

Only the cleanup refund can cross the ceiling

h2c->send_window is written in three places in NGINX's HTTP/2 implementation. Each site is correct on its own terms. The composed system has a hole exactly where no single site is responsible for the invariant.

The reservation site is ngx_http_v2_send_chain in src/http/v2/ngx_http_v2_filter_module.c. When NGINX commits bytes to a DATA frame and queues it for output, the function subtracts those bytes from send_window:

h2c->send_window -= frame_size;

stream->send_window -= frame_size;
stream->queued++;

The on-wire site is in the frame-send handler. Once a queued frame reaches the wire, the handler does nothing to send_window: those bytes were deducted at reservation and never need to be deducted again. The handler updates per-stream state and payload_bytes for logging.

The refund site is ngx_http_v2_filter_cleanup. When a stream dies before its queued frames reach the wire, cleanup walks the stream's reserved payload and adds it back to the connection counter:

h2c->send_window += window;

Each site treats send_window as "credit available for NGINX to spend on this connection." Each site honors that definition locally. The protocol semantics, from the client's side, are different. The client's view of the connection window reflects only what NGINX has already acknowledged shipping on the wire. Queued-but-not-sent bytes are, from the client's view, still owed. The client is free to raise the connection window at any moment up to 0x7fffffff minus what NGINX has shipped.

Now compose. A queued frame costs frame_size against send_window. Immediately after that reservation, the client sends a WINDOW_UPDATE that fills the gap exactly, and send_window returns to the ceiling. The frame has not reached the wire. The stream is reset by any means the protocol permits. Cleanup fires. send_window += frame_size. The counter is now frame_size above NGX_HTTP_V2_MAX_WINDOW.

The invariant that the validator reads was broken by the only path that never checks it.

Reaching the signed midpoint takes 2^33 WINDOW_UPDATEs and 52 GiB of them

Making send_window legally larger than 0x7fffffff is a DoS primitive by itself; NGINX later casts the counter to a signed type in the output path and misreads it. The Rapid7 PoC walks from the unsigned wrap all the way to that cast.

The bootstrap stage drives the exact race described above. It opens two Range-response streams against zero stream credit so the DATA frames stay queued, grants per-stream credit so the DATA frames exist as queued-but-not-sent bytes, then sends the client-side event that trips the refund:

event = (window_update(0, reserved) + window_update(0, MAX_WINDOW)
         + window_update(target_streams[0], MAX_WINDOW - 1)
         + window_update(target_streams[1], MAX_WINDOW - 1)
         + settings_window(2) + window_update(0, MAX_WINDOW)
         + settings_window(65535)
         + range_request(release_stream, ...))

The first window_update(0, reserved) refills the connection window to exactly cover the queued bytes. The second window_update(0, MAX_WINDOW) raises the connection window to the ceiling. The two per-stream updates push each target stream's window to MAX_WINDOW - 1. The settings_window(2) changes SETTINGS_INITIAL_WINDOW_SIZE to 2, which pushes each target stream's window to MAX_WINDOW + 1, illegal under HTTP/2 flow control. NGINX resets both streams with NGX_HTTP_V2_FLOW_CTRL_ERROR. Cleanup refunds each stream's queued frame_size into send_window, which is already at MAX_WINDOW. send_window is now above MAX_WINDOW. The next window_update(0, MAX_WINDOW) is accepted because the validator's subtraction has already underflowed.

From there the primitive is monotonic. Every subsequent 13-byte WINDOW_UPDATE carrying 0x7fffffff adds 0x7fffffff to send_window and the unsigned-subtraction check keeps wrapping. The PoC sends exactly 2^33 + 1 such increments through 96 live stream owners, rotating the owner on each tranche boundary so no DATA is released and no owner waits for NGINX's send timeout:

17:39:43 INFO replaying 8589934593 legal WINDOW_UPDATE frames across 96 owners
...
17:41:19 INFO wrapped flow-control distance reached; tailored increment=0x7fffc0d5

8589934593 is 2^33 + 1. Each WINDOW_UPDATE is 13 bytes on the wire. The replay sends 111.67 GiB of application plaintext just to walk the counter. NGINX's flood-protection budget would normally drop traffic that over-represents control frames relative to parsed payload, so the stage is preceded by a 15 GiB fixed carrier of maximum-size HEAD-request HEADERS payloads that pays NGINX's accounting cost for the WINDOW_UPDATE flood that follows.

At the end of the replay, send_window has crossed the 64-bit signed midpoint. It is a legal positive size_t whose top bit is set.

(off_t) send_window is the primitive

send_window is read by two sinks. The validator reads it through the unsigned subtraction. The output path reads it through a signed cast, in the same function that reserves:

if (limit == 0 || limit > (off_t) h2c->send_window) {
    limit = h2c->send_window;
}

off_t is signed 64-bit on x86-64 Linux. Casting a size_t whose top bit is set to off_t produces a negative number. The comparison limit > (off_t) h2c->send_window holds for any non-negative limit, so the branch body runs. limit = h2c->send_window assigns the unsigned counter back. The implicit conversion to limit's type is where the wrapped value re-enters the output filter as a very large positive integer. From there limit flows into the per-frame-size budget that controls how many bytes the output filter copies into the TLS record staging buffer. The Rapid7 profile targets a glibc EVEX/YMM memcpy path that walks that budget directly into the heap.

The PoC refines the wrap into something smaller than the full crash primitive. The send_numeric_stage routine computes a tailored final WINDOW_UPDATE increment so send_window lands at a specific distance past the signed midpoint, not at the top of its range:

def near_wrap(start, distance):
    target = (-distance) & MASK64
    for extra in range(8):
        count = (1 << 33) + extra
        current = (start + count * MAX_WINDOW) & MASK64
        tailored = (target - current) & MASK64
        if 1 <= tailored <= MAX_WINDOW:
            return count, tailored
    raise RuntimeError("could not construct legal near-wrap transition")

That tailored value turns the memcpy's walk from "crash the worker" into "read a profiled region of the worker's heap." The exploit picks up the disclosure, recovers h2c's address and libc's base through a chain of NGINX pool and chunk invariants, and reclaims the vacated slot with a forged ngx_http_request_t whose cleanup handler points at system() and whose attached data is the --cmd string. Nginx runs the cleanup. Nginx runs system("touch /tmp/rapid7-nginx-h2-proof-01").

Everything after the signed-midpoint crossing is operational engineering. The primitive is the wrap. The wrap is the refund crossing a ceiling the validator's unsigned subtraction trusted would hold.

The patch does not add a bounds check. It adds a column.

The commit is e27f5fa84fe6e98505e70bc543b748747dad0a3b, by Roman Arutyunyan, dated 2026-10-29. It touches three files and changes six lines. It does not add a bounds check to the cleanup refund. It does not clamp send_window to NGX_HTTP_V2_MAX_WINDOW. It does not change the shape of the validator's arithmetic. It introduces a second counter:

     size_t                           send_window;
+    size_t                           send_queued;
     size_t                           recv_window;
     size_t                           init_window;

send_queued tracks exactly the bytes that are reserved against a queued-but-not-yet-sent DATA frame. The reservation site adds to it:

     h2c->send_window -= frame_size;
+    h2c->send_queued += frame_size;

     stream->send_window -= frame_size;
     stream->queued++;

The on-wire site subtracts from it:

     h2c->payload_bytes += frame->length;
+    h2c->send_queued -= frame->length;

The cleanup refund subtracts from it:

     h2c->send_window += window;
+    h2c->send_queued -= window;

And the validator's check is now:

-    if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) {
+    if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window - h2c->send_queued) {

The validator's arithmetic shape is the same as before. What has changed is the input. The validator is now asking "is the increment greater than the ceiling minus what NGINX has spent and what NGINX has committed to spend?" The committed-to-spend column is send_queued. Before the patch, NGINX did not track it; send_window was treated as both "unspent credit" and "unreserved credit" at different sites, which are the same quantity only when the queue is empty.

The commit message names the structural error directly:

Previously, this could increase the flow control beyond NGX_HTTP_V2_MAX_WINDOW, if it was increased by the client after the stream frames were queued and before the stream was terminated. [...] From the client's point of view, the queued frames still belong to the flow control window.

The server's view and the client's view of the flow-control window disagreed exactly during the queued-but-not-sent interval. The patch does not reconcile them with a check. It gives the server the second column it needed to see the same window the client was seeing.

This is refund-breaks-the-invariant. A single state variable is written by a primary spend path and a secondary refund path. The primary path maintains an invariant that downstream validators compute against. The refund path writes without enforcing that invariant, because its local semantics are "return reserved resource to the pool" and the pool's ceiling is not visible to it. A separate accounting dimension, the committed-but-not-released column the patch introduces, is what makes the refund path's writes safe. Where that column is missing, the refund's write is the primitive.

The commit message is the disclosure

The commit landed on NGINX's public mainline on 2026-10-29 at 21:37 +0400. It is credited "Reported by Xint.io." Its message contains a four-sentence prose description of the exact bug class, including the specific phrase "memory corruption and a possible segmentation fault" as the eventual consequence. Any defender watching NGINX's commit stream on a grep -i "flow control\|HTTP/2.*WINDOW" filter saw the shape of the bug within minutes of the push.

The release tag for NGINX 1.31.9, c2c4470, is dated 2026-11-06, eight days later. Rapid7's advisory records their outreach to F5 on 2026-11-11, five days after the release. CVE-2026-123007 was assigned on 2026-11-16. F5's public advisory and Rapid7's full RCE repository published on 2026-11-18.

That calendar maps onto the catalog's release-lag-disclosure shape. NGINX's commit log carried a legible security disclosure on 2026-10-29. The CVE record caught up to it on 2026-11-18, 20 days later. The release tag landed in the middle of that window. Vulnerability-management products that gate their urgency on CVE publication saw this bug on 2026-11-18. The commit log saw it on 2026-10-29 with a commit message that read, in English, like a vendor advisory in draft.

The 300-line exploit module Rapid7 shipped on disclosure day is not the kind of artifact built in a weekend. The commit-message disclosure is the enabling signal; what is distinctive here is how much of the chain already existed when Rapid7 made the Nov 11 outreach call: the profile-driven ASLR disclosure, the heap-layout grooming, the deferred-execution path, the EVEX/YMM memcpy profile. The 18-day gap between a public commit and a public CVE is the window. The exploit is what Rapid7 built inside it.

Audit your size_t counters for a missing second column

The Rapid7 exploit's full chain is operational craft. The primitive is one patched struct field. Every HTTP/2 or gRPC implementation that tracks flow-control credit in a single counter, that services queued-but-not-sent DATA frames, and that admits a stream-reset path that refunds reserved credit is a candidate for the same bug. The question to ask of such a codebase is not "does the validator check the ceiling." It is "does the refund path know about the ceiling the validator reads." Where that answer is maintained by the client's protocol compliance rather than by a second counter, the next WINDOW_UPDATE is the primitive.

The validator has been reading send_window since NGINX shipped HTTP/2 in 2015. For eleven years the number it was reading was the right one by accident.