RC RANDOM CHAOS

Twenty-one ß characters walk one byte past Ruby's heap

A one-byte heap overflow in Ruby's case conversion of ß reaches unauthenticated RCE on default Rails. Fixed in Ruby 3.3.14, 3.4.13 and 4.0.10.

· 3 min read
Twenty-one ß characters walk one byte past Ruby's heap

A string of 21 ß characters, case-converted under one of Ruby’s legacy single-byte encodings, writes one byte past the end of a heap buffer. Veria Labs, which found the bug and was first to demonstrate it, says that one byte is enough to reach unauthenticated remote code execution on a default Rails install.

The mechanism is small and old. Most of Ruby’s single-byte encodings have no capital form of ß, so upcasing it produces two bytes, SS. The conversion loop bounds-checks only one of those writes against the end of the output buffer, the to < to_end test. The buffer is sized as the input length plus 20 bytes, and each ß adds exactly one byte to the output. Feed it 21 ß characters and the output runs one byte past the allocation. The byte written past the end is S (0x53) on upcase or s (0x73) on case-fold, landing directly after the buffer. Copying the result back out then reads one byte out of bounds as well. The attacker picks the buffer size by choosing the input length.

The same loop lives in several ISO-8859 and Windows-125x encodings and has been there since Ruby 2.4.0. It is reached through upcase, swapcase, downcase(:fold) and casecmp?. UTF-8 strings take a different code path and are untouched, which is why this went unnoticed so long: most modern Ruby is UTF-8 end to end, and the vulnerable path only opens when a string arrives in a legacy encoding and some code upcases or folds it. In the common frameworks that reach it by default, that happens without a login.

Severity is critical, access is network with no authentication. The fixed Ruby releases are 3.3.14, 3.4.13 and 4.0.10, with the upstream fix in commit d582f8f. If you run your own Ruby, upgrading to one of those closes it everywhere, including application code of your own that upcases legacy-encoded input. That last case is worth a grep if you cannot upgrade at once: externally-sourced strings in a legacy encoding passed through any of the four methods above are exposed even on frameworks that are not vulnerable in their default setup.

Self-hosted products that bundle their own Ruby are the harder half. The vulnerable interpreter ships inside the product, so the patch has to come from the vendor and you cannot swap it out yourself. Veria Labs lists some products with no fixed release at all, where every current version is vulnerable. For those, the only move is the vendor’s advisory and whatever network-level mitigation you can put in front of them.

There is a clock on this. Veria Labs says it will publish a proof of concept for RCE on stock Rails, holding it until major vendors have shipped fixes. The bundled-Ruby products are the exposure that outlives your own patching.

Several groups reported the primitive independently. Veria Labs found it and demonstrated RCE first; the Ruby advisory also credits Stephan Lipp of Ada Logics and Anthropic with reporting the underlying overflow, and names Moritz Sanft, working with OpenAI, among additional discoverers. Rediscovery that broad means the path is not hard to find, so expect exploitation attempts ahead of the published proof of concept.

Share

Keep Reading

Latest on the Wire

Full wire →

New signal daily · RSS

Stay in the loop

New writing delivered when it's ready. No schedule, no spam.