Non project members can view public projects Deploy Keys
The autocomplete endpoint for deploy keys did not check the current user's permissions, allowing non-project members to view deploy keys of public projects. An attacker could see the keys, which are normally restricted to project members with write access.
GitLab
Originally disclosed on GitLab
- Fixed in 43 days
- Disclosed after 43 days
HackerOne report #1600325 by jimeno on 2022-06-14, assigned to @nmalcolm:
Report | Attachments | How To Reproduce
Report
Summary
Non project member can view Deploy Keys of public projects while they shouldn't. REST API strictly forbids this behavior while the /-/autocomplete/* special endpoint allows it.
As you can see here in the official documentation, deploy keys can only be seen from Repository settings. An area to which non members do not have access.
Steps to reproduce
- Victim creates a public project with any dummy file
- Browse to settings -> repository -> deploy keys (not tokens, be careful!!)
- Create one with any contents, with write permissions
- As a different user who is NOT a project member, browse to the project page and copy the project identifier via the UI
- As this user, browse to
https://gitlab.com/-/autocomplete/deploy_keys_with_owners?project_id=[project-id]and notice how the keys are shown to you.
Impact
Non project members can view project deploy keys.
Examples
- Sign in to your GitLab SaaS account.
- Browse to
https://gitlab.com/-/autocomplete/deploy_keys_with_owners?project_id=37015326and you'll see Deploy Keys ofhttps://gitlab.com/jimen0/x(project ID is37015326).
What is the current bug behavior?
Deploy keys autocomplete endpoint just checks if the user can view the repository, not if they have write access to it.
This doesn't happen through the REST API:
$ curl -H 'Content-Type:application/json' -H "PRIVATE-TOKEN: ${PAT_ATTACKER}" "https://gl.jimenolabs.net/api/v4/projects/160/deploy_keys" -s | jq .
{
"message": "403 Forbidden"
}
Notice the difference in the code.
-
Autocomplete endpoint:
Ruby def deploy_keys_with_owners deploy_keys = DeployKey.with_write_access_for_project(project) # --> NOTICE HOW HERE THE KEYS ARE FETCHED WITHOUT TAKING INTO ACCOUNT THE CURRENT USER render json: DeployKeys::BasicDeployKeySerializer.new.represent( deploy_keys, { with_owner: true, user: current_user } ) end -
Ruby get ":id/deploy_keys" do keys = user_project.deploy_keys_projects.preload(deploy_key: :user) present paginate(keys), with: Entities::DeployKeysProject end
What is the expected correct behavior?
Autocomplete endpoint takes current_user into account when fetching the project keys.
Relevant logs and/or screenshots
N/A.
Output of checks
This bug happens on GitLab.com.
Results of GitLab environment info
root@gl:/# gitlab-rake gitlab:env:info
System information
System:
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.7.5p203
Gem Version: 3.1.4
Bundler Version:2.2.33
Rake Version: 13.0.6
Redis Version: 6.2.6
Sidekiq Version:6.4.0
Go Version: unknown
GitLab information
Version: 15.0.1-ee
Revision: d69f38d4a95
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 12.10
URL: https://gl.jimenolabs.net
HTTP Clone URL: https://gl.jimenolabs.net/some-group/some-project.git
SSH Clone URL: [email protected]:some-group/some-project.git
Elasticsearch: no
Geo: no
Using LDAP: no
Using Omniauth: yes
Omniauth Providers: auth0
GitLab Shell
Version: 14.3.0
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Impact
Non project members can view project deploy keys.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
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 autocomplete endpoint fetched deploy keys without considering the current user's permissions, only checking if the user could view the repository.
Impact
Non-project members can view deploy keys of public projects.
What the attacker needed
A public project with deploy keys; Attacker has any GitLab account
The fix
The autocomplete endpoint should take the current user into account when fetching project keys.
How it was found
- Victim creates a public project with any dummy file
- Browse to settings -> repository -> deploy keys
- Create one with any contents, with write permissions
- As a different user who is NOT a project member, browse to the project page and copy the project identifier
- As this user, browse to the autocomplete endpoint with the project ID and notice the keys are shown
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.
Deploy keys are special SSH keys that let a server or service access a Git repository. Normally, only project members with write access can see them. Here, a different part of the website (an autocomplete feature) forgot to check who was asking, so anyone could see the keys of a public project.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.