Skip to content
RCE Write-up Intermediate

RCE In GitLab's CLI Tool

GitLab's CLI tool passed a user-controlled branch name into a Windows command without proper escaping, allowing an attacker to inject arbitrary commands. An attacker could create a repository with a malicious branch name and convince a victim to run a specific CLI command, leading to remote code execution on the victim's machine.

ameya Follow

Published on blog.takemyhand.xyz

After starting at GitLab in October last year as a security engineer, one of the first reviews that came my way was our CLI tool, which was only recently published officially.

ameya (@0xtakemyhand), on blog.takemyhand.xyz

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The CLI tool used a user-controlled branch name in a Windows shell command without properly escaping shell metacharacters, allowing command injection.

Impact

An attacker could execute arbitrary commands on a victim's Windows machine if the victim clones a malicious repository and runs the CLI tool with the --web flag; the exploit is limited to Windows and requires user interaction.

What the attacker needed

Victim uses Windows; victim clones attacker's repository; victim runs glab mr create --web

The fix

The CLI tool should properly escape or sanitise user-controlled input before passing it to shell commands, or avoid using a shell altogether.

How it was found

  1. Attacker creates a repository and a branch with a name containing command delimiters.
  2. Attacker sets that branch as the default branch to increase the chance the victim uses it.
  3. Victim clones the repository on their machine.
  4. Victim runs the CLI command to create a merge request with the --web flag.
  5. The CLI builds a URL containing the branch name and passes it to a Windows command, which executes the injected commands.

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 write-up has not been written yet. The Original tab links to the source.

The GitLab command-line tool (glab) builds a web address from your branch name and then opens it in a browser using a Windows command. Because the branch name is inserted into that command without being made safe, a branch name containing special characters can trick Windows into running extra commands. An attacker can create a repository with such a branch name and set it as default, so when a victim uses the tool to create a merge request, the attacker's commands run on the victim's computer.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.