Skip to content
SSRF Disclosed report Advanced

Arbitrary file read during project import

A misused JSON schema validator during project import allowed an attacker to read arbitrary files on the GitLab server, leaking about 250 bytes per file. The same flaw also acted as an SSRF, and on self-hosted instances could expose the shell token used to mint admin access tokens.

saltyyolk Follow

Originally disclosed on HackerOne

Bounty$16,000 Critical View original
  • Triaged in 2 hours
  • Fixed in 15 days
  • Paid in 2 hours
  • Disclosed after 2 months

NOTE! Thanks for submitting a report! Please replace all the (parenthesized) sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!

Summary

A mis-usage of json schema validator could be used by an attacker to read any file in GitLab server. The issue allows the attacker to leak ~250 bytes of data of any file. At the same time, as the root cause of the issue here is 'open-uri'. It's an SSRF issue at the same time.

Steps to reproduce

  1. Use the import feature of gitlab.com to import the attached import.tar.gz as 'GitLab export' ███████
  2. Wait the import process to finish
  3. Access URL: https://gitlab.com/api/v4/projects/PROJECT_ID/import where PROJECT_ID is the id of the imported project, which could be found in the home page of the project.
  4. The connection information of gitlab's production database is in the output, as attached.

Impact

For GitLab.com, this issue could be used to leak some critical credentials. I went through the charts in https://gitlab.com/gitlab-org/charts/gitlab/-/tree/master/charts/gitlab/charts/sidekiq/templates. It seems that there're a bunch of juicy credentials could be leaked with this method, including Rails secret_key_base, database credentials and GitLab's smtp credentials. The object storage service account credential is limitedly accessed because of the 250 bytes limitation.

For self-hosted GitLab instances, this issue could cause more severe problems since most of self-hosted GitLab instances has sidekiq running with gitlab-rails & gitlab-shell. So .gitlab_shell_token could be easily downloaded and be used to access internal APIs such as '/api/v4/internal/personal_access_token', which could issue an private access token of an admin of someone else.

Relevant logs and/or screenshots

███ ███████

Output of checks

This bug happens on GitLab.com

Impact

For GitLab.com, this issue could be used to leak some critical credentials. I went through the charts in https://gitlab.com/gitlab-org/charts/gitlab/-/tree/master/charts/gitlab/charts/sidekiq/templates. It seems that there're a bunch of juicy credentials could be leaked with this method, including Rails secret_key_base, database credentials and GitLab's smtp credentials. The object storage service account credential is limitedly accessed because of the 250 bytes limitation.

For self-hosted GitLab instances, this issue could cause more severe problems since most of self-hosted GitLab instances has sidekiq running with gitlab-rails & gitlab-shell. So .gitlab_shell_token could be easily downloaded and be used to access internal APIs such as '/api/v4/internal/personal_access_token', which could issue an private access token of an admin of someone else.

The original report as published on HackerOne, by saltyyolk. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

GitLab's project import feature lets a user bring an existing project into an instance, including gitlab.com, by uploading an export archive. The archive is processed by a background worker (Sidekiq) that reads the exported data and reconstructs the project. The import runs server-side, so any file the worker can reach on the host is potentially within reach of whatever the import code chooses to open.

This report describes a path traversal and file read that abuses the import pipeline. The researcher notes that the same root cause, open-uri, also makes it an SSRF issue. The affected asset is gitlab.com, and the bug was reported through HackerOne and disclosed on 24 May 2021. The weakness is classified as path traversal, with critical severity and a bounty of 16,000 USD.

Setup

The only precondition stated is the ability to use the import feature of gitlab.com to import an archive as a 'GitLab export'. The researcher attached an archive named import.tar.gz to the report. No account role, tooling or version information is given.

Finding it

The researcher identified that a JSON schema validator was being mis-used during import, and that this mis-use could be turned into reading arbitrary files on the GitLab server. The read is partial: the issue leaks roughly 250 bytes of data from any file. The researcher also identified open-uri as the root cause, which is why the same bug is simultaneously an SSRF issue.

Exploitation

Step 1: Import the crafted archive

Use the import feature of gitlab.com to import the attached import.tar.gz as a 'GitLab export'.

Text
import.tar.gz

The archive is the payload; the report does not describe its contents. The report does not describe the archive's contents.

Step 2: Wait for the import to finish

