MFA / 2FA Bypass Vulnerabilities
Overview
Poorly implemented MFA can be bypassed through various techniques:
- Client-side MFA check: MFA validation happens in JavaScript that can be disabled
- Predictable OTP: TOTP/OTP generated with Math.random() instead of cryptographically secure RNG
- Missing MFA enforcement: Endpoints that allow direct access skipping the MFA step
- Long-lived OTP: OTP codes valid for too long (> 5 minutes)
- No attempt limit on OTP: Brute-forceable OTP codes
Detection Strategy
- OTP generation using
Math.random()orrand()instead of CSPRNG - MFA verification that can be bypassed by manipulating the
mfa_verifiedsession variable - Hardcoded backup codes in source
Remediation
- Use TOTP (RFC 6238) with a cryptographically secure library like
speakeasyorpyotp - Validate MFA server-side, never client-side
- Limit OTP attempts (max 3-5 before requiring restart)
- Keep OTP validity window to 30-60 seconds
Vulnerable (Node.js):
const otp = Math.floor(Math.random() * 1000000);
Safe (Node.js):
const speakeasy = require('speakeasy');
const token = speakeasy.totp({ secret: user.mfa_secret, encoding: 'base32' });