Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

feat: add better storage error handling

towfiqi7af1f7e9cd62
diff --git a/backend/__tests__/services/PlanService.test.ts b/backend/__tests__/services/PlanService.test.ts
index 75b47f8..e15abd1 100644
--- a/backend/__tests__/services/PlanService.test.ts
+++ b/backend/__tests__/services/PlanService.test.ts
@@ -82,10 +82,14 @@ describe('PlanService', () => {
performBackupSpy.mockRestore();
});
+ // Use an OS-appropriate absolute path: local storage on a Windows host
+ // requires a drive letter, while a POSIX host requires a leading slash.
+ const localStoragePath = process.platform === 'win32' ? 'C:\\backups\\test' : '/backups/test';
+
const planData: NewPlanReq = {
title: 'Test Plan',
storage: { id: 'storage-123', name: 'Test Storage' },
- storagePath: '/backups/test',
+ storagePath: localStoragePath,
sourceId: 'main', // Testing with the local device
sourceType: 'device',
sourceConfig: { includes: ['/data/important'], excludes: [] },
@@ -327,6 +331,27 @@ describe('PlanService', () => {
// Act & Assert
await expect(planService.updatePlan(planId, invalidUpdateData as any)).rejects.toThrow(); // Zod will throw its own specific error
});
+
+ it('should reject changing the destination storage with a 400', async () => {
+ mockPlanStore.getById.mockResolvedValue(currentPlan);
+
+ await expect(
+ planService.updatePlan(planId, { storageId: 'storage-999' } as any)
+ ).rejects.toHaveProperty('statusCode', 400);
+ expect(mockPlanStore.update).not.toHaveBeenCalled();
+ });
+
+ it('should reject changing the destination path with a 400', async () => {
+ mockPlanStore.getById.mockResolvedValue({
+ ...currentPlan,
+ storagePath: '/backups/original',
+ });
+
+ await expect(
+ planService.updatePlan(planId, { storagePath: '/backups/moved' } as any)
+ ).rejects.toHaveProperty('statusCode', 400);
+ expect(mockPlanStore.update).not.toHaveBeenCalled();
+ });
});
// -------------------------
diff --git a/backend/__tests__/utils/sanitizeStoragePath.test.ts b/backend/__tests__/utils/sanitizeStoragePath.test.ts
index 23d1d68..e69abdf 100644
--- a/backend/__tests__/utils/sanitizeStoragePath.test.ts
+++ b/backend/__tests__/utils/sanitizeStoragePath.test.ts
@@ -267,4 +267,49 @@ describe('sanitizeStoragePath', () => {
expect(result).toBe('/var/home/backups');
});
});
+
+ describe('UNC and rootless Windows paths', () => {
+ it('should reject a UNC path with a share', () => {
+ expect(() => sanitizeStoragePath('\\\\server\\share', 'local', 'windows')).toThrow(AppError);
+ expect(() => sanitizeStoragePath('\\\\server\\share', 'local', 'windows')).toThrow(
+ 'Network (UNC) destinations are not supported'
+ );
+ });
+
+ it('should reject a bare UNC host (the silent F:\\host defect)', () => {
+ expect(() => sanitizeStoragePath('\\\\server', 'local', 'windows')).toThrow(
+ 'Network (UNC) destinations are not supported'
+ );
+ });
+
+ it('should reject a forward-slash UNC path', () => {
+ expect(() => sanitizeStoragePath('//server/share', 'local', 'windows')).toThrow(
+ 'Network (UNC) destinations are not supported'
+ );
+ });
+
+ it('should reject a rootless path with no drive letter', () => {
+ expect(() => sanitizeStoragePath('/mnt/data', 'local', 'windows')).toThrow(AppError);
+ expect(() => sanitizeStoragePath('/mnt/data', 'local', 'windows')).toThrow(
+ 'Include a drive letter'
+ );
+ });
+
+ it('should reject a single-backslash rootless path', () => {
+ expect(() => sanitizeStoragePath('\\folder\\sub', 'local', 'windows')).toThrow(
+ 'Include a drive letter'
+ );
+ });
+
+ it('should accept a valid drive-letter path', () => {
+ const result = sanitizeStoragePath('C:\\backups\\plan1', 'local', 'windows');
+ expect(result).toContain('backups');
+ expect(result).toMatch(/^[A-Za-z]:/);
+ });
+
+ it('should not reject a UNC-style path on a Linux target', () => {
+ // On POSIX, "//host/share" is a legal absolute path, not UNC.
+ expect(() => sanitizeStoragePath('//host/share', 'local', 'linux')).not.toThrow();
+ });
+ });
});
diff --git a/backend/src/services/PlanService.ts b/backend/src/services/PlanService.ts
index 1aaeacc..19ac046 100644
--- a/backend/src/services/PlanService.ts
+++ b/backend/src/services/PlanService.ts
@@ -213,6 +213,26 @@ export class PlanService {
throw error;
}
+ // The backup destination is immutable after a plan is created — the restic
+ // repository and all its snapshots live there. Refuse any change.
+ if (parsedPlanData.storageId != null && parsedPlanData.storageId !== currentPlan.storageId) {
+ throw new AppError(
+ 400,
+ 'The backup destination storage cannot be changed after the plan is created.'
+ );
+ }
+ if (
+ parsedPlanData.storagePath != null &&
+ parsedPlanData.storagePath !== currentPlan.storagePath
+ ) {
+ throw new AppError(
+ 400,
+ 'The backup destination path cannot be changed after the plan is created, because the repository and its snapshots are stored there.'
+ );
+ }
+ // Never let the immutable storageId reach the update.
+ delete (parsedPlanData as Record<string, unknown>).storageId;
+
const updatedPlan = await this.planStore.update(planId, parsedPlanData as Partial<Plan>);
if (!updatedPlan) {
throw new AppError(500, 'Failed to update plan in the database.');
diff --git a/backend/src/utils/sanitizeStoragePath.ts b/backend/src/utils/sanitizeStoragePath.ts
index 8950b74..71ee9e3 100644
--- a/backend/src/utils/sanitizeStoragePath.ts
+++ b/backend/src/utils/sanitizeStoragePath.ts
@@ -44,6 +44,27 @@ export function sanitizeStoragePath(
}
if (storageType === 'local') {
+ if (isTargetWindows) {
+ // Refuse UNC paths. Test the RAW input, because
+ // path.win32.normalize('\\\\host') collapses to '\host' and destroys the
+ // UNC signature (the silent F:\host defect). The raw test finds
+ // '\\host\share', '\\host', and '//host/share'.
+ const parsedRoot = path.win32.parse(normalizedPath).root;
+ if (/^[\\/]{2}/.test(trimmedPath) || parsedRoot.startsWith('\\\\')) {
+ throw new AppError(
+ 400,
+ 'Invalid Storage Destination path: Network (UNC) destinations are not supported. Map the share to a drive letter on the Pluton host, or add the share as an SMB storage.'
+ );
+ }
+ // Refuse a rootless path (no drive letter). Also fixes '/mnt/data' -> 'F:\mnt\data' defect.
+ if (parsedRoot === '\\' || parsedRoot === '/') {
+ throw new AppError(
+ 400,
+ 'Invalid Storage Destination path: Include a drive letter (e.g., "C:\\backups").'
+ );
+ }
+ }
+
// For local storage, we need a fully qualified absolute path.
// Check *before* resolve() because resolve() always returns an absolute path
// by prepending the server's CWD, which mangles paths for remote devices
diff --git a/frontend/src/components/Plan/EditPlan/EditPlan.tsx b/frontend/src/components/Plan/EditPlan/EditPlan.tsx
index aed7975..907375d 100644
--- a/frontend/src/components/Plan/EditPlan/EditPlan.tsx
+++ b/frontend/src/components/Plan/EditPlan/EditPlan.tsx
@@ -20,7 +20,9 @@ const EditPlan = ({ close, plan }: EditPlanProps) => {
}
console.log('newPlan :', newPlan);
- const allowedFields = ['title', 'description', 'isActive', 'storagePath', 'sourceConfig', 'tags', 'settings'] as const;
+ // storagePath is immutable after a plan is created (the repository lives there),
+ // so the client no longer sends it. The backend also refuses a change with a 400.
+ const allowedFields = ['title', 'description', 'isActive', 'sourceConfig', 'tags', 'settings'] as const;
const updatedPlan = Object.fromEntries(Object.entries(newPlan).filter(([key]) => allowedFields.includes(key as any)));
updatePlanMutation.mutate(
diff --git a/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx b/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx
index 757ad6f..6941db3 100644
--- a/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx
+++ b/frontend/src/components/common/form/StoragePicker/StoragePicker.tsx
@@ -89,7 +89,16 @@ const StoragePicker = ({ onUpdate, storagePath = '', storageId, disabled = false
return (
<div className={classes.storagePicker}>
- <div className={classes.storagePickerInput}>
+ <div
+ className={classes.storagePickerInput}
+ {...(disabled
+ ? {
+ 'data-tooltip-id': 'appTooltip',
+ 'data-tooltip-content': "The destination path can't be changed after a plan is created.",
+ 'data-tooltip-place': 'top',
+ }
+ : {})}
+ >
<div>
<div className={classes.storage}>
<Select