We were getting NGINX running again on localhost around the same time we needed to update it in production. I wanted to see how the rewrite bug worked, so I wrote a small C example.
In Inside PHP's 2026 Memory Bugs, I looked at what happens inside PHP when it's handling a request. This time the problem starts one step earlier. NGINX is putting together a new URL, and under certain conditions the result takes up more space than it set aside. That's the bug known as NGINX Rift (CVE-2026-42945).
Which release fixed Rift?
F5 disclosed Rift in May 2026. It's a heap buffer overflow in ngx_http_rewrite_module. By the time we updated in November, NGINX had released more security fixes, including ones for HTTP/2 and its DNS resolver. We went straight to the November stable release.
| Release point | Stable | Mainline |
|---|---|---|
| First upstream Open Source releases fixing Rift, May 2026 | 1.30.1 | 1.31.0 |
| Upstream targets after the November 18 updates, checked November 21 | 1.30.7 | 1.31.9 |
The NGINX security advisories list the fixes by branch, and F5's Rift advisory covers affected products and workarounds. If you installed NGINX through a Linux distribution, check that distribution's security tracker too. It may ship the fix under an older upstream version number.
Source links: Rift and the ten November CVEs
May: Rift. See CVE-2026-42945 and the F5 advisory. The November 18 release note lists the ten additional fixes below. The affected versions vary by issue.
- HTTP/2: CVE-2026-123007 (flow-control memory corruption), CVE-2026-123633 (use-after-free).
- HTTP/3 and DNS: CVE-2026-121810 (HTTP/3 use-after-free), CVE-2026-123634 (resolver use-after-free).
- TLS and stream: CVE-2026-118899 (TLS 1.3 request-body loop), CVE-2026-120967 (stream certificate validation), CVE-2026-123640 (stream preread validation).
- Other subsystems: CVE-2026-113425 (mail proxy use-after-free), CVE-2026-120993 (PROXY protocol v2 null pointer), CVE-2026-125283 (overflow involving alias and try_files).
For fixed and affected ranges, check the upstream security index; each entry also links to its F5 advisory. The NGINX 1.30.7 release records the stable update we deployed.
What happens before PHP sees the request?
Say a browser asks for /shop/42, and the app expects /store?item=42. A rewrite can make that change inside NGINX, before PHP sees the request. The NGINX worker builds the new address in memory and uses it to continue handling the request.
Watch: the request moves through NGINX (7-second loop)
The master process loads the config and manages the workers. A worker can serve a file itself or send the request to an app. In our stack it talks to PHP-FPM over FastCGI. The buffer involved in Rift belongs to that NGINX worker. The NGINX beginner's guide has a good overview of this setup.
How the byte count goes wrong
One way to build a string is to count the bytes first, allocate the buffer once, and then fill it. You can see why the first pass has to know what the second pass will do. Adding a separator or encoding a character can make the result longer.
| Stage | What must stay true |
|---|---|
| Measure | Count the bytes the finished string will use. |
| Reserve | Allocate enough space for the output and any terminator. |
| Write | Check the remaining space before copying. |
In Rift, the rewrite module allocated a buffer that turned out to be too small. The write went past the end of that allocation. The next byte can still be on the same writable memory page, so the worker might corrupt nearby data and keep running for a while before anything visibly goes wrong. F5 also lists possible code execution under certain conditions.
I'd have both passes use the same rules for building the output and check the available space before each copy. The example below checks by subtraction, which also avoids overflowing an integer while adding up lengths.
Run it: six bytes reserved, seven needed
Here's a small C example. I set aside six bytes: four for shop, one for a label, and one for the zero byte that ends a C string. Then I try to append 42, which is two bytes. The result, shop42, needs seven bytes including the terminator. In a six-byte buffer the letters and digits fit, and the terminator would go one byte past the end.
Watch: the write crosses the boundary (9-second loop)
The program allocates both sizes and tries the same append on each. The space check leaves the six-byte buffer unchanged and lets the seven-byte buffer hold shop42. The strings and numbers are made up for this example.
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Append a byte span and leave room for the C string terminator. */
static bool append_span(char *dst, size_t capacity, size_t *used,
const char *src, size_t length)
{
if (*used >= capacity || length >= capacity - *used) {
return false;
}
memmove(dst + *used, src, length);
*used += length;
dst[*used] = '\0';
return true;
}
int main(void)
{
const char prefix[] = "shop";
const char emitted[] = "42";
const size_t planned = sizeof prefix + 1;
const size_t needed = sizeof prefix + sizeof emitted - 1;
char *small = malloc(planned);
char *right = malloc(needed);
if (!small || !right) {
free(small);
free(right);
return EXIT_FAILURE;
}
memcpy(small, prefix, sizeof prefix);
memcpy(right, prefix, sizeof prefix);
size_t used = sizeof prefix - 1;
printf("planned: %zu bytes; actual needed: %zu bytes (both include NUL)\n",
planned, needed);
bool ok = append_span(small, planned, &used, emitted, sizeof emitted - 1);
assert(!ok && used == 4 && strcmp(small, "shop") == 0);
puts("Mismatched output rejected; destination unchanged.");
ok = append_span(right, needed, &used, emitted, sizeof emitted - 1);
assert(ok && used == 6 && strcmp(right, "shop42") == 0);
printf("Correctly sized buffer accepts the same output: %s\n", right);
assert(!append_span(right, needed, &used, "!", 1));
assert(!append_span(right, 0, &used, "", 0));
assert(append_span(right, needed, &used, "", 0));
puts("Full buffer, zero capacity, and empty append checks passed.");
free(right);
free(small);
}cc -std=c11 -Wall -Wextra -Werror -g \
-fsanitize=address,undefined rewrite_capacity.c -o rewrite_capacity
./rewrite_capacity- Check the current length. If
usedis at or past capacity, return before calculatingcapacity - used. The subtraction uses unsigned values. - Leave room for the zero byte. The six-byte buffer has two slots left, and the append needs three. The seven-byte buffer has exactly three slots.
- Check what changed. After the first call the buffer still holds
shopandusedis still four. After the second call the result isshop42.
For a real two-pass writer I'd test an empty string, an exact fit, and a buffer one byte too small. I'd also test an input whose encoded form changes length and compare the estimate with the number of bytes written.
What happens if a worker crashes?
The master can start a replacement worker. Requests that were already in progress on the crashed worker can still fail. I'd line up the worker exit times with request errors, then check whether a reload or an upstream outage happened around the same time. A restart alone leaves the cause open.
Address Space Layout Randomization (ASLR) makes memory addresses harder to predict. It's worth keeping enabled alongside the update, since the patch is what fixes this out-of-bounds write.
How we verified the upgrade
- Check where you're running NGINX, including the public proxy, utility containers, and any ingress. For NGINX Plus or a third-party package, use that vendor's patch guidance.
- Pin and pull the image you want. We used the official image at
nginx:1.30.7-alpineand tested the new image with the deployed config before recreating the container. - With the same Compose files, run
docker compose exec -T nginx nginx -vto check the version anddocker compose exec -T nginx nginx -tto check the config. Then load a PHP-backed page and a static asset. - If you need time before upgrading, check the F5 advisory for temporary measures that apply to your version.
On localhost we had two startup problems to sort out first. NGINX couldn't find PHP-FPM, and another service already had port 8090. We made the admin port opt-in and had Compose wait for PHP-FPM to start listening.
On the production server we recreated just the NGINX container. It reported nginx/1.30.7, and ShivasNotes, both Antsand homepages, and an existing article all returned HTTP 200.
Read next on ShivasNotes
- Inside PHP's 2026 Memory Bugs covers what can go wrong when a PHP worker cleans up after an allocation fails.
- Linux Memory Allocation: malloc, mmap, Pages, TLBs, and Huge Pages explains the memory pages behind a call to
malloc. - HTML Was Always the Interface. SVG Was Always the Diagram. is about how I use editable diagrams in articles and slides.
For more illustrated systems write-ups and runnable examples, subscribe to the ShivasNotes newsletter.
Comments
Join the conversation. Replies can go three levels deep.