DOS through markdown render caused by unlimited amount of code diffs in markdown
GitLab's markdown rendering pipeline lacked a limit on the number of inline code diffs, allowing a crafted payload to cause excessive CPU consumption. An attacker could send a small number of requests to make the instance unresponsive.
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 #2518563 by joaxcar on 2024-05-24, assigned to @cmaxim:
Report | How To Reproduce
Report
(This is one of the multiple subreports related to #2023684 where [@]gmyers asked me to seperate out these issues to their own reports)
Summary
When GitLab renders input text as markdown, it uses the banzai pipelines. The pipeline consists of multiple filters that either strip content or alter content based on certain rules.
There is an issue when these rules can be abused to expand a given payload in a way that causes high resource consumption and locks CPU threads at 100%. This is similar to how ReDoS issues work but this is not related to ReDoS, the issue stems from how the pipelines expand benine input into large outputs.
This has previously been fixed by limiting the number of hits for a certain rule. See the emoji expansion rule, which has a limit of 1000 emojis /lib/banzai/filter/emoji_filter.rb
The issue
Given a payload with 250000 code diffs {++}\n it will cause the CPU to lock in 100% for 1 minute and respond with a 500 Internal Server Error as the response.
Inline diffs are handled in this filter lib/banzai/filter/inline_diff_filter.rb and has no limitation
Steps to reproduce
Test this on a local instance!
- SSH to your local instance of Gitlab
- Install
htopwithapt-get update && apt-get install htop - start
htopwithhtop
Now log in to your instance
4. Log in
5. Got to https://gitlab.com/groups/new and create an a new group called test
6. In the new group create a project called test
7. Open devtools and run this snippet and note the value
document.getElementsByName('csrf-token')[0].content
- Go to
Applicationin devtools and opencookiesand copy the value of_gitlab_sessioncookie - Open a terminal and run this script (alter CSRF_TOKEN, COOKIE, SERVER and DURATION). This will make one request a second
COOKIE="<SESSION_COOKIE>"
CSRF_TOKEN="<CSRF_TOKEN>"
SERVER_URL="https://gitlab.example.com"
DURATION=60
cat > json_payload.json <<EOF
{"text": "$(printf -- '{++}\\n%.0s' {1..250000})"}
EOF
for (( i=1; i<=DURATION; i++ ))
do
# Make the curl request
curl --request POST -k \
--header "Cookie: _gitlab_session=$COOKIE;" \
--header "X-Csrf-Token: $CSRF_TOKEN" \
--header "Content-Type: application/json" \
-d [@]json_payload.json "$SERVER_URL/test/test/preview_markdown" &
# Wait for 1 second
sleep 1
done
- Look in htop and see all CPUs at 100%
- Try navigating in the GitLab instance and note you have a DOS delay of +10 seconds
Impact
Uncontrolled CPU resource consumption is caused by a low number of requests. Can keep an instance inaccessible with about 10 requests a minute. (tested on 1000 users reference architecture)
What is the current bug behavior?
There is no limit to the number inline diffs parsed and rendered
What is the expected correct behavior?
As with emojis, there needs to exist a limit to how many inline diffs are rendered
Output of checks
This bug happens on GitLab.com
Impact
Uncontrolled CPU resource consumption is caused by a low number of requests. Can keep an instance inaccessible with about 10 requests a minute. (tested on 1000 users reference architecture)
Impact
Uncontrolled CPU resource consumption is caused by a low number of requests. Can keep an instance inaccessible with about 10 requests a minute. (tested on 1000 users reference architecture)
How To Reproduce
Please add reproducibility information to this section:
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 diff filter in the markdown pipeline did not limit the number of inline diffs it processed, unlike the emoji filter which has a cap.
Impact
Uncontrolled CPU resource consumption is caused by a low number of requests, and about 10 requests a minute can keep an instance inaccessible (tested on a 1000-user reference architecture).
What the attacker needed
Access to a GitLab instance; ability to send authenticated requests; valid session cookie and CSRF token
The fix
A limit should be added to the number of inline diffs rendered, similar to the existing limit for emojis.
How it was found
- SSH to a local GitLab instance and start htop to monitor CPU.
- Log in and create a new group and project.
- Extract the CSRF token and session cookie from the browser.
- Run a script that sends repeated POST requests to the markdown preview endpoint with a payload containing many inline diffs.
- Observe all CPUs at 100% in htop and experience a denial-of-service delay when navigating the instance.
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.
GitLab converts text written in markdown into formatted HTML using a series of filters. One filter handles inline code diffs, but it had no limit on how many it would process. By sending a request with a huge number of these diffs, an attacker could make the server work very hard and slow down for everyone.
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.