Skip to content

Add CVE-2026-132825 "Ruby2Shell" detection (Ruby interpreter, seven advisories) - #16

Merged
kurt-r2c merged 2 commits into
mainfrom
ruby2shell-detection
Nov 19, 2026
Merged

kurt-r2c merged 2 commits into
mainfrom
ruby2shell-detection

Conversation

@diptendur2c

Copy link
Copy Markdown
Contributor

What this adds

A new incident directory, CVE-2026-132825/, with host detectors for the seven
memory-safety bugs fixed in Ruby 4.0.10, 3.4.13 and 3.3.14 on 2026-11-18:
CVE-2026-132825 (GHSA-34m4-m9fh-gqp5, "Ruby2Shell", the string case-conversion
heap overflow) and six sibling advisories that have GHSA IDs only so far.

File Purpose
linux/detect-ruby2shell.sh Host detector (bash 3.2+, also runs under dash and busybox sh)
linux/ssh-ruby2shell.sh, ansible-ruby2shell.yml, k8s-ruby2shell.yaml, k8s-exec-ruby2shell.sh Fleet wrappers, adapted from the JDK incident's
windows/Detect-Ruby2Shell.ps1, remote-ruby2shell.ps1 Windows detector and remoting wrapper
linux/tests/, windows/tests/ Test harnesses
.github/workflows/ruby2shell-*.yml CI: shellcheck, Docker tests, host-Ruby tests on Ubuntu and macOS, Windows tests

Same contract as the other detectors: one block per instance, [!] / OK /
[?] / n/a markers, last line impacted | not impacted | unknown, exit
0 / 1 / 2 / 3.

