fix: harden backup/restore error handling and security
- Stop analysis on WASM migration failure instead of continuing silently - Fail import when secrets exist but no encryption key is provided - Fail import on malformed secret values instead of skipping them - Tighten onboarding auth: missing onboarding row no longer grants access - Wrap WAL/SHM cleanup in try/catch so post-rename failure doesn't mask success - Show API errors immediately instead of waiting for animation to finish - Handle non-JSON server responses during restore (e.g. restart mid-request) - Surface fetchMigrations() failures as errors instead of empty array - Wrap migrations route I/O in try/catch with structured error response - Add server-side console.error logging to all backup API catch blocks - Fix export finally block: cleanup wrapped in try/catch to avoid masking - Fix misleading "Up to date" badge shown when migrations are pending - Remove dead PHASE_ICONS constant
This commit is contained in:
8 files changed
+88
-56
No files matched your search
@@ -90,8 +90,8 @@ export const BackupPreviewPanel = ({ analysis }: BackupPreviewPanelProps) => {
|
||||
: t("migrationsOlderVersionPlural", { count: String(pendingCount) })}
|
||||
</Text>
|
||||
</div>
|
||||
<Badge variant="light" color="green" ml="auto">
|
||||
{t("upToDate")}
|
||||
<Badge variant="light" color="orange" ml="auto">
|
||||
{t("migrationsPending", { count: String(pendingCount) })}
|
||||
</Badge>
|
||||
</Group>
|
||||
</Paper>
|
||||
|
||||
@@ -55,14 +55,17 @@ export const DatabaseRestoreFlow = ({ variant = "card", onRestoreComplete }: Dat
|
||||
}, [reset]);
|
||||
|
||||
const tryFinalize = useCallback(() => {
|
||||
if (!apiDoneRef.current || !animDoneRef.current) return;
|
||||
if (!apiDoneRef.current) return;
|
||||
|
||||
if (apiErrorRef.current) {
|
||||
setImportError(apiErrorRef.current);
|
||||
setStep("error");
|
||||
} else {
|
||||
onRestoreComplete?.();
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!animDoneRef.current) return;
|
||||
onRestoreComplete?.();
|
||||
window.location.reload();
|
||||
}, [onRestoreComplete]);
|
||||
|
||||
const handleConfirm = useCallback(async () => {
|
||||
@@ -77,13 +80,17 @@ export const DatabaseRestoreFlow = ({ variant = "card", onRestoreComplete }: Dat
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
const response = await fetch("/api/backup/import", { method: "POST", body: formData });
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
apiErrorRef.current = data.error ?? t("analyzeError");
|
||||
try {
|
||||
const data = await response.json();
|
||||
apiErrorRef.current = data.error ?? t("failed.title");
|
||||
} catch {
|
||||
apiErrorRef.current = `Server returned ${response.status}`;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
apiErrorRef.current = err instanceof Error ? err.message : t("analyzeError");
|
||||
} catch {
|
||||
apiErrorRef.current = t("failed.title");
|
||||
} finally {
|
||||
apiDoneRef.current = true;
|
||||
tryFinalize();
|
||||
|
||||
@@ -17,14 +17,6 @@ import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import type { MigrationFile } from "./types";
|
||||
|
||||
const PHASE_ICONS: Record<string, Icon> = {
|
||||
extracting: IconFileZip,
|
||||
migrating: IconDatabaseImport,
|
||||
encrypting: IconKey,
|
||||
swapping: IconTransform,
|
||||
restarting: IconRefresh,
|
||||
};
|
||||
|
||||
const BASE_PHASE_DURATIONS: Record<string, number> = {
|
||||
extracting: 1200,
|
||||
encrypting: 1500,
|
||||
|
||||
@@ -22,7 +22,7 @@ const getAppliedMigrationCount = (db: any): number => {
|
||||
|
||||
const fetchMigrations = async (): Promise<MigrationFile[]> => {
|
||||
const res = await fetch("/api/backup/migrations");
|
||||
if (!res.ok) return [];
|
||||
if (!res.ok) throw new Error("Failed to fetch migration files from server");
|
||||
const data = await res.json();
|
||||
return data.migrations ?? [];
|
||||
};
|
||||
@@ -133,13 +133,16 @@ export const useBackupAnalysis = () => {
|
||||
`INSERT INTO "${DRIZZLE_MIGRATIONS_TABLE}" ("hash", "created_at") VALUES (?, ?)`,
|
||||
[migration.tag, Date.now()],
|
||||
);
|
||||
} catch {
|
||||
} catch (migrationErr) {
|
||||
setMigrationProgress({
|
||||
current: i + 1,
|
||||
total: pendingMigrations.length,
|
||||
tag: migration.tag,
|
||||
phase: "error",
|
||||
});
|
||||
throw new Error(
|
||||
`Migration ${migration.tag} failed: ${migrationErr instanceof Error ? migrationErr.message : "Unknown error"}`,
|
||||
);
|
||||
}
|
||||
|
||||
setMigrationProgress({
|
||||
|
||||
Reference in new issue
Block a user