The import is processed asynchronously, so the researcher waits for the import process to complete before querying the result.

Step 3: Query the import status endpoint

Access the following URL, where PROJECT_ID is the id of the imported project, which can be found on the project's home page:

The connection information of GitLab's production database appears in the output.

Step 4: Read the leaked data

The researcher attached the output to the report. The leak is bounded to about 250 bytes per file, which is enough for credentials but not for larger files such as an object storage service account credential.

Root cause

The report attributes the bug to a mis-usage of a JSON schema validator, with open-uri as the underlying mechanism.

Impact

On gitlab.com, the issue could be used to leak critical credentials. The researcher reviewed the charts under https://gitlab.com/gitlab-org/charts/gitlab/-/tree/master/charts/gitlab/charts/sidekiq/templates and concluded that a number of credentials could be leaked this way, including the Rails secret_key_base, database credentials and GitLab's SMTP credentials. The object storage service account credential is only partially accessible because of the 250 byte limit.

On self-hosted GitLab instances the impact could be more severe, since most self-hosted instances run Sidekiq alongside gitlab-rails and gitlab-shell. In that setup .gitlab_shell_token could be downloaded and used to access internal APIs such as /api/v4/internal/personal_access_token, which could issue a private access token for an admin or for another user.

Fix

The direction implied by the root cause is to stop the import path from resolving attacker-controlled URIs and paths, and to constrain the validator so it cannot open local files or make outbound requests.

Variants to test

  1. Other importers and exporters that parse attacker-supplied archives and report status back to the user. A positive result is file content appearing in a status or error response.
  2. Any feature that validates JSON against a schema supplied by the user. A positive result is a $ref or similar construct causing a local file read or an outbound request.
  3. Endpoints that echo import or processing errors. A positive result is a stack trace or partial file content in the response body.
  4. Self-hosted instances where Sidekiq shares a host with gitlab-rails and gitlab-shell. A positive result is reading .gitlab_shell_token and using it against /api/v4/internal/personal_access_token.

Hunting notes

This kind of bug tends to hide in asynchronous import and migration pipelines, where user-supplied archives are parsed by background workers and the result is surfaced through a status endpoint. During recon, look for import features that accept an archive, for status endpoints under /api/v4/projects/PROJECT_ID/import, and for any JSON schema validation applied to user data. The signal is a status response that contains more than the expected metadata. The researcher demonstrated impact by reading production database connection information and by reviewing the deployment charts for reachable credentials.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

GitLab is a website where teams keep and share code. One of its features lets you move a project from somewhere else into GitLab by uploading a single packed file, called an export archive. GitLab unpacks that file on its own servers and rebuilds the project from it.

The researcher found that a specially built archive could make GitLab open a file on its own server that the attacker was never meant to see, and then show a small piece of that file back to the attacker. The piece is small, about 250 bytes, but 250 bytes is plenty when what you are after is a password or a secret key.

