Skip to content
Info disclosure Disclosed report Beginner

Vulnerability in the doorkeeper gem allows any user to retrieve OAuth application client secret after authorizing

The doorkeeper gem's JSON endpoint for authorized OAuth applications returned all database columns, including the application's client secret, to any user who had authorized that application. An attacker could therefore obtain the secret and use it to authenticate users as the application and act as it.

GitLab

Originally disclosed on GitLab

  • Fixed in 2 months
  • Disclosed after 2 months

HackerOne report #808299 by stefansundin on 2020-03-02, assigned to @vdesousa:

Summary

I have discovered a vulnerability in the doorkeeper gem, and am disclosing the bug to GitLab in order to collect a bug bounty. I will disclose it to the gem authors in a few hours.

While discovering this bug, I have accidentally exposed the client secret for Gitter. I had already authorized Gitter previously, so it was very much accidental. With that out of the way, I will use Gitter as an example in this report. After patching the vulnerability, you should regenerate the client secret for Gitter.

After a user on GitLab has authorized an OAuth application, the user is able to retrieve the full application database record. This includes all database columns in the table that stores the OAuth application. In GitLab.com's case, this data: id, name, uid, secret, redirect_uri, scopes, created_at, updated_at, owner_id, owner_type, trusted, confidential.

Doorkeeper provides a page that lets you see what applications you have authorized, and it also has functionality to revoke access to the apps. This is available at /oauth/authorized_applications. On GitLab, this list is available on /oauth/applications, but the route for /oauth/authorized_applications still exists (but returns a 5xx error on GitLab). The gem also provides routes for API clients (i.e. /oauth/authorized_applications.json), and it does not filter the fields returned for applications, which means it returns all the attributes for the apps that you have authorized.

There is not a CVE number for this vulnerability yet, but I will obtain one after contacting the gem author.

Steps to reproduce

  1. Have a GitLab user.
  2. Authorize an OAuth application, for example Gitter (https://gitter.im/).
  3. Open https://gitlab.com/oauth/authorized_applications.json
  4. See the following response (secret partly redacted):
[{"id":113598,"name":"Gitter.im","uid":"e2803ae4f09cebdcff56813a0bfbb1a4f0b187355b509eb6d5367a07ad523762","secret":"e08cdf64xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","redirect_uri":"https://login.gitter.im/login/gitlab/callback","scopes":["api","read_user"],"created_at":"2018-03-27T21:43:32.100Z","updated_at":"2019-09-25T06:37:25.988Z","owner_id":1577466,"owner_type":"User","trusted":false,"confidential":false}]  

Impact

An attacker can authenticate users as part of the app and act as it. I don't think the attacker can get access to tokens previously issued to the app.

Monkeypatch fix

The vulnerability can be patched with this monkeypatch until a fixed version of the gem is released:

In config/initializers/doorkeeper.rb:

Doorkeeper::Application.class_eval do  
  def as_json(_options = {})  
    {  
      id: id,  
      name: name,  
    }  
  end  
end  

This will restrict the serialization to these fields.

Additional hardening

In Doorkeeper v5.1.0, they added the ability to hash application secrets. This would render any accidental exposure like this less harmful, since the database will only store the hash secret. Upgrade to this version and hash all existing secrets to take advantage of this.

Regenerate secrets

In Doorkeeper v5.2.2, it is easier to regenerate secrets thanks to this code that I contributed to the gem: https://github.com/doorkeeper-gem/doorkeeper/pull/1315

I think GitLab is using an older version of Doorkeeper, though. But for Gitter you can do it in a rails console as described in the PR.

Impact

They can obtain client secrets for any OAuth application that they can authorize for. This identifier is supposed to stay secret, as the name implies.

An attacker can then authenticate users as part of the app and act as it. I don't think the attacker can get access to tokens previously issued to the app.

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 gem serialised the whole application record to JSON without restricting which fields were exposed, so the secret column was included.

Impact

An attacker could obtain client secrets for any OAuth application they can authorize, then authenticate users as part of the app and act as it; the reporter does not think previously issued tokens are exposed.

What the attacker needed

A GitLab user account; authorize the target OAuth application

The fix

Restrict JSON serialisation to non-sensitive fields via a monkeypatch; optionally hash secrets and regenerate them.

How it was found

  1. Have a GitLab user account.
  2. Authorize an OAuth application such as Gitter.
  3. Open the JSON endpoint for authorized applications.
  4. Observe that the response includes the application's secret and other database fields.

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.

OAuth lets you sign in to a site using another account, and each app has a secret password (client secret) that proves its identity. The bug meant that after you approved an app, a page on the site showed you that secret, which should never be visible. With the secret, someone could pretend to be the app and act on its behalf.

What is Info disclosure?

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

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.