Skip to content

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

fix: various security issues.

towfiqi9d96362653a7
diff --git a/backend/package.json b/backend/package.json
index aadc7d4..b5910b4 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -1,7 +1,7 @@
{
"name": "@plutonhq/core-backend",
"description": "Pluton Core Backend Library",
- "version": "0.1.7",
+ "version": "0.1.8",
"author": "plutonhq",
"license": "Apache-2.0",
"publishConfig": {
@@ -25,6 +25,7 @@
"ejs": "^3.1.10",
"express": "^4.21.2",
"express-rate-limit": "^7.5.1",
+ "helmet": "^8.1.0",
"jsonwebtoken": "^9.0.2",
"nanoid": "^5.0.9",
"node-ssh": "^13.2.0",
diff --git a/backend/src/controllers/RestoreController.ts b/backend/src/controllers/RestoreController.ts
index 9df45a9..8755f9c 100644
--- a/backend/src/controllers/RestoreController.ts
+++ b/backend/src/controllers/RestoreController.ts
@@ -27,6 +27,7 @@ export class RestoreController {
try {
if (!req.params.id) {
res.status(400).json({ success: false, error: 'Restore ID is required' });
+ return;
}
const restore = await this.restoreService.getRestore(req.params.id);
@@ -65,6 +66,7 @@ export class RestoreController {
try {
if (!req.params.id) {
res.status(400).json({ success: false, error: 'Restore ID is required' });
+ return;
}
await this.restoreService.deleteRestore(req.params.id);
diff --git a/backend/src/routes/health.ts b/backend/src/routes/health.ts
index 1fee09c..cb24332 100644
--- a/backend/src/routes/health.ts
+++ b/backend/src/routes/health.ts
@@ -2,9 +2,37 @@ import { Router, Request, Response } from 'express';
import { existsSync } from 'fs';
import { db } from '../db';
import { getBinaryPath } from '../utils/binaryPathResolver';
+import authMiddleware from '../middlewares/authMiddleware';
export function createHealthRouter(router: Router = Router()): Router {
+ /**
+ * Public health endpoint — returns only overall status.
+ * Safe for Docker health checks / load balancers.
+ */
router.get('/', async (req: Request, res: Response) => {
+ try {
+ // Quick database check to determine overall health
+ let dbOk = false;
+ try {
+ db.run('SELECT 1');
+ dbOk = true;
+ } catch {
+ dbOk = false;
+ }
+
+ const status = dbOk ? 'healthy' : 'unhealthy';
+ const statusCode = dbOk ? 200 : 503;
+ res.status(statusCode).json({ status });
+ } catch (error) {
+ res.status(503).json({ status: 'unhealthy' });
+ }
+ });
+
+ /**
+ * Detailed health endpoint — auth required.
+ * Returns component-level checks for debugging.
+ */
+ router.get('/details', authMiddleware, async (req: Request, res: Response) => {
try {
const health = {
status: 'healthy',
diff --git a/backend/src/stores/DeviceStore.ts b/backend/src/stores/DeviceStore.ts
index 0a1d86a..7b72d81 100644
--- a/backend/src/stores/DeviceStore.ts
+++ b/backend/src/stores/DeviceStore.ts
@@ -49,19 +49,6 @@ export class DeviceStore {
return result[0] || null;
}
- async updateVersions(id: string, dependency: string, version: string): Promise<Device | null> {
- const result = await this.db
- .update(devices)
- .set({
- versions: sql`json_set(${devices.versions}, '$.${dependency}', ${version})`,
- updatedAt: sql`(unixepoch())`,
- })
- .where(eq(devices.id, id))
- .returning();
-
- return result[0] || null;
- }
-
async delete(id: string): Promise<boolean> {
const result = await this.db.delete(devices).where(eq(devices.id, id));
diff --git a/backend/src/utils/restic/restic.ts b/backend/src/utils/restic/restic.ts
index 2d9d87b..c00ddb5 100644
--- a/backend/src/utils/restic/restic.ts
+++ b/backend/src/utils/restic/restic.ts
@@ -50,8 +50,6 @@ export function runResticCommand(
path.join(appPaths.getTempDir(), 'restic-cache'),
];
- console.log('runResticCommand :', [resticBinary, ...finalArgs], envVars);
-
const resticProcess = spawn(resticBinary, finalArgs, { env: envVars });
if (onProcess) {
diff --git a/backend/src/utils/sanitizeStoragePath.ts b/backend/src/utils/sanitizeStoragePath.ts
index 41c5209..1e3b2af 100644
--- a/backend/src/utils/sanitizeStoragePath.ts
+++ b/backend/src/utils/sanitizeStoragePath.ts
@@ -57,6 +57,11 @@ export function sanitizeStoragePath(storagePath: string, storageType: string): s
remotePath = remotePath.slice(0, -1);
}
+ // 4. disallow any remaining ".." segments to prevent directory traversal in remote storage contexts
+ if (remotePath.startsWith('..') || remotePath.includes('/../') || remotePath.endsWith('/..')) {
+ throw new AppError(400, 'Invalid path: Directory traversal not allowed.');
+ }
+
return remotePath;
}
}
diff --git a/backend/src/utils/versions.ts b/backend/src/utils/versions.ts
index b25fabd..ade71eb 100644
--- a/backend/src/utils/versions.ts
+++ b/backend/src/utils/versions.ts
@@ -1,4 +1,4 @@
-import { execSync } from 'child_process';
+import { execFileSync } from 'child_process';
import { getBinaryPath } from './binaryPathResolver';
/**
@@ -11,7 +11,7 @@ import { getBinaryPath } from './binaryPathResolver';
export function getResticVersion(): string {
try {
const resticBinary = getBinaryPath('restic');
- const resticOutput = execSync(`${resticBinary} version --json`).toString().trim();
+ const resticOutput = execFileSync(resticBinary, ['version', '--json']).toString().trim();
return resticOutput ? JSON.parse(resticOutput).version : 'not_installed';
} catch {
return 'not_installed';
@@ -28,7 +28,7 @@ export function getResticVersion(): string {
export function getRcloneVersion(): string {
try {
const rcloneBinary = getBinaryPath('rclone');
- const rcloneOutput = execSync(`${rcloneBinary} version`).toString().trim();
+ const rcloneOutput = execFileSync(rcloneBinary, ['version']).toString().trim();
const versionMatch = rcloneOutput.match(/rclone v(\d+\.\d+\.\d+)/);
return versionMatch ? versionMatch[1] : 'not_installed';
} catch {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 64af31a..146e9a3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -71,6 +71,9 @@ importers:
express-rate-limit:
specifier: ^7.5.1
version: 7.5.1([email protected])
+ helmet:
+ specifier: ^8.1.0
+ version: 8.1.0
jsonwebtoken:
specifier: ^9.0.2
version: 9.0.2
@@ -4111,6 +4114,10 @@ packages:
resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==}
hasBin: true
+ resolution: {integrity: sha512-jOiHyAZsmnr8LqoPGmCjYAaiuWwjAPLgY8ZX2XrmHawt99/u1y6RgrZMTeoPfpUbV96HOalYgz1qzkRbw54Pmg==}
+ engines: {node: '>=18.0.0'}
+
resolution: {integrity: sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==}
@@ -10957,6 +10964,8 @@ snapshots:
+