Skip to content
Memory corruption Write-up Advanced

Ruby2ßhell: Pre-authentication RCE on stock Rails

A one-byte heap overflow exists in Ruby's case-mapping routines for several single-byte encodings, because upcasing the character ß writes two bytes while the loop only bounds-checks one. The authors state this is reachable pre-authentication on stock Rails and that they will publish a proof of concept showing remote code execution.

verialabs.com

Published on verialabs.com

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.

The author, on verialabs.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The upcasing loop bounds-checks only one output byte while a single input character can expand to two bytes, so the output buffer (input length plus 20) overflows once enough expanding characters are supplied.

Impact

The authors claim pre-authentication remote code execution on stock Rails, but the proof of concept is not yet published, so the full exploit chain is unproven in this text.

What the attacker needed

Affected Ruby with a single-byte encoding; input reaches upcase/swapcase/downcase(:fold); Rails or Sinatra classic default config

The fix

It was fixed upstream in Ruby, and users should upgrade to 3.3.14, 3.4.13 or 4.0.10, or install the vendor's patched release for bundled products.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Ruby stores text in memory in a buffer sized to fit the input. When it changes the case of certain characters in older text encodings, one character turns into two, and the code writes the extra byte past the end of the buffer. That stray byte can corrupt nearby memory, and the authors say this can be turned into running attacker code on a default Rails site.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.