79% vs 51%: independent neobanks lag on app security. Read the report

Deep Dive

Deep Dive

Ruby Regexp RCEs: Seven Flaws Fixed in 4.0.10 (CVE-2026-132825)

Seven memory-safety flaws in Ruby's regexp engine and string case conversion can lead to code execution. Fixed in 4.0.10, 3.4.13 and 3.3.14.

TL;DR

  • Seven memory-safety flaws affect Ruby's regular expression engine and its case conversion of strings. The Ruby project says it is aware of proof-of-concept code that reaches code execution in some scenarios, and it published the advisory on 2026-11-19.
  • Ruby 3.3.13 and earlier, 3.4.0 through 3.4.12, and 4.0.0 through 4.0.9 are affected. Applications that case-convert untrusted strings or compile untrusted patterns are the main exposure.
  • Three advisories are rated Critical by GitHub; the published CVE-2026-132825 is CVSS v3.1 7.4 High. No exploitation is known in the wild, and none is in CISA KEV as of 2026-11-19.
  • Upgrade to Ruby 4.0.10, 3.4.13 or 3.3.14. Ruby 3.2 and earlier will not receive these fixes; see "How do I fix it?" for the upgrade commands and partial workarounds.

Am I affected?

You are exposed when all of these conditions hold:

  • You run Ruby 3.3.13 or earlier, Ruby 3.4.0 through 3.4.12, or Ruby 4.0.0 through 4.0.9.
  • Your application passes attacker-influenced data to string case conversion, or builds a regular expression from attacker-influenced data.
  • The affected code path uses an encoding that triggers the flaw. The sharp-s overflow needs a single-byte encoding such as ISO-8859-1 or Windows-1252. The matcher bugs need UTF-16, UTF-32 or Emacs-Mule.

The case-conversion flaws also affect code that calls String#upcase, String#downcase, String#capitalize, String#swapcase or String#casecmp? on untrusted input. The regexp flaws affect Regexp.new and regexp literals built at runtime. A literal regexp with a fixed pattern is affected only if the subject string triggers the matcher bug.

Ruby 3.2 and earlier have reached end of life. The advisory says they will not receive these fixes.

Branch Affected versions Fixed version
Ruby 3.3 3.3.0 through 3.3.13 3.3.14
Ruby 3.4 3.4.0 through 3.4.12 3.4.13
Ruby 4.0 4.0.0 through 4.0.9 4.0.10
Ruby 3.2 and earlier All releases No fix (end of life)

Check the runtime that your application actually uses:

ruby -v
ruby -e 'puts RUBY_VERSION'

For a running container, check inside the container rather than the image on disk:

docker exec <container> ruby -v

Also check any version pin in the application directory:

cat .ruby-version
grep -A1 'RUBY VERSION' Gemfile.lock

How do I fix it?

Upgrade to Ruby 4.0.10, 3.4.13 or 3.3.14. The Ruby project released all three on 2026-11-18 and recommends upgrading immediately.

  1. With rbenv, install the fixed release and select it for the application: bash rbenv install 4.0.10 rbenv global 4.0.10 rbenv rehash
  2. With RVM, install and select the fixed release: bash rvm install 4.0.10 --binary rvm use 4.0.10 --default
  3. With asdf or mise, install the fixed release and pin it in the project: bash asdf install ruby 4.0.10 asdf set -u ruby 4.0.10
  4. In a container, use an updated base image tag and recreate the container. Pulling a new image does not change a running container: bash docker pull ruby:4.0.10 docker rm -f <container> docker run --name <container> ... ruby:4.0.10
  5. Restart every Ruby process after the upgrade. Puma, Unicorn, Sidekiq and any long-running worker keep the old interpreter in memory until they restart.
  6. If you install Ruby from a distribution package, check whether the distribution has rebuilt the package. A package version that predates 2026-11-18 does not contain these fixes.

If you cannot upgrade yet, reduce exposure with these partial measures:

  1. Force untrusted strings to UTF-8 before case conversion. This avoids the single-byte sharp-s path, but it does not cover the integer overflow in rb_str_casemap or any of the regexp flaws.
  2. Do not compile regular expressions from untrusted patterns. Use a fixed set of patterns and reject input that is meant to become a pattern. This reduces exposure to the compilation and matching flaws, but it is not a complete fix for a service that legitimately accepts patterns.
  3. Limit pattern and subject size at the application boundary. This makes the compilation-overflow path harder to reach, but it does not fix the double free or the out-of-bounds reads.

