2FA Bypass Through OAuth Misconfiguration: Patterns and Fixes

OAuth and "Sign in with" buttons can let users skip a site's two-factor authentication when the application treats the identity provider's login as complete without checking how the user authenticated, or when it links accounts by an unverified email address. Other flaws, such as loose redirect_uri matching or a missing state parameter, let attackers steal codes or log victims into attacker accounts.

Jul 26, 2025 - 17:16
Updated: 
103.7k

Active Directory & Identity Security in Cybersecurity & Ethical Hacking · Troubleshooting

Web & API Security, Security Tools, Authorized Labs & CTFs

2FA Bypass Through OAuth Misconfiguration: Patterns and Fixes

Quick answer: OAuth and "Sign in with" buttons can let users skip a site's two-factor authentication when the application treats the identity provider's login as complete without checking how the user authenticated, or when it links accounts by an unverified email address. Other flaws, such as loose redirect_uri matching or a missing state parameter, let attackers steal codes or log victims into attacker accounts. The fixes are in RFC 9700: exact redirect URI matching, PKCE, state or nonce checks, verified-email linking only, and enforcing your own MFA or checking the provider's acr and amr claims.

Key takeaways

  • A social login does not prove the user passed MFA unless you check for it.
  • Linking an OAuth identity to an existing account by email alone enables takeover.
  • Exact redirect_uri matching and PKCE block code theft.
  • Every route to a session (password, OAuth, password reset, magic link) must apply the same 2FA policy.
  • Test only on your own apps, labs or authorised bug bounty scopes.

Table of Contents

Why Can OAuth Weaken 2FA?

When a site offers both "email and password with 2FA" and "Sign in with Google", there are two doors into the same account. If the OAuth door creates a session directly, the account is only as strong as the user's login at the identity provider, which may have no MFA. Teams often add 2FA to the password flow and forget the others. For background on the protocols, read OAuth 2.0 and OpenID Connect explained.

Is There a Real-World Example?

The earlier version of this article described a "real-world" case we could not verify, so it has been replaced with the documented patterns below. Public bug bounty reports on platforms such as HackerOne include many OAuth account takeover findings; read disclosed reports directly rather than relying on summaries.

Which Misconfigurations Cause Bypass or Takeover?

PatternWhat goes wrongFix
OAuth login skips local 2FASession issued straight after callbackApply the same 2FA step after OAuth
No check of provider MFAApp trusts any IdP loginRequire acr/amr values showing MFA
Linking by unverified emailAttacker IdP account with victim's email logs in as victimLink only on email_verified from trusted IdPs, or require login first
Loose redirect_uriCode or token sent to attacker-controlled URLExact string match of registered URIs
Missing stateLogin CSRF; victim linked to attacker accountRandom state bound to session; nonce for OIDC
No PKCEIntercepted code can be redeemedPKCE with S256 (RFC 7636)
Implicit flow tokens in URLTokens leak via history and RefererAuthorization code flow only

How Would an Authorised Tester Check This?

  1. Create two test accounts you control, one with 2FA enabled.
  2. Log in to the 2FA account through each social provider. Does the app ask for the second factor?
  3. Create an identity provider account using the test account's email without verifying it. Does the app link or log in?
  4. In a proxy such as Burp Suite, change redirect_uri to a subdomain, path or encoded variant. Is it accepted?
  5. Remove or reuse the state parameter. Does the callback still succeed?
  6. Try password reset and magic-link flows. Do they create a full session without 2FA?

The OWASP OAuth 2.0 Cheat Sheet lists more checks.

What Should Developers Do?

  • Follow RFC 9700: authorization code flow with PKCE, exact redirect URIs, no implicit flow.
  • Decide per account whether OAuth login counts as one factor or two, and enforce it.
  • When you need MFA from the provider, request it (for example with acr_values) and verify the acr or amr claim (RFC 8176); use step-up challenges per RFC 9470 for APIs.
  • Require the user to log in to the existing account before linking a new social identity.
  • Validate ID token signature, issuer, audience, expiry and nonce with a maintained library.

What Does a Correct Server-Side Check Look Like?

A simplified Python example after the OIDC library has validated the ID token:

def after_oidc_login(claims, user, session):
    # claims: validated ID token claims (iss, aud, exp, nonce already checked)
    if not claims.get("email_verified"):
        raise PermissionError("email not verified by provider")

    amr = set(claims.get("amr", []))
    provider_did_mfa = bool(amr & {"mfa", "otp", "hwk", "swk"})

    if user.requires_2fa and not provider_did_mfa:
        session["pending_user"] = user.id      # not logged in yet
        return redirect("/2fa/verify")          # same 2FA step as password login

    session["user"] = user.id
    return redirect("/dashboard")

Not every provider returns amr; where it is missing, assume no MFA and require your own.

Where Can You Practise Legally?

PortSwigger Web Security Academy's OAuth labs are free and legal to attack. Also read MFA protocols and broken access control explained. WebAsha's web application security training covers OAuth testing hands on.

References

Frequently Asked Questions

Yes, if the app issues a session after the OAuth callback without applying its own 2FA or checking the provider did MFA.

OpenID Connect claims describing the authentication context and methods used, which can show whether MFA happened.

An attacker can create a provider account with the victim’s email and be logged in as the victim if the email is not verified.

It stops an intercepted authorization code being redeemed by anyone other than the client that started the flow.

Loose matching lets attackers send authorization codes or tokens to URLs they control.

The IETF Best Current Practice for OAuth 2.0 Security, published in January 2025.

No. RFC 9700 recommends the authorization code flow with PKCE instead.

PortSwigger Web Security Academy offers free OAuth labs that you are allowed to attack.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.