fix: resolve 20 audit findings and stabilize BFF proxy integration
Summary of Changes
This PR addresses and resolves all 20 audit findings identified in the frontend code review according to AGENTS.md standards, removing all mock fallbacks, securing application origins, improving accessibility, and ensuring 0 TypeScript errors.
Key Improvements
1. Service Layer & State Integrity (Findings 001, 002, 006)
-
Removed All Mock Fallbacks: Completely eliminated
MOCK_arrays and module-scoped mutable variables (localSchedules,localApiKeys,localWebhooks) fromcrawl-schedule.service.tsanddeveloper.service.ts. - Proper Error Propagation: Mutating and reading operations now re-throw server errors instead of silently swallowing them or generating fake responses.
2. Hooks & Performance (Findings 004, 005)
-
Simplified Rerun Mutation: Removed module-level
rerunInFlightSet and unsafe type assertions inuse-crawl-jobs.ts. -
Controlled Polling: Set default
refetchIntervaltofalseforuseCrawlJobLogsto prevent unintended background network polling.
3. Authentication & Security (Findings 007, 010, 014, 015, 017, 020)
-
Edge Middleware RBAC: Added
/settings/developertoSTRICT_ADMIN_ROUTESwith case-insensitive role verification. -
Strict Sandbox Isolation: Removed
allow-same-originfromsafe-html-preview.tsxiframe sandbox to strictly isolate crawled preview HTML from the app origin. -
Auth Provider Memoization: Wrapped
login,register, andrefreshProfileinuseCallback; memoizedroles,permissions, andcontextValuewithuseMemo. -
Redirect Loop Protection: Added
/verify-emailtogetSafeRedirectUrlauth blocklist.
4. Internationalization & UX (Findings 011, 012, 016)
-
Hydration Mismatch Fix: Initialized
LanguageProviderwith consistent'vi'locale across SSR and client, deferring stored locale sync to client-side microtask. -
Robust Cron Validation: Upgraded
isValidCronExpressionwith regex checking each field of the 5-part cron syntax. -
Accessibility (A11y): Added
aria-haspopup="menu",aria-expanded,role="menu", androle="menuitem"toUserMenu.
5. Network & Utils (Findings 003, 008, 009, 013, 018, 019)
-
Deterministic Timezone Range: Standardized
getLocalDateRangeISOusing fixedDate.UTC()offset (+7h) independent of browser runtime timezone. -
Proxy Body Forwarding: Added
DELETEmethod to request body forwarding in BFF proxy route. -
Type Safety & Devtools: Eliminated double type casts in
crawler-task-table.tsxanddownload-helper.ts; restrictedReactQueryDevtoolsto development environments only.