Users can create OAuth applications even if User OAuth applications is disabled by instance admin

⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.

HackerOne report #2058026 by js_noob on 2023-07-08, assigned to @dcouture:

Report | Attachments | How To Reproduce

Report

Summary

Hello team, a GitLab instance admin can disable OAuth applications for his instance which should block all users from creating OAuth applications. This is pretty obvious as the UI shows the following:

image.png

However, a user can still easily create group OAuth applications.

Steps to reproduce

As the instance admin:

  1. Spin up a GitLab instance
  2. Navigate to https://YOUR_DOMAIN/admin/application_settings/general#js-account-settings and disable User OAuth applications

image.png

  1. As a sanity check, verify that you can't create applications https://YOUR_DOMAIN/-/profile/applications

As any other user in that instance:

  1. Verify that you can't applications
  2. Create a new group
  3. Navigate to https://YOUR_DOMAIN/groups/GROUP/-/settings/applications, and verify that you can't create applications
  4. Send the following request, but change the vars according to your preferences (if you faced any issues constructing this request, take a look at the attached POC/video I used some workaround for this)
POST /groups/poc/-/settings/applications HTTP/2  
Host: gitlab-private.net  
Cookie: REDACTED
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8  
Accept-Language: en-US,en;q=0.5  
Accept-Encoding: gzip, deflate  
Referer: https://gitlab-private.net/groups/poc/-/settings/ci_cd  
Content-Type: application/x-www-form-urlencoded  
Content-Length: 347  
Origin: https://gitlab-private.net  
Upgrade-Insecure-Requests: 1  
Sec-Fetch-Dest: document  
Sec-Fetch-Mode: navigate  
Sec-Fetch-Site: same-origin  
Sec-Fetch-User: ?1  
Te: trailers

authenticity_token=ShGv3cieF3Hubv4jJrYEXBo_X5gbZPLf4uMRBHg7iDJFnIWhmKizn5g3_PN7LcIGmyV9kkvmmJKzfpy8dNAwEw&doorkeeper_application%5Bname%5D=My+App&doorkeeper_application%5Bredirect_uri%5D=https%3A%2F%2Fdocs.gitlab.com&doorkeeper_application%5Bconfidential%5D=0&doorkeeper_application%5Bconfidential%5D=1&doorkeeper_application%5Bscopes%5D%5B%5D=api  
  1. Verify the successful response (200 OK), now the HTML contains the necessary OAuth app info, either search in it or view it in a browser, it should look similar to the following

REDACTED

  1. At this point the application is created successfully bypassing the admin's setting, but if you want to confirm that this app works as expected, continue the steps
  2. Navigate to https://YOUR_DOMAIN/oauth/authorize?client_id=APP_ID&redirect_uri=https://docs.gitlab.com&response_type=code&state=test_state_123&scope=api (you might have to change vars if you changed them in step 7)
  3. Click authorize
  4. You should be redirected to a link similar to https://docs.gitlab.com/?code=authorization_code&state=test_state_123
  5. To get an auth token, send the following request
curl -X POST -d 'client_id=APP_ID&client_secret=APP_SECRET&code=CODE_FROM_STEP_12&grant_type=authorization_code&redirect_uri=https://docs.gitlab.com' https://YOUR_DOMAIN/oauth/token  
  1. The response should be similar to the following
{
    "access_token": "access_token",  
    "token_type": "Bearer",  
    "expires_in": 7200,  
    "refresh_token": "refresh_token",  
    "scope": "api",  
    "created_at": 1688831273  
}
  1. Now you can use the access_token to access the API, for example below
curl -X GET -H "Authorization: Bearer access_token" "https://gitlab-private.net/api/v4/projects/14"  
Examples/POC

REDACTED

Output of checks

I believe this also happens on gitlab.com but I can't verify.

Results of GitLab environment info
System information  
System:         Debian 11  
Proxy:          no  
Current User:   git  
Using RVM:      no  
Ruby Version:   3.0.6p216  
Gem Version:    3.4.13  
Bundler Version:2.4.14  
Rake Version:   13.0.6  
Redis Version:  6.2.11  
Sidekiq Version:6.5.7  
Go Version:     unknown

GitLab information  
Version:        16.1.1-ee  
Revision:       d3582d7719f  
Directory:      /opt/gitlab/embedded/service/gitlab-rails  
DB Adapter:     PostgreSQL  
DB Version:     13.11  
URL:            https://gitlab-private.net  
HTTP Clone URL: https://gitlab-private.net/some-group/some-project.git  
SSH Clone URL:  git@gitlab-private.net:some-group/some-project.git  
Elasticsearch:  no  
Geo:            no  
Using LDAP:     no  
Using Omniauth: yes  
Omniauth Providers: 

GitLab Shell  
Version:        14.23.0  
Repository storages:  
- default:      unix:/var/opt/gitlab/gitaly/gitaly.socket  
GitLab Shell path:              /opt/gitlab/embedded/service/gitlab-shell  

Impact

Users can create OAuth applications despite having them disabled by the instance admin, which allows other users to authenticate to the newly created app.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

REDACTED

How To Reproduce

Please add reproducibility information to this section:

Proposal

Based on additional discussion in this issue, we should verify that the Group OAuth applications are not managed by the User OAuth setting, and:

  • Remove the banner that indicates Group OAuth apps are disabled as they aren't controlled by the admin setting.
  • Update the User OAuth setting description label to state Allow users to register any application to use GitLab as an OAuth provider via their own account
Edited by Rohit Shambhuni