Skip to content
XSS Disclosed report Advanced

Arbitrary API PUT requests via HTML injection in user's name

A user's full name was only partly stripped of HTML, so a crafted name could inject an anchor element that the merge request page treated as a draft-toggle button. When a victim clicked anywhere on that page, the page sent an API PUT request of the attacker's choosing on the victim's behalf, which could transfer a project to the attacker's group.

GitLab

Originally disclosed on GitLab

  • Fixed in 3 months
  • Disclosed after 3 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 #2225710 by yvvdwf on 2023-10-25, assigned to @kmorrison1:

Report | How To Reproduce

Report

Hello,

Full name of a user is sanitized by the following function:

Ruby
  def sanitize_name  
    return unless self.name  
    self.name = self.name.gsub(%r{</?[^>]*>}, '')  
  end  

The name can be any HTML tag without closing bracket.

When it is displayed in the navigation bar of gitlab, it is sanitized once more times using simple_sanitize function which allows a, span tags and class, href, ... attributes.

Thus, a user's fullname can be <a class=x href=y

In a merge request page, we got this gadget:

JavaScript
  const draftToggles = document.querySelectorAll('.js-draft-toggle-button');

  if (draftToggles.length) {  
    draftToggles.forEach((draftToggle) => {  
      draftToggle.addEventListener('click', (e) => {  
        ...  
        axios  
          .put(draftToggle.href, null, { params: { format: 'json' } })  

This means that if a user's fullname is <a class=js-draft-toggle-button href=xxx and this fullname is shown in a merge request page, then we can trick victim to execute any RESTful API PUT requests if the victim clicks on the fullname.

To easily capture victim's clicks, we can add fixed-top class to create a transparent topmost layer, and tree-list-holder class to hide this topmost layer on other pages (but the topmost shows only on a merge request page), for example, a<a class="fixed-top tree-list-holder js-draft-toggle-button" href=xxxxxx

Reproduce

The vulnerability allows attackers to execute any RESTful API PUT requests on behalf of victim. The following scenario is to execute PUT /projects/:id/transfer, thus to allow attacker to steal a victim's project by escalating to the owner of the project.

  • step 0: as victim

    • create a new, private project and note its ID, e.g., 11111111 (we will steal this project: e.g., to be owner of the project)
  • step 1: as attacker

    • create a new group, note its ID, e.g., 99999999
    • invite victim as Maintainer of the group
  • step 2: as attacker

    • create a new project, edit its readme then commit to another branch, then create a new merge request from the new branch to the default one. The objective is to have a merge request page, e.g., https://gitlab.com/attacker/project-a/-/merge_requests/1
    • goto attacker profile page (https://gitlab.com/-/profile), change "Full name" to: a<a class="fixed-top tree-list-holder js-draft-toggle-button" href=/api/v4/projects/111111111/transfer?namespace=999999999 . Then click Update profile settings button. Important note: there must be no closed-bracket character > in the full name.
    • go back to the merge request page, https://gitlab.com/attacker/project-a/-/merge_requests/1, you should notice a topmost transparent layer.
    • change the project to public or add victim as a project member so that victim can view the merge request page
  • step 3: as victim

    • visit the merge request page, then click any where

You might now notice that the project 111111111 has been transfer to the group 999999999 and attacker becomes owner of the project.

Best regards,
yvvdwf

Impact

The vulnerability allows attackers to execute any RESTful API PUT requests on behalf of victim.

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 name sanitiser only removed complete tags, so an unclosed tag survived and was later rendered as an anchor that a JavaScript gadget used as a request target.

Impact

An attacker could make a victim's browser send any API PUT request as the victim, for example transferring the victim's project to the attacker's group and making the attacker its owner.

What the attacker needed

Attacker account; victim account; victim visits attacker's merge request page; victim clicks on the page

How it was found

  1. As the victim, create a private project and note its ID.
  2. As the attacker, create a group, note its ID, and invite the victim as Maintainer.
  3. As the attacker, create a project with a merge request so a merge request page exists.
  4. Change the attacker's full name to an unclosed anchor carrying the gadget classes and an API transfer URL as its href.
  5. Make the merge request page visible to the victim, for example by making the project public or adding the victim as a member.
  6. As the victim, visit the merge request page and click anywhere.

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 website lets people set a display name. The site tried to remove HTML tags from that name, but its filter missed tags that were never closed, so part of the name was treated as real page markup. A page then trusted that markup as a button and, when the victim clicked, sent a request to the site's API using the victim's login, letting the attacker change things the victim owns.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.