Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: allow repos on secondary volumes through the workspace-root check

[._.]/ Adam Eivy7f86d136c91b
diff --git a/.changelog/next/fixed-agent-d060349c.md b/.changelog/next/fixed-agent-d060349c.md
new file mode 100644
index 0000000000..40eedd9089
--- /dev/null
+++ b/.changelog/next/fixed-agent-d060349c.md
@@ -0,0 +1 @@
+- An app's Submodules tab (and other views that send a repo path to the server) no longer fails with "path is outside allowed directories" when the repo lives on a secondary volume. The allowed-workspace-root defaults were POSIX-only, so a Windows repo on a drive other than C: matched nothing, and a Linux repo under /mnt or /media did the same. Defaults now cover /mnt and /media alongside /Volumes, and on Windows they are your home directory, the temp directory, and any lettered non-system drive (C:\Windows and C:\Program Files stay off-limits). PORTOS_WORKSPACE_ROOTS is also split on ";" on Windows, so a value like D:\repos;E:\projects is no longer cut apart at the drive letter.
diff --git a/.env.example b/.env.example
index b7eea641d1..5090904524 100644
--- a/.env.example
+++ b/.env.example
@@ -112,8 +112,13 @@ PGPASSWORD=portos
# Absolute path to the bash binary used when spawning shell sessions (auto-detected if unset)
# PORTOS_BASH=/bin/bash
-# Colon-separated list of extra directory roots exposed in the workspace file browser
-# PORTOS_WORKSPACE_ROOTS=/home/user/projects:/mnt/data
+# Extra directory roots exposed in the workspace file browser, on top of the
+# defaults (home, /tmp, /Users, /Volumes, /mnt, /media, /opt — on Windows: home,
+# the temp dir, and any lettered non-system drive). Separated by the platform
+# path delimiter: `:` on macOS/Linux, `;` on Windows, where a colon would split
+# a value like D:\repos at the drive letter.
+# PORTOS_WORKSPACE_ROOTS=/home/user/projects:/srv/git
+# Windows: PORTOS_WORKSPACE_ROOTS=D:\repos;E:\projects
# PyTorch CUDA index URL suffix for Windows GPU installs (e.g. cu121); auto-detected on Linux
# PORTOS_TORCH_CUDA_INDEX=cu121
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index 3008b999b1..75d41aadbb 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -176,6 +176,20 @@ PortOS no longer falls back silently, so a misconfigured app now surfaces as one
**Note for Windows**: use a real filesystem path with a drive letter (`C:\...`). Both `C:\Users\...` and `C:/Users/...` work, as does a leading `~`; a path inside OneDrive-redirected folders is fine as long as it exists locally.
+### "path is outside allowed directories" for a Repo on a Secondary Drive
+
+**Symptom**: Opening an app's **Submodules** tab (or another view that sends a repo path to the server) fails, and the server log shows:
+
+```
+❌ Route error [GET /api/git/submodules/status]: path is outside allowed directories
+```
+
+**Cause**: Routes that accept a caller-supplied filesystem path confine it to a set of allowed roots. Those defaults were POSIX-only (`/tmp`, `/Users`, `/Volumes`, `/opt`) — on Windows they resolve to whatever drive the process happens to be running from, so a repo on a second drive (`D:\code\myapp`) matched nothing, and on Linux a repo under `/mnt` or `/media` matched nothing either. Either way the request was rejected with a 403.
+
+**Solution**: Update PortOS. The defaults now cover wherever each platform mounts secondary volumes: `/Volumes` on macOS, `/mnt` and `/media` on Linux, and on Windows your home directory, the temp directory, and any lettered drive that isn't the system drive. The rest of the Windows system drive stays off-limits (`C:\Windows`, `C:\Program Files`), as do UNC paths (`\\server\share`) — map the share to a drive letter if you keep repos on it.
+
+For anywhere else, set `PORTOS_WORKSPACE_ROOTS`. Separate entries with `;` on Windows (`D:\repos;E:\projects`) — a colon would split the value at the drive letter. macOS/Linux still use `:` (`/srv/git:/data/projects`).
+
### Memory System Not Working
**Symptom**: Memory search returns no results, embeddings fail.
diff --git a/server/lib/README.md b/server/lib/README.md
index ebf5c8c882..4e36c77ce5 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -364,7 +364,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `uuid.js` | `v4()` thin wrapper over `crypto.randomUUID()`. |
| `versionUtils.js` | `compareSemver(a, b)` — semver ordering (-1/0/1) with pre-release precedence and build-metadata stripping. Shared by the self-update checker (`updateChecker.js`) and the local-LLM Ollama update detector (`localLlm.js`). Inputs must be `v`-stripped. |
| `workTracker.js` | `WORK_TRACKERS`/`CONCRETE_WORK_TRACKERS`/`DEFAULT_WORK_TRACKER`, `workTrackerLabel`, `hostToWorkTracker`, `isGithubHost` (GitHub-family host test — github.com + enterprise github.*; enterprise-aware replacement for the github.com-only `isGithub` gate), `githubRepoSpec(origin)` (host-qualified `HOST/OWNER/REPO` selector for `gh --repo`, or null for a non-GitHub origin — pairs the isGithubHost gate with the selector so prWatcher/branchReconcile/issueReconcile share one "resolvable GitHub repo" definition), `forgeCliForTracker`, `isFileTracker` (true when the tracker records work as repo files — PLAN.md — so an agent's proposal necessarily dirties the worktree; false for github/gitlab/jira), `trackerToClaimTaskType`, `hostFromOriginUrl` (subgroup-tolerant host parse), pure `resolveWorkTracker({configured,host})`, async `resolveAppWorkTracker(app)` — resolves a managed app's autonomous work source (PLAN.md / GitHub / GitLab / JIRA), defaulting `'auto'` to the git origin host. Async `resolveRepoForgeTarget(repoPath)` — the ONE definition of "which forge can we query for this checkout", returning `{ forge, fullName, repoSpec, apiHost }` (enterprise-aware `gh --repo` selector for GitHub; `repoSpec: null` for GitLab, which `glab` resolves from its cwd) or null for a non-forge origin; shared by `issueReconcile.js` and `appIssues.js`. Async `resolveAppForgeTarget(app, {repoPath})` — the composed `resolveAppWorkTracker` + `resolveRepoForgeTarget` for callers holding the managed-app record, returning `{ tracker, target }` with the app's github/gitlab pin threaded in as `preferredForge` (so a self-hosted forge on a hostname matching neither pattern still resolves); use this instead of re-threading the pin by hand. Also owns the `{trackerInstructions}` prompt block shared by the TRACKER-FILING task types (types that read the app read-only and deliver findings as tracker items, not a commit): `TRACKER_FILING_PRESETS` (per-task-type slug prefix / label / body requirements — `reference-watch`, `ux`, `repo-study`), `TRACKER_FILING_TASK_TYPES` (derived from the presets, so a gated type always has wording), and `formatTrackerInstructions(tracker, options)` which renders the plan/github/gitlab/jira block (reference-watch is the default option set, so a bare call stays byte-identical for it). Consumed by the `claim-work` router in `cosTaskGenerator.js`, `referenceRepos.js`, and `routes/apps.js`. |
-| `workspaceRoots.js` | Shared allow-list for routes that take a caller-supplied filesystem path. `ALLOWED_WORKSPACE_ROOTS` (defaults + `PORTOS_WORKSPACE_ROOTS`, symlink-resolved), `isWithinRoot(resolvedPath, root)` (separator-safe containment), `isWithinAllowedRoots(realPath)`, and `WORKSPACE_ROOTS_CONFIGURED` (true when the operator set the env var — lets a permissive-by-default route like `routes/detect.js` opt into confinement). Used by `routes/commands.js` (always scoped) and `routes/detect.js` (scoped only when configured). |
+| `workspaceRoots.js` | Shared allow-list for routes that take a caller-supplied filesystem path. `isWithinAllowedRoots(realPath)` is the single complete test — on Windows it also allows any lettered non-system drive (`D:\code`), which appears in no root, so never render `ALLOWED_WORKSPACE_ROOTS` as "the directories you may use". Also `ALLOWED_WORKSPACE_ROOTS` (defaults + `PORTOS_WORKSPACE_ROOTS`, split on the platform path delimiter — `;` on Windows — and symlink-resolved), `isWithinRoot(resolvedPath, root)` (separator-safe containment), and `WORKSPACE_ROOTS_CONFIGURED` (true when the operator set the env var — lets a permissive-by-default route like `routes/detect.js` opt into confinement). Defaults cover home plus wherever the platform mounts secondary volumes: `/tmp` + `/Users` + `/Volumes` + `/mnt` + `/media` + `/opt` on POSIX; home + the temp dir plus the non-system-drive rule on Windows, where those POSIX literals would resolve to whatever drive the process happens to be on. Used by `routes/commands.js`, `routes/scaffold.js`, and `routes/git.js` (always scoped) and `routes/detect.js` (scoped only when configured). |
| `zodCompat.js` | Zod 4 compatibility helpers. `partialWithoutDefaults(objectSchema)` — like `.partial()` but strips inner field defaults first, so a PATCH/update schema doesn't inject (and clobber) the stored values of fields the caller didn't send. Use for any update schema derived from a defaulted base. |
## Test support
diff --git a/server/lib/workspaceRoots.js b/server/lib/workspaceRoots.js
index 1a0dc083d6..772edaa951 100644
--- a/server/lib/workspaceRoots.js
+++ b/server/lib/workspaceRoots.js
@@ -1,23 +1,42 @@
import { realpathSync } from 'fs';
-import { resolve, relative, isAbsolute } from 'path';
-import { homedir } from 'os';
+import { resolve, relative, isAbsolute, delimiter } from 'path';
+import { homedir, tmpdir } from 'os';
// Allowed workspace roots shared by routes that accept a caller-supplied
-// filesystem path (command execution scoping in `routes/commands.js`, repo
-// detection in `routes/detect.js`).
+// filesystem path: command execution (`routes/commands.js`), repo detection
+// (`routes/detect.js`), scaffolding (`routes/scaffold.js`), submodule reads
+// (`routes/git.js`).
//
-// Defaults cover common single-user Tailscale deployments (home + /tmp +
-// /Users so multiple macOS accounts' repos work, plus /Volumes for external
-// drives and /opt for Linux server layouts). Operators can extend via
-// PORTOS_WORKSPACE_ROOTS="/path1:/path2" if their repos live somewhere more
-// exotic.
+// Repos legitimately live on secondary volumes, so the defaults cover home plus
+// the places each platform mounts them: /Volumes (macOS), /mnt + /media (Linux),
+// and — because Windows has no such directory — any lettered non-system drive,
+// via the rule below. Windows also drops the POSIX literals entirely: there is
+// no /tmp or /opt there, and `resolve('/tmp')` means "\tmp on whatever drive the
+// process happens to be on", which is both meaningless and non-deterministic.
+//
+// Operators extend either platform with PORTOS_WORKSPACE_ROOTS, split on the
+// platform path delimiter (`;` on Windows, where `:` would cut `D:\repos` at
+// the drive letter).
//
// Roots are symlink-resolved (e.g. /tmp -> /private/tmp on macOS) so a path
// the caller passed and we realpath() still matches.
-export const DEFAULT_WORKSPACE_ROOTS = [homedir(), '/tmp', '/Users', '/Volumes', '/opt'];
+const IS_WINDOWS = process.platform === 'win32';
+
+export const DEFAULT_WORKSPACE_ROOTS = IS_WINDOWS
+ ? [homedir(), tmpdir()]
+ : [homedir(), '/tmp', '/Users', '/Volumes', '/mnt', '/media', '/opt'];
+
+// The drive Windows itself is installed on, e.g. `C:`. Everything on it stays
+// confined to the roots above, so C:\Windows and C:\Program Files are out.
+const WINDOWS_SYSTEM_DRIVE = IS_WINDOWS ? (process.env.SystemDrive || 'C:').toUpperCase() : null;
+
+// A lettered drive prefix: `D:\` or `D:/`. UNC paths (\\server\share) do not
+// match — but note a network share mapped to a letter (`net use Z: …`) is
+// indistinguishable from a local volume here, and is allowed.
+const WINDOWS_DRIVE_PREFIX = /^([A-Za-z]:)[\\/]/;
export const EXTRA_WORKSPACE_ROOTS = (process.env.PORTOS_WORKSPACE_ROOTS || '')
- .split(':')
+ .split(delimiter)
.map(s => s.trim())
.filter(Boolean);
@@ -27,6 +46,9 @@ export const EXTRA_WORKSPACE_ROOTS = (process.env.PORTOS_WORKSPACE_ROOTS || '')
// it and enforce against ALLOWED_WORKSPACE_ROOTS unconditionally.
export const WORKSPACE_ROOTS_CONFIGURED = EXTRA_WORKSPACE_ROOTS.length > 0;
+// NOT the whole answer on Windows — the non-system-drive rule below allows paths
+// that appear in no root here. `isWithinAllowedRoots` is the only complete test;
+// don't render this list as "the directories you may use".
export const ALLOWED_WORKSPACE_ROOTS = [...DEFAULT_WORKSPACE_ROOTS, ...EXTRA_WORKSPACE_ROOTS]
.map(r => {
const abs = resolve(r);
@@ -42,8 +64,19 @@ export function isWithinRoot(resolvedPath, root) {
return !!rel && !rel.startsWith('..') && !isAbsolute(rel);
}
+// Windows counterpart of /Volumes and /mnt: a repo on a data drive (D:\code) is
+// as legitimate a workspace as ~/projects. Node can't enumerate drives portably,
+// so this is a rule rather than another entry in ALLOWED_WORKSPACE_ROOTS.
+function isOnWindowsWorkspaceDrive(realPath) {
+ if (!IS_WINDOWS) return false;
+ const match = WINDOWS_DRIVE_PREFIX.exec(realPath);
+ return !!match && match[1].toUpperCase() !== WINDOWS_SYSTEM_DRIVE;
+}
+
// True when a symlink-resolved path sits inside any allowed root. Callers must
-// pass an already-realpath()'d path so a symlink can't escape the check.
+// pass an already-realpath()'d path so a symlink can't escape the check. This is
+// the single entry point — see the ALLOWED_WORKSPACE_ROOTS caveat above.
export function isWithinAllowedRoots(realPath) {
+ if (isOnWindowsWorkspaceDrive(realPath)) return true;
return ALLOWED_WORKSPACE_ROOTS.some(root => isWithinRoot(realPath, root));
}
diff --git a/server/lib/workspaceRoots.test.js b/server/lib/workspaceRoots.test.js
index 1ec4fee62e..ffda3ef88c 100644
--- a/server/lib/workspaceRoots.test.js
+++ b/server/lib/workspaceRoots.test.js
@@ -1,6 +1,6 @@
import { describe, it, expect, afterEach, vi } from 'vitest';
import { homedir } from 'os';
-import { join } from 'path';
+import { join, delimiter } from 'path';
import {
isWithinRoot,
isWithinAllowedRoots,
@@ -8,6 +8,9 @@ import {
DEFAULT_WORKSPACE_ROOTS,
} from './workspaceRoots.js';
+const IS_WINDOWS = process.platform === 'win32';
+const SYSTEM_DRIVE = (process.env.SystemDrive || 'C:').toUpperCase();
+
describe('isWithinRoot', () => {
it('returns true when the path IS the root', () => {
expect(isWithinRoot('/Users/alice', '/Users/alice')).toBe(true);
@@ -44,6 +47,30 @@ describe('isWithinAllowedRoots', () => {
});
});
+// Windows repos routinely live off the system drive (D:\code, E:\projects), and
+// the POSIX defaults (/tmp, /Users, /Volumes, /opt) resolve to nothing useful
+// there — so a non-system lettered drive is allowed, the way /Volumes is on macOS.
+describe('Windows non-system drives', () => {
+ const otherDrive = SYSTEM_DRIVE === 'Z:' ? 'Y:\\' : 'Z:\\';
+
+ it.runIf(IS_WINDOWS)('accepts a path on a non-system drive', () => {
+ expect(isWithinAllowedRoots(`${otherDrive}code\\myapp`)).toBe(true);
+ });
+
+ it.runIf(IS_WINDOWS)('rejects system-drive paths outside the allowed roots', () => {
+ expect(isWithinAllowedRoots(`${SYSTEM_DRIVE}\\Windows\\System32`)).toBe(false);
+ });
+
+ it.runIf(IS_WINDOWS)('rejects UNC paths', () => {
+ expect(isWithinAllowedRoots('\\\\server\\share\\repo')).toBe(false);
+ });
+
+ it.runIf(!IS_WINDOWS)('mounted-volume roots cover the Linux mount points', () => {
+ expect(isWithinAllowedRoots('/mnt/data/code')).toBe(true);
+ expect(isWithinAllowedRoots('/media/usb/repo')).toBe(true);
+ });
+});
+
describe('ALLOWED_WORKSPACE_ROOTS', () => {
it('includes every default root', () => {
// Defaults are symlink-resolved, so compare on length/non-empty rather than
@@ -70,8 +97,10 @@ describe('PORTOS_WORKSPACE_ROOTS opt-in gate', () => {
expect(mod.EXTRA_WORKSPACE_ROOTS).toEqual([]);
});
- it('parses colon-separated roots, trimming and dropping empties', async () => {
- vi.stubEnv('PORTOS_WORKSPACE_ROOTS', ' /srv/repos : : /data/projects ');
+ it('splits on the platform path delimiter, trimming and dropping empties', async () => {
+ // `;` on Windows, `:` on POSIX — splitting a Windows value on `:` would cut
+ // `D:\repos` in half at the drive letter.
+ vi.stubEnv('PORTOS_WORKSPACE_ROOTS', ` /srv/repos ${delimiter}${delimiter} /data/projects `);
vi.resetModules();
const mod = await import('./workspaceRoots.js');
expect(mod.WORKSPACE_ROOTS_CONFIGURED).toBe(true);
diff --git a/server/routes/detect.js b/server/routes/detect.js
index 171f9a4753..60370ee998 100644
--- a/server/routes/detect.js
+++ b/server/routes/detect.js
@@ -25,9 +25,9 @@ const router = Router();
// confinement is required for safety.
//
// Operators who still want to confine detection to specific directories can set
-// PORTOS_WORKSPACE_ROOTS="/path1:/path2" (the same allow-list `routes/commands.js`
-// uses to scope command execution). When that env var is set, this route enforces
-// the allow-list too — a path outside the configured roots returns valid:false
+// PORTOS_WORKSPACE_ROOTS (see `.env.example` for the format — the same allow-list
+// `routes/commands.js` uses to scope command execution). When that env var is set,
+// this route enforces the allow-list too — a path outside the roots returns valid:false
// rather than reading its files. When it is unset (the default), detection is
// unrestricted, matching the pre-existing behavior.
router.post('/repo', asyncHandler(async (req, res) => {