Request correlation and CSRF
A forged callback hands Ava's printer account an authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. for someone else's photos. This lesson follows that callback, the session-bound checks that stop it, how SameSite cookies behave on the way back from the photo service, and the other printer actions another site can trigger.
A callback Ava did not start
Most attacks on an OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. client try to take something from the person using it. The forged callback works the other way round. The attacker gives Ava Archer something, an authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. code for their own photo account, and lets her browser deliver it to the printer.
This is a case of cross-site request forgery, or CSRF, in which another site causes a person's browser to send a request they did not intend and the receiving application treats it as theirs. The defense rests on the pending transaction that Correlating requests and responses had the printer keep for each attempt, bound to the browser session that started it. The details of that binding decide whether it holds, and an innocent change to a cookieA small value that a website asks the browser to store and send back with later matching requests. Cookies commonly carry a session identifier, so the site can recognize an ongoing sign-in without your password. setting can quietly break it.
Against an OAuth client, the forged request that matters is the callback. Current guidance describes CSRF in this setting as a request to the client's redirect URI that did not come from the authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. in a flow the person started, but was planted by someone else.
All domains, codes, and cookie values in these examples are fictional. Here are the attacker's steps, with the values the printer would see:
- They sign in to the printer with an account of their own and select Connect photo account.
- At the photo service, they sign in to their own photo account and approve the printer.
- The photo service redirects their browser back with a code for the attacker's photos. The attacker stops the browser before it loads the callback and keeps the address.
- They put that address where Ava's browser will open it, such as a link in a message or a page that sends her browser there.
- Ava's browser requests the callback from printer.example and includes her printer session cookie, as it would for any visit to the printer.
The address the attacker kept looks exactly like an honest response:
https://printer.example/oauth/callback
?code=demo-attacker-code-5
&state=demo-attacker-state-2
&iss=https%3A%2F%2Fauth.photos.exampleA printer that looks up demo-attacker-state-2 in one list of every pending attempt finds the attacker's attempt. It exchanges the code with the verifier saved in that attempt, so PKCE passes as well, and the printer attaches the result to the session that delivered the callback, which is Ava's. Her printer account is now connected to the attacker's photo library.
The harm grows with what the connection is used for. Suppose the printer also saves each finished photo book to the connected library as a new album, using the photos.write scope. The photos Ava uploads from her computer for her next book end up in the attacker's account. And if the connection were also used to sign in, as OpenID ConnectAn identity layer on top of OAuth 2.0 that lets an application sign people in with an account at another service. It adds the ID token, standard claims, and discovery to the OAuth exchange. allows, the attacker could later sign in to Ava's printer account with their own photo account.
What stops the forged callback
Session-bound state. Ava's browser arrives with demo-attacker-state-2. The printer looks for that value among the pending attempts of her session and finds nothing, because the attempt belongs to the attacker's session. It stops before any tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. request. This is why state must also be unpredictable and used only once: an attacker who could guess the value for an attempt Ava had just started would get past this check.
A PKCE verifier held in the session. A printer that relies on PKCE would finish the callback with the verifier from Ava's pending attempt, if she had one. The attacker's code is bound to the challenge from the attacker's attempt, so the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect. rejects the exchange. If she had no pending attempt, there is no verifier to send and nothing to finish.
Current guidance lets a client rely on PKCE against forged callbacks in place of state, on one condition: the client must first confirm that the authorization server enforces it, for example from code_challenge_methods_supported, the member of the server's metadata that lists the PKCE methods it supports. The reason is a downgrade. The attacker can leave the challenge out of their own authorization request and receive a code with no binding at all. A server that then accepts the verifier the printer sends from Ava's attempt, without noticing that the code never had a challenge, completes the forged connection. Current guidance therefore says the authorization server must refuse a verifier presented for a code that was issued without a challenge.
OpenID Connect adds a third mechanism, a nonceA random value used for one attempt only. In OpenID Connect, the client sends one in its sign-in request and checks that the same value comes back inside the ID token, showing the token answers this attempt.: a random value the client puts in its request and then expects to find inside the ID tokenIn OpenID Connect, a signed JWT from the provider, addressed to one client, saying which account authenticated, when, and in answer to which request. It reports a sign-in and is not used to call APIs.. All three work the same way underneath: the response must match something held for the browser that started the attempt, and the careless printer above lost that link when it searched every attempt at once.
Forged Connect and Disconnect
The callback is not the only printer address another site can trigger. If Disconnect works as a plain link, such as https://printer.example/account/photos/disconnect, any page that sends Ava's browser there disconnects her photo account. She would find out in December, when her photo calendar fails to print.
A Connect address that takes its choices from parameters is riskier. A link to https://printer.example/connect?service=pixelvault&return_to=https://attacker.example/ starts a connection Ava did not choose, with a service the attacker picked and a destination the attacker set. If she has approved that service before, it may not show a consent screen at all, so the connection can complete without anything for her to notice.
Both are actions that change state, and both deserve the protection Backends for frontends gave the editor's own endpoints. Accept them only as POST requests, with SameSite cookies plus something another site cannot supply, such as a custom request header or a random value embedded in the printer's own form. Take the service from a fixed list of supported services, take the scope from the printer's own configuration, and validate any return destination. Disconnect should also revokeCancelling a credential, token, certificate, or authenticator before it would expire, so that it is no longer accepted. Whether every copy stops working at once depends on how services check it. the printer's tokens, as Token revocation described.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Confirm a callback is bound to the browser that started itWatch a real client refuse a callback whose state belongs to another browser, see a Strict attempt cookie go missing on the way back while a Lax one arrives, and see a forged sign-out refused.