Site icon GetPageSpeed

NGINX Hardening After NGINX2Root: Limit the Blast Radius

NGINX Hardening After NGINX2Root: Limit the Blast Radius

NGINX hardening after NGINX2Root comes down to one rule: patch first, then make the next memory-safety bug cost an attacker less. Install a fixed NGINX (1.30.7 or later, 1.30.8 today), then sandbox the service with a systemd drop-in, block the SCTP kernel module and stop advertising your version. Every step below was run on Rocky Linux 10.1 with the GetPageSpeed NGINX 1.30.8 build.

RHEL, Rocky Linux, AlmaLinux, CentOS, Amazon Linux

sudo dnf -y install https://extras.getpagespeed.com/release-latest.rpm
sudo dnf -y upgrade nginx && sudo nginx -t && sudo systemctl restart nginx
nginx -v

On CentOS 7 and RHEL 7, use yum in place of dnf. Free to install; commercial production use requires a subscription. Without one, a small license notice appears on HTML pages after 30 days.

Ubuntu and Debian

curl -fsSLO https://extras.getpagespeed.com/release-latest.deb
sudo apt-get -y install ./release-latest.deb
sudo apt-get update
sudo apt-get -y -o Dpkg::Options::=--force-confold install nginx
sudo nginx -t && sudo systemctl restart nginx
Free to install; commercial production use requires a subscription. Without one, a small license notice appears on HTML pages after 30 days.

Not sure whether your current build is patched? Paste nginx -v, rpm -q nginx or dpkg -l nginx into the free NGINX2Root checker. It reads distro backports, so it can tell a fixed package from an old version number.

Why patching is not the whole job

NGINX2Root, also called NGINX2Shell, is five memory-safety flaws in NGINX, led by CVE-2026-123007 in HTTP/2. Two facts from the research shape the rest of this guide:

So the question after patching is: the next time a worker is compromised, what can that code reach? On a stock systemd unit, quite a lot.

Step 1: check the binary hardening you already have

Memory hardening is a property of the build. Check it on the installed binary with readelf:

B=$(readlink -f /usr/sbin/nginx)
readelf -h "$B" | grep Type
readelf -dW "$B" | grep -E 'BIND_NOW|FLAGS_1'
readelf -lW "$B" | grep -E 'GNU_RELRO|GNU_STACK'
readelf -sW --dyn-syms "$B" | grep -cE '__stack_chk_fail|__memcpy_chk'

On the GetPageSpeed nginx-1.30.8-80.el10.gps package, the output shows a position-independent executable (DYN), full RELRO (BIND_NOW plus GNU_RELRO), a non-executable stack (GNU_STACK ... RW), and calls to the stack protector and FORTIFY_SOURCE checks. These are the defaults of the distribution toolchain, and the GetPageSpeed builds keep them for every platform, CentOS 7 included. A hand-compiled ./configure && make build often has none of them.

Step 2: NGINX hardening with a systemd sandbox

The NGINX unit file only says how to start NGINX. It applies no restrictions at all:

systemd-analyze security nginx | tail -1
→ Overall exposure level for nginx.service: 9.6 UNSAFE :-{

A drop-in fixes that without touching the packaged unit, so package upgrades keep it. Create /etc/systemd/system/nginx.service.d/hardening.conf:

[Service]
NoNewPrivileges=yes
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SETUID CAP_SETGID CAP_CHOWN CAP_DAC_OVERRIDE
ProtectSystem=strict
ReadWritePaths=/var/log/nginx /var/cache/nginx /run
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
ProtectProc=invisible
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallErrorNumber=EPERM

Apply it and check the result:

sudo systemctl daemon-reload
sudo nginx -t && sudo systemctl restart nginx
systemd-analyze security nginx | tail -1
→ Overall exposure level for nginx.service: 2.6 OK :-)

What the drop-in changes for a compromised worker

We ran the same probe inside an NGINX worker with and without the drop-in. Without it, the worker could list /home and reach sudo, which only asked for a password. With it:

/etc/cron.d/x: Read-only file system
/usr/share/nginx/html/x.php: Read-only file system
ls: cannot open directory '/home': Permission denied
sudo: The "no new privileges" flag is set, which prevents sudo from running as root.

In detail:

