It's possible to create a note with any commit_id value
The backend did not validate the commit_id value when creating a note, allowing an attacker to send a commit_id longer than the database column limit, which caused a server error. By sending many such requests, an attacker could achieve denial of service.
GitLab
Originally disclosed on GitLab
- Fixed in 13 months
- Disclosed after 13 months
HackerOne report #717278 by amac on 2019-10-18, assigned to @jeremymatos:
Summary
Backend doesn't validate commit_id value on note creation, as result an attacker can send multiple requests to achieve denial of service.
Steps to reproduce
- Create a new project.
- Create a new file in the project.
- Create a new merge request with changes in the file created above.
- Send create note request with the following body (use just created merge_request_id instead of
<merge_request_id>),commit_idvalue length is 511 characters .
POST /andrew.richardson22/p1/notes?target_id=39915470&target_type=merge_request
{
"view": "inline",
"line_type": "old",
"merge_request_diff_head_sha": "314fd6bd72d5715d1cac211522cb286a5fe3f0ad",
"in_reply_to_discussion_id": "",
"note_project_id": "",
"target_type": "merge_request",
"target_id": <merge_request_id>,
"return_discussion": true,
"note": {
"note": "todo5",
"position": "{\"base_sha\":\"f0f267368c4a332cfd4e2fba4400eaf36994abe0\",\"start_sha\":\"f0f267368c4a332cfd4e2fba4400eaf36994abe0\",\"head_sha\":\"314fd6bd72d5715d1cac211522cb286a5fe3f0ad\",\"old_path\":\"index.js\",\"new_path\":\"index.js\",\"position_type\":\"text\",\"old_line\":null,\"new_line\":2}",
"noteable_type": "MergeRequest",
"noteable_id": <merge_request_id>,
"commit_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"type": "DiffNote",
"line_code": "a77b15c0d64cf6111e025645e562faf8ccabb9d7_3_3"
}
}
- Server returns error 500.
Impact
Firstly, I tried to inject javascript in commit_id, and I found only one place where this field is used - to generate discussion_path. But this url is escaped, so I continued to research and found that commit_id field has type string and there are no validations on commit_id in models/note.rb. In database used by gitlab.com, string type maxLength is 510 characters, so saving commit_id value with a length greater than 510 characters results in a database error.
Examples
Please see the attached p1.tar.gz
The full path to the project:
https://gitlab.com/andrew.richardson22/p1
What is the current bug behavior?
- Server returns error 500 when
commit_idvalue length exceeds 510 characters.
What is the expected correct behavior?
Server must validate commit_id parameter before creating a note.
- Ensure that it has the correct format.
- Ensure that it's related to the current user.
Output of checks
This bug happens on GitLab.com
Impact
An attacker can send multiple such requests to achieve denial of service.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
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 application did not validate the length or format of the commit_id parameter before saving it to a database column with a maximum length of 510 characters.
Impact
An attacker could send multiple such requests to achieve denial of service.
How it was found
- Create a new project.
- Create a new file in the project.
- Create a new merge request with changes in the file created above.
- Send a create note request with a commit_id value of 511 characters.
- The server returns error 500.
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.
When you create a comment on a merge request, the server stores a commit identifier. The server did not check how long that identifier was. If it was too long for the database, the server crashed with an error. Sending many such requests could make the service 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.