Skip to content
Access control Disclosed report Beginner

Unable to protect branches that have HTML tags in the branch name if branch created locally/in WebIDE

Branches with HTML tags in their names, created locally or via the Web IDE, cannot be protected because the protection feature sanitises the branch name, causing a mismatch. The branch remains unprotected.

GitLab

Originally disclosed on GitLab

  • Fixed in 53 days
  • Disclosed after 53 days

Summary

Branches with HTML tags in the name (which considered valid by git) created locally or through the Web IDE cannot be protected. This is happening despite the branches being added to the protected branches list.

Followup from the HackerOne reporter: The same behavior exists on settings for protected tags.

Context

This is a followup to a recently fixed security issue. It was brought to our attention by HackerOne reporter who identified the original vulnerability. This issue has been made confidential because the details of the original vulnerability have not yet been released. Please note that this does not have the same severity/priority as the original issue, even though it is considered an edge case of the originally described vulnerability.

Steps to reproduce

  1. Create a project
  2. From the repository page, click the "Web IDE" button
  3. Add a new file with some content (or make any other changes) and click Commit
  4. Make sure the Create a new branch radio button is selected and give it a name containing some HTML, such as <h1>test</h1>.
  5. Click Commit
  6. Visit Settings -> Repository from the left-side menu and Expand the Protected Branches section
  7. Choose the branch you just made -- note that it will be we appear encoded as &lt;h1&gt;test&lt;/h1&gt;
  8. Choose No one for both the Allowed to merge and Allowed to push dropdowns and click Protect
  9. On the project repository page, select the branch that you just protected (ex <h1>test</h1>, click the + sign and choose 'Add a new file'. Enter a filename and some content and click Commit changes
  10. Notice that the changes made were applied directly to the branch (which is supposed to be protected)
    • When a branch is properly protected, clicking Commit changes opens a merge request for that branch -- instead of the changes being directly applied

Original comment from HackerOne reporter

Below is the information provided by the HackerOne reporter:

I think that this report got a fix in 14.5.2 (link). This is good news, but the patch does not fix all aspects of the reported vulnerability. The patch adds this filter to the branch name when added as a protection

def sanitize_branch_name(name)
      name = CGI.unescapeHTML(name)
      name = Sanitize.fragment(name)

      # Sanitize.fragment escapes HTML chars, so unescape again to allow names
      # like `feature->master`
      CGI.unescapeHTML(name)
end

This will take names such as feature->master and return it as is. It will also take names such as <h1>test</h1> and return test. The problem here is that GitLab does not enforce a consistent branch name standard. A problem is that "HTML tags" are not forbidden in branch names by Git, and thus branches created locally and then pushed to GitLab can have names containing HTML tags. A user can also create branch names containing HTML tags in the Web IDE, while creation of branches in the regular UI will strip HTML tags. This inconsistency is a bit confusing for users. What this lead to is that the "protected branch" feature is still broken for branches containing HTML. Trying to protect a branch like this will leave the branch unprotected as before, even when the branch is chosen in the dropdown. Test this by creating a branch in the Web IDE named <h1>test</h1> and then try to protect it by picking the branch in the dropdown.

I dont think that this constitutes a new vulnerability, but I do think that it should be addressed. And particularly, GitLab might need to chose if you are going to allow branch names containing HTML or not. And if not, document that these names that are allowed in Git are not allowed in GitLab.

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

Likely the branch name sanitisation in the protection feature does not match the actual branch name stored, because GitLab does not enforce a consistent branch naming standard.

What the attacker needed

GitLab account with project access; Ability to create branches via Web IDE or push locally

The fix

GitLab should either disallow branch names containing HTML tags or ensure the protection feature handles them consistently.

How it was found

  1. Create a project and open the Web IDE.
  2. Add a file, commit, and create a new branch with a name containing HTML tags.
  3. Go to Settings > Repository, expand Protected Branches, and select the branch (shown encoded).
  4. Set 'Allowed to merge' and 'Allowed to push' to 'No one' and click 'Protect'.
  5. On the repository page, select the protected branch, add a new file, and commit changes.
  6. Observe that the commit is applied directly to the branch instead of opening a merge request.

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.

Git allows branch names to contain characters like angle brackets, which are used in HTML. GitLab's protected branch feature tries to clean these names, so when you select such a branch to protect, it doesn't match the actual branch. As a result, the branch remains unprotected.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.