← OAuth / OIDC lesson
IdentityOAuth / OIDCAdvanced40 min+150 XP

The Token in the Fragment

The Fiscal SSO authorization server has a flawed redirect_uri policy or token flow. Make the victim bot authorize the attacker origin, steal the code or token, and read the protected API secret.

“The login button trusted any redirect that started with the right domain, so the authorization code arrived at the attacker's callback.”

RFC 6749: The OAuth 2.0 Authorization FrameworkRFC 6750: Bearer Token UsageRFC 7636: Proof Key for Code Exchange (PKCE)RFC 9700: OAuth 2.0 Security Best Current PracticeOpenID Connect Core 1.0
The story
OAuth delegates authorization, not authentication. The authorization server makes a decision about a resource owner and hands a code or token to a client. Every weak comparison of redirect_uri, missing state, reusable code or accepted implicit token moves that handoff to an attacker-chosen origin.

The authorization endpoint sends credentials to whatever redirect_uri passes validation. Prefix matching, suffix matching, path-only checks and open redirects on the client let an attacker satisfy the check while receiving the code elsewhere. Without state binding, a victim can be logged into the attacker's account. Without PKCE or code binding, a stolen code can be exchanged. Implicit flow puts the token in the fragment, where attacker JavaScript reads it directly.

Your objective
  • Inspect the authorization request
  • Bypass the redirect_uri policy
  • Steal the code or implicit token at the attacker origin
  • Read /api/me and capture the flag
Boundary under test

Browser to client application

Field guide · request anatomy

Where to look before you type a payload

01Request

The client sends the browser to /authorize with client_id, redirect_uri, scope, state and response_type.

02Decide

The authorization server authenticates the user, checks consent and validates the redirect_uri against its registration.

03Redirect

The server sends a code or token to the redirect_uri. A weak comparison or open redirect sends it to the attacker.

04Exchange

The client posts the code and client credentials or PKCE verifier to /token in exchange for an access token.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Start at the client page and capture the exact authorize request, including redirect_uri, state and response_type.

Hint 2

The lab tells you which redirect_uri validation mode is active; look for the comparison that is weaker than exact matching.

Hint 3

The implicit flow is enabled. Request response_type=token and read the fragment on the attacker origin.

Hint 4 · near the answer

Exchange the code at /oauth/token, then call /api/me with the bearer token to capture the flag.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — The Token in the Fragment

- Family: OAuth / OIDC
- Lab ID: web-oauth-implicit-token
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "The Token in the Fragment" and record the entry point, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects the entry point, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: Report http://attacker.lab.localhost:3001/attack to the bot. The attacker page builds the malicious authorize URL and exchanges the result for the API secret.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: the redirect_uri parameter.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • The redirect_uri is reflected in an error page but the authorization server refuses to redirect there.
  • The attacker can change redirect_uri only for a client they own, with no victim consent or data.
  • State is missing but the flow is same-site and the impact is limited to a self-login, not another user's account.

Regression tests to name

  • Exact redirect match: The authorization server rejects the request before issuing a code
  • State is required: The client rejects the response and does not establish a session
  • PKCE binding: The token endpoint rejects the exchange
The defender's move
  • Compare redirect_uri with an exact registered value, including scheme, host, port and path; reject everything else.
  • Require and validate state, bind codes to client and redirect_uri, enforce PKCE S256 for public clients, and use one-time codes.
  • Prefer authorization code with PKCE; disable implicit and password grants for browser clients.
  • Keep access tokens out of URLs, use short lifetimes and sender constraints, and validate issuer, audience and nonce in OIDC.
See the secure-code pattern and all 4 regression tests →
الخلاصة

OAuth تفويض وليست مصادقة بحد ذاتها. الخطر الأكبر أن يقرر خادم التفويض إرسال الكود أو التوكن إلى عنوان يتحكم به المهاجم. تحقق من redirect_uri بمطابقة تامة، واشترط state وPKCE، واربط الكود بالعميل والعنوان، وأوقف implicit flow، وتحقق من issuer وaudience وnonce. لا تضع التوكنات في الروابط، واجعل الأعمار قصيرة.