From 3f08dcb2037c865912d271ca57b8719c2255e6b8 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 00:47:34 +0000 Subject: [PATCH] Refactor: Simplify CAPTCHA bypass logic --- .env.example | 6 ++-- src/hooks/useAdminSettings.ts | 6 ---- src/hooks/useCaptchaBypass.ts | 21 ++++---------- src/pages/AdminSettings.tsx | 53 ++--------------------------------- 4 files changed, 10 insertions(+), 76 deletions(-) diff --git a/.env.example b/.env.example index 618c48a2..ef4279f5 100644 --- a/.env.example +++ b/.env.example @@ -15,9 +15,9 @@ VITE_TURNSTILE_SITE_KEY=your-turnstile-site-key VITE_CLOUDFLARE_ACCOUNT_HASH=your-cloudflare-account-hash # CAPTCHA Bypass Control (Development/Preview Only) -# This acts as a safety gate - even if admins enable bypass in settings, -# it will only work if this is set to 'true' -# MUST be 'false' or unset in production +# Set to 'true' to bypass CAPTCHA verification during authentication +# This is controlled ONLY via environment variable for simplicity +# MUST be 'false' or unset in production for security VITE_ALLOW_CAPTCHA_BYPASS=false # Novu Configuration diff --git a/src/hooks/useAdminSettings.ts b/src/hooks/useAdminSettings.ts index d03075c8..9da234de 100644 --- a/src/hooks/useAdminSettings.ts +++ b/src/hooks/useAdminSettings.ts @@ -78,11 +78,6 @@ export function useAdminSettings() { return settings?.filter(s => s.category === category) || []; }; - const getCaptchaBypassEnabled = (): boolean => { - const value = getSettingValue('auth.captcha_bypass_enabled', 'false'); - const cleanValue = typeof value === 'string' ? value.replace(/"/g, '') : value; - return cleanValue === 'true' || cleanValue === true; - }; const updateSetting = async (key: string, value: any) => { return updateSettingMutation.mutateAsync({ key, value }); @@ -185,6 +180,5 @@ export function useAdminSettings() { getAutoRefreshStrategy, getPreserveInteractionState, getUseRealtimeQueue, - getCaptchaBypassEnabled, }; } \ No newline at end of file diff --git a/src/hooks/useCaptchaBypass.ts b/src/hooks/useCaptchaBypass.ts index 1060f1ef..72ec1569 100644 --- a/src/hooks/useCaptchaBypass.ts +++ b/src/hooks/useCaptchaBypass.ts @@ -1,26 +1,17 @@ import { useEffect } from 'react'; -import { useAdminSettings } from './useAdminSettings'; export function useCaptchaBypass() { - const { getSettingValue } = useAdminSettings(); - - // Layer 1: Check if environment allows bypass - const environmentAllowsBypass = import.meta.env.VITE_ALLOW_CAPTCHA_BYPASS === 'true'; - - // Layer 2: Check if admin has enabled bypass - const adminEnabledBypass = getSettingValue('auth.captcha_bypass_enabled', false) === true || - getSettingValue('auth.captcha_bypass_enabled', false) === 'true'; - - // Both layers must allow bypass - const bypassEnabled = environmentAllowsBypass && adminEnabledBypass; + // Single layer: Check if environment allows bypass + const bypassEnabled = import.meta.env.VITE_ALLOW_CAPTCHA_BYPASS === 'true'; // Log warning if bypass is active useEffect(() => { if (bypassEnabled && typeof window !== 'undefined') { console.warn( '⚠️ CAPTCHA BYPASS IS ACTIVE\n' + - 'This should only be enabled in development/preview environments.\n' + - 'Verify VITE_ALLOW_CAPTCHA_BYPASS=false in production!' + 'CAPTCHA verification is disabled via VITE_ALLOW_CAPTCHA_BYPASS=true\n' + + 'This should ONLY be enabled in development/preview environments.\n' + + 'Ensure VITE_ALLOW_CAPTCHA_BYPASS=false in production!' ); } }, [bypassEnabled]); @@ -28,7 +19,5 @@ export function useCaptchaBypass() { return { bypassEnabled, requireCaptcha: !bypassEnabled, - environmentAllowsBypass, - adminEnabledBypass }; } diff --git a/src/pages/AdminSettings.tsx b/src/pages/AdminSettings.tsx index 9b504d86..5a999c4f 100644 --- a/src/pages/AdminSettings.tsx +++ b/src/pages/AdminSettings.tsx @@ -24,8 +24,7 @@ export default function AdminSettings() { error, updateSetting, isUpdating, - getSettingsByCategory, - getCaptchaBypassEnabled + getSettingsByCategory } = useAdminSettings(); if (roleLoading || isLoading) { @@ -436,15 +435,11 @@ export default function AdminSettings() { - + Moderation - - - Auth - Users @@ -493,50 +488,6 @@ export default function AdminSettings() { - - - - - - Authentication Settings - - - Configure authentication security, CAPTCHA, and login settings - - - - {getCaptchaBypassEnabled() && ( - - -
- -
-

- CAPTCHA Bypass is Currently Enabled -

-

- Authentication requests will not require CAPTCHA verification. - This should ONLY be enabled in development environments. -

-
-
-
-
- )} - {getSettingsByCategory('auth').length > 0 ? ( - getSettingsByCategory('auth').map((setting) => ( - - )) - ) : ( -
- -

No authentication settings configured yet.

-
- )} -
-
-
-