2FA bypass using git command
A group with 2FA enforced still allowed a member without 2FA to clone and push to its private projects using only their username and password over Git. An attacker with stolen credentials could read and write code despite the 2FA requirement.
GitLab
Originally disclosed on GitLab
- Fixed in 15 months
- Disclosed after 15 months
HackerOne report #898477 by fushbey on 2020-06-15, assigned to @jeremymatos:
I reported a 2FA bypass using the API, but I was told it was an intended behavior, I also added that we could bypass 2FA using git command, and I was asked to report it here.
Summary
If we make a group 2FA enabled, that means we want to restrict its access to users with 2FA enabled if they don't have that enabled, they are redirected to the page settings to enable it, they can't move elsewhere until they do it or they leave that group they are part of.
However, this can be bypassed with read and write access to the projects under the 2FA enabled group using the git command using the username and password, so no personal tokens involved here.
Steps to reproduce
We need two users, both are members of an example group. I used private groups and private projects.
1 - As "userA" Create a private Group.
2 - User A configures the Group to require 2fa, set "Time before enforced" to 0 to test this now.
3 - User A invites user B to the private Group, give him a role so he can push code(Developer minimum)
4 - User B tries to access Gitlab through the Web, you can see it is required to set up 2fa, you are always redirected to [2fa settings] page(https://gitlab.com/profile/two_factor_auth)
6 - UserB can, however, bypass this restriction using the git command without the personal access token, only using his username, and password, I used
https://gitlab.com/anothergroup1/spring-security-group/test-project as an example, you can see I succeed to clone AND push(read and write).
$ git clone https://gitlab.com/anothergroup1/spring-security-group/test-project
Cloning into 'test-project'...
Username for 'https://gitlab.com': MYUSERNAME
Password for 'https://[email protected]': MYPASSWORD
warning: redirecting to https://gitlab.com/anothergroup1/spring-security-group/test-project.git/
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 12 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), 926 bytes | 231.00 KiB/s, done.
laro at laro in ~
$ cd test-project/
laro at laro in ~/test-project on master
$ git checkout -b new-branch
Switched to a new branch 'new-branch'
laro at laro in ~/test-project on new-branch
$ nano README.md
laro at laro in ~/test-project on new-branch*
$ git add .
laro at laro in ~/test-project on new-branch*
$ git commit -m 'updated'
[new-branch 57c88e0] updated
1 file changed, 1 insertion(+), 1 deletion(-)
laro at laro in ~/test-project on new-branch
$ git push https://gitlab.com/anothergroup1/spring-security-group/test-project
warning: redirecting to https://gitlab.com/anothergroup1/spring-security-group/test-project.git/
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 260 bytes | 260.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for new-branch, visit:
remote: https://gitlab.com/anothergroup1/spring-security-group/test-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=new-branch
remote:
To https://gitlab.com/anothergroup1/spring-security-group/test-project
* [new branch] new-branch -> new-branch
laro at laro in ~/test-project on new-branch
Impact
If you want to enforce 2FA for users, that means you want to add an extra layer of security so user credentials that get compromised would not be able to be used to leak and push code, however, this does not happen with the git command.
Examples
(If the bug is project related, please create an example project and export it using the project export feature)
(If you are using an older version of GitLab, this will also help determine whether the bug has been fixed in a more recent version)
(If the bug can be reproduced on GitLab.com without violating the Rules of Engagement as outlined in the program policy, please provide the full path to the project.)
What is the current bug behavior?
Broken access control: allows users to read/write code only using credentials, no 2FA is enforced whatsoever.
What is the expected correct behavior?
if 2FA is enabled for a group to restrict access, a user should not be able to read nor write code unless he has 2FA enabled.
Impact
If you want to enforce 2FA for users, that means you want to add an extra layer of security so user credentials that get compromised would not be able to be used to leak and push code, however, this does not happen with the git command.
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 Git-over-HTTPS authentication path did not check the group's 2FA enforcement, only the web interface did.
Impact
A user with stolen credentials could read and write code in a 2FA-enforced group without having 2FA enabled, defeating the extra protection.
What the attacker needed
Two accounts; group with 2FA enforced; victim credentials (username and password)
How it was found
- As user A, create a private group.
- Configure the group to require 2FA and set the enforcement time to zero.
- Invite user B to the group with a role that allows pushing code.
- As user B, try to access GitLab through the web and observe the redirect to the 2FA settings page.
- As user B, use the git command with username and password to clone and push to a project in the group.
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.
Two-factor authentication (2FA) is an extra login step, like a code from your phone, on top of your password. A group owner can require all members to use 2FA. Here, a member who had not set up 2FA could still use the Git command-line tool with just their username and password to download and upload code, so the extra protection was skipped for that route.
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.