ESCALATED: 2FA requirement bypass using the API
GitLab's group-level requirement for two-factor authentication could be bypassed by using the API with a session cookie or a private token. An attacker with a valid session or token could access group resources and perform actions without setting up 2FA.
GitLab
Originally disclosed on GitLab
- Fixed in 12 months
- Disclosed after 12 months
HackerOne report #691592 by xanbanx on 2019-09-10, assigned to jmatos_bgtvf:
Hi GitLab Security team,
Summary
GitLab allows to require all users of a group to setup Two-factor authentication. The group owner can setup a grace period, and after that amount of time all group members who are not using 2FA yet are redirected to the personal 2FA settings page before being able continuing using GitLab.
However, this can be completely bypassed using the API. The same user can use the session cookie or a previously generated private token to access the API, in particular the group and all sub-resources, which actually mandate 2FA authentication for its members.
Using the session cookie, you can make all GET requests on the API. POST requests are not working due to CSRF protection. However, a previously generated private token can be arbitrarily used within the group.
Steps to reproduce
- Let
user-acreate a group, add some resources, e.g., a project with some issues - Go to
https://example.gitlab.com/groups/test-group-with-2fa/-/edit#js-permissions-settings, enableRequire all users in this group to setup Two-factor authenticationand setTime before enforcedto 0. This means, that 2FA is required immediately - As a second user
user-b, first generate a private token with API scope, i.e.,private-token-user-b - As
user-aadduser-bto the previously created group with developer access - As
user-byou will now immediately be redirected to the 2FA settings page when using GitLab through the browser - Extract the session cookie for
user-bfrom the browser - Perform the following API request:
curl --cookie "_gitlab_session=<session-cookie-user-b>" https://example.gitlab.com/api/v4/groups
You will receive a JSON response with all groups you have access to including the one requiring 2FA. You can then use the group id of that group to make further requests to get information of all sub-resources, e.g, projects, issues, etc...
- You can also use the private token to authenticate. This even allows to make arbitrary post requests, e.g., to create a project withing the group:
curl --request POST --Header "Private-token: <private-token-user-b>" https://gitlab.com/api/v4/projects?namespace_id=<namespace-of-group>&name=my-project
Impact
The restriction of 2FA can be completely bypassed using the API. Because GitLab's API is very powerful, almost all operations can bypass a 2FA requirement, thus making this settings almost useless.
What is the current bug behavior?
API access is allowed using the session cookie and the private token although the required two factor authentication is not enabled.
What is the expected correct behavior?
API access with session cookie and private token need to be rejected until a user sets up 2FA.
Output of checks
This bug happens on GitLab.com
Best regards,
Xanbanx
Impact
See above
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
Impact
The 2FA requirement could be completely bypassed via the API, allowing almost all operations to be performed without enabling 2FA, making the setting almost useless.
What the attacker needed
A GitLab account; membership in a group that requires 2FA; a private token with API scope or a session cookie
The fix
API access with session cookie and private token should be rejected until the user sets up 2FA.
How it was found
- Create a group and add resources such as a project with issues.
- Enable the group setting to require all users to set up two-factor authentication and set the grace period to zero.
- As a second user, generate a private token with API scope.
- Add the second user to the group with developer access.
- As the second user, observe being redirected to the 2FA settings page in the browser.
- Extract the session cookie and make an API request to list groups, or use the private token to make API requests including POST requests.
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) adds a second step to logging in, like a code from your phone. GitLab lets group owners require all members to use 2FA, but the API (a way for programs to talk to GitLab) did not check this requirement. So a user could skip setting up 2FA and still use the API to read or change group data.
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.