None of these measures replaces the upgrade.

What is the root cause?

Ruby implements string case conversion and its regular expression engine in C. The case conversion calls an encoding-specific case_map function for each encoding. The regexp engine is Onigmo, which parses a pattern, compiles it into a bytecode program and then matches it. The seven advisories cover memory-safety mistakes in that code. They include a one-byte overflow in case mapping and an integer overflow in the case-mapping buffer accounting. They also include a double free during regexp parsing and out-of-bounds reads or writes in the compiler and matcher.

The one-byte overflow is in the single-byte encoders. This is case_map in enc/iso_8859_1.c at the 3.4.12 tag:

while (*pp < end && to < to_end) {
  code = *(*pp)++;
  if (code == SHARP_s) {
    if (flags & ONIGENC_CASE_UPCASE) {
      flags |= ONIGENC_CASE_MODIFIED;
      *to++ = 'S';
      code = (flags & ONIGENC_CASE_TITLECASE) ? 's' : 'S';
    }
    else if (flags & ONIGENC_CASE_FOLD) {
      flags |= ONIGENC_CASE_MODIFIED;
      *to++ = 's';
      code = 's';
    }
  }
  /* ... */
  *to++ = code;

The loop condition only guarantees that one byte is free in the output buffer. The sharp s (0xDF) expands to two bytes, SS or ss, and both branches write one byte before the common *to++ = code writes the second. When the output buffer ends exactly at the last input character, the second write lands one byte past the buffer. Fourteen encoders had the same check: ISO-8859-1, -2, -3, -4, -9, -10, -13, -14, -15 and -16, plus Windows-1250, -1252, -1254 and -1257.

The integer overflow is in rb_str_casemap in string.c, which sizes and accumulates the output buffers for a case conversion. At 3.4.12 it stores the running total in an int:

int target_length = 0;
/* ... */
size_t capa = (size_t)(source_end-source_current)*++buffer_count + CASE_MAPPING_ADDITIONAL_LENGTH;
/* ... */
target_length  += current_buffer->used = buffer_length_or_invalid;

A very large source string makes the allocation arithmetic and the total length wrap. The advisory describes the result as a heap-based buffer overflow that may lead to code execution.

The regexp compiler has a separate size-accounting problem. At 3.4.12, add_opcode checks the compiled program size before it writes one opcode:

static int
add_opcode(regex_t* reg, int opcode)
{
  if (reg->used > MAX_COMPILED_PROGRAM_SIZE)
    return ONIGERR_TOO_BIG_COMPILED_PROGRAM;
  BBUF_ADD1(reg, opcode);
  return 0;
}

The bulk writers do not go through that check. add_bytes, add_bitset and add_multi_byte_cclass write straight into the program buffer. add_compile_string, compile_cclass_node and compile_quantifier_node also ignored the return value of those calls. A long concatenation of multibyte property classes can therefore push the program past its size limit and wrap the accounting before the final add_opcode(OP_END) is reached. compile_length_tree separately summed lengths in an int, so a large pattern could make the sum negative and return it as an error code.

The remaining four flaws have smaller fixes:

  • GHSA-7x2q is a double free in parse_char_class. The && handler frees cc->mbuf but leaves the pointer in cc, and the error path frees it again.
  • GHSA-wpqw is an out-of-bounds read in OP_EXACT1_IC and OP_EXACTN_IC. The matcher advances by the length of a character's case fold without checking it against the operand. A fold of a different length makes it execute the following pattern bytes as instructions.
  • GHSA-7whj is a heap overflow in Regexp#to_s. It compiled the raw source inside (?opts:...) while Regexp.new compiles the preprocessed source, so a (?#...) comment inside a character class can mean a different pattern and produce an out-of-bounds write.
  • GHSA-pvgc is an out-of-bounds read in string_cmp_ic. The case-insensitive backreference comparison folds the character at the end of the subject without checking that the subject pointer is still inside the subject.

The seven advisories, their ratings and their fix commits are:

Advisory Flaw class Rating Main fix commit
GHSA-34m4-m9fh-gqp5 Heap buffer overflow in case conversion Critical b841d6f4f1
GHSA-7x2q-68qv-6p8x Double free in regexp compilation Critical 28aad344e1
GHSA-3p8q-wmhx-vm2w Heap buffer overflow in regexp compilation Critical 6c6e6c9273, 57c24699fe, 65b71a8844
GHSA-87fm-7w84-j2px Integer overflow in case conversion High f2e5063748
GHSA-wpqw-5qxg-m68r Out-of-bounds read in case-insensitive matching High e12e722695
GHSA-7whj-cfh7-xgm4 Heap buffer overflow in Regexp#to_s High cdd499eccd
GHSA-pvgc-g7gj-pv6h Out-of-bounds read in backreference matching Moderate b469749b37

How is it exploited?

  1. The attacker supplies a crafted string to a case-conversion call, or a crafted pattern or subject to the regexp engine. The application has to pass that data through to Ruby without replacing the encoding or rejecting the pattern.
  2. For the sharp-s overflow, the attacker chooses an affected single-byte encoding and places 0xDF bytes so that the output buffer ends at a two-byte expansion. The write that follows lands one byte past the allocation.
  3. For the integer overflow, the attacker supplies a very large string. The buffer size and running total wrap, and the case-mapping write runs past the allocation.
  4. For the regexp compiler, the attacker supplies a large pattern built from multibyte classes or long exact strings. The compiled program passes the size limit, the accounting wraps, and a later write goes past the program buffer.
  5. A malformed pattern or subject drives the parser or matcher into an error path. That path frees the same buffer twice or reads past the operand or subject.
  6. Heap grooming turns the corruption into a controlled write or a leaked pointer. The Ruby project says it is aware of proof-of-concept code that reaches code execution in some scenarios, but it has not published that code.

The trigger differs by flaw. The sharp-s overflow needs the affected encoding and a string whose case conversion expands at the buffer boundary. The compiler overflow needs a pattern large enough to pass the limit. The matcher reads need a case fold that changes length, which is easiest in UTF-16 and UTF-32. An application that only handles UTF-8 and fixed patterns is exposed to fewer of the seven.

How does the attack flow?

One crafted string or pattern reaches a C routine that trusts its own length calculation, corrupts memory, and can turn into code execution in the Ruby process.

flowchart LR A["Attacker-controlled string or pattern"] --> B["Ruby case conversion or Regexp compile"] B --> C["missing room, size or end-of-buffer check"] C --> D["one-byte overflow, integer wrap, double free or out-of-bounds read"] D --> E["heap corruption or pattern bytes executed as opcodes"] E --> F["code execution as the Ruby process user"]

What can an attacker do?

A successful exploit runs code as the user that runs the Ruby process. That user can read environment variables and files the application can read, modify data the application can write, and use the application's credentials to reach other systems.

Every condition has to hold:

  • The application runs an affected Ruby version.
  • The application passes attacker-influenced data to case conversion or to Regexp.new.
  • The data reaches the specific encoding and code path that the chosen flaw needs.
  • The attacker can shape the heap enough to turn the memory error into code execution.

The Ruby advisory says the proof-of-concept code reaches code execution "in some scenarios". It does not claim a universal exploit. The CVE record for the case-conversion overflow scores it CVSS v3.1 7.4 with an AV:L vector and high attack complexity, so treat remote exploitation as application-dependent. A service that case-converts request data in ISO-8859-1 or Windows-1252 is a plausible remote path, but the sources do not demonstrate one.

Why does the fix work?

The case-mapping fix changes the loop condition in all fourteen single-byte encoders so that the loop only runs while at least two bytes are free. This is the change from b841d6f4f1:

-  while (*pp < end && to < to_end) {
+  while (*pp < end && to_end - to > 1) {
     code = *(*pp)++;

The sharp-s branch can now write both of its two bytes. The fix also adds a regression test that runs upcase, downcase(:fold), swapcase, capitalize and casecmp? over repeated 0xDF strings in every affected encoding.

The case-map accounting fix changes target_length to long. It rejects a source larger than INT_MAX - CASE_MAPPING_ADDITIONAL_LENGTH and computes the buffer capacity with an overflow check. It raises ArgumentError instead of wrapping. It is in f2e5063748.

The compiler fix adds check_compiled_program_size() and calls it before every bulk write, not only before a single opcode. It also propagates the return codes through the functions that ignored them. This is the core of 6c6e6c9273:

+static int
+check_compiled_program_size(regex_t* reg, OnigDistance add_len)
+{
+  if (reg->used > MAX_COMPILED_PROGRAM_SIZE ||
+      add_len > (OnigDistance )(MAX_COMPILED_PROGRAM_SIZE - reg->used))
+    return ONIGERR_TOO_BIG_COMPILED_PROGRAM;
+  return 0;
+}

57c24699fe moves the BBuf size arithmetic to size_t and caps it at ONIG_MAX_BBUF_SIZE, so the buffer macros cannot wrap either. 65b71a8844 adds the limit check to compile_length_tree so the length pass cannot wrap before compilation starts.

The four smaller fixes are narrow. The double-free fix sets cc->mbuf = NULL after freeing it. The exact-match fix checks the folded length against the operand. The Regexp#to_s fix preprocesses the source before it compiles the group. The backreference fix stops when the subject pointer reaches the end. Together they close the seven reported paths. The same release also carries other regexp hardening commits that are not part of the seven advisories, including stricter handling of byte escapes, comments, Emacs-Mule folds and surrogate code points. Those are defense in depth.

How do I check if I was compromised?

The Ruby project has published no indicators of compromise for these flaws. It reports proof-of-concept code but no exploitation in the wild, and CISA KEV does not list any of the seven as of 2026-11-19. The sources provide no reliable file path, domain or request signature to search for.

These checks can still surface a crash or an unusual pattern:

# Ruby crashes recorded by the kernel
dmesg | grep -i -E 'ruby|segfault'
journalctl -k --since '30 days ago' | grep -i -E 'ruby|segfault'
# Very large regexp patterns or case-conversion inputs in application logs
grep -R -i -E 'RegexpError|too big compiled program|string size too big' /var/log/<app>/

A crash in a Ruby worker is a lead, not proof. An attempt that fails cleanly may leave no trace. If you find a crash that matches one of these code paths, preserve the process image and the input before restarting the service.

Timeline

  • 2026-10-28: The first fix commits for the case-mapping and regexp memory-safety flaws are authored.
  • 2026-11-18: Ruby 4.0.10, 3.4.13 and 3.3.14 are released.
  • 2026-11-19 00:00 UTC: The Ruby security advisory is published.
  • 2026-11-19 06:34 UTC: CVE-2026-132825 is published for the case-conversion overflow.
  • No exploitation in the wild has been reported.

The first fix for the case-mapping overflow was authored on 2026-10-28, and the public advisory followed 22 days later.

First fix to public advisory took 22 days
Figure 1: From the first fix to the Ruby security advisory and CVE. Source: ruby-lang.org and ruby/ruby commits, checked November 19, 2026.

FAQ

Is my application affected if it only uses UTF-8? It can still be affected by the regexp flaws. The sharp-s overflow needs a single-byte encoding, but the compiler overflow, the double free and the case-insensitive reads do not. Check the version first, then the code paths.

Is this remotely exploitable? It depends on the application. The case-conversion CVE is scored AV:L with high complexity, while the Ruby advisory says its proof-of-concept code reaches code execution in some scenarios. A network service that passes attacker data into the affected methods is the realistic remote path.

Is there a public exploit? No working exploit code is public. The Ruby project says it is aware of proof-of-concept code that proves code execution in some scenarios, and it has not published it.

Does upgrading Ruby require rebuilding my native gems? No. The fixes are in the Ruby interpreter and its bundled regexp engine. Reinstalling the interpreter is enough. Restart the application and any native extension processes afterward.

Is Ruby 3.2 fixed? No. Ruby 3.2 and earlier are end of life and will not receive these fixes. Upgrade to a supported branch.

Was it exploited in the wild? No exploitation has been reported. None of the seven advisories is in CISA KEV as of 2026-11-19.

Find Ruby runtimes with Ostorlab

Ostorlab's software composition analysis inventories the runtimes, base images and gems your applications ship, so you can find the Ruby versions and dependencies that need this update. See how Ostorlab SCA and SBOM work.

References

  • Ruby security advisory, "Security advisories: multiple vulnerabilities in Regexp and String case conversion" (2026-11-19). https://www.ruby-lang.org/en/news/2026/11/18/multiple-vulnerabilities-in-regexp-and-string/ (checked November 19, 2026)
  • GitHub advisory GHSA-34m4-m9fh-gqp5, "Heap buffer overflow in case conversion of strings". https://github.com/ruby/ruby/security/advisories/GHSA-34m4-m9fh-gqp5 (checked November 19, 2026)
  • GitHub advisory GHSA-7x2q-68qv-6p8x, "Double free in regular expression compilation". https://github.com/ruby/ruby/security/advisories/GHSA-7x2q-68qv-6p8x (checked November 19, 2026)
  • GitHub advisory GHSA-87fm-7w84-j2px, "Integer overflow in case conversion of strings". https://github.com/ruby/ruby/security/advisories/GHSA-87fm-7w84-j2px (checked November 19, 2026)
  • GitHub advisory GHSA-wpqw-5qxg-m68r, "Out-of-bounds read in case-insensitive regular expression matching". https://github.com/ruby/ruby/security/advisories/GHSA-wpqw-5qxg-m68r (checked November 19, 2026)
  • GitHub advisory GHSA-3p8q-wmhx-vm2w, "Heap buffer overflow in regular expression compilation". https://github.com/ruby/ruby/security/advisories/GHSA-3p8q-wmhx-vm2w (checked November 19, 2026)
  • GitHub advisory GHSA-7whj-cfh7-xgm4, "Heap buffer overflow in Regexp#to_s". https://github.com/ruby/ruby/security/advisories/GHSA-7whj-cfh7-xgm4 (checked November 19, 2026)
  • GitHub advisory GHSA-pvgc-g7gj-pv6h, "Out-of-bounds read in case-insensitive backreference matching". https://github.com/ruby/ruby/security/advisories/GHSA-pvgc-g7gj-pv6h (checked November 19, 2026)
  • CVE record CVE-2026-132825. https://www.cve.org/CVERecord?id=CVE-2026-132825 (checked November 19, 2026)
  • Ruby 4.0.10 release announcement. https://www.ruby-lang.org/en/news/2026/11/18/ruby-4-0-10-released/ (checked November 19, 2026)
  • Ruby 3.4.13 release announcement. https://www.ruby-lang.org/en/news/2026/11/18/ruby-3-4-13-released/ (checked November 19, 2026)
  • Ruby 3.3.14 release announcement. https://www.ruby-lang.org/en/news/2026/11/18/ruby-3-3-14-released/ (checked November 19, 2026)
  • Fix commit b841d6f4f1, "Fix a heap buffer overflow in case mapping of the sharp s". https://github.com/ruby/ruby/commit/b841d6f4f1b442ac9cc8de590b43f9e4ba6d3603 (checked November 19, 2026)
  • Fix commit f2e5063748, "Check the lengths in rb_str_casemap". https://github.com/ruby/ruby/commit/f2e5063748b9b2c9dc93733b9989f9fce03abcf2 (checked November 19, 2026)
  • Fix commit 28aad344e1, "Fix a double free in the && handler of parse_char_class". https://github.com/ruby/ruby/commit/28aad344e14f288cdb0fea452a2570e9efc1c923 (checked November 19, 2026)
  • Fix commit e12e722695, "Fix an out-of-bounds read in the case-insensitive exact match". https://github.com/ruby/ruby/commit/e12e722695e017a67078cb52c37658e886e1f710 (checked November 19, 2026)
  • Fix commit 6c6e6c9273, "Bound compiled program writes against size accounting". https://github.com/ruby/ruby/commit/6c6e6c9273cec3ba8679dbb825a7c10fa9b36bfe (checked November 19, 2026)
  • Fix commit 57c24699fe, "Harden BBuf size arithmetic against 32-bit overflow". https://github.com/ruby/ruby/commit/57c24699fe45ef74052b277ffdc2f366a21d6395 (checked November 19, 2026)
  • Fix commit 65b71a8844, "Check the compiled program size while computing the length". https://github.com/ruby/ruby/commit/65b71a8844e09f23c7177f3ba64dae055785f165 (checked November 19, 2026)
  • Fix commit cdd499eccd, "Preprocess the source before Regexp#to_s checks it with Onigmo". https://github.com/ruby/ruby/commit/cdd499eccd1a8ec60021e5f7cec02a22d4c0b790 (checked November 19, 2026)
  • Fix commit b469749b37, "Check the end of the subject in string_cmp_ic". https://github.com/ruby/ruby/commit/b469749b37d57d2cb293918a895c5bec562d7eb2 (checked November 19, 2026)
  • Docker Hub, official ruby image, 1,595,151,215 pulls. https://hub.docker.com/_/ruby (checked November 19, 2026)
  • RubyGems, rails gem, 818,979,335 downloads. https://rubygems.org/gems/rails (checked November 19, 2026)
  • CISA Known Exploited Vulnerabilities catalog. https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json (checked November 19, 2026)