Language: 中文 | English
This is a lightweight scanner for checking whether an NGINX configuration contains the risky CVE-2026-42945, also known as NGINX Rift, configuration pattern.
The issue was disclosed by depthfirst in NGINX Rift: Achieving NGINX RCE via an 18-Year-Old Vulnerability. Based on the article and F5/NVD descriptions, the risk depends on a specific ngx_http_rewrite_module configuration sequence: in the same configuration context, a rewrite replacement contains ?, and a following rewrite, if, or set references unnamed PCRE captures such as $1 or $2.
This tool looks for high-risk sequences like:
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true;
set $original_endpoint $1;
}
The risk is not a standalone rewrite or set directive. The risky condition is the execution order inside the same context:
rewrite uses a regex capture and its replacement contains ?rewrite, if, or set uses unnamed capture variables such as $1 or $2This combination can cause inconsistent state between NGINX script length calculation and the actual copy phase, potentially leading to a heap buffer overflow.
The depthfirst article lists the affected range as:
Use the official F5 advisory or your distribution security advisory as the source of truth for fixed versions and product-specific impact. Even when the version is in the affected range, the vulnerable configuration sequence is typically also required to trigger the issue.
The script prints both the current NGINX version and the configuration scan result:
0.6.27 - 1.30.0 and vulnerable config is found: upgrade NGINX or adjust the config.0.6.27 - 1.30.0 but vulnerable config is not found: upgrade is recommended, but this scanner did not find the triggering config pattern.Scan the full NGINX configuration on the current host:
python3 scan_rift.py
The script runs:
nginx -T
If the current user cannot read the full configuration, run it with sudo:
sudo python3 scan_rift.py
You can also scan an exported configuration file:
python3 scan_rift.py /path/to/nginx-full.conf
For example:
sudo nginx -T > nginx-full.conf
python3 scan_rift.py nginx-full.conf
When no vulnerable sequence is found:
--- NGINX Rift Config Scanner (CVE-2026-42945) ---
Current NGINX Version: nginx version: nginx/1.23.3
Version Status: Affected version range for NGINX Open Source (0.6.27 - 1.30.0)
[+] No vulnerable CVE-2026-42945 sequences detected.
[Recommendation]: Current NGINX version is in the affected range, but no vulnerable config sequence was detected. Upgrade is recommended, but config risk was not found by this scanner.
When a suspicious sequence is found:
--- NGINX Rift Config Scanner (CVE-2026-42945) ---
Current NGINX Version: nginx version: nginx/1.23.3
Version Status: Affected version range for NGINX Open Source (0.6.27 - 1.30.0)
[!] VULNERABLE SEQUENCE FOUND:
Context: location ~ ^/api/(.*)$ {
[1. Rewrite With ?] rewrite ^/api/(.*)$ /internal?migrated=true;
[2. Follow-up $N] set $original_endpoint $1;
[Action Required]: Current NGINX version is affected and vulnerable config was found. Upgrade NGINX or adjust the reported rewrite/if/set sequence.
If the scanner reports a match, manually verify whether that configuration context is reachable by external requests, then upgrade NGINX or adjust the configuration.
rewrite / set combinations in location, server, if, and related contexts.$1 or $2 after a rewrite that contains ?.This is a static configuration scanner intended to quickly identify high-risk patterns. It is not an exploit validator.
include expansion, or dynamically generated configuration may affect scan quality.