Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(hosted-team): git reads need the shared root to be its own repository (C1)
review2dad4f430708
diff --git a/CLAUDE.md b/CLAUDE.mdindex f16d905f1..28d17f896 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -6185,7 +6185,11 @@ The invariants, each with its reason:**"Read" is not "safe"**: relay peers were fully trusted, so every VIEW entry carries its ownargument check. `fs:*` is realpath-jailed to a shared project's realpathed cwd; `git:diff` jailsthe FILE too (`--no-index` diffs any file on the host); a `git:show-file` ref starting with `-`- is an option (`--output=` writes a file); `pty:create` is cut down to a whitelist, because+ is an option (`--output=` writes a file); **every git read also needs the shared root holding+ the cwd to be the top of its OWN repository** (a `.git` dir or worktree file): `git show+ <ref>:<p>` resolves `<p>` against the repository's top level and `git status`/`log` report the+ whole repository, so from a shared `repo/shared/` a Viewer read `repo/secret/key.txt` (measured,+ C1) — a monorepo subfolder gets no git panel; `pty:create` is cut down to a whitelist, because`sshRemote`'s args run `ssh` on the host during the existence probe. Editors pass untouched(Editor is shell access). The UI mirror (`@shared/hosted-access.ts`, `bridge/hosted-gate.ts`) isconvenience; `access-policy.guard.test.ts` pins it equal and fails on any relay-API channeldiff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.mdindex 37cf9c996..af86fa626 100644--- a/docs/hosted-team-relay.md+++ b/docs/hosted-team-relay.md@@ -180,7 +180,8 @@ later, is Editor-only until someone decides otherwise.|---|---|---|---|---|| See the shared projects' canvas, presence and cursors (`workspace:load`, `presence:hello/cursor/focus/project`) | ✓ | ✓ | ✓ | ✓ || Watch a terminal of a shared project that is **already running** | ✓ | ✓ | ✓ | ✓ |-| Read files and git state inside a shared project | ✓ | ✓ | ✓ | ✓ |+| Read files inside a shared project | ✓ | ✓ | ✓ | ✓ |+| Read a shared project's git state (status, diffs, history, file versions) | only when the project is the top folder of its own repository | same as Viewer | ✓ | ✓ || Read a shared project's board log | ✓ | ✓ | ✓ | ✓ || Cursor chat (`presence:chat`), board-log comments (`board-log:append`) | — | ✓ | ✓ | ✓ || Type into terminals, start terminals, write files, every git mutation, canvas edits, settings, credentials, logs, GitHub | — | — | ✓ | ✓ |@@ -200,9 +201,10 @@ session key** in the team store.| `pty:kill` | Detaches the caller's own view; the session keeps running. || `pty:capture`, `pty:read-scrollback`, `pty:pane-command` | Nodes of shared projects only. || `pty:tmux-status` | Allowed. |-| `fs:list`, `fs:read`, `fs:read-binary`, `fs:exists`, `git:status`, `git:repo-root`, `git:history` | The path must be absolute and its **realpath** inside a shared project's cwd (also realpathed). A symlink planted inside the project that points out of it is outside. |-| `git:diff` | The cwd **and** the file are jailed; a pathspec starting with `:` is refused; an untracked diff (`git diff --no-index`, which diffs any file) needs a real path inside. |-| `git:show-file` | Cwd jailed; a ref starting with `-` is refused (it would become an option, and `--output=` writes a file). |+| `fs:list`, `fs:read`, `fs:read-binary`, `fs:exists` | The path must be absolute and its **realpath** inside a shared project's cwd (also realpathed). A symlink planted inside the project that points out of it is outside. |+| `git:status`, `git:repo-root`, `git:history` | The cwd is jailed like a file read, **and** the shared project that contains it must be the top folder of its own repository: a `.git` directory, or a worktree's `.git` file. Otherwise: "Git is available to viewers only in a project that is the top folder of its own repository, never in a subfolder of a larger one." A cwd jail alone does not bound git: `git status` and `git log` report the whole repository, and `git show <ref>:<path>` reads `<path>` from the repository's top level, so from a shared `repo/shared/` a Viewer could read `repo/secret/key.txt`. |+| `git:diff` | The cwd (with the repository rule above) **and** the file are jailed; a pathspec starting with `:` is refused; an untracked diff (`git diff --no-index`, which diffs any file) needs a real path inside. The file is relative to the cwd, not the repository's top level. |+| `git:show-file` | The cwd jailed, with the repository rule above; a ref starting with `-` is refused (it would become an option, and `--output=` writes a file). Any other revision is allowed. || `agent:subagent-snapshot` | The response is trimmed to shared nodes. || `board-log:read/subscribe/unsubscribe` (+ `append` for Commenters) | Shared projects only. |@@ -385,6 +387,12 @@ The human `team status` reads `state`, `idle` and `lastError` together:same as SSH access".- **A Viewer sees terminal output** (the dialog says "including anything printed in them") and canread **every file** under a shared project's folder, including `.env` files and `.git`.+- **Sharing a repository shares its whole history.** When a shared project is the top folder of its+ own repository, `git:show-file` takes any revision, so a Viewer can read every branch, tag, stash+ and past commit of it, including files deleted since. A worktree shares its main repository's+ object store and refs, so sharing a worktree's folder exposes the whole repository's history+ (the main checkout's stash included), not only that checkout. A project that is a subfolder of a+ larger repository gets no git at all for Viewers and Commenters.- **Nothing is served before mutual approval.** A pre-approval request answers `E_UNAUTHORIZED`and never reaches a handler. Frames that arrive between approval and open (while the pin iswritten) are held (at most 256), then served through the same checks.@@ -427,6 +435,9 @@ The human `team status` reads `state`, `idle` and `lastError` together:- **Kanban, bridge and rope edits made in a relay tab are never propagated or saved.** `canvas:mut`carries nodes only (an upsert or a remove), so project-level state (`kanban`, `bridges`, `ropes`)never leaves the tab. This predates the hosted relay; it holds for Team Access relay tabs too.+- **No git for Viewers in a subfolder of a larger repository.** Viewers and Commenters get the git+ panel only for a project that is the top folder of its own repository (or a worktree's). A+ monorepo subfolder shows its files but refuses every git read (see [Roles](#roles)).- **One shared project per tab.** A joiner's tab adopts the first shared project; other sharedprojects are allowed by the policy but not reachable from the UI.- **Viewers watch only what is already running.** A terminal must be live on the host (a tmuxdiff --git a/src/core/relay/access-policy.test.ts b/src/core/relay/access-policy.test.tsindex 9c7312b56..b1184eddc 100644--- a/src/core/relay/access-policy.test.ts+++ b/src/core/relay/access-policy.test.ts@@ -428,3 +428,92 @@ describe('narrowResponseForRole', () => {expect(narrowResponseForRole(IPC.fsRead, r, ctx('viewer'))).toBe(r)})})++// C1 / R43. `git show <ref>:<p>` resolves a bare <p> against the REPOSITORY'S TOP LEVEL, not the cwd:+// measured with real git, from repo/shared/ a `git show HEAD:secret/key.txt` prints repo/secret/key.txt,+// and `git status` / `git log` list every changed path and commit of the whole repository. The cwd+// jail cannot stop that, so a non-editor gets git only when the shared root holding the cwd is the+// top of its OWN repository (a `.git` directory, or a worktree's `.git` file).+describe('access policy: git needs a shared root that is its own repository (C1)', () => {+ const NOT_OWN_REPO = 'Git is available to viewers only in a project that is the top folder of its own repository, never in a subfolder of a larger one.'+ const GIT_CALLS: Array<[string, unknown[]]> = [+ [IPC.gitStatus, ['/repo/shared']],+ [IPC.gitRepoRoot, ['/repo/shared']],+ [IPC.gitHistory, ['/repo/shared']],+ [IPC.gitDiff, ['/repo/shared', 'a.txt', false, false]],+ [IPC.gitShowFile, ['/repo/shared', 'HEAD', 'secret/key.txt']]+ ]+ // The shared project is repo/shared; only repo/ holds a `.git`.+ const subfolder = (role: AccessContext['role']): AccessContext => ({+ ...ctx(role),+ projectCwds: () => ['/repo/shared'],+ realpath: (p) => (p.endsWith('/.git') && p !== '/repo/.git' ? null : p)+ })++ it('every git VIEW method is refused, with the reason, when the shared root has no .git of its own', () => {+ for (const [m, args] of GIT_CALLS) {+ expect(decideAccess('req', m, args, subfolder('viewer')), m).toEqual({ allow: false, message: NOT_OWN_REPO })+ expect(decideAccess('req', m, args, subfolder('commenter')), m).toEqual({ allow: false, message: NOT_OWN_REPO })+ }+ // Files are still readable: the jail for fs:* is the folder, and the folder IS shared.+ expect(decideAccess('req', IPC.fsRead, ['/repo/shared/a.txt'], subfolder('viewer')).allow).toBe(true)+ })++ it('editors and owners are unaffected', () => {+ for (const [m, args] of GIT_CALLS) {+ expect(decideAccess('req', m, args, subfolder('editor')), m).toEqual({ allow: true })+ expect(decideAccess('req', m, args, subfolder('owner')), m).toEqual({ allow: true })+ }+ })++ it('a cwd outside every shared root is still the read jail, not the repository reason', () => {+ expect(decideAccess('req', IPC.gitStatus, ['/elsewhere'], subfolder('viewer'))).toEqual({ allow: false, message: READ_JAIL_MSG })+ })++ it('a nested shared root with its own .git allows the cwds under it, and only those', () => {+ // Shared: /mono/a (no .git of its own) and /mono/a/b (its own repository).+ const c: AccessContext = {+ ...ctx('viewer'),+ projectCwds: () => ['/mono/a', '/mono/a/b'],+ realpath: (p) => (p.endsWith('/.git') && p !== '/mono/a/b/.git' ? null : p)+ }+ expect(decideAccess('req', IPC.gitStatus, ['/mono/a/b/src'], c).allow).toBe(true)+ expect(decideAccess('req', IPC.gitStatus, ['/mono/a/x'], c)).toEqual({ allow: false, message: NOT_OWN_REPO })+ })++ it.skipIf(process.platform === 'win32')('on disk: a subfolder is refused, the repo root and a worktree root (a .git FILE) are allowed', () => {+ const base = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'access-git-')))+ try {+ fs.mkdirSync(path.join(base, 'repo', '.git'), { recursive: true })+ fs.mkdirSync(path.join(base, 'repo', 'shared'), { recursive: true })+ fs.mkdirSync(path.join(base, 'wt'), { recursive: true })+ fs.writeFileSync(path.join(base, 'wt', '.git'), `gitdir: ${path.join(base, 'repo', '.git', 'worktrees', 'wt')}\n`)+ const onDisk = (root: string): AccessContext => ({+ role: 'viewer',+ sharedProjects: new Set(['P']),+ projectOfNode: () => undefined,+ projectCwds: () => [root],+ realpath: (p) => {+ try {+ return fs.realpathSync(p)+ } catch {+ return null+ }+ }+ })+ const show = (root: string, cwd: string) => decideAccess('req', IPC.gitShowFile, [cwd, 'HEAD', 'secret/key.txt'], onDisk(root))+ const shared = path.join(base, 'repo', 'shared')+ expect(show(shared, shared)).toEqual({ allow: false, message: NOT_OWN_REPO })+ expect(decideAccess('req', IPC.gitStatus, [shared], onDisk(shared))).toEqual({ allow: false, message: NOT_OWN_REPO })+ // The repository root is shared as a whole: its history is the project's own.+ expect(show(path.join(base, 'repo'), shared).allow).toBe(true)+ expect(decideAccess('req', IPC.gitStatus, [path.join(base, 'repo')], onDisk(path.join(base, 'repo'))).allow).toBe(true)+ // A worktree's .git is a file; its root is the top of its own checkout.+ expect(decideAccess('req', IPC.gitStatus, [path.join(base, 'wt')], onDisk(path.join(base, 'wt'))).allow).toBe(true)+ } finally {+ fs.rmSync(base, { recursive: true, force: true })+ }+ })+})++const READ_JAIL_MSG = 'Viewers can only read files inside a shared project.'diff --git a/src/core/relay/access-policy.ts b/src/core/relay/access-policy.tsindex 17e73cc74..eb5eb5741 100644--- a/src/core/relay/access-policy.ts+++ b/src/core/relay/access-policy.ts@@ -85,6 +85,34 @@ function realInSharedCwd(p: unknown, ctx: AccessContext): string | null {const READ_JAIL = 'Viewers can only read files inside a shared project.'+const NOT_OWN_REPO =+ 'Git is available to viewers only in a project that is the top folder of its own repository, never in a subfolder of a larger one.'++/**+ * Is `real` (a realpath inside a shared root) under a shared root that holds its OWN `.git` — a+ * directory, or a worktree's `.git` file? The cwd jail alone does not bound git: `git show <ref>:<p>`+ * resolves a bare `<p>` against the repository's TOP LEVEL, and `git status` / `git log` report the+ * whole repository, so from `repo/shared/` a viewer could read `repo/secret/key.txt` (measured with+ * real git). A root with its own `.git` stops git's upward discovery at or below it, so every+ * repository reachable from `real` is inside something that is shared anyway. Any containing root+ * counts: a nested shared root that is its own repository is fine even when the outer one is not.+ * Planting a `.git` (or a `gitdir:` file pointing elsewhere) takes write access to the shared root,+ * which only an editor has.+ */+function underOwnRepoRoot(real: string, ctx: AccessContext): boolean {+ return sharedRoots(ctx).some((root) => within(root, real) && ctx.realpath(path.join(root, '.git')) !== null)+}++/** Every git VIEW check: the cwd jailed like a file read, then the repository rule above. */+const gitView =+ (rest: Check = pass): Check =>+ (a, ctx) => {+ const cwd = realInSharedCwd(a[0], ctx)+ if (!cwd) return no(READ_JAIL)+ if (!underOwnRepoRoot(cwd, ctx)) return no(NOT_OWN_REPO)+ return rest(a, ctx)+ }+const nodeArg0: Check = (a, ctx) => (sharedNode(a[0], ctx) ? OK : no('That terminal is not in a shared project.'))const pathArg0: Check = (a, ctx) => (realInSharedCwd(a[0], ctx) ? OK : no(READ_JAIL))const projectArg0: Check = (a, ctx) => (sharedProject(a[0], ctx) ? OK : no('That project is not shared.'))@@ -101,7 +129,10 @@ function viewerCreateOptions(o: Record<string, unknown>): Record<string, unknownreturn { ...out, joinOnly: true, sizeVote: false }}-/** `git diff` (handler args: cwd, file, staged, untracked). The FILE is jailed as well as the cwd. */+/** `git diff` (handler args: cwd, file, staged, untracked). The FILE is jailed as well as the cwd.+ * Its pathspec is cwd-relative, not top-level-relative (measured: from `repo/shared/`,+ * `git diff -- secret/key.txt` matches nothing), so the lexical file jail below holds; the+ * repository rule (`gitView`) runs first all the same, like for every git VIEW method. */const gitDiff: Check = (a, ctx) => {const cwd = realInSharedCwd(a[0], ctx)if (!cwd) return no(READ_JAIL)@@ -118,9 +149,9 @@ const gitDiff: Check = (a, ctx) => {}/** `git show <ref>:<file>` (handler args: cwd, ref, file). A ref starting with `-` becomes an- * OPTION of `git show`; measured: `--output=<path>` writes the command's output to that path. */-const gitShowFile: Check = (a, ctx) => {- if (!realInSharedCwd(a[0], ctx)) return no(READ_JAIL)+ * OPTION of `git show`; measured: `--output=<path>` writes the command's output to that path. The+ * file is relative to the repository's top level, which is why `gitView` runs first. */+const gitShowFile: Check = (a) => {const ref = a[1]if (ref !== undefined && ref !== null && (typeof ref !== 'string' || ref.startsWith('-'))) {return no('That is not a revision name.')@@ -160,12 +191,13 @@ export const VIEW: Readonly<Record<string, Check>> = Object.freeze({[IPC.fsRead]: pathArg0,[IPC.fsReadBinary]: pathArg0,[IPC.fsExists]: pathArg0,- [IPC.gitStatus]: pathArg0,- [IPC.gitRepoRoot]: pathArg0,- [IPC.gitDiff]: gitDiff,- [IPC.gitShowFile]: gitShowFile,+ // Every git VIEW method: the cwd jail, then the shared root must be its own repository (C1).+ [IPC.gitStatus]: gitView(),+ [IPC.gitRepoRoot]: gitView(),+ [IPC.gitDiff]: gitView(gitDiff),+ [IPC.gitShowFile]: gitView(gitShowFile),// Its only other argument's ref (`baseRef`) is refused by the core when it starts with `-`.- [IPC.gitHistory]: pathArg0,+ [IPC.gitHistory]: gitView(),// The RESPONSE is trimmed by narrowResponseForRole (it is a response, not an event).[IPC.agentSubagentSnapshot]: pass,[IPC.presenceHello]: pass,