All posts

Yet another ẞug

Universal pre-auth RCE in Ruby on Rails, or "I � Character Encodings"

After php2shell and the Brotli bug (node2shell, etc.) happened, I wanted to look into other interpreted, commonly internet-exposed languages for a while. After some of the usual procrastination, I started looking into Ruby, which perfectly fits that description, on Oct 23rd, 2026. I asked Codex to map CRuby's pre-authentication attack surface reachable from Rails, triaged its findings, and steered it toward the interesting ones. Less than 24 hours later, Codex came back with a handful of vulnerabilities, two of which should turn out to yield to pre-auth RCE in many Ruby on Rails apps including GitHub and GitLab. A plain rails new app is enough to be exploitable.

ẞug 1: Heap OOB write in case_map implementations of several encodings

For the following encodings, there can be a 1-byte OOB write on the heap upon lower- or uppercasing of a sharp s (ß) character, since they don't include the capital sharp s (ẞ):

  • ISO-8859-1, 2, 3, 4, 9, 10, 13, 14, 15 and 16
  • Windows-1250, 1252, 1254 and 1257

This is now tracked as GHSA-34m4-m9fh-gqp5.

The root cause is in the case_map functions of the above encodings, which do the following:

while (*pp < end && to < to_end) {
// ^ This checks that at least 1 (!) dest byte remains
    code = *(*pp)++;
    if (code == SHARP_s) {
      if (flags & ONIGENC_CASE_UPCASE) {
	flags |= ONIGENC_CASE_MODIFIED;
	*to++ = 'S'; // This consumes the final byte when uppercasing
	code = (flags & ONIGENC_CASE_TITLECASE) ? 's' : 'S';
      }
      else if (flags & ONIGENC_CASE_FOLD) {
	flags |= ONIGENC_CASE_MODIFIED;
	*to++ = 's'; // This does too when case-folding
	code = 's';
      }
    }
    // ...
    *to++ = code; // This may write 1 byte OOB
    // ...
}

This can write either one 0x53 (S) or one 0x73 (s) byte OOB, when uppercasing or case-folding, respectively. This can be reproduced with the following Ruby snippet:

s = ("\xDF".b * 21).force_encoding("ISO-8859-1")
s.upcase

21 bytes are the minimum because rb_str_casemap adds 20 bytes of additional space before calling the case_map function of the respective encoding:

// ...
size_t capa = (size_t)(source_end-source_current)*++buffer_count + CASE_MAPPING_ADDITIONAL_LENGTH; // capa = input_len + 20
// ...

This bug applies to the following functions, when used with the vulnerable encodings:

  • upcase / upcase!
  • swapcase / swapcase!
  • downcase(:fold) / downcase!(:fold)
  • casecmp?
  • Corresponding Symbol methods

Impact on Rails

When handling multipart form submissions, Rack, the HTTP server used by Rails, allows the client to override the request method through a special _method multipart field. This also calls .upcase on the method:

# ...
method = method_override_param(req) ||
  env[HTTP_METHOD_OVERRIDE_HEADER]
begin
  method.to_s.upcase
# ...

So, if we could get the _method value to be parsed in one of the vulnerable encodings, this could trigger the overwrite. Luckily, Rack also allows us to specify the encoding of a multipart field via the charset key:

# ...
if k == "charset"
  encoding = find_encoding(v)
end
# ...

Combined, a multipart field like this triggers the bug:

Content-Disposition: form-data; name="_method"
Content-Type: text/plain; charset=ISO-8859-1
ßßß...

Bug 2: Integer overflow in rb_str_casemap leads to large heap OOB write

In rb_str_casemap, the mapping buffer lengths are size_t, but the intermediate buffer length used during processing is an int.
In each loop iteration, after calling the corresponding case_map function of the encoding, the intermediate length is then incremented:

// ...
target_length += current_buffer->used = buffer_length_or_invalid;
// ...

This is now tracked as GHSA-87fm-7w84-j2px.

