Common Two-Factor Authentication Bugs and How to Catch Them

Two‑factor authentication (2FA) adds a critical barrier against credential theft, yet implementation flaws turn that barrier into a weak point that attackers can bypass or abuse. This guide walks thro

June 09, 2026 · 21 min read · Common Issues

Common Two-Factor Authentication Bugs and How to Catch Them

Two‑factor authentication (2FA) adds a critical barrier against credential theft, yet implementation flaws turn that barrier into a weak point that attackers can bypass or abuse. This guide walks through the most common 2FA bugs, shows how they appear to users, explains why they happen, and gives concrete steps to reproduce, detect, fix, and prevent each issue. The material is organized for engineers who need a reference they can bookmark, with a test matrix, manual and automated approaches, real‑world examples, and a short checklist you can paste into your CI pipeline.

---

Why 2FA Bugs Matter

When a login flow relies on a password plus a second factor, the overall security is only as strong as the weakest link in that chain. A flaw in the OTP generation, delivery, validation, or session handling can let an attacker:

These issues are not theoretical; they have appeared in production releases of banking apps, enterprise SSO portals, and consumer services. Detecting them early requires a combination of unit‑level checks, integration tests, and exploratory testing that mimics real user behavior—including the varied personas that autonomous QA platforms like SUSA can simulate.

---

Overview of a Typical 2FA Flow

Understanding the baseline helps you spot where things can go wrong. A typical TOTP‑based 2FA flow looks like this:

  1. Username/password submission → server validates credentials and creates a temporary session token (often marked pre‑2fa).
  2. Challenge generation → server creates a nonce, stores it tied to the temporary session, and sends the user a prompt to enter a six‑digit code.
  3. User enters OTP → client sends the code plus the temporary session token.
  4. Server verification → server recomputes the expected OTP using the shared secret and the current time step, checks the nonce for reuse, validates the code within the allowed window, and if successful upgrades the session to authenticated.
  5. Post‑login actions → the authenticated session is used for subsequent API calls; any attempt to reuse the pre‑2fa token is rejected.

Variations include push‑notification approvals, email‑based magic links, or backup codes, but the core security properties remain: *the OTP must be used once, must be time‑bound, must be tied to the specific login attempt, and must not be reusable after a successful login.*

---

Bug Pattern 1: Time‑Based OTP Drift and Clock Skew

Cause

TOTP algorithms (RFC 6238) derive the code from a shared secret and the current Unix time divided by a timestep (usually 30 seconds). If the server’s clock is significantly ahead or behind the user’s device, the computed OTP will not match, causing legitimate users to be locked out. Conversely, an overly generous validation window (e.g., accepting codes from ± 2 steps) can widen the attack surface for replay.

User Impact

Reproduction Steps

  1. Set up a test environment where you can manipulate the system clock (e.g., using faketime on Linux or adjusting the VM’s time).
  2. Register a TOTP secret for a test account.
  3. Shift the server clock forward by 45 seconds (1.5 timesteps).
  4. Attempt login with a freshly generated OTP from the authenticator app.
  5. Observe failure despite the code being valid for the user’s device.

Detection

Fix

Prevention

---

Bug Pattern 2: OTP Replay / Missing Nonce Enforcement

Cause

After a successful OTP validation, the server must ensure that the same code cannot be used again. Some implementations only check the OTP value against the expected value and neglect to store a nonce or a used‑code flag tied to the login attempt.

User Impact

Reproduction Steps

  1. Capture a valid OTP during a legitimate login (use a proxy like Burp Suite to log the request).
  2. Complete the login flow normally.
  3. Immediately replay the captured OTP request (same payload, same temporary session token) to the verification endpoint.
  4. Observe whether the server accepts the replay and grants a second authenticated session.

Detection

Fix

Prevention

---

Bug Pattern 3: Insecure Delivery Channel (SMS Interception, SIM Swap)

Cause

When the second factor is delivered via SMS, the security depends on the integrity of the mobile telecom layer. Vulnerabilities such as SIM‑swap social engineering, SS7 exploits, or malware that reads incoming SMS can give an attacker the OTP without needing the victim’s device.

User Impact

Reproduction Steps

*This pattern is harder to reproduce in a pure unit‑test setting because it relies on external telecom behavior. However, you can simulate the risk:*

  1. Configure the account to use SMS OTP delivery.
  2. Use a tool like SMS‑Getter (open‑source Android app) to forward incoming SMS to a controlled number.
  3. Trigger a login that sends an OTP via SMS.
  4. Verify that the forwarded message arrives at the attacker’s number and can be used to complete login.

Detection

Fix

Prevention

---

Bug Pattern 4: Missing Rate Limiting / Brute Force on OTP Entry

Cause

The OTP verification endpoint may lack limits on the number of attempts per session, per IP, or per account. An attacker can therefore try all 1,000,000 possible six‑digit codes (or a reduced set if they know the time window) until they hit the correct value.

User Impact

Reproduction Steps

  1. Obtain a valid temporary session token (by completing the password step).
  2. Write a script that sends OTP verification requests with sequential codes from 000000 to 999999.
  3. Monitor the response codes; a 200 OK or session upgrade indicates success.
  4. Note the number of requests required and any throttling responses (e.g., 429 Too Many Requests).

Detection

Fix

Prevention

---

Bug Pattern 5: Fallback to Less Secure Methods (Email Link, Backup Code) Bypass

Cause

Some services allow users to fall back to an alternative verification method if the primary 2FA fails (e.g., “Didn’t receive the code? Try email instead”). If the fallback method is not protected by the same rigor (no rate limiting, weak token, or predictable URL), an attacker can trigger the fallback and bypass the stronger factor.

User Impact