How it decides

  • Version and backport. These are interpreter bugs, so the verdict rests
    on the Ruby that is running. The version is read from the ruby X.Y.Z (
    banner inside the process's own libruby, without executing anything. A
    patched and an unpatched Ruby return identical results for every input and
    the fix leaves no marker in the binary, so there is nothing to probe.
    Distribution packages are checked through the package changelog (dpkg, rpm).
  • CVE-2026-132825 is [!] on an unpatched Ruby when the application
    mounts Rack::MethodOverride (Rails unless api_only, classic-style
    Sinatra, or an explicit use), enables Rodauth's create_account with
    login confirmation, or the process has one of the 14 affected encoding
    modules loaded. We confirmed the MethodOverride and Rodauth paths at
    runtime with benign instrumentation: a multipart part's declared charset
    survives into the case-conversion call, before authentication.
  • The six siblings depend on application code (for example a Regexp
    compiled from user input), so they stay [?] on an unpatched Ruby. A
    running unpatched Ruby is therefore never not impacted.
  • Only running Rubies decide the verdict. Most hosts have an idle Ruby on
    disk (macOS ships 2.6 in /usr/bin), so installed-but-not-running
    interpreters are listed with => not counted. --count-installed /
    -CountInstalled counts them. The README states the blind spot (anything
    not running during the scan).
  • Containers are read through /proc/PID/root: nothing is started inside a
    container and the DaemonSet needs no nsenter.

Testing

  • linux/tests/run-tests.sh (official ruby 3.4.12 and 3.4.13 images, pinned
    by digest): 20/20 passed locally before the final review changes. It has
    NOT been re-run since those changes and five cases were added afterwards;
    CI on this PR is its first run in that state.
  • linux/tests/run-tests-host.sh (no Docker, uses the host's own unpatched
    Ruby): 20/20 under WSL Ubuntu 22.04 with the distribution's Ruby 3.0.2,
    which also exercises the dpkg backport path.
  • windows/tests/Run-Tests.ps1 (stand-in ruby.exe built from
    FakeRuby.cs): 24/24 under Windows PowerShell 5.1.

Not verified, please look at these in review:

  • The macOS process scan (ps and lsof instead of /proc) has never run on
    a Mac. The test-macos job is its first test.
  • shellcheck has not been run (not installed where this was written).
  • The fleet wrappers are syntax-checked only: no SSH fleet, Ansible inventory
    or Kubernetes cluster was used. The DaemonSet approach was exercised as a
    privileged sidecar container sharing another container's PID namespace.
  • The Windows detector has not seen a real Windows Ruby, PowerShell 7 or
    remoting.
  • No distribution has shipped a fixed package yet, so the "changelog lists the
    CVE" branch of the backport check has only been read, not observed.

Sources

🤖 Generated with Claude Code

Host detectors for the seven Ruby interpreter advisories fixed in Ruby
4.0.10, 3.4.13 and 3.3.14 (2026-11-18): CVE-2026-132825, the string
case-conversion heap overflow, and six siblings in case conversion and
the regular expression engine.

- linux/detect-ruby2shell.sh: reads the running interpreter's version
  from libruby, checks package backports, and reports CVE-2026-132825 as
  impacted when the application mounts Rack::MethodOverride (Rails unless
  api_only, classic Sinatra), enables Rodauth create_account, or has an
  affected encoding module loaded. Containers are read through
  /proc/PID/root. Only running Rubies decide the verdict;
  --count-installed counts idle ones.
- windows/Detect-Ruby2Shell.ps1: the same decisions for Windows.
- SSH, Ansible, DaemonSet, kubectl exec and PowerShell remoting wrappers.
- Test harnesses and CI workflows (Ubuntu with Docker, host Ruby on
  Ubuntu and macOS, Windows).

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
metadata:
labels:
app: ruby2shell
spec:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low severity issue identified in your code:

The ruby2shell pod has no runAsNonRoot requirement, so its privileged detect container can run as root. With hostPID: true and one pod per node, a compromised image or script could access host processes and attempt node compromise across the cluster.

More details about this

spec defines the ruby2shell DaemonSet pod without a pod-level securityContext, and the detect container does not set runAsNonRoot. As a result, the container can run its shell and detect-ruby2shell.sh as UID 0; this is especially sensitive because detect is also privileged: true and the pod uses hostPID: true.

A plausible attack is:

  1. An attacker compromises the debian:stable-slim image, the ConfigMap-mounted detect-ruby2shell.sh, or a process that can modify the DaemonSet.
  2. When ruby2shell rolls out, the attacker-controlled command runs inside the detect container as root because no non-root requirement is present.
  3. The payload can inspect host processes through the shared PID namespace, for example with ps -ef, and use its privileged container context to access host devices or attempt a container escape.
  4. Because this is a DaemonSet, the same root-capable detect workload runs on every Linux node, turning one compromised deployment into node-wide and potentially cluster-wide access.

The finding is at the DaemonSet pod spec; the existing privileged: true setting increases the impact but does not establish that the workload runs as a non-root user.

To resolve this comment:

✨ Commit fix suggestion

Suggested change
spec:
spec:
securityContext:
runAsNonRoot: true #:
View step-by-step instructions
  1. Add a pod-level securityContext under spec.template.spec so every container must run as a non-root user:

    spec:
      template:
        spec:
          securityContext:
            runAsNonRoot: true
            runAsUser: 101
            runAsGroup: 101
            fsGroup: 101
            seccompProfile:
              type: RuntimeDefault
  2. Ensure the debian:stable-slim image and the mounted files allow UID 101 to run /bin/sh, bash, and the detector script. Use a purpose-built non-root image if the current image requires root.

  3. Keep privileged: true only if the detector requires host-level access. A non-root security context limits the process user, but privileged still grants extensive capabilities.

💬 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.

containers:
- name: detect
image: debian:stable-slim
securityContext:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium severity issue identified in your code:

The detect container runs privileged on every Linux node but does not disable privilege escalation. A compromise of the image or mounted detection script could expose host processes and provide a path to node-level access.

More details about this

The detect container in the ruby2shell DaemonSet declares securityContext, but it only sets privileged: true; it does not set allowPrivilegeEscalation: false. Because this DaemonSet runs one debian:stable-slim container on every Linux node, a shell obtained through the image, /scripts/detect-ruby2shell.sh, or a process exposed by the application can retain elevated privileges and use the container’s privileged capabilities. hostPID: true also places that shell in the node’s process namespace, exposing host processes and making actions against them possible.

A plausible attack is:

  1. An attacker gains code execution in detect, for example through a compromised debian:stable-slim image or a malicious command/configuration delivered through the mounted detect ConfigMap.
  2. They run kubectl -n ruby2shell exec <pod> -- /bin/sh and execute commands as the container’s privileged user.
  3. Since allowPrivilegeEscalation is not disabled and privileged: true grants broad Linux capabilities and device access, the attacker can inspect or interfere with node processes through the shared PID namespace, then use available host devices or kernel attack surface to escape the container and access node-level resources.
  4. Because this is a DaemonSet, the same compromise is deployed across every matching Linux node, allowing the attacker to repeat the attack and expand access across the cluster.

To resolve this comment:

✨ Commit fix suggestion

Suggested change
securityContext:
securityContext:
allowPrivilegeEscalation: false #:
View step-by-step instructions
  1. Remove privileged: true from the detect container, or set it to false. A privileged container cannot safely use allowPrivilegeEscalation: false.

  2. Set the container security context explicitly:

    securityContext:
      privileged: false
      allowPrivilegeEscalation: false
  3. If the detector currently depends on privileged access, change it to use only the specific capabilities, host paths, or Kubernetes permissions it requires instead of enabling full container privilege. Keep hostPID: true only if it is strictly required.

  4. Keep the security context at the container level, directly under the container’s image and alongside the other container properties.

💬 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.

labels:
app: ruby2shell
spec:
hostPID: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium severity issue identified in your code:

The privileged detect container shares the node’s PID namespace, allowing compromised code to enumerate and ptrace host or other-pod processes. An attacker could extract secrets or execute code with a target process’s privileges.

More details about this

ruby2shell sets spec.hostPID: true, so each privileged detect container shares the node’s process-ID namespace instead of seeing only its own processes. Because the container is also configured with securityContext.privileged: true, code running inside it can target processes from other pods and the host; the script’s stated purpose of reporting Rubies in other pods confirms that cross-container process visibility is intentional.

A plausible attack:

  1. An attacker gains command execution in the detect container, for example through a compromised ConfigMap script or access to the DaemonSet’s container.
  2. The attacker uses the shared PID namespace to enumerate host and other-pod processes with commands such as ps -ef and identifies a long-running service process.
  3. The attacker attaches to that process with ptrace (for example, strace -p <pid> or a custom injector), using the container’s privileged capabilities to inspect memory or execute code in the target process.
  4. The attacker extracts credentials, tokens, or application data from the target, or runs code with the target’s host-side privileges, potentially moving from the container into control of the node and workloads scheduled there.

This setting therefore turns compromise of the detect container into a path for observing and interacting with processes that belong to the node and unrelated pods.

To resolve this comment:

✨ Commit fix suggestion
  1. Remove hostPID: true from the pod template.

  2. Update detect-ruby2shell.sh so it does not inspect host or other pod processes through /proc. A pod without host PID access can only see its own process namespace.

  3. If node-wide process visibility is required, redesign the detector to use a dedicated, approved node-level monitoring mechanism instead of sharing the host PID namespace, such as a node agent that exposes only the required data through an authenticated interface.

  4. Keep the detector container unprivileged unless a separate, documented requirement needs elevated permissions; remove privileged: true when it is not required.

💬 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.

No behaviour change: quoting literal assignments only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kurt-r2c
kurt-r2c merged commit e29b053 into main Nov 19, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants