Skip to content
DoS Disclosed report Intermediate

Backend: ReDoS in CI interpolation (fix bypass)

The fix for a previous ReDoS vulnerability in GitLab's CI interpolation regex was incomplete, still allowing catastrophic backtracking. An attacker could supply a specially crafted string to exhaust server resources, causing a denial of service.

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 #2358689 by joaxcar on 2024-02-08, assigned to GitLab Team:

Report | Attachments | How To Reproduce

Report

Summary

Bypass of fix for CVE-2023-6386

The 16.8.2 security release contained a fix for a ReDoS issue in /lib/gitlab/ci/config/interpolation/block.rb adding this regexp

PATTERN = /(?<block>\$\[\[\s*(?<data>\S{1}.*?\S{1})\s*\]\])/  

This fixes the previous issue but still allows for catastrophic backtracking. Given a string of this form

JavaScript
']$[['.repeat(100000) + ']'  

The regex will blow up. Causing the same denial of service as prior the fix

Steps to reproduce

Set up a test Gitlab instance

  1. Log in to the gitlab instance
  2. Create a project
  3. Upload the two files added to this report into the project
  1. Open devtools
  2. Go to https://gitlab.com/GROUP/PROJECT/-/ci/editor?branch_name=main
  3. You should see a GraphQL call getting stuck and failing. This request can be copied and run X times to exhaust the server
Screenshot_2024-02-08_at_16.04.55.png
Screenshot_2024-02-08_at_16.04.55.png From the original on GitLab
Impact

ReDos exhausting server resources

What is the current bug behavior?

The fixed regexp is still vulnerable to catastrophic backtracking

What is the expected correct behavior?

The regexp should not allow catastrophic backtracking

Impact

ReDos exhausting server resources

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

Technical Details

Added by @avielle during refinement.

  1. This vulnerability doesn't exist on GitLab master anymore because of the Ruby 3.2 upgrade. Ruby 3.2 has builtin ReDoS prevent: https://reinteractive.com/articles/regex-improvements-in-the-new-ruby-3-2
  2. Despite that, we should still fix the vulnerability because the backports will apply to GitLab versions with Ruby 3.1
  3. We should try using Gitlab::UntrustedRegex to fix the vulnerability. This may require rewriting the RegEx to avoid backtracking (hence the weight 3). More details in https://gitlab.com/gitlab-org/gitlab/-/issues/433520#note_1791372534

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 regex pattern used for CI interpolation contains nested quantifiers that allow catastrophic backtracking on crafted input.

Impact

An attacker could exhaust server resources, causing a denial of service. The vulnerability does not exist on GitLab master due to Ruby 3.2's built-in ReDoS prevention, but backports to Ruby 3.1 versions remain affected.

What the attacker needed

A GitLab instance (test or production); ability to create a project and upload files; victim (or attacker) opens the CI editor

The fix

The regex should be rewritten to avoid backtracking, possibly using Gitlab::UntrustedRegex.

How it was found

  1. Set up a test GitLab instance
  2. Log in to the GitLab instance
  3. Create a project
  4. Upload the two files added to this report into the project
  5. Open devtools
  6. Go to the CI editor URL for the project

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 search text. Some regex patterns can take a very long time to process certain inputs, especially if they have nested repetition. This is called catastrophic backtracking. An attacker can exploit this to make a server unresponsive by sending a malicious input, causing a denial of service (DoS).

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.