A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.
fix: Missing device update input validation
towfiqibb9b40a16849
diff --git a/backend/src/services/DeviceService.ts b/backend/src/services/DeviceService.tsindex aa0d8bb..e516425 100644--- a/backend/src/services/DeviceService.ts+++ b/backend/src/services/DeviceService.ts@@ -1,5 +1,5 @@import path from 'path';-import { Device } from '../db/schema/devices';+import { Device, deviceUpdateSchema } from '../db/schema/devices';import { BaseSystemManager } from '../managers/BaseSystemManager';import { DeviceStore } from '../stores/DeviceStore';import { PlanStore } from '../stores/PlanStore';@@ -144,20 +144,19 @@ export class DeviceService {throw new Error('Device not found.');}- const updatedObj: { name?: string; settings?: any; tags?: string[] } = {};- if (data.name) {- updatedObj.name = data.name;- }-- if (data.settings) {- updatedObj.settings = data.settings;- }-- if (data.tags) {- updatedObj.tags = data.tags;+ // Validate the update object against the schema+ let updatedObj: Partial<Device> = {};+ try {+ updatedObj = deviceUpdateSchema.parse({+ name: data.name ?? existingDevice.name,+ settings: data.settings ?? existingDevice.settings,+ tags: data.tags ?? existingDevice.tags,+ });+ } catch (error) {+ console.error('Error parsing Device data:', error);+ throw new AppError(400, 'Invalid device data provided');}- // TODO: set the restic and rclone settings values as env variables from the device settingsif (data.settings) {if (existingDevice.id !== 'main') {try {diff --git a/backend/src/services/StorageService.ts b/backend/src/services/StorageService.tsindex 644a0be..4f729c5 100644--- a/backend/src/services/StorageService.ts+++ b/backend/src/services/StorageService.ts@@ -152,8 +152,8 @@ export class StorageService {try {parsedStorageData = storageUpdateSchema.parse(storagePayload);} catch (error) {- console.error('Error parsing plan data:', error);- throw error;+ console.error('Error parsing storage data:', error);+ throw new AppError(400, 'Invalid storage data provided');}const { authType, credentials, settings, tags } = parsedStorageData;// Update remote settings of all the devices first