Fix MFA bypass vulnerability

This commit is contained in:
gpt-engineer-app[bot]
2025-10-31 14:52:15 +00:00
parent dade374c2a
commit 4bbb2de0b5

View File

@@ -149,17 +149,31 @@ export default function Auth() {
const postAuthResult = await handlePostAuthFlow(data.session, 'password'); const postAuthResult = await handlePostAuthFlow(data.session, 'password');
if (postAuthResult.success && postAuthResult.data.shouldRedirect) { if (postAuthResult.success && postAuthResult.data.shouldRedirect) {
// Get the TOTP factor ID // MFA IS REQUIRED - we must show the challenge or sign out
const { data: factors } = await supabase.auth.mfa.listFactors(); const { data: factors } = await supabase.auth.mfa.listFactors();
const totpFactor = factors?.totp?.find(f => f.status === 'verified'); const totpFactor = factors?.totp?.find(f => f.status === 'verified');
if (totpFactor) { if (totpFactor) {
// Show MFA challenge
setMfaFactorId(totpFactor.id); setMfaFactorId(totpFactor.id);
setLoading(false); setLoading(false);
return; // Stay on page, show MFA modal return; // Stay on page, show MFA modal
} else {
// MFA is required but no factor found - FORCE SIGN OUT for security
console.error('[Auth] SECURITY: MFA required but no verified factor found');
await supabase.auth.signOut();
toast({
variant: "destructive",
title: "Authentication Error",
description: "Multi-factor authentication is required but not properly configured. Please contact support."
});
setLoading(false);
return;
} }
} }
// ONLY show success toast if MFA was NOT required
if (postAuthResult.success && !postAuthResult.data.shouldRedirect) {
// Verify session was stored // Verify session was stored
setTimeout(async () => { setTimeout(async () => {
const { data: { session } } = await supabase.auth.getSession(); const { data: { session } } = await supabase.auth.getSession();
@@ -176,6 +190,7 @@ export default function Auth() {
}); });
} }
}, 500); }, 500);
}
} catch (error) { } catch (error) {
// Reset CAPTCHA widget to force fresh token generation // Reset CAPTCHA widget to force fresh token generation