DEV Community

Cover image for Patch Your Ruby! Again! Seven Regexp and String Fixes in 4.0.10, 3.4.13, and 3.3.14
christine
christine

Posted on Originally published at christine-seeman.com

Patch Your Ruby! Again! Seven Regexp and String Fixes in 4.0.10, 3.4.13, and 3.3.14

Less than a month after the regexp fixes for GitLab's CVEs, Ruby posted seven more security advisories last night, at 6 p.m. Central. Five are in the regular expression engine and two are in string case conversion. Three are rated critical, and the Ruby team says proofs of concept show some of them can lead to remote code execution, meaning an attacker could run their own code on your server. The fixes are in Ruby 4.0.10, 3.4.13, and 3.3.14.

We had the upgrade merged by 10:30 that night and running in production just after midnight. More on how below.

Am I Affected?

Ruby series Affected Fixed in
4.0 4.0.0 through 4.0.9 4.0.10
3.4 3.4.0 through 3.4.12 3.4.13
3.3 3.3.13 and earlier 3.3.14
3.2 and older Yes No fix (end of life)

Last month the answer was simple: if every regexp in your app was written by a developer, you weren't affected. That's no longer the whole answer. Three of the seven only need the attacker to control the string, not the pattern:

  • Two are in case conversion, so changing the case of a crafted string can corrupt memory.
  • One is in case-insensitive backreference matching (a pattern like /(a)\1/i, where \1 repeats an earlier match), which can read past the end of the string being matched.

So even an app that never builds a regexp from user input should upgrade.

No CVE IDs have been assigned yet. The Ruby team has requested them, and for now each issue is tracked by its GitHub Security Advisory (GHSA) ID.

The Seven Advisories

Advisory What it is Severity Attacker needs to control
GHSA-34m4-m9fh-gqp5 Case conversion writes one byte past its buffer in some single-byte encodings, such as ISO-8859-1 and Windows-1252 Critical The string
GHSA-87fm-7w84-j2px Case conversion length overflows when the result is over 4 GiB High The string
GHSA-7x2q-68qv-6p8x Double free when compiling a character class intersection (&&) Critical The pattern
GHSA-3p8q-wmhx-vm2w Compiled pattern size overflows during compilation Critical The pattern
GHSA-7whj-cfh7-xgm4 Regexp#to_s writes past its buffer High The pattern
GHSA-wpqw-5qxg-m68r Out-of-bounds read in case-insensitive matching High The pattern
GHSA-pvgc-g7gj-pv6h Out-of-bounds read in case-insensitive backreference matching Moderate The string

A few terms: a double free means memory is released twice, which can corrupt it. An integer overflow is a number too big for its type, so it wraps around and Ruby allocates too little space. An out-of-bounds read means Ruby reads memory it shouldn't, which can leak data or crash the process. Writing past a buffer, the block of memory set aside for some data, can overwrite whatever sits next to it, and that's what can turn into code execution.

A character class intersection matches characters that are in both sets, like [a-z&&[^aeiou]] for lowercase consonants.

The advisories don't name specific String methods for the case conversion bugs. The safe reading is anything that changes case: upcase, downcase, capitalize, swapcase, and their ! versions.

Four of the seven are credited jointly to Stephan Lipp of Ada Logics and to Anthropic. Two came through HackerOne, a bug bounty platform, and one from two Ruby committers.

How We Patched Last Night

We're in scope. Our app compiles regexps from patterns stored in the database, the kind of code the pattern advisories target.

Last month, bumping Ruby the day the fix came out broke our CI (continuous integration, the tests that run on every pull request), because we changed the version before the Docker image and setup-ruby, the GitHub Action that installs Ruby, knew about it. The lesson was the order: wait for the base image, update CI, then change .tool-versions.

This time a teammate followed that order. All times are Central, November 18:

Time What happened
6:00 p.m. Ruby posts the advisories
6:48 p.m. Docker Hub moves ruby:4.0-alpine to 4.0.10
Shortly after Our CI image is rebuilt and reports 4.0.10
7:11 p.m. Pull request (PR) opened, a one-line change to .tool-versions
7:41 p.m. Marked ready for review
7:51 p.m. First approval
8:33 p.m. Second approval
10:30 p.m. Merged
After midnight Production deployed on 4.0.10

A few things made it boring, which is what you want from a security upgrade:

  • Production didn't need a code change. Our Dockerfiles use the 4.0 tag, so the next build gets 4.0.10. The PR only moves the version for local development.
  • CI was already on 4.0.10. Every workflow now runs in our own CI container, which was rebuilt after Docker Hub updated, so there was no setup-ruby version to bump.
  • Review took 10 minutes. A one-line PR with a clear reason in the description is easy to approve, even in the evening.
  • No cooldown to bypass. Our 14-day gem cooldown applies to gems, not to Ruby itself, so nothing held this one back.

What to Do

  1. Upgrade to Ruby 4.0.10, 3.4.13, or 3.3.14. Check every place Ruby's version is set: your version manager file (.ruby-version or .tool-versions), the ruby line in your Gemfile, your Docker base image, and any CI image you build separately.

  2. Confirm what production runs. RUBY_VERSION in a console on the server is the quickest check.

  3. If you upgrade the same day, check that your base image and CI setup have the new version before you change your version file.

If You Can't Upgrade Yet

The advisories give no workaround, only the upgrade.

For the pattern bugs, the advice from last month still applies: don't compile regexps from input you don't control.

For the string bugs, the risk depends on your data. The one-byte overflow only happens in single-byte encodings like ISO-8859-1 and Windows-1252, and most Rails apps work in UTF-8. Watch for places you convert imported legacy files. The other needs a converted string over 4 GiB, which request size limits usually rule out. Neither is a reason to put off the upgrade.

If you're on Ruby 3.2 or older, there's no fix coming (FYI! Upgrade now!) Ruby 3.3 is still supported until the end of March 2027, and starting with 3.3.14 it also gets selected bug fixes, not just security fixes. The Ruby team now calls this the legacy maintenance phase.

More Information

Top comments (0)