Ruby2Shell is a one-byte bug with a very long tail
Ruby2Shell is a good name for a bad bug. The advisory, published by Veria Labs under GHSA-34m4-m9fh-gqp5, describes a one-byte heap overflow in Ruby's handling of several legacy single-byte encodings. The overflow is reachable through ordinary string methods such as upcase, swapcase, downcase(:fold), and casecmp?. Rails and Sinatra applications are exposed in their default configurations. So are several self-hosted products that ship their own Ruby runtime, including GitLab 19.6.0 and GitHub Enterprise Server 3.22.5.
The one-byte detail is the part that makes people underestimate it. A single byte does not sound like a remote code execution primitive. But the advisory says the byte lands immediately after an output buffer whose size is controlled by the input length, and a later copy reads one byte out of bounds. That is enough to corrupt adjacent heap state or leak a byte of memory, depending on how the allocator and the surrounding code behave. The advisory promises a proof of concept in a week, after users have had time to upgrade. It does not publish the full exploitation chain yet.
The bug is in the encoding table, not the application
Most Ruby string processing happens in UTF-8, and UTF-8 takes a different code path. The vulnerable path is the one used for single-byte encodings such as ISO-8859 and Windows-125x. Those encodings are old, but they are not extinct. They show up in form data, CSV imports, email, legacy APIs, and database columns that predate UTF-8. That is why the bug is not limited to applications that explicitly ask for a legacy encoding. It is reachable wherever untrusted input is decoded into one of those encodings and then passed through a case-conversion method.
The specific character is ß, the German sharp-s. In most single-byte encodings, there is no capital form. Upcasing it produces two bytes, SS. The loop that performs the conversion checks whether there is room for one byte before writing, but the ß branch writes two. The output buffer is allocated as the input length plus 20 bytes. Each ß adds one byte to the output, so an input with 21 of them overflows by one byte. The byte written is S (0x53) when upcasing or s (0x73) when case-folding.
That is the entire primitive. It is not a logic bug in Rails, a bad regular expression, or a missing authorization check. It is a bounds check that was written for a one-byte replacement and then used for a two-byte replacement. The same loop exists in several encodings and dates back to Ruby 2.4.0. The fix is upstream commit d582f8f13d700d8e39714d3a8f11eb4bd2bc69f0.
The methods that reach it are common enough that the bug can hide in a framework. upcase is used for case-insensitive comparisons, normalization, and display. casecmp? is used for header and token comparisons. downcase(:fold) is used for Unicode-aware folding. An application does not need to call a suspicious API. It needs to process attacker-controlled text in a legacy encoding and then normalize it.
Who is actually exposed
The advisory is unusually clear about scope. Rails and Sinatra in classic style are affected in their default configurations. Other frameworks and plain Rack are not exposed by default. Application code that upcases strings received in a legacy encoding may also be vulnerable, even if it does not use Rails or Sinatra.
That distinction matters because "Ruby is vulnerable" is not the same as "every Ruby process is remotely exploitable." A UTF-8-only application that never accepts legacy encodings has a much smaller exposure. A Rails application that accepts form posts, query parameters, or API payloads and lets Rack decode them into a legacy encoding is in the risky group. The framework provides the reachable path; the application provides the input.
The self-hosted software list is the operational wake-up call. GitLab 19.6.0 bundles Ruby 3.3.13, which is in the affected range. GitHub Enterprise Server 3.22.5 bundles Ruby 4.0.9, also affected. Chatwoot 4.20.0 bundles Ruby 3.4.4, affected. Mastodon 4.7.6, OpenProject 17.9.8, and the Discourse base image 2.0.20261119-0203 bundle fixed Ruby versions. The advisory was updated on 19 November at 13:59 UTC, so this list may change.
The bundled-runtime problem is the reason a simple operating-system patch is not enough. If you run GitLab from an omnibus package, the Ruby that matters is the one inside the package, not the one in /usr/bin/ruby. If you run a container, the Ruby that matters is in the image layer. If you run a vendored application, the Ruby that matters may be in a directory that your package manager has never heard of. The patch has to land in the runtime that actually executes the request.
Where legacy encodings enter a modern stack
It is tempting to treat legacy encodings as a problem for old applications. The opposite is often true. Modern applications accept more input from more sources than ever: CSV uploads, email bodies, calendar invites, form posts from old browsers, partner APIs, database migrations, and log lines. Each of those can carry an encoding declaration. A JSON parser may normalize to UTF-8, but a form decoder or a CSV reader may not. A library that accepts a charset parameter may hand Ruby a string tagged as ISO-8859-1 or Windows-1252.
The advisory does not enumerate every framework path. It does say that Rails and Sinatra classic are affected by default, and that application code which upcases strings in a legacy encoding may be vulnerable. That is enough to build a test plan. Find every place where untrusted bytes become a Ruby string with a non-UTF-8 encoding. Then find every downstream call to upcase, swapcase, downcase(:fold), or casecmp?. If the same data can reach both, you have a candidate path.
The fix is not to ban legacy encodings everywhere. Some applications genuinely need them. The fix is to make the conversion boundary explicit. Decode at the edge, validate the declared encoding, transcode to UTF-8 before normalization, and reject input that cannot be represented. That is good hygiene even after the patch. It also makes the application easier to test, because the encoding path is no longer implicit in a framework default.
A useful detection exercise is to run the encoding test suite with a sanitizer build. The bug is a one-byte overflow, so a normal test may pass while the sanitizer catches the write. Ruby's own test suite has encoding cases, but application tests rarely cover the sharp-s edge case. Add a regression test that sends 21 ß characters through the same path a real request would take. If the test crashes or trips a sanitizer before the patch, you have confirmed reachability. After the patch, the same test should pass cleanly.
The patch matrix
The fixed versions are Ruby 4.0.10, 3.4.13, and 3.3.14. The affected ranges are 4.0.0 through 4.0.9, 3.4.0 through 3.4.12, and 3.3.0 through 3.3.13. Ruby 3.2 and older, back to 2.4.0, are end-of-life. The advisory does not provide a fix for those branches. If you are still running Ruby 3.2 in production, this is the moment to decide whether you are maintaining a fork or upgrading the application.
A version check is the first step, but it is not sufficient. Start with the interpreter that runs the application:
ruby -v
bundle exec ruby -v
The first command tells you what is on PATH. The second tells you what Bundler will actually use. They can differ. Then check the package version, not just the binary version:
dpkg-query -W -f='${Package} ${Version}\n' ruby3.3 ruby3.4 ruby4.0 2>/dev/null
rpm -qa | grep -E '^ruby(3|4)'
On Debian and Ubuntu, a backport can fix the vulnerability without changing the upstream version string. The full package version is the thing to compare against the distribution's security advisory. On containers, inspect the image rather than the host:
docker run --rm IMAGE ruby -v
docker run --rm IMAGE sh -c 'cat /etc/os-release; dpkg -l | grep ruby'
For GitLab and GitHub Enterprise, use the vendor's fixed release. Do not try to replace the bundled Ruby by hand unless the vendor explicitly supports it. The same applies to Chatwoot and any other application that ships its own runtime. The vendor knows which patches were backported and which extensions were compiled against which ABI.
The inventory problem does not end with the application server. CI runners often carry a separate Ruby for build scripts, linters, and deployment tooling. A compromised runner can execute the same vulnerable code on input that never reaches production. Build images with a pinned, patched Ruby and rebuild them on a schedule. If your SBOM lists the Ruby version, check that it records the full package version, not just the upstream version. The upstream version is exactly the field that backports do not change.
Why a one-byte overflow still matters
Modern exploit mitigations make one-byte overflows harder to turn into reliable code execution. They do not make them harmless. A one-byte corruption can change a length field, flip a tag, alter a pointer's low byte, or corrupt allocator metadata. The exact effect depends on the heap layout, the allocator, and what the program does next. The advisory describes an out-of-bounds read after the write. That read can leak a byte of adjacent memory, which is often the first step in defeating address-space randomization in a larger chain.
The other reason not to dismiss it is reachability. A bug that requires a custom parser and a rare encoding is a niche bug. A bug that sits behind upcase in a web framework is a bug that can be reached by ordinary traffic. The attacker does not need to find a new endpoint. They need to find an endpoint that accepts text, get it decoded into a legacy encoding, and make the application normalize it. That is a much lower bar.
The advisory does not claim that exploitation has been observed in the wild. It also does not claim that the proof of concept is trivial. It says a proof of concept will be published in a week. That is a short window. If you are exposed, the useful work is to patch before the details become public, not to wait for a scanner signature.
What to do this week
First, inventory every Ruby runtime you operate. That includes the application runtime, the CI runtime, the background-worker runtime, and the runtime inside every self-hosted product. A patch that covers the web tier but not the job runner is incomplete, because the same input can reach both.
Second, upgrade to a fixed Ruby or a fixed vendor release. Rebuild containers from a patched base image. Do not rely on a running container that was patched in place, because the next deploy will revert it. If you maintain a fork of an affected application, backport the upstream commit and test the encoding path with representative input.
Third, check your input decoding. If your application never accepts legacy encodings, say so explicitly in your Rack or framework configuration and reject ambiguous input. If it does accept them, treat every case-conversion call on that input as security-sensitive until the runtime is patched. This is not a permanent fix, but it reduces exposure during the upgrade window.
Fourth, watch the vendor advisories. GitLab, GitHub, and Chatwoot may publish their own updates with different version numbers and backport details. The Ruby advisory tells you what is wrong with the runtime. The vendor advisory tells you what is actually inside the product you run.
The broader lesson is that language runtimes are part of the supply chain. A Rails application is not just Rails and its gems. It is the Ruby interpreter, the C extensions compiled against it, the base image, and the vendor package that bundles all three. Ruby2Shell is a one-byte bug, but its tail is long: old encodings, old Ruby versions, and old self-hosted products that are still running in production. The fix is a version bump. The hard part is finding every place the version lives.