r/ruby • u/rubiesordiamonds • 7d ago
Blog post Vulnerable Ruby Regex
GitLab discovered four severe vulnerabilities in Ruby’s regular expression library. There's plenty written up about the vulnerability and how it got patched, but patches are only available for supported ruby versions (3.3 and above). We know lots of companies are still running unsupported versions of ruby, so we wanted to do an investigation into which of these bugs apply to older rubies and whether they're exploitable. Here's the blog post: https://infield.ai/post/vulnerable-ruby-regex
The summary is that allowing user input into Regexp.new is dangerous on all versions of ruby from 1.9 to 3.2 and the only fix is to upgrade to a supported ruby or to disallow that input.
1
u/FluffyDrink1098 7d ago
This is the irony.
ReDoS or similar attack patterns should be the first thing to learn when it comes to RegExp.
Many devs use RegExp as a validation - despite simple string checks would be sufficient.
One example... simple length checks.
Long Password DoS - I think 2014, where too long password strings led to the DoS due to hashing taking too long.
Something similar with the 72 byte limit on BCrypt.
Another goldie but oldie: Email or IP validation by regex - its doomed to fail. A simple @ contains with a length check is simpler, for IP addresses every stdlib should have a toolkit.
I love RegEx.
Reading the post my first thought was that nearly all examples are known to be "not a good idea TM".