Skip to content
Access control Disclosed report Beginner

Unprivileged access to Private Composer Package Repository packages

A private Composer package's archive could be downloaded without authentication via its dist URL. An attacker who obtained the URL could download private repository files.

GitLab

Originally disclosed on GitLab

  • Fixed in 15 months
  • Disclosed after 15 months

HackerOne report #1074148 by sjerdo on 2021-01-08, assigned to @dcouture:

Report | How To Reproduce

Report

Summary

Gitlab features a Package Registry which can be used for public and private repositories.
When a private repository publishes a Composer package (for private use), the package can be download by the URL, without any authentication. The only requirement is to obtain the dist download link from the composer.lock file

Steps to reproduce
  1. Create a new Private group
  2. Create a new Private project in the newly private group
  3. Add a default composer.json file to the project / create a composer package
{
    "name": "sjerdo/private-project"  
}
  1. Create a tag, e.g. 1.0.0
  2. Create a personal access token with api access.
  3. Publish the composer package using the API and the personal access token
  4. Create a blank composer project and install the package
  5. Obtain the dist url from the composer.lock file
  6. Download the zip at the dist url without setting authentication credentials. (eg. by using curl).
Impact

Private repositories (files) can be download by unauthorised users who can obtain the dist download URL or project ID, package name and git commit hash (eg. from a composer.lock file).

Examples

Repository: https://gitlab.com/my-private-group3/private-project
Published package: https://gitlab.com/my-private-group3/private-project/-/packages/958076

composer.json

JSON
{
    "name": "sjerdo/security-test",  
    "authors": [  
        {  
            "name": "Sjoerd Wenker",  
            "email": "[email protected]"  
        }  
    ],  
    "require": {  
        "sjerdo/private-project": "^1.0"  
    },  
    "repositories": {  
        "gitlab.com/10584961": {  
            "type": "composer",  
            "url": "https://gitlab.com/api/v4/group/10584961/-/packages/composer/packages.json"  
        }  
    }  
}

composer.lock:

JSON
{
    "_readme": [  
        "This file locks the dependencies of your project to a known state",  
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",  
        "This file is [@]generated automatically"  
    ],  
    "content-hash": "92f07e65c18a1a095eefd9baa735f09f",  
    "packages": [  
        {  
            "name": "sjerdo/private-project",  
            "version": "1.0.0",  
            "dist": {  
                "type": "zip",  
                "url": "https://gitlab.com/api/v4/projects/23533789/packages/composer/archives/sjerdo/private-project.zip?sha=76b4344d0ab1491807c8bace4aee112bf09e843d",  
                "reference": "76b4344d0ab1491807c8bace4aee112bf09e843d",  
                "shasum": ""  
            },  
            "type": "library"  
        }  
    ],  
    "packages-dev": [],  
    "aliases": [],  
    "minimum-stability": "stable",  
    "stability-flags": [],  
    "prefer-stable": false,  
    "prefer-lowest": false,  
    "platform": [],  
    "platform-dev": [],  
    "plugin-api-version": "2.0.0"  
}

dist download URL in composer.json: https://gitlab.com/api/v4/projects/23533789/packages/composer/archives/sjerdo/private-project.zip?sha=76b4344d0ab1491807c8bace4aee112bf09e843d

Alternative download URL which does require authentication: https://gitlab.com/api/v4/projects/23533789/repository/archive.zip?sha=76b4344d0ab1491807c8bace4aee112bf09e843d

What is the current bug behavior?

When I download the archive without authentication, download is not prohibited.

ZSH
% curl 'https://gitlab.com/api/v4/projects/23533789/packages/composer/archives/sjerdo/private-project.zip?sha=76b4344d0ab1491807c8bace4aee112bf09e843d' --output response.zip  
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  
                                 Dload  Upload   Total   Spent    Left  Speed  
100   709  100   709    0     0   2037      0 --:--:-- --:--:-- --:--:--  2037  
% unzip archive.zip  
   creating: private-project-76b4344d0ab1491807c8bace4aee112bf09e843d-76b4344d0ab1491807c8bace4aee112bf09e843d/  
 extracting: private-project-76b4344d0ab1491807c8bace4aee112bf09e843d-76b4344d0ab1491807c8bace4aee112bf09e843d/composer.json    
What is the expected correct behavior?

When I download the archive without authentication, download should be prohibited.

ZSH
% curl 'https://gitlab.com/api/v4/projects/23533789/packages/composer/archives/sjerdo/private-project.zip?sha=76b4344d0ab1491807c8bace4aee112bf09e843d'  
{"message":"404 Project Not Found"}  
Relevant logs and/or screenshots

Publishing the package:

ZSH
% curl --data tag=1.0.0 "https://__token__:<TOKEN>[@]gitlab.com/api/v4/projects/23533789/packages/composer"                                        
{"message":"201 Created"}  

Alternative URL does check authentication:

ZSH
% curl 'https://gitlab.com/api/v4/projects/23533789/repository/archive.zip?sha=76b4344d0ab1491807c8bace4aee112bf09e843d'                       
{"message":"404 Project Not Found"}  
Output of checks

This bug happens on GitLab.com

Results of GitLab environment info

n/a

Impact

Attacker can download private repository files without authorization.

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

Likely the Composer package archive endpoint did not enforce project authorisation, unlike the equivalent repository archive endpoint.

Impact

An unauthorised user who obtains the dist download URL or the project ID, package name and commit hash could download private repository files.

What the attacker needed

Private project with a published Composer package; attacker knows the dist URL or project details

How it was found

  1. Create a private group and a private project in it.
  2. Add a composer.json file and create a tag.
  3. Create a personal access token with api access and publish the Composer package using the API.
  4. Install the package in a blank Composer project and obtain the dist URL from composer.lock.
  5. Download the zip from the dist URL without authentication.

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 private project on GitLab should only let authorised people see its files. The report found that a special download link for a Composer package skipped the login check, so anyone with the link could get the files. Composer is a tool for managing code libraries, and the link is normally stored in a lock file.

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.