Skip to content
Info disclosure Disclosed report Intermediate

Snippet JS template allows attacker to read a user's private snippets

The JavaScript template for snippets did not check whether the snippet was private, so appending .js to a private snippet ID returned its contents. An attacker could embed that script on a third-party site and read the private snippet's text.

jobert Follow

Originally disclosed on HackerOne

Bounty$300 Low View original
  • Triaged in 46 days
  • Fixed in 9 months
  • Paid in 45 days
  • Disclosed after 10 months

These days snippets can be embedded in a site other than the GitLab instance. An embed link is only generated for public snippets, as can be seen in the app/views/shared/snippets/_header.html.haml:

HAML
  - if public_snippet?
    .embed-snippet
      .input-group
        .input-group-btn
          %button.btn.embed-toggle{ 'data-toggle': 'dropdown', type: 'button' }
            %span.js-embed-action= _("Embed")
            = sprite_icon('angle-down', size: 12)
          %ul.dropdown-menu.dropdown-menu-selectable.embed-toggle-list

When visiting a public snippet, the embed link is shown at the top of the page, as such:

Screen_Shot_2018-05-07_at_8.01.10_PM.png
Screen_Shot_2018-05-07_at_8.01.10_PM.png From the original on HackerOne

As you can see, there's no entropy other than the snippet ID, which is an auto incrementing ID. It turns out that the controller itself doesn't limit the user to generate a JS template for a private snippet though. When appending .js to a private snippet, it'll return the JavaScript template, which contains the contents of a private snippet. This can be used to access a private snippet the attacker doesn't have access to from a 3rd party website.

To reproduce, sign in on gitlab.com and create a private snippet. For the sake of the PoC, let's create global snippet (not one that is tied to a project). It also works with a project, but in that case the attacker has to know the namespace and project path. Here's a PoC that'll call the alert function with the first line of a private snippet:

HTML
<html>
<head>
<style>
.gitlab-embed-snippets {
  display: none;
}
</style>
<script src="https://gitlab.com/snippets/1714319.js"></script>
</head>
<body>
  <script>
    alert(document.getElementById('LC1').innerHTML);
  </script>
</body>
</html>

Simply replace the snippet ID in the script tag with whichever snippet ID the private snippet has. Save the HTML and load it from any other location, e.g. localhost or some domain. You'll notice that it'll alert the first line of the contents:

Screen_Shot_2018-05-07_at_8.05.10_PM.png
Screen_Shot_2018-05-07_at_8.05.10_PM.png From the original on HackerOne

Impact

An attacker could enumerate IDs and inject multiple script tags to try to determine the contents of private snippets. Not knowing which snippet IDs belong to a user increases the attack complexity, which lowers the overall severity of the vulnerability. Private snippets may contain sensitive information that is not supposed to be viewable to anyone outside of the creator itself.

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

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 controller that renders the JavaScript template for snippets did not verify that the snippet was public before returning its contents.

Impact

An attacker could enumerate snippet IDs and inject multiple script tags to try to determine the contents of private snippets, though not knowing which IDs belong to a user increases complexity and lowers severity.

What the attacker needed

Attacker knows or guesses a private snippet ID

How it was found

  1. Sign in and create a private snippet.
  2. Note the snippet ID.
  3. Create an HTML page that loads the snippet's .js URL in a script tag.
  4. Open the HTML page from another location and read the snippet contents.

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 snippet is a small piece of saved text or code. The site could show a special JavaScript version of a snippet, and that version did not check if the snippet was private. So anyone who knew or guessed the snippet's number could load that JavaScript on another website and read the private text.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by jobert

View all

67 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.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.