From a68e5ac4f89b3e64ebc6d452dcc72e3e2a1a8e67 Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Mon, 1 Jun 2026 22:51:02 +0530 Subject: [PATCH 1/2] fix: use Blob URL for JSON export instead of DOM appendChild pattern --- client/src/components/AssessmentResult.tsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/src/components/AssessmentResult.tsx b/client/src/components/AssessmentResult.tsx index 2a843fe50..38faa7068 100644 --- a/client/src/components/AssessmentResult.tsx +++ b/client/src/components/AssessmentResult.tsx @@ -52,13 +52,13 @@ export function AssessmentResult({ assessment }: AssessmentResultProps) { const [view, setView] = useState<"patient" | "clinician">("patient"); const exportToJson = () => { - const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(assessment, null, 2)); - const downloadAnchor = document.createElement('a'); - downloadAnchor.setAttribute("href", dataStr); - downloadAnchor.setAttribute("download", `diabetes-risk-assessment-${assessment.id ?? "report"}.json`); - document.body.appendChild(downloadAnchor); - downloadAnchor.click(); - downloadAnchor.remove(); + const blob = new Blob([JSON.stringify(assessment, null, 2)], { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = `diabetes-risk-assessment-${assessment.id ?? "report"}.json`; + a.click(); + URL.revokeObjectURL(url); }; const getRiskColor = (category: string) => { From d04d8b911266f7c525a613265f3f43ca0389e7fb Mon Sep 17 00:00:00 2001 From: Sumit Kumar Date: Mon, 1 Jun 2026 23:04:28 +0530 Subject: [PATCH 2/2] fix: resolve syntax errors in auth.ts and rateLimiter.ts for CI --- server/auth.ts | 61 ++++++++++++++++++++------------ server/middleware/rateLimiter.ts | 2 +- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/server/auth.ts b/server/auth.ts index cde5a1d0a..92234d029 100644 --- a/server/auth.ts +++ b/server/auth.ts @@ -26,6 +26,27 @@ interface RegisteredUser { // removed duplicated functions +const SALT_LENGTH = 32; +const KEY_LENGTH = 64; + +function hashPassword(password: string): string { + const salt = randomBytes(SALT_LENGTH).toString("hex"); + const hash = scryptSync(password, salt, KEY_LENGTH).toString("hex"); + return `${salt}:${hash}`; +} + +function verifyPassword(password: string, stored: string): boolean { + const [salt, key] = stored.split(":"); + if (!salt || !key) return false; + const hash = scryptSync(password, salt, KEY_LENGTH); + const keyBuffer = Buffer.from(key, "hex"); + return hash.length === keyBuffer.length && timingSafeEqual(hash, keyBuffer); +} + +function ipKeyGenerator(ip: string): string { + return ip.replace(/[^a-zA-Z0-9.:]/g, "_"); +} + /** * In-memory store for registered users. * In production, this should be replaced with a persistent database. @@ -204,12 +225,6 @@ export function createAuthRouter(): Router { if (existingDbUser) { return res.status(409).json({ message: "An account with this email already exists." }); } - registeredUsers.set(email, { - fullName, - email, - passwordHash: hashPassword(password), - licenseNumber: licenseNumber, - }); const passwordHash = hashPassword(password); @@ -246,10 +261,14 @@ export function createAuthRouter(): Router { attemptCount: 0, }); - // In production, send OTP via email. For development, return it in the response. - logDevOtp(email, otp); + // In production, send OTP via email. For development, return it in the response. + logDevOtp(email, otp); - return res.status(201).json({ success: true, pendingEmail: email, ...(process.env.NODE_ENV !== "production" && { devOtp: otp }) }); + return res.status(201).json({ success: true, pendingEmail: email, ...(process.env.NODE_ENV !== "production" && { devOtp: otp }) }); + } catch (err) { + console.error("Registration error:", err); + return res.status(500).json({ message: "Registration failed due to a server error." }); + } }); /** @@ -276,11 +295,11 @@ export function createAuthRouter(): Router { // Check in-memory store (legacy) const registeredUser = registeredUsers.get(email); if (registeredUser && verifyPassword(password, registeredUser.passwordHash)) { - userFullName = registeredUser.fullName; + userName = registeredUser.fullName; } // Also check DB - if (!userFullName) { + if (!userName) { try { const db = getDb(); const [dbUser] = await db @@ -290,21 +309,21 @@ export function createAuthRouter(): Router { .limit(1); if (dbUser && verifyPassword(password, dbUser.passwordHash)) { - userFullName = dbUser.fullName; + userName = dbUser.fullName; + } + } catch (_err) { + // DB not available — fall back to in-memory only + console.warn("DB unavailable for login, using in-memory only."); + const registeredUser = registeredUsers.get(email); + if (registeredUser && verifyPassword(password, registeredUser.passwordHash)) { + userName = registeredUser.fullName; } - } - } catch (_err) { - // DB not available — fall back to in-memory only - console.warn("DB unavailable for login, using in-memory only."); - const registeredUser = registeredUsers.get(email); - if (registeredUser && verifyPassword(password, registeredUser.passwordHash)) { - userFullName = registeredUser.fullName; } } } - if (!userFullName) { + if (!userName) { return res.status(401).json({ message: "Invalid email or password." }); } @@ -346,9 +365,7 @@ export function createAuthRouter(): Router { pendingOtps.delete(email); - const registeredUser = registeredUsers.get(email); const devEmail = process.env.DEV_CLINICIAN_EMAIL || ""; - const name = email === devEmail ? "Dr. Smith" : (registeredUser?.fullName ?? email); let id: string; let name: string; diff --git a/server/middleware/rateLimiter.ts b/server/middleware/rateLimiter.ts index d19fa96a4..f7d66b5e8 100644 --- a/server/middleware/rateLimiter.ts +++ b/server/middleware/rateLimiter.ts @@ -11,7 +11,7 @@ function pruneExpiredRecords(now: number) { if (now > record.resetTime) { requestStore.delete(clientId); } - }); + } } function trimRequestStore(now: number) {