liveBook · Manning

Cross-site request forgery

As explained in Secure APIs

Cross-site request forgery is an attack in which a victim's authenticated browser is induced to send an unintended request.

Cross-site request forgery (CSRF) tricks an authenticated user’s browser into sending an unintended authorization request. In OAuth, the attacker can obtain an authorization code and exchange it for an access token. section 7.4.1 section 10.3

A typical attack starts with a malicious link or website. If the user already has an active identity-provider session, the authorization step is skipped. An unconstrained redirect_uri can send the resulting code to the attacker’s server. section 7.4.1 section 10.3

Defend the authorization flow by:

  • Requiring an opaque, unguessable state value, binding it to the client’s request, and carrying it through every request and response until token exchange. section 7.4.1
  • Constraining redirect_uri values so attackers cannot use an open redirect to capture authorization codes. section 7.4.1
  • Apply FAPI’s additional session-integrity requirements when stronger protection against authorization-endpoint CSRF is needed. section 10.3
https://auth.example.com/authorize?response_type=code
&client_id=s6BhdRkqt3&redirect_uri=https://example.com&state=35ce

Use the authorization URL to inspect how a state value accompanies the client identifier and redirect URI. section 7.4.1

How Secure APIs covers it

How deep it goes
Traces the attack through authorization, redirection, and token exchange, then gives state and redirect-URI mitigations.
Examples
Uses malicious links, authorization URLs, active IdP sessions, redirect URIs, authorization codes, and access-token exchanges.
What it assumes
Assumes an active identity-provider session and familiarity with authorization requests, redirect URIs, authorization codes, and access tokens.
What you can do after
Apply state validation and constrained redirect URIs to reduce authorization-code and access-token hijacking.
How it connects
Connects CSRF with OAuth, authorization code flow, open redirects, state parameters, FAPI, OIDC, and ID tokens.

Also explained in

Compare how 5 books explain cross-site request forgery →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secure APIs. The section links point to the parts of the book it draws on.