OAuth Flow Without a State Parameter

The OAuth client does not bind the sign-in response to the user's browser with a state value, so an attacker can make a victim complete a sign-in or account link of the attacker's choosing.

SeverityMedium
CVSS 3.15.4 CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N Open in the calculator
CVSS 4.05.3 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-352: Cross-Site Request Forgery (CSRF)
OWASP Top 10A01:2025 Broken Access Control
CategoryInsecure Design

Description

When a client application sends a user to an OAuth 2.0 or OpenID Connect authorisation server, it should include a state parameter holding an unguessable value tied to the user's session, and check on the user's return that the same value comes back before it accepts the authorisation code. This binds the response to the browser that started the flow. The client omits the parameter, uses a fixed or predictable value, or does not check it on return, and no other protection takes its place (PKCE, or in OpenID Connect a checked nonce, also prevents the attack when properly enforced).

Without that binding, the client's redirect endpoint is open to cross-site request forgery. An attacker starts a sign-in with their own account at the identity provider, stops before their authorisation code is used, and then makes the victim's browser load the client's redirect address with the attacker's code, for example through a link or a hidden image on a page the victim visits.

Where the flow is used for sign-in, the victim is silently signed in to the client as the attacker, and anything they then enter, such as personal details, payment information or documents, is stored in an account the attacker controls. Where the same redirect endpoint is used to connect a social or enterprise identity to an existing account, the attacker's external identity is linked to the victim's account, and the attacker can then sign in as the victim at will, which is an account takeover and would raise the severity. That form needs the victim to be signed in to the client when they visit the attacker's page; no other interaction is needed.

The weakness is identified by checking authorisation requests for a state value, and by replaying a redirect with the parameter removed, altered or taken from another session to see whether the client still accepts the code.

Remediation

Bind every authorisation response to the session that started it:

  • Generate a new unguessable state value (at least 128 bits from a cryptographically secure generator) for each authorisation request, store it in the user's session or a short-lived HttpOnly cookie, and send it with the request.
  • On the redirect back, reject the response unless state is present and exactly matches the stored value, then discard the stored value so it cannot be used again.
  • Use PKCE for every client and, in OpenID Connect, send a nonce and check it in the ID token. Both also bind the response to the browser that started the flow.
  • Where the client links external identities to existing accounts, ask the user to confirm the link, and notify the account owner whenever a new identity is linked.
  • Prefer a maintained OAuth or OpenID Connect client library, which handles state, nonce and PKCE correctly when configured to.

Confirm the fix by replaying the redirect with a missing, altered and reused state value, and with a code obtained in another session, and checking that each is rejected.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding