# CSRF protection on OIDC login is broken

OIDC login callback returned the expected CSRF state in a JSON error response, letting an attacker bypass state validation and forge login callbacks.

- Payout: $500
- Severity: medium
- Program: Nextcloud
- Found by: mikaelgundersen
- Disclosed: 2023-04-04
- CVE: CVE-2023-28848
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1878381
- Library page: https://bugbountylibrary.com/r/h1%3A1878381
- Tags: area:web domain:web impact:integrity kind:bounty platform:hackerone sev:medium tech:oauth tech:oidc technique:source-review vuln:csrf vuln:info-disclosure

**Target:** Nextcloud user_oidc app, OIDC/ID4ME login callback endpoint
**Root cause:** On state mismatch the LoginController returns a JSON error that includes the expected state value, leaking the CSRF token to the attacker.
**Steps:**
1. Trigger OIDC login flow to obtain a session
2. Send callback request with an incorrect `state` parameter
3. Read the JSON error response which contains the expected `state`
4. Replay callback with the leaked correct `state` to pass CSRF validation
**How found:** Code review of LoginController.php lines 336-344 revealed a debug leftover returning the expected state in the error response; noted Id4meController has near-identical code.
**Exploitation:** Attacker initiates a victim's OIDC flow or observes a callback, submits a wrong state, harvests the expected state from the JSON error, then submits a forged callback with the valid state to defeat CSRF protection.
**Insight:** When auditing OIDC/OAuth flows, check error/debug responses for leaked state, nonce, or PKCE verifier values—debug leftovers in callback handlers often echo the very secret meant to prevent CSRF.

