ruby2ßhell

Ruby2Shell is a one-byte heap overflow to remote code execution in Ruby's string case conversion. Reachable without authentication in the default configuration of common Ruby web frameworks and self-hosted software.

Severity
Critical
Fixed in
3.3.14, 3.4.13, 4.0.10
Access needed
Network, no authentication

Affected software

Ruby versions

Ruby series Affected Fixed in
4.0 4.0.0 to 4.0.9 4.0.10
3.4 3.4.0 to 3.4.12 3.4.13
3.3 3.3.0 to 3.3.13 3.3.14
3.2 and older All releases back to 2.4.0 EOL

Frameworks

The bug is reachable from the following frameworks in their default configuration. Other frameworks are not exposed by default, but application code that upcases strings received in a legacy encoding may also be vulnerable.

Framework Status on an affected Ruby
Rails Affected
Sinatra (classic style) Affected
Other frameworks and plain Rack Not exposed by default

Self-hosted software

These products bundle their own Ruby, so the fix has to come from the vendor. Products marked Vulnerable have no fixed release yet: every current version is vulnerable.

Software Affected versions Fixed in Status
GitHub Enterprise Server 3.22.5 and earlier None Vulnerable
Chatwoot 4.20.0 and earlier 4.20.1 Patched
GitLab 19.6.0 and earlier 19.6.1, 19.5.8, 19.4.10 Patched
Mastodon 4.7.5 and earlier 4.7.6, 4.6.12, 4.5.22, 4.4.29 Patched
OpenProject 17.9.7 and earlier 17.9.8, 17.8.3 Patched
Discourse base image Before 2.0.20261119-0203 2.0.20261119-0203 Patched

Updated .

Remediation

Your deployment

Upgrade Ruby to a fixed release: 3.3.14, 3.4.13 or 4.0.10.

Self-hosted software

Install the vendor's fixed release. See Self-hosted software for fixed versions of popular products.

Technical details

Root cause

Most of Ruby's single-byte encodings have no capital ß. Upcasing it writes two bytes, SS, but the loop only bounds-checks one (to < to_end).

while (*pp < end && to < to_end) { /* room for one byte */
code = *(*pp)++;
if (code == SHARP_s) {
if (flags & ONIGENC_CASE_UPCASE) {
*to++ = 'S'; /* first byte */
code = 'S';
}
/* ... */
}
/* ... */
*to++ = code; /* second byte, unchecked */
}

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 the buffer by one byte.

The same loop is in several ISO-8859 and Windows-125x encodings and has been there since Ruby 2.4.0. It is reached by upcase, swapcase, downcase(:fold) and casecmp?.

UTF-8 strings take a different code path and are not affected.

Fixed upstream in ruby/ruby@d582f8f.

Primitive

A one-byte heap overflow. The byte written is S (0x53) when upcasing or s (0x73) when case-folding, and it lands directly after the output buffer. The attacker controls the size of the buffer through the input length.

Copying the result out of the buffer then reads one byte out of bounds.

Proof of concept

We'll be publishing a proof of concept demonstrating remote code execution on stock Rails on , or later if major vendors have not shipped a fix by then.

Credits

Veria Labs found this vulnerability independently and was the first to demonstrate remote code execution.

The Ruby security advisory also credits Stephan Lipp (Ada Logics) and Anthropic with reporting the underlying primitive. Additional discoverers include Moritz Sanft in collaboration with OpenAI.