Skip to content

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

fix: broken ALLOW_FILE_BROWSER config

towfiqica015222a198
diff --git a/backend/src/services/ConfigService.ts b/backend/src/services/ConfigService.ts
index 9f3089e..b272c97 100644
--- a/backend/src/services/ConfigService.ts
+++ b/backend/src/services/ConfigService.ts
@@ -19,6 +19,7 @@ const baseConfigSchema = z.object({
// User Interface
ALLOW_CUSTOM_RESTORE_PATH: z.coerce.boolean().default(true).optional(),
ALLOW_FILE_BROWSER: z.coerce.boolean().default(true).optional(),
+ FILE_BROWSER_ROOT: z.string().optional(),
// Security (optional in setup mode)
ENCRYPTION_KEY: z
@@ -58,6 +59,7 @@ const userConfigSchema = baseConfigSchema
MQTT_PORT: true,
ALLOW_CUSTOM_RESTORE_PATH: true,
ALLOW_FILE_BROWSER: true,
+ FILE_BROWSER_ROOT: true,
DISABLE_EVENT_SCRIPTS: true,
})
.partial();
diff --git a/backend/src/services/DeviceService.ts b/backend/src/services/DeviceService.ts
index 54d5866..1711787 100644
--- a/backend/src/services/DeviceService.ts
+++ b/backend/src/services/DeviceService.ts
@@ -1,3 +1,4 @@
+import path from 'path';
import { Device } from '../db/schema/devices';
import { BaseSystemManager } from '../managers/BaseSystemManager';
import { DeviceStore } from '../stores/DeviceStore';
@@ -7,6 +8,8 @@ import { DeviceLogger } from '../utils/logger';
import { LocalStrategy, RemoteStrategy, SystemStrategy } from '../strategies/system';
import { StorageStore } from '../stores/StorageStore';
import { providers } from '../utils/providers';
+import { configService } from './ConfigService';
+import { AppError } from 'src/utils/AppError';
export class DeviceService {
protected connectedDeviceIds: Set<string> | undefined;
@@ -223,21 +226,34 @@ export class DeviceService {
return response.result;
}
- async getBrowsePath(id: string, path: string): Promise<any> {
+ async getBrowsePath(id: string, reqPath: string): Promise<any> {
const device = await this.deviceStore.getById(id);
if (!device) {
- throw new Error('Device not found.');
+ throw new AppError(404, 'Device not found.');
+ }
+
+ if (configService.config.ALLOW_FILE_BROWSER === false) {
+ throw new AppError(403, 'File browser is disabled');
+ }
+
+ const browserRoot = configService.config.FILE_BROWSER_ROOT;
+ if (browserRoot && reqPath) {
+ const resolved = path.resolve(reqPath);
+ const resolvedRoot = path.resolve(browserRoot);
+ if (!resolved.startsWith(resolvedRoot)) {
+ throw new AppError(403, 'Access denied: path outside allowed root');
+ }
}
const strategy = this.getSystemStrategy(id);
- const response = await strategy.getBrowsePath(path);
+ const response = await strategy.getBrowsePath(reqPath);
return response;
}
async getMountPoints(id: string): Promise<any> {
const device = await this.deviceStore.getById(id);
if (!device) {
- throw new Error('Device not found.');
+ throw new AppError(404, 'Device not found.');
}
const strategy = this.getSystemStrategy(id);
@@ -248,14 +264,14 @@ export class DeviceService {
async updateRestic(id: string, version: string): Promise<string> {
const device = await this.deviceStore.getById(id);
if (!device) {
- throw new Error('Device not found.');
+ throw new AppError(404, 'Device not found.');
}
const strategy = this.getSystemStrategy(id);
const response = await strategy.updateRestic();
const updatedVersion = response.result;
if (!response.success) {
- throw new Error('Failed to update restic');
+ throw new AppError(500, 'Failed to update restic');
}
try {
@@ -274,7 +290,7 @@ export class DeviceService {
async updateRclone(id: string, version: string): Promise<string> {
const device = await this.deviceStore.getById(id);
if (!device) {
- throw new Error('Device not found.');
+ throw new AppError(404, 'Device not found.');
}
const strategy = this.getSystemStrategy(id);
@@ -282,7 +298,7 @@ export class DeviceService {
const updatedVersion = response.result;
if (!response.success) {
- throw new Error('Failed to update rclone');
+ throw new AppError(500, 'Failed to update rclone');
}
try {
const versions = device.versions || { restic: '', rclone: '', agent: '' };