This can lead to a signed-negative, but also a signed-positive integer overflow when assembling the output string through rb_str_new. The former case is handled by str_enc_new, but the latter results in a “valid” allocation of a small string, while the full size_t-based data is moved into the output string. In the minimal overflowing case, this results in a large (~4GB) OOB write on the heap:

source = "\u0390" * 715_827_883
source.upcase

The \u390 Unicode code point is used because it’s one of two code points (U+0390 and U+03B0) which is only 2 bytes in input size, but results in 6 bytes (3 code points) of output size when expanded through the case mapper:

U+0390 GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
  = U+0399  GREEK CAPITAL LETTER IOTA
  + U+0308  COMBINING DIAERESIS
  + U+0301  COMBINING ACUTE ACCENT

715,827,883 is used because it’s the smallest multiple of 6 over 2^32 (2^32 + 2, to be exact, resulting in a 2-byte output buffer size but ~4GB of data).

Impact on Rails

This can be reached in the exact same way as ẞug 1. Any multipart field like this is sufficient:

Content-Disposition: form-data; name="_method"
Content-Type: text/plain; charset=UTF-8

*large UTF-8 value containing U+0390*

The impact of this bug is limited to Rack versions <=3.2.1, however. Rack 3.2.2 added limits for multipart field sizes that forbid the payload above.

The Exploitation Journey

I started trying to get this exploited by Codex immediately after finding it on Oct 23rd, 2026.

For a toy Rails app, the first exploit working end-to-end was completed on Oct 26th, 2026. The same day, I posted its hash to Twitter / X:

root@sploitforge:~/Developer/ruby-research# sha256sum work/toy_rce_exploit.py
091e82fbb2795d4516d2e464c96c3f41cbedd9b85755fee808b7dbd06d3ee5bf  work/toy_rce_exploit.py

Two days later, on Oct 28th, 2026, with the severity of the bugs in mind and without a working exploit on a real-world app so far, I reached out to my friend Sylvie from OpenAI to help with exploitation and disclosure. Sylvie was travelling at the time, but by Nov 5th, 2026, she had demonstrated RCE against a plain rails new app from the sharp-s bug. The next day, she demonstrated RCE from the integer overflow against a Rails app pinned to Rack 3.2.0.

Sylvie connected me with OpenAI's security team, who already had contacts with the Ruby security team. Together, we sent them descriptions of both bugs and continued to work on exploits and patches.

Although the coordination with the Ruby team was a bit bumpy at times, I'm happy that the bugs are disclosed now and that OpenAI coordinated with WAF vendors to help protect against real-world exploitation of these vulnerabilities. Thanks to my friend Sylvie and the whole security team at OpenAI for that.

Timeline

  • 2026-10-23 CET: I began looking at Ruby's pre-authentication attack surface.
  • 2026-10-26 CET: I completed an end-to-end exploit against a toy Rails app and posted its SHA-256 hash on X.
  • 2026-10-28 CET: I contacted Sylvie for help with exploitation and disclosure.
  • 2026-11-05 CET (2026-11-04 PST): Sylvie demonstrated pre-authentication RCE against a plain jemalloc rails new app using the sharp-s bug.
  • 2026-11-05 CET: OpenAI sent reports covering both bugs to the Ruby security team that evening.
  • 2026-11-06 CET: Sylvie reproduced the sharp-s exploit with the default glibc allocator. She also demonstrated RCE from the integer overflow against a Rails app pinned to Rack 3.2.0.
  • 2026-11-07 CET (2026-11-06 PST): OpenAI sent the Ruby maintainers working exploit proofs for both bugs and discussed their severity and coordinated disclosure.
  • 2026-11-10 CET: We reviewed patch candidates, identified remaining issues, and prepared revised patches and regression tests.
  • 2026-11-19 CET (2026-11-18 PST): Ruby published the advisories and released fixed versions 3.3.14, 3.4.13, and 4.0.10. Around the release, OpenAI invited WAF providers and other defenders to collaborate on defense work.