Skip to content
DoS Disclosed report Intermediate

An RDoc file containing a specially crafted regex can crash puma

A specially crafted regex in an RDoc file triggers a stack-buffer-overflow in Ruby's regex compiler, causing a segmentation fault and crashing Puma. An attacker could repeatedly request the file to crash all Puma processes and deny access to the GitLab instance.

GitLab

Originally disclosed on GitLab

  • Fixed in 3 months
  • Disclosed after 3 months

HackerOne report #1415071 by vakzz on 2021-12-02, assigned to @dcouture:

Report | Attachments | How To Reproduce

Report

Summary

There is a stack-buffer-overflow in ruby still affecting ruby 2.7.x that can cause a segmentation fault and crash when compiling certain regexes.

Normally there would be no way for a user to specify their own regex to be compiled, but when rendering rdoc files there is a check to see if a block of text is valid ruby:

https://github.com/ruby/rdoc/blob/master/lib/rdoc/markup/to_html.rb#L427

Ruby
  ##  
  # Returns true if text is valid ruby syntax

  def parseable? text  
    verbose, $VERBOSE = $VERBOSE, nil  
    eval("BEGIN {return true}\n#{text}")  
  rescue SyntaxError  
    false  
  ensure  
    $VERBOSE = verbose  
  end  

This will never execute any code except for returning true due to how BEGIN works (I'm pretty sure anyway) but will run it through the ruby parser to generate an ast. Since regexes are compiled during this stage, it's possible to trigger the stack overflow using the following readme.rdoc:

RDOC
code:  
  /(())(?<X>)((?(2147483647)))/  

I might me possible to exploit the buffer overflow instead of just causing a crash, but if it is possible it would be quite difficult due to not having a leak for aslr and single shot.

Steps to reproduce
  1. Create a new project
  2. Create a new file aaa.rdocwith the following contents:
RDOC
code:  
  /(())(?<X>)((?(2147483647)))/  
  1. Commit and try to view the file
  2. There will be an error loading the viewer, the request for the rich version will return 502 as puma has crashed
Impact

A malicious rdoc can cause puma to crash when it's rendered. A user could constantly request the url, constantly crashing all of the puma processes and denying access to the gitlab instance. For example running the following ffuf with a rate of just 1 request per second is enough to bring down my vm and prevent any legitimate requests:

Bash
ffuf -u 'http://localhost:8888/root/crash/-/blob/main/aaa.rdoc?format=json&viewer=rich&FUZZ' -w /usr/share/dict/words -rate 1 -t 5  
Examples

POC repo - https://gitlab.com/vakzz-h1/rdoc-crash/
Crashing example: https://gitlab.com/vakzz-h1/rdoc-crash/-/blob/main/aaa.rdoc?format=json&viewer=rich

What is the current bug behavior?

Ruby crashes when trying to parse a specific regex

What is the expected correct behavior?

Ruby shouldn't crash when parsing regexes, and rdoc probably shouldn't eval code even with the BEGIN guard

Relevant logs and/or screenshots
Output of checks

This bug happens on GitLab.com

Impact

A malicious rdoc can cause puma to crash when it's rendered. A user could constantly request the url, constantly crashing all of the puma processes and denying access to the gitlab instance. For example running the following ffuf with a rate of just 1 request per second is enough to bring down my vm and prevent any legitimate requests:

Bash
ffuf -u 'http://localhost:8888/root/crash/-/blob/main/aaa.rdoc?format=json&viewer=rich&FUZZ' -w /usr/share/dict/words -rate 1 -t 5  

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

How To Reproduce

Please add reproducibility information to this section:

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

A malicious RDoc file can crash Puma when rendered, and an attacker could repeatedly request the URL to crash all Puma processes and deny access to the GitLab instance.

What the attacker needed

Ability to create a project and file; ability to request the rendered RDoc URL

How it was found

  1. Create a new project.
  2. Create a new file named aaa.rdoc with the crafted regex content.
  3. Commit the file and try to view it.
  4. The request for the rich version returns 502 as Puma has crashed.

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 report has not been written yet. The Original tab links to the source.

A regular expression (regex) is a pattern used to match text. Ruby has a bug where compiling certain regexes can overflow a memory buffer, crashing the program. When GitLab renders an RDoc file, it checks if the text is valid Ruby code, which compiles any regexes inside. So a malicious RDoc file can crash the server process (Puma) that handles web requests.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.