Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(worktrees): keep runtime paths out of build tracing

Rahmand3b71b7a1028
diff --git a/lib/host/project-worktree.ts b/lib/host/project-worktree.ts
index eb125c12..b6bba270 100644
--- a/lib/host/project-worktree.ts
+++ b/lib/host/project-worktree.ts
@@ -54,10 +54,11 @@ export type PreparedProjectWorktree = {
* another by hiding or committing its source state.
*/
export async function prepareProjectWorktree(projectPath: string): Promise<PreparedProjectWorktree> {
+ // Runtime host paths are policy-guarded inputs, never deploy-time project assets.
const canonicalPath = await fs.realpath(projectPath).catch(() => null);
if (!canonicalPath) throw new HostError("Project path does not exist");
const top = await git(canonicalPath, ["rev-parse", "--show-toplevel"]);
- const topReal = await fs.realpath(top).catch(() => top);
+ const topReal = await fs.realpath(/* turbopackIgnore: true */ top).catch(() => top);
if (topReal !== canonicalPath) throw new HostError("Source isolation requires the exact Git project root");
const marker = await fs.lstat(path.join(canonicalPath, ".git")).catch(() => null);
@@ -73,9 +74,9 @@ export async function prepareProjectWorktree(projectPath: string): Promise<Prepa
const baseCommit = await git(canonicalPath, ["rev-parse", "HEAD"]);
if (!/^[a-f0-9]{40}$/.test(baseCommit)) throw new HostError("Could not prove the canonical Git commit");
- const root = path.resolve(worktreeRoot());
+ const root = path.resolve(/* turbopackIgnore: true */ worktreeRoot());
await fs.mkdir(root, { recursive: true, mode: 0o700 });
- const rootReal = await fs.realpath(root);
+ const rootReal = await fs.realpath(/* turbopackIgnore: true */ root);
const token = randomUUID().replace(/-/g, "").slice(0, 12);
const slug = safeSlug(path.basename(canonicalPath));
const workspacePath = path.join(rootReal, `${slug}-${token}`);
@@ -117,7 +118,7 @@ export async function discardWorkflowWorktreeIfUnchanged(input: { canonicalPath:
const canonicalPath = await fs.realpath(input.canonicalPath).catch(() => null);
const workspacePath = await fs.realpath(input.workspacePath).catch(() => null);
if (!canonicalPath || !workspacePath || canonicalPath === workspacePath) return false;
- const root = await fs.realpath(path.resolve(worktreeRoot())).catch(() => null);
+ const root = await fs.realpath(/* turbopackIgnore: true */ path.resolve(/* turbopackIgnore: true */ worktreeRoot())).catch(() => null);
if (!root) return false;
const rel = path.relative(root, workspacePath);
if (rel === "" || rel.startsWith("..") || path.isAbsolute(rel)) return false;
@@ -141,7 +142,7 @@ function insideRoot(root: string, candidate: string): boolean {
* This is the explicit exception that lets project-scoped tools operate on a task
* workspace without making arbitrary hidden directories globally resolvable. */
export async function linkedWorkflowWorktreeCanonicalPath(candidatePath: string): Promise<string | null> {
- const root = await fs.realpath(path.resolve(worktreeRoot())).catch(() => null);
+ const root = await fs.realpath(/* turbopackIgnore: true */ path.resolve(/* turbopackIgnore: true */ worktreeRoot())).catch(() => null);
const candidate = await fs.realpath(candidatePath).catch(() => null);
if (!root || !candidate || candidate === root || !insideRoot(root, candidate)) return null;
const marker = await fs.lstat(path.join(candidate, ".git")).catch(() => null);
diff --git a/lib/memory-backup/history.ts b/lib/memory-backup/history.ts
index da06393f..5dff7d7f 100644
--- a/lib/memory-backup/history.ts
+++ b/lib/memory-backup/history.ts
@@ -24,7 +24,7 @@ export async function listSnapshots(root: string, options: Options = {}): Promis
try {
const revision = stamp(await pin.directory.stat());
if (offset > 0 && revision !== options.revision) throw new Error("backup history changed; refresh the first page");
- dir = await fs.opendir(/* turbopackIgnore: true */ path.dirname(pin.file));
+ dir = await fs.opendir(path.dirname(pin.file));
const items: MemoryBackupHistory["items"] = [];
const deadline = Date.now() + 5000;
let position = 0, scannedEntries = 0, finished = false;
diff --git a/lib/memory-backup/io.ts b/lib/memory-backup/io.ts
index 8eb9bc7e..f56c6cee 100644
--- a/lib/memory-backup/io.ts
+++ b/lib/memory-backup/io.ts
@@ -13,7 +13,7 @@ export async function existing(file: string) {
for (const part of file.split("/").filter(Boolean)) {
// Host-owned runtime paths are guarded below, not deployable build assets.
current = path.join(/* turbopackIgnore: true */ current, part);
- if ((await fs.lstat(/* turbopackIgnore: true */ current)).isSymbolicLink()) throw new Error("unsafe path");
+ if ((await fs.lstat(current)).isSymbolicLink()) throw new Error("unsafe path");
}
}
export async function readBytes(file: string, max: number) {
@@ -21,7 +21,7 @@ export async function readBytes(file: string, max: number) {
const pin = await pinSecurityStorePath(file);
let handle;
try {
- handle = await fs.open(/* turbopackIgnore: true */ pin.file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
+ handle = await fs.open(pin.file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
const before = await handle.stat();
if (!before.isFile() || before.uid !== process.getuid?.() || (before.mode & 0o022) || before.size > max) throw new Error("unsafe or oversized input");
const bytes = Buffer.alloc(before.size + 1);
@@ -43,7 +43,7 @@ export async function writeExclusive(file: string, bytes: Buffer) {
let handle;
try {
if ((await pin.directory.stat()).mode & 0o077) throw new Error("backup directory is not private");
- handle = await fs.open(/* turbopackIgnore: true */ pin.file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
+ handle = await fs.open(pin.file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
await handle.writeFile(bytes); await handle.sync();
} finally { await handle?.close(); await pin.directory.close(); }
}
diff --git a/lib/memory-backup/scan.ts b/lib/memory-backup/scan.ts
index 180d8b8c..fde54ad8 100644
--- a/lib/memory-backup/scan.ts
+++ b/lib/memory-backup/scan.ts
@@ -21,11 +21,11 @@ export async function scanSources(sources: Source[], limits: Limits, consume?: (
if (depth > 32 || !safeRelative(name)) { report.rejected++; return; }
try {
await existing(file);
- const stat = await fs.lstat(/* turbopackIgnore: true */ file);
+ const stat = await fs.lstat(file);
if (stat.isDirectory()) {
const pin = await pinSecurityStorePath(path.join(file, ".backup-index"));
try {
- const dir = await fs.opendir(/* turbopackIgnore: true */ path.dirname(pin.file));
+ const dir = await fs.opendir(path.dirname(pin.file));
for await (const entry of dir) {
if (stopped()) break;
if (excluded.test(entry.name)) { entries++; report.excluded++; continue; }
diff --git a/lib/memory-backup/service.ts b/lib/memory-backup/service.ts
index 33a58d12..84805289 100644
--- a/lib/memory-backup/service.ts
+++ b/lib/memory-backup/service.ts
@@ -50,7 +50,7 @@ export async function createSnapshot(sources: Source[], root: string, sourceDisc
}
export async function createMemoryBackup() {
- const space = await fs.statfs(/* turbopackIgnore: true */ os.homedir());
+ const space = await fs.statfs(os.homedir());
if (space.bavail * space.bsize < LIMITS.bytes * 3 + 1024 * 1024 * 1024) throw new Error("insufficient headroom for a backup and isolated restore; source files preserved");
const inventory = await memorySources();
return createSnapshot(inventory.sources, memoryBackupRoot(), inventory.incomplete);