Skip to content
RCE Write-up Advanced

Nginx Rift: RCE via heap buffer overflow in rewrite module (CVE-2026-42945)

A heap buffer overflow in NGINX's rewrite module occurs when a rewrite directive uses an unnamed regex capture and a replacement containing a question mark, followed by another rewrite, if, or set directive. An unauthenticated attacker can send crafted HTTP requests to corrupt the heap, potentially achieving remote code execution or crashing worker processes.

depthfirst.com

Published on depthfirst.com

CVE-2026-42945 · Heap-based Buffer Overflow · CVSS v4.0 9.2 (Critical) found autonomously by depthfirst

The author, on depthfirst.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely, the rewrite module sets a flag indicating a question mark is present but fails to clear it, causing a later length calculation to use raw bytes while the actual copy escapes certain characters, leading to a buffer overflow.

Impact

An unauthenticated attacker could send a single request to overflow the heap and achieve remote code execution, or repeatedly crash workers to degrade availability.

What the attacker needed

NGINX with vulnerable rewrite configuration; attacker can send HTTP requests

The fix

The vulnerability was fixed in NGINX Open Source 1.31.0 and 1.30.1, and NGINX Plus R36 P4 and R32 P6; if upgrading is not possible, replace unnamed captures with named captures in affected rewrite directives.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

NGINX is a popular web server. A bug in how it handles certain URL rewriting rules can let an attacker send a specially crafted web request that overwrites memory, which can crash the server or let the attacker run their own code. This happens because the server miscalculates how much space it needs when rewriting URLs that contain a question mark and certain characters.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.