The drop-in kept everything else working in our tests: systemctl reload nginx, proxy_cache (a MISS, then a HIT), request bodies buffered to client_temp, HTTP/2 over TLS, and SELinux in enforcing mode with no AVC denials. A dnf reinstall nginx also went through the GetPageSpeed in-place binary upgrade: the master PID changed, systemd tracked the new one, and NGINX kept serving.

Adjust ReadWritePaths if NGINX writes anywhere else: a proxy_cache_path outside /var/cache/nginx, an upload directory served by NGINX itself, or logs in a custom location. NGINX fails at startup with “Read-only file system” when a path is missing, so nginx -t catches it before a restart.

Two caveats: Lua and PCRE JIT

MemoryDenyWriteExecute=yes forbids memory that is writable and executable at once, which is what exploit payloads want. It also stops two legitimate just-in-time compilers:

Step 3: block the SCTP kernel module

This step closes the path from worker to root that Xint used. It is a kernel setting, not a systemd one, and the sandbox above does not cover it. We tested that on Rocky Linux 10.1 with the distribution’s SCTP blacklist removed, rebooting between runs because SCTP cannot be unloaded once loaded:

Configuration Can the nginx user open an SCTP socket?
No blacklist, systemd sandbox with ProtectKernelModules, RestrictAddressFamilies, NoNewPrivileges Yes, and the kernel loads sctp
No blacklist, install sctp /bin/false No: Protocol not supported
Rocky Linux default (blacklist sctp) No: Protocol not supported

RestrictAddressFamilies cannot help: SCTP uses the ordinary AF_INET and AF_INET6 families, which NGINX needs. ProtectKernelModules stops NGINX from loading modules itself, but an SCTP socket makes the kernel load the module on the process’s behalf.

On hosts that do not use SCTP (almost every web server), block it outright:

echo 'install sctp /bin/false' | sudo tee /etc/modprobe.d/nginx2root-sctp.conf
lsmod | grep -w sctp || echo "sctp not loaded"

If lsmod shows sctp already loaded, reboot once to unload it.

Step 4: reduce what NGINX tells scanners

Mass scanning for NGINX2Root starts with the Server header, which shows the exact version by default. Turn it off in the http context, for example in /etc/nginx/conf.d/00-hardening.conf:

server_tokens off;
sudo nginx -t && sudo systemctl reload nginx
curl -sI http://localhost/ | grep -i '^server'
Server: nginx

This hides nothing from a determined attacker, but it takes your host out of version-filtered target lists.

The other NGINX2Root flaws each need a feature to be turned on: HTTP/3 listeners, a resolver with variables in proxy_pass, or the mail proxy. If you do not use a feature, remove it from the configuration. The stopgaps section of the NGINX2Root page lists the exact trigger for each CVE.

Step 5: audit the configuration with Gixy

Gixy 0.2.64 and later report a known CVE when both the version and the triggering configuration are present. On our test server with an HTTP/2 TLS listener:

sudo gixy --nginx-version 1.30.6 /etc/nginx/nginx.conf
>> Problem: [nginx_cves] Known nginx CVE affects your installed version.
Reason: CVE-2026-123007: Memory corruption in HTTP/2 flow control. Your installed version is vulnerable and the trigger pattern is present in this config. Fixed in: 1.30.7, 1.31.9.

Run with --nginx-version 1.30.8, the same configuration reports no CVE findings. Gixy then still reports ordinary hardening items such as missing HSTS and ssl_protocols; the NGINX hardening guide and our TLS 1.3 hardening article cover those.

Conclusion

A hardened NGINX stays hardened only until the next config change or package update. A new proxy_cache_path, an HTTP/3 listener or a forgotten server_tokens can quietly reopen what you just closed. GetPageSpeed Amplify runs scheduled gixy scans across every host and ties findings to live NGINX runtime metrics. Drop-in compatible with the deprecated nginx-amplify-agent (EOL January 2026).

Patching NGINX2Root is the only fix. NGINX hardening is what comes next: the sandbox, the SCTP block and the quieter Server header limit what the next memory-safety bug can do. All of it starts with a current, fully hardened NGINX build on every server, including the ones your distribution stopped supporting. The GetPageSpeed repository ships NGINX 1.30.8 for RHEL 7 to 10, CentOS 7, Amazon Linux, Ubuntu and Debian, and every security release arrives as an ordinary dnf upgrade or apt-get upgrade. Subscribe to the GetPageSpeed repository to keep receiving fixed NGINX builds as soon as upstream ships them.

Exit mobile version