Repository navigation
nginx2root: detectors for the five nginx CVEs fixed in 1.31.9 / 1.30.7 - #9
diptendukar wants to merge 2 commits into
Conversation
…30.7 Host detector and fleet wrappers for CVE-2026-123007, CVE-2026-123633, CVE-2026-121810, CVE-2026-123634 and CVE-2026-113425. The detector reports a status per CVE for every running or installed nginx, then one line per CVE for the host and an overall verdict, with the same exit-code contract as the other directories (0 not impacted, 1 impacted, 2 unknown, 3 usage). It reads the version, build options and a patch marker from the nginx binary as strings and reads the configuration from disk, through /proc/PID/root for containers. It does not execute nginx and enters no namespace. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
| metadata: | ||
| labels: | ||
| app: nginx2root | ||
| spec: |
There was a problem hiding this comment.
🔵 Low severity issue identified in your code:
The detect container can run as root and is already privileged with host PID visibility. A compromise of its image or command could therefore expose or tamper with sensitive data and processes on every node running this DaemonSet.
More details about this
The pod template spec for the nginx2root DaemonSet does not require its detect container to run as a non-root user. The container uses debian:stable-slim, whose command runs /bin/sh -c and then bash /scripts/detect-nginx2root.sh; without an effective non-root restriction, those processes can run as UID 0. This is especially dangerous here because detect is also privileged: true and the pod enables hostPID: true, so a compromise has unusually broad visibility and host-level access.
A plausible attack path is:
- An attacker compromises the
debian:stable-slimimage, the/scripts/detect-nginx2root.shcontent, or any service that can execute commands in this DaemonSet pod. - The attacker runs
kubectl exec-equivalent code indetectand executesid, observinguid=0(root)because no container-level non-root requirement is present. - From the privileged
detectcontainer, the attacker inspects host processes through the shared PID namespace (psor/proc) and accesses privileged kernel/device interfaces available to the container. - The attacker uses that root-level, privileged position on every node where the
nginx2rootDaemonSet runs to read sensitive host or workload data, tamper with processes, or establish persistence.
The finding is on the pod-template spec because its containers list lacks a runAsNonRoot: true security setting for detect.
To resolve this comment:
💡 Follow autofix suggestion
| spec: | |
| spec: | |
| securityContext: | |
| runAsNonRoot: true #: |
View step-by-step instructions
-
Add a pod-level security context under the workload's
spec.template.spec:spec: template: spec: securityContext: runAsNonRoot: true
-
If
securityContextalready exists at that location, addrunAsNonRoot: truewithout removing the existing settings. -
Confirm that the
debian:stable-slimimage and its startup commands work as a non-root user. If they require root, update the image or commands to use a dedicated non-root user before enabling this setting.
Alternatively, if this manifest is intentionally insecure Semgrep test data, add its specific path to .semgrepignore rather than weakening the rule for production manifests.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by run-as-non-root.
You can view more details about this finding in the Semgrep AppSec Platform.
| labels: | ||
| app: nginx2root | ||
| spec: | ||
| hostPID: true |
There was a problem hiding this comment.
🟡 Medium severity issue identified in your code:
The privileged detect container shares each node's process namespace, allowing a container compromise to inspect or tamper with host processes via ptrace.
More details about this
hostPID: true makes every nginx2root pod share the node's process ID namespace instead of seeing only container processes. This DaemonSet also runs the detect container as privileged: true on every Linux node (including tainted nodes), so code execution in detect—for example through a compromised debian:stable-slim image or /scripts/detect-nginx2root.sh—can target host processes with ptrace.
A plausible attack is:
- An attacker gains a shell in the
detectcontainer and runsps -ef; because ofhostPID, the output includes node processes such as PID 1, kubelet, and workloads outside this pod. - The attacker selects a host PID and reads
/proc/<pid>/environor attaches withstrace -p <pid>. With the container's privileged security context, they can useptraceto inspect or manipulate that process rather than being limited to the container's own processes. - The attacker extracts credentials or tokens from a host process, or alters a privileged host process to execute commands on the node. Since this is a DaemonSet with an
Existstoleration, the same attack surface is deployed across the cluster's Linux nodes.
Summary: hostPID: true exposes node processes to the privileged detect container. A compromised container could use ptrace to read secrets from or tamper with host processes across every node running this DaemonSet.
To resolve this comment:
✨ Commit fix suggestion
- Remove
hostPID: truefrom the DaemonSet pod template atspec.template.spec. - Update
/scripts/detect-nginx2root.shor any related logic that depends on host process IDs to use container-local process IDs or a supported node-monitoring API instead. - Keep the pod in its default process namespace so it cannot inspect or interact with processes running outside the container.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by hostpid-pod.
You can view more details about this finding in the Semgrep AppSec Platform.
| - name: detect | ||
| image: debian:stable-slim | ||
| securityContext: | ||
| privileged: true |
There was a problem hiding this comment.
🟡 Medium severity issue identified in your code:
The detect container is privileged and shares the host PID namespace, allowing an attacker with command execution in the pod to take control of the underlying Linux node. The DaemonSet deploys this exposure across matching nodes.
More details about this
The detect container in the nginx2root DaemonSet runs with securityContext.privileged: true. Because this DaemonSet tolerates all taints and targets Linux nodes, an attacker who gains the ability to execute commands in detect can abuse host-level privileges on every Linux node where it runs; hostPID: true also exposes host processes.
A plausible attack is:
- An attacker obtains workload-execution access and runs
kubectl -n nginx2root exec -it <detect-pod> -- /bin/sh. - Inside
detect, they use the host process namespace exposed byhostPID: true, for examplensenter -t 1 -m -u -i -n -p -- /bin/sh. - The resulting shell can inspect or alter host processes, read host files such as
/etc/shadow, install persistence, or access credentials used by services on that node. Since this is a DaemonSet, the same compromise path is available on each matching Linux node.
To resolve this comment:
✨ Commit fix suggestion
-
Remove
privileged: truefrom the container’ssecurityContext. -
If a security context is required, set it explicitly to least privilege:
securityContext: privileged: false allowPrivilegeEscalation: false capabilities: drop: - ALL seccompProfile: type: RuntimeDefault
-
Add
runAsNonRoot: trueif the detection script works without root:securityContext: runAsNonRoot: true
-
Update the script so it does not depend on host-level capabilities. If it requires a specific capability, add only that capability under
capabilities.addinstead of enabling privileged mode.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by privileged-container.
You can view more details about this finding in the Semgrep AppSec Platform.
| containers: | ||
| - name: detect | ||
| image: debian:stable-slim | ||
| securityContext: |
There was a problem hiding this comment.
🟡 Medium severity issue identified in your code:
The detect container is privileged and shares the host PID namespace, but its securityContext does not restrict privilege escalation. A compromised script or process could abuse setuid/setgid binaries to access host processes and sensitive node resources.
More details about this
The detect container uses debian:stable-slim with securityContext.privileged: true, but does not explicitly restrict privilege escalation. It also runs with hostPID: true at the pod level, so a process launched through the container's command/args—including bash /scripts/detect-nginx2root.sh—can potentially use setuid/setgid binaries or other privilege-escalation paths to access host processes and sensitive node resources.
A plausible attack path is:
- An attacker gains control of the
detectprocess, for example by compromising the script mounted from thedetectConfigMap or by exploiting a command it invokes. - The attacker runs a setuid utility inside the
debian:stable-slimcontainer, such asfind / -perm -4000 -type f, and executes one of the discovered binaries to obtain elevated process privileges. - Because the container is already configured with
privileged: trueand the pod shares the node process namespace throughhostPID: true, the attacker can inspect or interfere with host processes and use the container's node-level access to read sensitive data or further compromise the Kubernetes node.
The finding is specifically on the container's securityContext because it lacks an allowPrivilegeEscalation setting, leaving this escalation path unrestricted.
To resolve this comment:
✨ Commit fix suggestion
| securityContext: | |
| securityContext: | |
| allowPrivilegeEscalation: false #: |
View step-by-step instructions
-
Remove
privileged: truefrom the container unless the detector can run without full host privileges. A privileged container can still escalate even whenallowPrivilegeEscalationis set tofalse. -
Set the container security context to disable privilege escalation and drop unnecessary Linux capabilities:
securityContext: allowPrivilegeEscalation: false privileged: false capabilities: drop: - ALL
-
Remove
hostPID: trueif the detector does not need to inspect host processes. If host access is required, redesign the detector to use the smallest required permissions and avoid running the container as privileged. -
Ensure the detector does not require setuid or setgid binaries. If it does, replace those operations with explicitly granted, narrowly scoped capabilities rather than enabling
privileged.
💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by allow-privilege-escalation.
You can view more details about this finding in the Semgrep AppSec Platform.
…gured With a resolver and Lua or njs handlers but no *_pass containing a variable, CVE-2026-123634 was reported "not impacted". Lua cosockets and njs fetch resolve names through the same resolver while a request runs, and both can make subrequests, so that case is now "unknown". Also clear the two shellcheck warnings (an eval-assigned variable in the SSH wrapper, an unused "$@" in a test helper) and add tests for the resolver cases. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
|
Closing this in favour of a smaller change. #8 is merged and already covers three of the five CVEs, so rather than add a second nginx detector next to it, I will open a PR that adds the remaining two (CVE-2026-121810, HTTP/3, and CVE-2026-113425, mail proxy) to the merged script. The branch stays on my fork in case any of this is useful later. |
Host and fleet detectors for the five nginx bugs disclosed on 2026-11-18 as "nginx2root" and fixed in nginx 1.31.9 and 1.30.7 (nginx.org advisories).
What it does
Run one script on a host and it tells you, for every nginx it finds, whether that nginx is exposed to each of the five CVEs, and why.
impacted,not impactedorunknown) with the reason, then one line per CVE for the whole host and an overall verdict.Wrappers run the same script across a fleet over SSH, Ansible or Kubernetes.
Sample output
A real run: two containers with the same configuration (HTTP/2 on, requests proxied to a backend), one on the official
nginx:1.31.8image and one onnginx:1.31.9.Exit code 1. With
-qonly the fivethis hostlines and the verdict are printed.The
host kernelblock is extra information. The nginx bugs give code execution as the nginx worker; becoming root needs a separate Linux kernel SCTP bug that has no fix yet. The line says whether SCTP is reachable on this kernel and does not change the verdict.What counts as impacted
Per CVE, all three must hold:
unknown.NGINX2ROOT_FIXED_PKGS.proxy_pass,grpc_pass,fastcgi_pass, ...)listen ... quicdirective and requests passed to a backendresolver, a*_passtarget with a variable, and a subrequest directive (mirror,ssi,auth_request, ...)mail {}block with at least one serverHow it reads an nginx
/proc/PID/exe, so a binary replaced on disk but not restarted is judged on the code that is running.nginx -t/nginx -Tare not run./proc/PID/root. The detector executes nothing from an nginx installation and enters no namespace.Relation to #8
#8 checks three of the five: the two HTTP/2 CVEs and the resolver one. This checks all five, so a host with HTTP/2 off but an HTTP/3 listener or a mail proxy is still reported. The two overlap and should not both land as they are.
Where they differ on the CVEs both cover:
resolverinhttp {}as impacted. This one asks for evidence that names are resolved while a request runs:impactedwith a variable*_passand a subrequest directive,unknownwhen Lua or njs handlers could do it,not impactedwhen the resolver has no request-time user (for example OCSP stapling only). nginx: detectors for CVE-2026-123007, CVE-2026-123633 (HTTP/2) and CVE-2026-123634 (resolver) #8 is noisier and never misses; this is quieter and depends on that reading of the bug.impactedeither way, through CVE-2026-123007.#8 has things this does not: a mapping of NGINX Plus releases to fixes, recognition of nginx.org packages, macOS support and a CI workflow. Those could be ported here.
Files
Everything is in a new
nginx2root/directory, plus one row in the root README table.linux/detect-nginx2root.sh: host detector.linux/ssh-nginx2root.sh,linux/ansible-nginx2root.yml,linux/k8s-nginx2root.yaml,linux/k8s-exec-nginx2root.sh: fleet wrappers adapted from the JDK ones. The DaemonSet is privileged by design, as before, but needs no extra packages.linux/tests/run-tests.sh: test harness.README.md: usage, output, coverage, fleet runs and what to do if a host is impacted.Tests
Run locally on Ubuntu 22.04 under WSL, bash 5.1, x86_64: 117 checks pass, and
shellcheck -S warningis clean on all four scripts.${var}, Lua blocks, includes).-c/-p, workers ignored, a binary replaced on disk, single-process mode.nginx:1.31.8image, scanned from a privileged--pid=hostcontainer, as the DaemonSet does.ssh.nginx:1.31.9image (sample above), the distribution packages of Ubuntu 24.04, Alpine 3.20 and AlmaLinux 9, and OpenResty 1.31.8.1.Not yet verified
🤖 Generated with Claude Code