Ruby Patched a One-Byte Heap Overflow in String Case Conversion on November 18. A Security Firm Says It Gives Pre-Auth Code Execution on Stock Rails and Plans a Proof of Concept for November 25. Upgrade Ruby This Weekend.
On November 18 the Ruby team shipped 4.0.10, 3.4.13 and 3.3.14 with a fix for a heap buffer overflow in string case conversion, rated Critical on GitHub. A security firm called Veria Labs named the bug Ruby2Shell, says it gives code execution without a login on a default Rails app, and says it will publish a working proof of concept on November 25. If you run Rails on a server you manage yourself, you have this weekend to get onto a fixed Ruby.
What the Ruby team confirmed
The official advisory is a post on ruby-lang.org titled "Multiple vulnerabilities in Regexp and String." The entry that matters here is GHSA-34m4-m9fh-gqp5, "Heap buffer overflow in case conversion of strings." The GitHub advisory describes it this way: when Ruby changes the case of a string in some single-byte encodings, such as ISO-8859-1 and Windows-1252, it could write one byte past the end of the output buffer.
The affected versions are Ruby 3.3.13 and earlier, 3.4.0 through 3.4.12, and 4.0.0 through 4.0.9. The fixed versions are 4.0.10, 3.4.13 and 3.3.14. Ruby 3.2 and earlier are end of life, and the advisory says they will not receive these fixes.
Two lines in that advisory are worth reading slowly. The first: "Changing the case of a crafted string may allow remote code execution." The second says the team is aware of proofs of concept showing the flaw can trigger code execution "in some scenarios." That is a language maintainer telling you someone has a working exploit, which doesn't happen often.
The same post lists six more advisories for Regexp bugs, fixed in the same releases. So this upgrade closes seven holes, and only one of them has a brand name.
What only the researchers say
Everything about Rails comes from Veria Labs. The Ruby advisory doesn't mention Rails, Rack, or any gem. Veria's page says Rails is reachable in its default configuration with network access and no authentication, that UTF-8 strings take a different code path and aren't affected, and that other frameworks are not exposed by default. It doesn't say which Rails code path gets an attacker's bytes into a single-byte-encoded string, and I think that omission is deliberate until the proof of concept is out.
Veria's write-up of the mechanism is specific. Most single-byte encodings have no capital form of the German ß, so upcasing it writes two bytes, "SS", while the loop checks bounds for one. The output buffer is the input length plus 20 bytes, so 21 of those characters overflow it by one byte. Veria names upcase, swapcase, downcase(:fold) and casecmp? as the methods that reach the bug. None of that detail is in the Ruby advisory, though it is consistent with the advisory's one-line description.
A few claims I couldn't confirm. Veria lists a CVE number, while the Ruby advisory says identifiers were requested and not yet assigned, and the GitHub page showed no CVE when I checked. I'm using the GHSA identifier for that reason. Veria also says it found the bug independently and was first to show code execution. The Ruby advisory credits Stephan Lipp of Ada Logics and Anthropic for the report and doesn't mention Veria.
The ten-minute check
Start with the Ruby your app runs in production, which may not be the one on your laptop.
# on the server, or inside the running container ruby -v bundle exec ruby -v
If the output shows 4.0.10, 3.4.13 or 3.3.14, you're done with this advisory. If not, find every place the version is pinned:
grep -rn "ruby" .ruby-version .tool-versions Gemfile Dockerfile* .github/workflows 2>/dev/null
A typical small Rails app pins Ruby in three places: .ruby-version, the ruby line in the Gemfile, and the FROM line of the Dockerfile. Change all three to the fixed patch release for your series, rebuild, run the test suite and deploy. A patch release within the same series should be a drop-in change. I'd still run the tests, because the same releases changed Regexp internals.
If you deploy to a platform that builds Ruby for you, check that the platform already offers the new patch versions before you push. The same goes for the official Docker images and for version managers like rbenv, which need their definitions updated before they can install a release that is three days old. I haven't checked each one.
If you are on Ruby 3.2 or older
This is the uncomfortable case. The advisory gives no workaround, no configuration switch and no backport. Veria says the bug goes back to Ruby 2.4.0, and the Ruby team's statement is only that end-of-life versions won't be fixed.
I'd treat an internet-facing Rails app on Ruby 3.2 as needing a jump to 3.3.14 this week. Going from 3.2 to 3.3 is a minor-version upgrade that most apps survive with a bundle update and a few deprecation fixes. If the app can't move in days, put it behind something that limits who can reach it, such as HTTP basic auth at the proxy or an IP allowlist, until it can. That lowers the odds without fixing the bug.
Where I could be wrong
Turning a one-byte overflow into code execution is hard, and the Ruby team's own wording is "in some scenarios." The Hacker News thread had people arguing about whether the framing is inflated, and I can't settle that. I haven't reproduced the bug and I haven't seen the proof of concept. It's possible the Rails path needs conditions most small apps don't meet.
I still wouldn't wait to find out. Veria's date carries a condition: November 25, "or later if major vendors have not shipped a fix by then." It may slip. I'd plan for the 25th regardless, since the upgrade is a patch release I'd want anyway.
What I'd actually do
Today, run ruby -v in production and write down the answer. This weekend, move to the fixed patch release for your series and deploy it. If you're on 3.2 or older, schedule the move to 3.3.14 before November 25 and restrict access in the meantime. Then add a calendar reminder to read the Ruby news page once a month. Three security releases shipped on one day, and I only saw them because a researcher gave the bug a name.
Author
Lukas
@lukcombinator