Ruby RegEx could lead to RCE
Ruby's regular expression engine (Onigmo) had memory corruption bugs (double free and integer overflows) that could be triggered when compiling attacker-controlled regex patterns, potentially leading to remote code execution on GitLab servers. GitLab patched its shipped Ruby and assigned four CVEs, and Ruby released fixes in versions 4.0.9, 3.4.12 and 3.3.13.
ruby-lang.org
Published on ruby-lang.org
We have released Ruby 4.0.9, 3.4.12 and 3.3.13. They fix several bugs in Ruby’s regular expression engine (Onigmo) that GitLab found could be used for remote code execution on GitLab servers.
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
Likely memory corruption bugs in Ruby's regex compiler: a double free when parsing fails after an alternation, integer overflows in the compiled pattern size, and overflow of internal IDs with many repeats.
Impact
An attacker who can control a regex pattern compiled by a vulnerable Ruby application could corrupt memory and potentially achieve remote code execution on the server.
What the attacker needed
Application compiles attacker-controlled regex; vulnerable Ruby version
The fix
Upgrade to Ruby 4.0.9, 3.4.12 or 3.3.13 or later; if unable, avoid compiling regular expressions from untrusted input.
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 is a programming language, and its regular expression engine is the part that handles pattern matching. If a program lets a user supply the pattern, a malicious pattern could crash or corrupt the program's memory, and in some cases an attacker could run their own code on the server. This only affects applications that compile patterns from untrusted input.
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.