From 7f4f75a8074f4eb2f5947e2373b06761f936cec8 Mon Sep 17 00:00:00 2001 From: Anurag Saxena Date: Fri, 3 Apr 2026 21:52:31 -0400 Subject: [PATCH] fix: pass HOME explicitly in sudo inlineCmd so MITM server resolves correct data dir (closes #478) (#482) --- src/mitm/manager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mitm/manager.js b/src/mitm/manager.js index ed585b97..31c362f1 100644 --- a/src/mitm/manager.js +++ b/src/mitm/manager.js @@ -450,7 +450,9 @@ async function startServer(apiKey, sudoPassword) { if (_updateSettings) await _updateSettings({ mitmCertInstalled: true }).catch(() => { }); } else if (isSudoAvailable()) { - const inlineCmd = `ROUTER_API_KEY='${apiKey}' NODE_ENV='production' '${process.execPath}' '${SERVER_PATH}'`; + // Pass HOME explicitly so os.homedir() resolves to the unprivileged user's home + // instead of /root when sudo resets the environment. + const inlineCmd = `HOME='${os.homedir()}' ROUTER_API_KEY='${apiKey}' NODE_ENV='production' '${process.execPath}' '${SERVER_PATH}'`; serverProcess = spawn( "sudo", ["-S", "-E", "sh", "-c", inlineCmd], { detached: false, stdio: ["pipe", "pipe", "pipe"] }