# Gitlab Pages token theft using service workers

Service worker on attacker.gitlab.io intercepts /auth OAuth2 callback to steal a Pages session cookie, which is not bound to subdomain, granting access to all victim's private Pages sites.

- Payout: $1,680
- Severity: medium
- Program: GitLab
- Found by: ehhthing
- Disclosed: 2022-06-08
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1439552
- Library page: https://bugbountylibrary.com/r/h1%3A1439552
- Tags: area:web domain:web impact:ato impact:internal-access kind:bounty platform:hackerone sev:medium tech:oauth technique:chained technique:recon vuln:access-control vuln:auth-bypass

**Target:** GitLab Pages OAuth2 /auth endpoint and session cookie validation
**Root cause:** gitlab-pages session cookies are not validated against the subdomain they were issued for, so a cookie obtained on one Pages subdomain is accepted on any other Pages subdomain the user can access.
**Steps:**
1. Create private-to-collaborators Pages project at `attacker.gitlab.io` and invite victim as collaborator.
2. Register a service worker on `attacker.gitlab.io` that passes all requests through except `/auth`, which it intercepts.
3. Attacker server requests a redirect URL + session cookie from `attacker.gitlab.io` to obtain valid OAuth2 `state`.
4. Redirect victim to that redirect URL; since victim is logged in, OAuth2 completes without interaction.
5. OAuth2 redirects to `attacker.gitlab.io/auth?code=...&state=...`; service worker captures code+state and exfiltrates to attacker server.
6. Attacker server replays code+state with original session cookie to `/auth` to obtain authenticated Pages session cookie.
7. Use stolen cookie: `curl -v --cookie '{cookie}' https://{victim}.gitlab.io/{private-project}` to access victim's private Pages sites.
**How found:** Observation that Pages session cookies lacked subdomain binding; hypothesized a service worker on an attacker-controlled Pages subdomain could intercept the /auth OAuth2 callback and replay it, bypassing the OAuth2 state CSRF protection by obtaining state from the attacker's own server first.
**Exploitation:** Attacker controls a Pages subdomain and a service worker on it, uses it to intercept the OAuth2 callback on /auth, then replays the code+state with the pre-obtained session cookie to mint an authenticated Pages cookie that is accepted cross-subdomain, yielding access to all private Pages sites the victim can reach.
**Escalation:** Single stolen cookie grants access to every private GitLab Pages site the victim has access to, not just the attacker's project.
**Insight:** When a platform issues per-subdomain session cookies, test whether the cookie is validated against the issuing subdomain; a service worker on an attacker-controlled subdomain can intercept OAuth callbacks on shared auth endpoints and replay code+state obtained from the attacker's own session.

