From 6e22abb1ba921477cdcb24c18a4a67543d968101 Mon Sep 17 00:00:00 2001 From: vaibhav Date: Fri, 6 Feb 2026 17:52:16 +0530 Subject: [PATCH] fix: replace hardcoded /Users/user fallback with os.homedir() The HOME_DIR fallback '/Users/user' is macOS-specific and incorrect. Use os.homedir() from Node's os module which works cross-platform and returns the actual home directory from /etc/passwd on Linux. Co-authored-by: Cursor --- src/config.ts | 3 ++- src/mount-security.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 6c64cb8..da25429 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,3 +1,4 @@ +import os from 'os'; import path from 'path'; import { readEnvFile } from './env.js'; @@ -19,7 +20,7 @@ export const SCHEDULER_POLL_INTERVAL = 60000; // Absolute paths needed for container mounts const PROJECT_ROOT = process.cwd(); -const HOME_DIR = process.env.HOME || '/Users/user'; +const HOME_DIR = process.env.HOME || os.homedir(); // Mount security: allowlist stored OUTSIDE project root, never mounted into containers export const MOUNT_ALLOWLIST_PATH = path.join( diff --git a/src/mount-security.ts b/src/mount-security.ts index d0d1416..3dceea5 100644 --- a/src/mount-security.ts +++ b/src/mount-security.ts @@ -7,6 +7,7 @@ * Allowlist location: ~/.config/nanoclaw/mount-allowlist.json */ import fs from 'fs'; +import os from 'os'; import path from 'path'; import pino from 'pino'; @@ -121,7 +122,7 @@ export function loadMountAllowlist(): MountAllowlist | null { * Expand ~ to home directory and resolve to absolute path */ function expandPath(p: string): string { - const homeDir = process.env.HOME || '/Users/user'; + const homeDir = process.env.HOME || os.homedir(); if (p.startsWith('~/')) { return path.join(homeDir, p.slice(2)); }