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.
Topic: Active Directory & Identity Security in Cybersecurity & Ethical Hacking · Troubleshooting
Also covers: Web & API Security, Security Tools, Authorized Labs & CTFs
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_urimatching 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?
- Is There a Real-World Example?
- Which Misconfigurations Cause Bypass or Takeover?
- How Would an Authorised Tester Check This?
- What Should Developers Do?
- What Does a Correct Server-Side Check Look Like?
- Where Can You Practise Legally?
- References
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?
| Pattern | What goes wrong | Fix |
|---|---|---|
| OAuth login skips local 2FA | Session issued straight after callback | Apply the same 2FA step after OAuth |
| No check of provider MFA | App trusts any IdP login | Require acr/amr values showing MFA |
| Linking by unverified email | Attacker IdP account with victim's email logs in as victim | Link only on email_verified from trusted IdPs, or require login first |
| Loose redirect_uri | Code or token sent to attacker-controlled URL | Exact string match of registered URIs |
| Missing state | Login CSRF; victim linked to attacker account | Random state bound to session; nonce for OIDC |
| No PKCE | Intercepted code can be redeemed | PKCE with S256 (RFC 7636) |
| Implicit flow tokens in URL | Tokens leak via history and Referer | Authorization code flow only |
How Would an Authorised Tester Check This?
- Create two test accounts you control, one with 2FA enabled.
- Log in to the 2FA account through each social provider. Does the app ask for the second factor?
- Create an identity provider account using the test account's email without verifying it. Does the app link or log in?
- In a proxy such as Burp Suite, change
redirect_urito a subdomain, path or encoded variant. Is it accepted? - Remove or reuse the
stateparameter. Does the callback still succeed? - 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 theacroramrclaim (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
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0