Multiple vulnerabilities in Regexp and String case conversion ruby-lang.org · 71...

@best

Multiple vulnerabilities in Regexp and String case conversion ruby-lang.org · 71 points · 15 comments · HN thread

TL;DR Ruby's maintainers published an advisory for seven vulnerabilities in the regular expression engine and in string case conversion, several of which the advisory says can be used for remote code execution in some scenarios. Fixed releases are Ruby 4.0.10, 3.4.13 and 3.3.14, and the advisory strongly recommends upgrading; CVE IDs were requested but not yet assigned.

  • Seven flaws are listed: heap buffer overflows, integer overflows, a double free, and out-of-bounds reads in regexp compilation, matching, Regexp#to_s and string case conversion.
  • The advisory says PoCs exist that show some flaws can lead to RCE; the case-conversion and regexp-compilation bugs are the ones called out for RCE.
  • Affected versions are Ruby 3.3.13 and earlier, 3.4.0 through 3.4.12, and 4.0.0 through 4.0.9.
  • Fixed in Ruby 4.0.10, 3.4.13 and 3.3.14; Ruby 3.3 is in security maintenance and 3.2 and earlier are end of life and will not get the fixes.
  • Credits go mainly to Stephan Lipp (Ada Logics) and Anthropic, with other individual reporters and Hiroya Fujinami and Hiroshi SHIBATA for one issue.

Discussion The thread is short and mostly focused on a single technical detail: commenter tptacek proposed that the case-conversion bug comes from Windows-1252, where lowercase German sharp s (ß) has no uppercase single-character form, so upcasing expands it to "SS" and the buffer check is done one character at a time, leading to a one-byte overflow at the end of a string. Others joined in on the wordplay and on the general state of security, with a few jokes about vacations. The mood is wry and somewhat alarmed, with a sideline debate about whether regexes could simply be replaced with plain code.

  • Bug is the ß-to-SS expansion in Windows-1252 upcasing (some): Commenters analyze the likely mechanism: ß uppercases to SS, lengthening the string, and the 1252 code checks buffer headroom per character, so a trailing ß causes a one-byte overflow. tptacek also noted that heap grooming for such an exploit would be difficult.
  • Joking about the bug name and vacations (many): A large share of replies are lighthearted, suggesting punny names like Ruby2ßhell or upcaße2Shell, and wishing for a vacation in response to the wave of vulnerability news.
  • Regexes should be replaced with plain code (a few): One commenter argues that regexes could be swapped for ifs, array access and comparisons, possibly with an LLM, to shrink the attack surface. Replies push back that regex complexity is underestimated and that Rails and gems would be hard to change.
  • Similar expansion bugs may exist for other characters (a few): One commenter wonders whether U+0130, which expands when lowercased, could trigger a similar bug; tptacek replies that it is not in Windows-1252 and so cannot trigger this particular counting bug.
  • Other ecosystems have comparable flaws (a few): A commenter points to a Java base64 decoder assembly vulnerability, shared as a link, as an example that serious bugs are not unique to Ruby.

Links from the comments

#ruby #security #regexp #bufferoverflow #cve #rce