ruby2shell: Why Rails default configuration is affected
This article has been automatically translated.
Loading article...
Loading article...
Ruby string case conversion has a heap buffer overflow (CVE-2026-132825, codenamed ruby2shell) that can be triggered in Rails and classic-style Sinatra apps with default configuration before authentication; the official fix is in Ruby 3.3.14, 3.4.13, and 4.0.10, and Cloudflare WAF has shipped blocking rules at the same time, but those are only a stopgap until patches are in place.
Ruby strings carry encoding information, and besides UTF-8 they support a large number of legacy single-byte encodings, such as ISO-8859-1 (Latin-1) and Windows-1252. In single-byte encodings one character occupies one byte, so case conversion usually produces output of the same length.
The German sharp s (ß) breaks that assumption: its uppercase form is two characters, SS. Under 14 ISO-8859 and Windows-125x encodings, Ruby writes two bytes but checks buffer space for only one byte. According to Veria Labs, 21 consecutive ß characters are enough to push the output buffer one byte out of bounds.
One byte sounds trivial, but writing past the end of a buffer on the heap is enough to corrupt adjacent objects or allocator metadata. Ruby officially states that a PoC that turns this into remote code execution is known to exist, and Veria Labs plans to publish its own PoC about a week after disclosure, so scanning is likely to follow.
HTML forms can only send GET and POST, so to emulate PUT, PATCH, and DELETE, many frameworks accept a _method parameter in POST requests. Rack implements this in the MethodOverride middleware by upcasing the value of _method.
Rails includes this middleware by default, and classic-style Sinatra enables it too. So an attacker only needs to send a multipart POST that declares a legacy charset in the _method part and stuffs in a run of ß characters, and the framework performs the upcase during routing, before any application code or authentication checks, hitting the vulnerability directly.
Veria Labs notes that other frameworks and plain Rack apps are not affected by default. But if your code performs case conversion on strings from arbitrary sources in legacy single-byte encodings, you may still be exposed.
The same release also fixed six other memory-safety flaws. One of them, GHSA-87fm-7w84-j2px, is an integer overflow in the same case-conversion code, and the other five are in the regex engine; most require the application to compile or match attacker-supplied patterns, which is not impossible in search, filter rules, and admin backends.
Cloudflare added two rules each to the Free Managed Ruleset and the Cloudflare Managed Ruleset, covering ruby2shell and the integer overflow respectively, with a default action of Block, effective on all plans (including Free). The Free plan's ruleset runs automatically and needs no enabling; on paid plans, because rulesets can be deployed more flexibly, it is worth confirming that the Cloudflare Managed Ruleset is actually enabled on the relevant zone.
But WAF is only a compensating control and cannot replace patching. It cannot see two kinds of traffic: requests that bypass Cloudflare, such as direct connections to origin IPs and communication between internal services; and other entry points into the same code, such as string case conversion when processing email, file imports, message queues, and background jobs.
Memory corruption is usually only the first step; the attacker still needs to deliver a second-stage payload such as a shell command or reverse shell and interact with the compromised server. WAF attack score uses machine learning to score each request, adding defense in depth at this layer.