Skip to content
DoS Disclosed report Intermediate

ReDoS in `Cargo.toml` blob viewer

The Cargo.toml blob viewer used user-controlled input directly in regular expressions, making it vulnerable to ReDoS. An attacker could craft a Cargo.toml file that causes excessive CPU consumption when viewed, potentially leading to denial of service.

GitLab

Originally disclosed on GitLab

  • Fixed in 2 months
  • Disclosed after 2 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 #2251278 by yvvdwf on 2023-11-14, assigned to @greg:

Report | Attachments | How To Reproduce

Report

Hello,

The following code is vulnerable to the regular expression denial of service attack (ReDoS) because it uses directly users' input in regex:

Ruby
###  https://gitlab.com/gitlab-org/gitlab/-/blob/b356ddbbd1929cdca10b3fcd83eacc198c79e58e/lib/gitlab/dependency_linker/cargo_toml_linker.rb#L33-47  
      def link_toml(key, value, type, &url_proc)  
        if value.is_a? String  
          link_regex(/^(?<name>#{key})\s*=\s*"#{value}"/, &url_proc)  
        elsif value.is_a? Hash  
          # Don't link when using a custom registry  
          return if value['registry']

          # Don't link unless a crates.io version is provided  
          # See https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#multiple-locations  
          return unless value['version']

          link_regex(/^(?<name>#{key})\s*=\s*\{/, &url_proc)  
          link_regex(/^\[#{type}\.(?<name>#{key})\]/, &url_proc)  
        end  
      end  

Reproduction

  • in an existing project, or create a new one.
  • add Cargo.toml file with the following content:
[dependencies]  
".*((a|b)+|c)+"="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"  
Cargo.toml.png
Cargo.toml.png From the original on GitLab
  • after clicking on Commit changes to save the file, you are redirected to a blob viewer page to view the file. You should see that the file takes long time to render and ended by an error. This is caused by the reDoS which comsumes high usage of a single CPU core.
  • refresh the page as many times as you want to consume other CPU cores to cause DoS of your Gitlab instance.

Impacts

ReDoS causes denial of services at back-end.

Best regards,
yvvdwf

Impact

ReDoS causes denial of services at back-end.

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

Likely the regular expression is built by inserting user-controlled strings directly into the pattern, allowing an attacker to supply a pattern that causes catastrophic backtracking.

Impact

ReDoS causes denial of service at the back-end, potentially affecting the entire GitLab instance if multiple requests are made.

What the attacker needed

Ability to create or modify a project; ability to add a Cargo.toml file

How it was found

  1. Create or use an existing project.
  2. Add a Cargo.toml file with malicious content.
  3. Commit the changes to save the file.
  4. View the file in the blob viewer, which takes a long time and ends with an error.
  5. Refresh the page repeatedly to consume more CPU cores and cause denial of service.

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 search text. If a pattern is badly written and given specially crafted input, the search can take a very long time, using up all the computer's processing power. This is called a regular expression denial of service (ReDoS), and it can make a website slow or unavailable.

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.