Reproduction Steps

  1. Begin a login flow and intentionally fail the OTP challenge (e.g., enter a wrong code).
  2. Observe whether the UI offers a fallback link or button (e.g., “Send code to email”).
  3. Trigger the fallback and complete the alternative verification (e.g., click a magic‑link sent to email).
  4. Verify that the resulting session grants the same privileges as a successful OTP login.
  5. Assess whether the fallback endpoint lacks rate limiting, uses predictable tokens, or does not invalidate after use.

Detection

Fix

Prevention

---

Bug Pattern 6: Improper Handling of Backup Codes

Cause

Backup codes are static strings meant for emergency access. If they are stored in plaintext, logged, or transmitted insecurely, they become a high‑value target. Additionally, if the service does not enforce one‑time use or does not invalidate the set after a certain number of uses, an attacker who obtains a single code can reuse it indefinitely.

User Impact

Reproduction Steps

  1. Generate a set of backup codes for a test account (usually via the account security page).
  2. Capture the HTTP response that returns the codes (intercept with a proxy).
  3. Verify whether the codes appear in plaintext in logs, response bodies, or emails.
  4. Use one code to log in successfully.
  5. Attempt to log in again with the *same* code; observe whether the server rejects it as used.
  6. Exhaust all codes and try a previously used code again to see if the server mistakenly re‑accepts it.

Detection

Fix

Prevention

---

Bug Pattern 7: Session Fixation After 2FA Success

Cause

After a user successfully completes the 2FA challenge, the application may retain the pre‑2fa session identifier and simply mark it as authenticated. An attacker who can force a victim to start a login session (e.g., via a link that sets a known session cookie) can then wait for the victim to complete 2FA and inherit the authenticated session.

User Impact

Reproduction Steps

  1. Obtain a valid session cookie (e.g., sessionid=attacker123) from the login page before any credentials are entered.
  2. Send the victim a link that includes this cookie (via URL parameter, same‑site cookie manipulation, or a cross‑site request that sets the cookie).
  3. Victim visits the link, enters username/password, and completes the 2FA challenge.
  4. Attacker uses the known session cookie to access protected resources.
  5. Verify that the attacker’s requests succeed without re‑prompting for credentials.

Detection

Fix

Prevention

---

Bug Pattern 8: Inconsistent UI State Leading to Phishing

Cause

The login page may display mixed messaging—for example, showing a “Enter your OTP” field while simultaneously presenting a “Forgot password?” link that triggers a password‑reset flow. If the UI does not clearly indicate which factor is being requested, an attacker can craft a look‑alike page that tricks the user into entering their OTP on a attacker‑controlled site, believing they are still on the legitimate service.

User Impact

Reproduction Steps

  1. Navigate to the login flow and capture the HTML of the OTP entry screen.
  2. Identify any elements that deviate from the expected branding (different logo, off‑domain action URLs, missing HTTPS indicators).
  3. Create a mirror page hosted on a controlled domain that replicates the OTP field but posts to an attacker’s endpoint.
  4. Send a phishing email or message with a link to the mirror page.
  5. Observe whether users (in a controlled test group) enter their OTP without noticing the discrepancy.

Detection

Fix

Prevention

---

Bug Pattern 9: Code Expiration Not Enforced Server‑Side

Cause

Some implementations rely on the client to enforce OTP expiration (e.g., showing a countdown timer) but fail to reject expired codes on the server. An attacker who records a valid OTP can then use it after the client‑side timer has expired, as long as the server still accepts it.

User Impact

Reproduction Steps

  1. Record a valid OTP from the authenticator app at time T.
  2. Wait until the client‑side countdown shows the code as expired (e.g., 45 seconds later).
  3. Submit the OTP to the verification endpoint.
  4. Verify whether the server accepts the code and grants access.

Detection

Fix

Prevention

---

Bug Pattern 10: Missing or Incorrect Cryptographic Binding (e.g., Not Verifying Signature)

Cause

When using push‑notification or QR‑code based 2FA (e.g., FIDO2, WebAuthn), the authenticator signs a challenge that the server must verify. If the server omits the signature check or verifies it against the wrong public key, an attacker can replay a previously captured signature or forge a response.

User Impact

Reproduction Steps

  1. Initiate a push‑notification based login and capture the signed challenge sent by the authenticator (via a proxy or debugging tool on the device).
  2. Replay the exact same signed payload to the verification endpoint after the original completed.
  3. Check whether the server accepts the replay and grants a session.
  4. Alternatively, tamper with the payload (e.g., change the username) and see if the server still accepts it due to missing signature verification.

Detection

Fix

Prevention

---

Bug Pattern 11: Inadequate Logging and Alerting for 2FA Failures

Cause

If failed OTP attempts are not logged with sufficient context (IP, user‑agent, timestamp, reason), abuse campaigns can go unnoticed. Likewise, missing alerts on anomalies (e.g., a sudden surge of failed attempts from a new geographic region) delay response.

User Impact

Reproduction Steps

  1. Generate a burst of incorrect OTP submissions (e.g., 20 attempts in 10 seconds) from a single IP.
  2. Check the service’s logs for entries corresponding to these attempts.
  3. Verify whether the log contains the IP address, the reason for failure (invalid code, expired, used nonce), and a timestamp.
  4. Confirm whether an alert (email, PagerDuty, etc.) is fired based on a threshold (e.g., > 5 failures/minute).

Detection

Fix

Prevention

---

Bug Pattern 12: Improper Handling of Device Registration / Trust

Cause

Some services allow users to “trust” a device after a successful 2FA login, skipping the second factor on subsequent logins from that device. If the trust token is predictable, poorly protected, or not tied to a strong device identifier, an attacker can clone or steal the trust token and bypass 2FA entirely.

User Impact

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free