Xem nội dung tiếng Việt tại đây / Read the Vietnamese version
| Field | Detail |
|---|---|
| CyStack Advisory ID | CSA-2026-NGINX-02 |
| CVE IDs | CVE-2026-42055 |
| GHSA | GHSA-46pw-w5p7-wjm4 (proxy HTTP/2), GHSA-pmgm-cjqr-vhr9 (gRPC) |
| Severity | High (CVSS v3.1) / Critical (CVSS v4.0) |
| CVSS score | 8.1 (CVSS v3.1), 9.2 (CVSS v4.0) |
| Classification | CWE-122 (Heap-based Buffer Overflow), rooted in CWE-131 |
| Affected modules | ngx_http_proxy_v2_module, ngx_http_grpc_module |
| Affected versions | NGINX Open Source 1.30.0 through 1.30.2 and 1.31.0 through 1.31.1, NGINX Plus accordingly |
| Fixed in | NGINX Open Source 1.30.3 and 1.31.2 |
| Vendor advisory | https://my.f5.com/manage/s/article/K000161584 |
CyStack Security Advisory – CVE-2026-42055: Heap buffer overflow in nginx HTTP/2 and gRPC proxy modules (ngx_http_proxy_v2_module, ngx_http_grpc_module). Fixed in nginx 1.30.3 / 1.31.2.
Summary
nginx is one of the most widely deployed pieces of infrastructure on the Internet, fronting millions of websites and serving as the default reverse proxy for countless cloud platforms. Since version 1.25.0, nginx supports HTTP/3 directly in the core rather than through an out-of-tree patch, which means the entire new attack surface of QUIC and QPACK runs straight inside the worker process that handles every connection.
While reviewing the part of nginx that builds upstream requests, I found a heap buffer overflow caused by length under-allocation. The request builder reserves a fixed 4 bytes for the length prefix of an HPACK string, but the HPACK varint encoder emits 5 bytes when the length value exceeds 2097278. Each oversized field therefore makes the write run past the allocated region, carrying attacker-controlled HPACK data with it.
The bug exists on both sides of the same code pattern: ngx_http_proxy_v2_module when proxy_http_version 2 is used, and ngx_http_grpc_module when grpc_pass is used. Because of the shared root cause, F5 merged both into a single CVE, CVE-2026-42055, published on June 17, 2026 in advisory K000161584 (internal ID NPS-52), rated High under CVSS v3.1 (8.1) and Critical under CVSS v4.0 (9.2). It is purely a data plane issue and only appears in non-default configurations, which I will make explicit in the Impact section. The fix ships in NGINX Open Source 1.30.3 and 1.31.2.
Background
HTTP/2 and gRPC use HPACK (RFC 7541) for header compression. In HPACK, a string (a header name or value) is encoded with a variable-length integer length prefix, called a varint, followed by the data bytes. The HPACK varint uses an N-bit prefix scheme: if the value is below the prefix threshold it fits in a single byte, otherwise the first byte holds the prefix maximum and the following bytes carry the remainder in groups of 7 bits.
When nginx proxies to an HTTP/2 or gRPC upstream, it does not forward the client’s HTTP/2 frames. It builds a brand-new HTTP/2 request: it takes the method, URI, authority, and the headers, then re-encodes them into HPACK to send to the upstream. This happens in ngx_http_proxy_v2_create_request() and ngx_http_grpc_create_request().
To build the request, nginx needs a scratch buffer. Rather than allocating piece by piece, it computes the total size up front, allocates a buffer of exactly that size, and then writes into it incrementally. The catch is that this up-front calculation must reserve enough room for each field’s varint. If it under-reserves by even a single byte for one field, the subsequent write overflows.
Root cause
Both request builders use the same formula to reserve room for each header line, for example in src/http/modules/ngx_http_grpc_module.c:
len += 1 + NGX_HTTP_V2_INT_OCTETS + value.len; ... b = ngx_create_temp_buf(r->pool, len);
NGX_HTTP_V2_INT_OCTETS is 4. That is the number of bytes reserved for a string’s varint prefix. But the function that actually emits the varint is ngx_http_v2_write_int(), and for a 7-bit prefix the number of bytes it produces depends on the magnitude of the value:
| Value range | Varint bytes |
|---|---|
0..126 | 1 |
127..253 | 2 |
254..16509 | 3 |
16510..2097278 | 4 |
2097279.. | 5 |
For any field whose value.len exceeds NGX_HTTP_V2_MAX_FIELD, which is 2097278, that is (1 << 21) + 127 - 1, the varint needs 5 bytes while the calculation reserved only 4. That one byte of difference is never counted into the total. When nginx writes the real varint into the buffer, its last byte, plus the field’s data bytes, falls outside the allocated region.
In the proxy module the situation is slightly worse, because when a continuation frame has to be inserted, nginx shifts the data with ngx_memmove:
ngx_memmove(p + sizeof(ngx_http_proxy_v2_frame_t), p, len);
The out-of-bounds tail sits at the end of the copied block, so AddressSanitizer reports the write size as the entire memmove rather than a single stray byte. The essence is still an overflow of 1 to a few bytes of attacker-controlled HPACK data past the valid memory region.
It is worth noting that nginx had already fixed this exact bug class, but only on the response side. Commit 58a7bc340 (“HTTP/2: limit Content-Type and Location response header length”) added a length limit for response headers. The request side, where nginx builds the request sent upstream, had no corresponding > NGX_HTTP_V2_MAX_FIELD check. Same family of root cause, just a different entry point.
Reproducing the bug
The bug fires when a field exceeding the roughly 2MB threshold reaches the upstream request builder. I reproduced it on both modules with an AddressSanitizer build of nginx 1.31.0.
For the proxy module, send a request with an oversized method and path to an HTTP/2 proxy location:
location / {
proxy_http_version 2;
proxy_pass_request_headers off;
proxy_set_header Host "";
proxy_pass http://h2-backend;
}
ERROR: AddressSanitizer: heap-buffer-overflow on address 0x... at pc 0x... WRITE of size 5710 at 0x... thread T0 0x... is located 0 bytes after 4202389-byte region SUMMARY: AddressSanitizer: heap-buffer-overflow (nginx+0x1649a8)
For the gRPC module, an oversized URI to a gRPC location is enough:
location / {
grpc_pass grpc://upstream;
}
ERROR: AddressSanitizer: heap-buffer-overflow on address 0x... at pc 0x... WRITE of size 8157 at 0x... thread T0 0x... is located 0 bytes after 2106533-byte region SUMMARY: AddressSanitizer: heap-buffer-overflow (nginx+0x1649a8)
The out-of-bounds write is 1 byte for the single-oversized-field variant, rising to 8 bytes when both :path and :method exceed the threshold. On an ordinary glibc build, the worker dies with corrupted double-linked list; the client may even have received an HTTP 200 from a fast upstream before the worker collapses during request-pool cleanup. Ten out of ten attempts in master/worker mode produced a clean SIGSEGV per request.
flowchart TD A[Request with a field over 2097278 bytes] --> B[Upstream request builder] B --> C[Reserve len += 1 + 4 + value.len for the field] C --> D[ngx_create_temp_buf allocates a buffer of the reserved size] D --> E[ngx_http_v2_write_int emits a 5-byte varint for the oversized field] E --> F[Writes 1 byte more per field than was reserved] F --> G[HPACK data tail falls outside the allocation] G --> H[Heap buffer overflow, worker crashes]
Impact
This is a heap overflow that writes attacker-controlled HPACK data past the boundary of the allocated region, triggered remotely and without authentication. The direct consequence is repeated worker process crashes, leading to sustained denial of service: each oversized request kills a worker, the master respawns workers, but every connection on the dying worker is dropped.
The trigger conditions must be stated plainly, because they are the most important factor in assessing real-world risk. The bug only fires when a header field longer than roughly 2MB reaches the upstream request builder. Per the F5 advisory, a deployment is exposed only when all three of the following non-default conditions hold:
- A location uses
grpc_passorproxy_http_version 2. - The
ignore_invalid_headersdirective is set to off, whereas the default is on. - The
large_client_header_buffersdirective is configured with a per-buffer size large enough to accept a multi-megabyte header line. The default of 4 buffers of 8K each blocks the attack.
In other words, the default nginx configuration is not affected. For a field over 2MB to survive long enough to reach the faulty write, the operator must deliberately raise large_client_header_buffers above 2MB and turn off the dropping of malformed headers. This substantially narrows the set of affected deployments, and it is also why F5 rated attack complexity as high together with the phrase “conditions beyond their control”.
On the technique itself, this is a short out-of-bounds write of 1 to 8 bytes whose content is HPACK data shaped by the attacker. The F5 advisory raises the possibility of code execution on systems with ASLR disabled or when the attacker can bypass ASLR. I do not demonstrate a complete RCE chain: compared with an arbitrary write-what-where, a short overflow at the tail of a large buffer is much harder to weaponize, depending on how the allocator lays out adjacent regions and on what sits immediately after that buffer. Even so, a controlled overwrite of heap metadata or a neighboring pointer is a classic starting point for escalation, which is why the advisory leaves code execution open rather than asserting the impact stops at denial of service.
On the scoring, the GHSA self-assessed CVSS v3.1 at 8.2 with the vector AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:H. F5’s official advisory rated it High at 8.1 under CVSS v3.1 and Critical at 9.2 under CVSS v4.0. F5 also notes the bug sits entirely in the data plane and does not touch the control plane.
The fix
nginx fixed the bug in the stable branch 1.30.3 and mainline 1.31.2, and the fix is exactly what one would expect: mirror the response-side commit 58a7bc340 onto the request side. The request builder now checks the length of each component before encoding, and rejects the request immediately if any field exceeds NGX_HTTP_V2_MAX_FIELD, instead of letting the buffer calculation run short.
In ngx_http_grpc_create_request(), the new checks are as follows:
if (r->method_name.len > NGX_HTTP_V2_MAX_FIELD) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"too long http2 method: \"%V\"", &r->method_name);
return NGX_ERROR;
}
if (ctx->host.len > NGX_HTTP_V2_MAX_FIELD) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"too long http2 host: "%V"", &ctx->host);
return NGX_ERROR;
}
if (uri_len > NGX_HTTP_V2_MAX_FIELD) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"too long http2 URI");
return NGX_ERROR;
}
if (key_len > NGX_HTTP_V2_MAX_FIELD) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"too long http2 header name");
return NGX_ERROR;
}
if (val_len > NGX_HTTP_V2_MAX_FIELD) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"too long http2 header value");
return NGX_ERROR;
}
The proxy module received the same set of checks via PR #1441. In the GHSA discussion, an nginx team member confirmed “the same issue in proxy v2 module and is fixed in the PR”, with the gRPC version fixed right after. For each field, a single > NGX_HTTP_V2_MAX_FIELD comparison rules out the case where the varint needs 5 bytes, so the 4-byte reservation is never short again. Oversized requests return an error and no connection is opened to the upstream.
The nginx changelog describes it as follows:
Security: a heap memory buffer overflow might occur in a worker process when using a configuration with “ignore_invalid_headers off;” and “large_client_header_buffers” with large configured values when proxying a specially crafted request to HTTP/2 or gRPC backend, allowing an attacker to cause worker process memory corruption or segmentation fault in a worker process (CVE-2026-42055).
Users should upgrade to NGINX Open Source 1.31.2 or 1.30.3, or the corresponding NGINX Plus release. If upgrading immediately is not possible, F5 recommends neutralizing the attack path by removing ignore_invalid_headers off from the configuration, or by reducing the large_client_header_buffers size below 2MB. Either change causes the oversized field to be rejected before it reaches the request builder.
The takeaway is a classic one in C programming: any manual buffer-size calculation must match, byte for byte, every branch of the write that follows it. A reservation constant like NGX_HTTP_V2_INT_OCTETS holds only until some input pushes the encoder into a longer branch. When the fix for the response side was written, the request side should have been reviewed at the same time, since they share the exact same varint encoding.
Timeline
- 2026-05-17: bug identified on mainline 1.31.0, in both the proxy HTTP/2 and gRPC modules.
- 2026-05-18: stable reproduction on 1.31.0 and master, with the out-of-bounds write characterized under ASAN, a guard allocator, and musl mallocng. Two reports were submitted to F5 via GitHub Security Advisory: GHSA-46pw-w5p7-wjm4 for proxy HTTP/2 and GHSA-pmgm-cjqr-vhr9 for gRPC. F5 SIRT acknowledged them the same day.
- The nginx team confirmed and fixed the proxy v2 module via PR #1441, then fixed the gRPC version right after.
- 2026-06-17: F5 merged the two reports into a single CVE, CVE-2026-42055, published advisory K000161584, and released the fix in NGINX Open Source 1.30.3 and 1.31.2.
References
- F5 advisory: https://my.f5.com/manage/s/article/K000161584
- GitHub Security Advisory (proxy HTTP/2): GHSA-46pw-w5p7-wjm4
- GitHub Security Advisory (gRPC): GHSA-pmgm-cjqr-vhr9
- nginx changelog (1.31.2): https://nginx.org/en/CHANGES
- nginx security advisories: https://nginx.org/en/security_advisories.html
- RFC 7541 (HPACK): https://www.rfc-editor.org/rfc/rfc7541