The same flaw has a second face: the underlying mechanism, called open-uri, can also be pointed at other machines, so the bug is also an SSRF issue (a way to make the server fetch something on the attacker's behalf).

The bug was reported through HackerOne, a platform where security researchers report problems to companies. It affected gitlab.com, was rated critical, and earned a bounty of 16,000 USD. It was disclosed on 24 May 2021. The weakness is classified as path traversal, which means tricking a program into stepping outside the folder it was supposed to stay in.

Context

To follow this, you need a few ideas from zero.

  • Import feature: a button in GitLab that says, in effect, "take this packed project and set it up here". You give it a file, GitLab does the rest.
  • Export archive: the packed file itself. Think of it as a suitcase with many labelled compartments inside. Here it is called import.tar.gz.
  • Background worker (Sidekiq): when a job would take too long to do while you wait, a website hands it to a helper program running quietly in the background. Sidekiq is GitLab's helper of that kind. It reads the archive and rebuilds the project.
  • Server-side: the work happens on GitLab's own computers, not in your browser. That matters because those computers hold files that ordinary users cannot see.
  • Path traversal: a program is supposed to open files in one folder, but a crafted input makes it open a file somewhere else, for example a settings file in a different directory. The everyday comparison is a hotel clerk told to fetch a guest's luggage from room 101, who can be tricked into going to room 999 instead.
  • SSRF (Server-Side Request Forgery): the attacker cannot reach some machine directly, but the website's server can, so the attacker makes the server do the fetching. The everyday comparison is asking a colleague who has a key to go and check a room for you.
  • open-uri: a piece of software that takes a location (a URI, which is a web address or a file location) and opens it. If you can control the location it is given, you can often control what it opens.
  • JSON schema validator: JSON is a common text format for data. A schema is a rulebook describing what that data should look like. A validator is the program that checks data against the rulebook. Some validators can be told to pull in extra pieces of rulebook from a location, and that is where things can go wrong.

The import runs on the server, so any file the background worker can reach is potentially within reach of whatever the import code chooses to open. That is the whole shape of the bug.

Setup

The only precondition the report states is the ability to use the import feature of gitlab.com to import an archive as a 'GitLab export'. The researcher attached an archive named import.tar.gz to the report. No account role, tooling or version information is given.

Finding it

The researcher worked out that a JSON schema validator was being mis-used during import, and that this mis-use could be turned into reading arbitrary files on the GitLab server. "Arbitrary" here just means "any file the server can reach", not a fixed list.

The read is partial: the issue leaks roughly 250 bytes of data from any file. To picture 250 bytes, a short line of text is around that size. That is enough to capture a password or a key sitting near the start of a settings file, but not enough to copy a large file.

The researcher also identified open-uri as the root cause, which is why the same bug is at the same time an SSRF issue: the same mechanism that opens a local file can be pointed at a network address.

Exploitation

Step 1: Import the crafted archive

Use the import feature of gitlab.com to import the attached import.tar.gz as a 'GitLab export'.

Text
import.tar.gz

This line is simply the name of the file the researcher attached. The report does not describe the archive's contents. The report does not describe the archive's contents, so we cannot say what is inside it.

Why this step: the import feature is the front door. It is the one place where an ordinary user is allowed to hand GitLab a file that GitLab will unpack and act on.

Step 2: Wait for the import to finish

The import is processed asynchronously, which means it does not finish while you watch. It is handed to the background worker and completed later. The researcher waits for the import process to complete before querying the result.

Why this step: the import is processed asynchronously, so the researcher waits for it to complete.

Step 3: Query the import status endpoint

Access the following URL, where PROJECT_ID is the id of the imported project, which can be found on the project's home page:

Line by line:

  • GET is the request method, the verb that means "give me this".
  • /api/v4/projects/PROJECT_ID/import is the address being asked for. An API is a way for programs to talk to a website without using the normal pages; here it is the part of GitLab that reports on an import. PROJECT_ID is a placeholder for the number that identifies the project you just imported, and you can find that number on the project's home page.
  • HTTP/1.1 is the version of the language used for web requests.
  • Host: gitlab.com says which website the request is for.

Why this step: the connection information of GitLab's production database appears in the output.

Step 4: Read the leaked data

The connection information of GitLab's production database appears in the output. The researcher attached the output to the report. "Production" means the live system that real users use, not a test copy.

The leak is bounded to about 250 bytes per file, which is enough for credentials but not for larger files such as an object storage service account credential. Credentials are the username and password style details a program uses to log in to another service. Object storage is a service for holding files, and its account credential is longer than the limit allows.

Root cause

The report attributes the bug to a mis-usage of a JSON schema validator, with open-uri as the underlying mechanism. In plain terms: the report attributes the bug to a mis-usage of a JSON schema validator, with open-uri as the underlying mechanism.

A schema reference is a pointer inside a rulebook saying "the rest of the rules are over there"; if the validator will follow such a pointer anywhere, it will open whatever it is pointed at.

Impact

On gitlab.com, the issue could be used to leak critical credentials. The researcher reviewed the charts under https://gitlab.com/gitlab-org/charts/gitlab/-/tree/master/charts/gitlab/charts/sidekiq/templates and concluded that a number of credentials could be leaked this way, including the Rails secret_key_base, database credentials and GitLab's SMTP credentials.

  • Charts: packaged configuration files that describe how GitLab is deployed, including where secrets are placed.
  • secret_key_base: a long secret value that a web framework uses to sign things, so that nobody can forge them. If it leaks, an attacker may be able to forge trusted data.
  • SMTP credentials: the login details GitLab uses to send email through a mail server.

The object storage service account credential is only partially accessible because of the 250 byte limit.

On self-hosted GitLab instances the impact could be more severe, since most self-hosted instances run Sidekiq alongside gitlab-rails and gitlab-shell. Self-hosted means the customer runs GitLab on their own machines rather than using gitlab.com. In that setup .gitlab_shell_token could be downloaded and used to access internal APIs such as /api/v4/internal/personal_access_token, which could issue a private access token for an admin or for another user.

  • .gitlab_shell_token: a secret file that lets one part of GitLab talk to another part and be trusted.
  • Internal API: an address meant only for GitLab's own components, not for the public.
  • Personal access token: a long password-like string a program uses instead of a user's real password. If one is issued for an admin, the attacker effectively becomes that admin.

Fix

The direction implied by the root cause is to stop the import path from resolving attacker-controlled URIs and paths, and to constrain the validator so it cannot open local files or make outbound requests.

Variants to test

These are the places a researcher would look next, once this pattern is known.

  1. Other importers and exporters that parse attacker-supplied archives and report status back to the user. A positive result is file content appearing in a status or error response.
  2. Any feature that validates JSON against a schema supplied by the user. A positive result is a $ref or similar construct causing a local file read or an outbound request. $ref is the schema's way of saying "look over there for the rest of the rules".
  3. Endpoints that echo import or processing errors. A positive result is a stack trace or partial file content in the response body. A stack trace is the internal list of steps a program was taking when it failed, which often reveals file paths and code details.
  4. Self-hosted instances where Sidekiq shares a host with gitlab-rails and gitlab-shell. A positive result is reading .gitlab_shell_token and using it against /api/v4/internal/personal_access_token.

Hunting notes

This kind of bug tends to hide in asynchronous import and migration pipelines, where user-supplied archives are parsed by background workers and the result is surfaced through a status endpoint. During recon, look for import features that accept an archive, for status endpoints under /api/v4/projects/PROJECT_ID/import, and for any JSON schema validation applied to user data. Recon means the early survey of a target to see what it offers.

The signal is a status response that contains more than the expected metadata. Metadata is the boring information about a job, such as whether it finished. If a status reply contains something that looks like a password or a file path, that is the signal.

The researcher demonstrated impact by reading production database connection information and by reviewing the deployment charts for reachable credentials.

Glossary

  • API: a way for programs to talk to a website directly, without the normal pages.
  • Archive: a single file that packs many files inside it.
  • Asynchronous: work that finishes later in the background rather than while you wait.
  • Background worker: a helper program that does long jobs quietly for a website.
  • Bounty: money paid by a company to a researcher who reports a valid security bug.
  • Charts: packaged configuration files describing how software is deployed.
  • Credentials: login details such as usernames, passwords and keys.
  • Critical severity: the highest rating a bug report usually gets, meaning very serious impact.
  • Export archive: the packed file that represents a project being moved.
  • HackerOne: a platform where researchers report bugs to companies.
  • Import feature: the GitLab button that takes a packed project and sets it up on the server.
  • Internal API: an address meant only for a system's own components.
  • JSON: a common text format for structured data.
  • JSON schema validator: a program that checks data against a rulebook describing its expected shape.
  • Metadata: descriptive information about something, such as whether a job finished.
  • Object storage: a service for storing files, often used for large amounts of data.
  • open-uri: software that opens a location given to it, whether a file or a web address.
  • Path traversal: tricking a program into opening a file outside the folder it was meant to use.
  • Payload: the malicious input an attacker supplies.
  • Personal access token: a long password-like string used by programs instead of a real password.
  • Production: the live system real users use, as opposed to a test copy.
  • Recon: the early survey of a target to see what it offers.
  • $ref: a pointer inside a JSON schema saying where the rest of the rules live.
  • secret_key_base: a long secret a web framework uses to sign data so it cannot be forged.
  • Self-hosted: software run on the customer's own machines rather than the vendor's.
  • Server-side: happening on the website's own computers, not in your browser.
  • Sidekiq: GitLab's background worker system.
  • SMTP credentials: the login details used to send email through a mail server.
  • SSRF: making a website's server fetch a location on the attacker's behalf.
  • Stack trace: the internal list of steps a program was taking when it failed.
  • URI: a location, such as a web address or a file path.
  • .gitlab_shell_token: a secret file that lets one part of GitLab trust another.

More by saltyyolk

View all

7 more disclosed reports, best first.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.