Summary
Plack::Middleware::OAuth through version 0.10 fails to bind OAuth 2.0 callback responses to the originating user session due to missing state parameter support.
As a result, attackers can perform login cross-site request forgery, causing a victim's session to be linked to the attacker's identity and access token whenever the victim processes a crafted OAuth callback.
Affected context
This vulnerability affects Perl applications that integrate OAuth 2.0 login using Plack::Middleware::OAuth's RequestTokenV2 and AccessTokenV2 flows.
It becomes relevant when the application relies on this middleware to initiate and complete provider logins, but does not add its own state parameter handling or callback correlation.
Environments where provider tokens or identities are persisted as account links are especially exposed, since incorrect associations can outlive the current session.
Exploit preconditions
- Attack surface: OAuth 2.0 authorization endpoints and redirect/callback URLs exposed by the application.
- Required access: Ability to initiate an OAuth login with the provider using the attacker's own account, and to induce the victim's browser to follow the resulting callback URL (e.g., via links, redirects, or embedded content).
- Trigger point: The victim's browser requests the OAuth callback endpoint carrying a valid authorization code obtained by the attacker, which the middleware accepts without session correlation.
- Why exploitation is possible: The middleware constructs OAuth authorization requests without a state parameter and processes callbacks without verifying that they correspond to the session that initiated the flow, so any valid code can be bound to any active session.
Why this happens
The underlying flaw is a missing anti-CSRF mechanism in the OAuth 2.0 login flow, mapping to CWE-352: Cross-Site Request Forgery.
RequestTokenV2 builds the provider redirect URL without a state value, and AccessTokenV2 exchanges the callback code for an access token and stores it in the session without verifying that this callback is tied to a specific, prior authorization request from that session.
This insecure pattern treats any successful OAuth callback as trustworthy, ignoring the need to bind the callback to the user's session and the original request, leaving the flow open to login CSRF and account-linking attacks.
Potential impact
- Victim sessions may be associated with an attacker's OAuth provider identity.
- Applications could incorrectly link victim accounts to attacker-owned provider accounts.
- Attackers can retain ongoing access to victim accounts via their own provider credentials.
- Audit trails and identity logs can be polluted with inaccurate user associations.
- Downstream services relying on provider tokens may expose victim data to the attacker.
General mitigation guidance
Defenses typically focus on binding OAuth authorization flows tightly to user sessions and enforcing anti-CSRF protections.
Common patterns include:
- Generating a cryptographically strong, per-request state value and storing it in the user's session before redirecting to the provider.
- Including the state parameter in the provider authorization request and validating it on callback, rejecting any mismatch or missing value.
- Ensuring that any access token or identity obtained on callback is only registered to the session that initiated the corresponding authorization request.
- Designing account-linking logic to require explicit user action in the correct session context, rather than auto-linking on any successful callback.
- Reducing trust in external identity assertions by layering additional application-side checks (e.g., step-up verification) before finalizing account association.
How teams detect issues like this
Detection efforts can focus on both code-level and behavioral indicators of insecure OAuth flows.
Potential approaches include:
- Static analysis rules that flag OAuth middleware or custom OAuth code that omits state parameter generation and validation.
- Code review checklists that explicitly require examination of authorization request construction and callback handling, looking for session-bound correlation.
- Security testing and automated integration tests that attempt to reuse authorization codes across different sessions to see if callbacks are incorrectly accepted.
- Policy enforcement in CI/CD pipelines requiring standard OAuth flow helpers or frameworks that implement state and CSRF protections by default.
- Runtime monitoring for unusual patterns, such as frequent account links or logins completed from callbacks not preceded by session-specific initiation events.

