Skip to content
CSRF Disclosed report Intermediate

CSRF-Token leak by request forgery

The web app builds relative URLs from the browser's location pathname, so a crafted link with a leading double slash makes the app send requests to an attacker-controlled domain. This leaks the Rails authenticity token, enabling state-changing CSRF attacks.

naure Follow

Originally disclosed on HackerOne

Medium 6.3 View original
  • Triaged in 20 hours
  • Fixed in 5 months
  • Disclosed after 6 months

Hi,

I found the following issue in my own Gitlab installation. This is a request forgery that reveals the Rails authenticity_token remotely, which in turn allows mounting state-changing CSRF attacks.

Vulnerability

The web app code relies on location.pathname in a number of places to create new relative URLs.

Here is one: https://gitlab.com/gitlab-org/gitlab-ce/blob/f78ecda55d5431f9a74ab2892b516ecb45f24d80/app/assets/javascripts/environments/folder/environments_folder_view.js#L21

And below, it sends a request to such a URL: https://gitlab.com/gitlab-org/gitlab-ce/blob/f78ecda55d5431f9a74ab2892b516ecb45f24d80/app/assets/javascripts/environments/folder/environments_folder_view.js#L86

Now, a forged link containing //namespace/repo/ will make these URLs absolute because of the leading double slashes. I was able to create an attack.com namespace which translates to https://attack.com/repo/. The app will then send a request including the anti-CSRF token to an attacker controlled domain. Which it definitely should not, ever (see point 2. below).

Impact

A malicious web page and the coordinated server will be able to perform actions through the victim's browser in a second.

In addition, this opens up a new attack surface as the app will process untrusted replies as trusted content. There is high risk of injecting javascript somewhere, maybe here: https://gitlab.com/gitlab-org/gitlab-ce/blob/f78ecda55d5431f9a74ab2892b516ecb45f24d80/app/assets/javascripts/environments/components/environment_terminal_button.js#L33

Recommendations

Issues of this kind should be fixed globally, since the code is recent and developers are likely to introduce more document.location dependencies regularly.

  1. Validate or normalize requested URLs against //, /../, and co. This can be done in Rails or in JS, or both.

  2. Forbid cross-domain requests in all Vue.http and $.ajax helpers, like this one:

https://gitlab.com/gitlab-org/gitlab-ce/blob/f78ecda55d5431f9a74ab2892b516ecb45f24d80/app/assets/javascripts/vue_shared/vue_resource_interceptor.js#L21

Best regards, Aurel

The original report as published on HackerOne, by naure. 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 app constructs URLs from `location.pathname` without validating or normalising them, so a path starting with `//` is treated as an absolute URL to another domain.

Impact

A malicious page and coordinated server could perform actions through the victim's browser, and the app may process untrusted replies as trusted content, risking JavaScript injection.

What the attacker needed

Attacker can create a namespace; victim clicks a crafted link

The fix

Validate or normalise requested URLs against `//`, `/../`, and similar patterns, and forbid cross-domain requests in all `Vue.http` and `$.ajax` helpers.

How it was found

  1. Create a namespace named `attack.com` so the app generates a URL like `https://attack.com/repo/`.
  2. Craft a link containing `//namespace/repo/` that the victim visits.
  3. The app builds an absolute URL to the attacker's domain and sends a request including the anti-CSRF token.
  4. The attacker's server receives the token and can use it to perform state-changing actions.

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.

The app uses the current web address to build links to its own server. If an attacker tricks a user into visiting a specially crafted address, the app can be made to send a secret security token to the attacker's website. With that token, the attacker can then perform actions on the user's behalf.

What is CSRF?

Another site makes a signed-in user's browser perform an action they did not intend.

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 request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.