Ringkasan

Race condition dan OAuth misconfiguration adalah dua kelas kerentanan web yang sering muncul di aplikasi modern. Race condition mengeksploitasi concurrent request untuk memanipulasi state. OAuth misconfiguration mengeksploitasi kesalahan implementasi flow otentikasi/delegasi. Keduanya bisa menyebabkan account takeover, privilege escalation, dan data breach.

Cross-link: oauth2-oidc-dan-api-authorization-architecturerace-condition-web-exploitationapi-security-deep-diveweb-hacking-exploitation


Daftar Isi


Bagian 1: OAuth Misconfiguration

1. Redirect URI Bypass

Redirect URI adalah parameter paling kritis di OAuth. Jika validation longgar, attacker bisa mendapatkan authorization code.

GET /oauth/authorize?
  response_type=code&
  client_id=app123&
  redirect_uri=https://attacker.com/  # ❌ Bisa redirect ke attacker

Bypass Techniques:

# Subdomain manipulation
https://target.com.evil.com/oauth-callback
https://evil.com/target.com/oauth-callback
 
# Path traversal
https://target.com/oauth/../evil.com/callback
 
# Open redirect
https://target.com/oauth/callback?redirect=https://evil.com
 
# Wildcard abuse
https://evil.com/  # jika whitelist *.target.com
https://evil.com%40target.com/  # @ confusion

2. State Parameter Missing

State parameter adalah CSRF token untuk OAuth flow. Jika tidak ada, attacker bisa melakukan CSRF login.

# ❌ Tanpa state — attacker bisa:
# 1. Mulai OAuth flow dengan akun attacker
# 2. Dapatkan code
# 3. Buat korban mengakses redirect dengan code tersebut
# 4. Akun korban ter-link ke akun attacker
 
GET /oauth/authorize?response_type=code&client_id=app123

3. CSRF on OAuth Flow

Tanpa state parameter, CSRF pada OAuth memungkinkan attacker mengikat akunnya ke akun korban.

<img src="https://target.com/oauth/link?code=ATTACKER_CODE" />
<!-- Korban mengakses → akun korban ter-link ke akun attacker -->

4. Scope Escalation

Scope escalation terjadi ketika aplikasi meminta scope lebih tinggi dari yang seharusnya.

# Aplikasi minta scope: read_profile
# Attacker modifikasi jadi:
GET /oauth/authorize?scope=read_profile%20admin%20write_posts
# Jika server tidak validasi scope sesuai yang diregister → escalation

5. Token Leakage via Referer

# OAuth flow dengan implicit grant
# Token ada di URL fragment (#access_token=...)
 
# Jika halaman redirect mengandung resource external (gambar, script)
# Referer header bisa bocorkan URL lengkap (tanpa fragment)
# Tapi beberapa browser kirim path via Referer-Policy

6. PKCE Missing

// Authorization Code tanpa PKCE
// Attacker dengan akses ke authorization code bisa exchange ke token
// PKCE mencegah ini dengan code_verifier + code_challenge
 
// ❌ Vulnerable: Authorization Code tanpa PKCE
// ✅ Safe: Authorization Code + PKCE (S256)

Bagian 2: Race Condition OAuth

7. OAuth + Race Condition

Race condition bisa terjadi di beberapa titik OAuth flow:

# 1. Token redemption race — redeem code berkali-kali
# Biasanya 1 code cuma bisa 1x redeem.
# Tapi dengan race condition:
POST /oauth/token
code=AUTHORIZATION_CODE  # × 10 requests concurrent
# Jika tidak ada locking → 10 token valid dari 1 code
# 2. Account binding race
# Saat binding akun OAuth ke akun lokal
# Format: POST /oauth/bind?provider=google&code=CODE
 
# Race condition:
# Kirim 10 request binding bersamaan dengan user session yang berbeda
# → Multiple account binding → takeover

8. Defense

OAuth IssueDefense
Redirect URIExact match whitelist, jangan pakai regex
StateWajib state parameter dengan CSRF token
ScopeValidasi scope sesuai registrasi aplikasi
PKCEWajib S256 PKCE untuk public clients
Race conditionDatabase locking + idempotency key untuk token redemption

Referensi: PayloadsAllTheThings /Ref/PayloadsAllTheThings/OAuth Misconfiguration/