@commonlyai/cli 0.1.386 → 0.1.388
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -58,7 +58,9 @@ import { spawn as childSpawn, spawnSync } from 'child_process';
|
|
|
58
58
|
import {
|
|
59
59
|
createHash, randomBytes, randomUUID, timingSafeEqual,
|
|
60
60
|
} from 'crypto';
|
|
61
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
accessSync, constants, readdirSync, realpathSync,
|
|
63
|
+
} from 'fs';
|
|
62
64
|
import {
|
|
63
65
|
chmod,
|
|
64
66
|
lstat,
|
|
@@ -93,7 +95,9 @@ import { closeHeldPaths, openHeldPath } from '../sandbox/bind-fd.js';
|
|
|
93
95
|
import { PUBLIC_SANDBOX_MODES, resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
94
96
|
import { UNSANDBOXED_FLAG } from '../sandbox/host-check.js';
|
|
95
97
|
import {
|
|
98
|
+
HOST_READ_DOT_ALLOW,
|
|
96
99
|
publicClaudeStateRoot,
|
|
100
|
+
resolveHostReadDirectories,
|
|
97
101
|
wrapArgvWithSeatbelt,
|
|
98
102
|
} from '../sandbox/seatbelt.js';
|
|
99
103
|
import {
|
|
@@ -143,6 +147,17 @@ const PARALLEL_READS_CUE = 'Parallel reads: when a row needs several files or so
|
|
|
143
147
|
const WORK_CUES = [PARALLEL_READS_CUE, ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE];
|
|
144
148
|
const RUNTIME_CREDENTIAL_PLACEHOLDER = '${COMMONLY_AGENT_TOKEN}';
|
|
145
149
|
|
|
150
|
+
// A workspace seat's sandbox.filesystem.read-outside, with `~` expanded the way
|
|
151
|
+
// bwrap.js expands it. Anything still relative is refused by the profile.
|
|
152
|
+
const workspaceReadOutside = (env) => {
|
|
153
|
+
const declared = env?.sandbox?.filesystem?.['read-outside'];
|
|
154
|
+
if (!Array.isArray(declared)) return [];
|
|
155
|
+
return declared.map((p) => {
|
|
156
|
+
if (p === '~') return homedir();
|
|
157
|
+
return typeof p === 'string' && p.startsWith('~/') ? join(homedir(), p.slice(2)) : p;
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
|
|
146
161
|
const QUOTE_SHELL_ARGUMENT = (value) => `'${String(value).replaceAll("'", "'\\''")}'`;
|
|
147
162
|
|
|
148
163
|
// The helper takes the token from one of two places. With a socket path and a
|
|
@@ -647,12 +662,43 @@ const permissionPath = (path, platform) => (platform === 'win32'
|
|
|
647
662
|
// The tools that read or write the seat's agent-wide memory.
|
|
648
663
|
const MEMORY_TOOLS = Object.freeze(['commonly_read_agent_memory', 'commonly_write_agent_memory', 'commonly_save_my_memory']);
|
|
649
664
|
|
|
650
|
-
const buildPublicClaudePolicyArgs = (mcpToolPatterns, {
|
|
665
|
+
export const buildPublicClaudePolicyArgs = (mcpToolPatterns, {
|
|
651
666
|
trust, allow = [], memoryWithheld = false, ownerWoken = false, platform = process.platform, home: homeOverride = null,
|
|
652
667
|
noShell = false,
|
|
668
|
+
// F122: a workspace seat's host read folders, already checked and resolved
|
|
669
|
+
// (resolveHostReadDirectories). The jail is the boundary; this lets the
|
|
670
|
+
// seat's Read, Grep and Glob reach them, which `Read(./**)` alone does not.
|
|
671
|
+
hostReads = [],
|
|
653
672
|
} = {}) => {
|
|
654
673
|
const home = homeOverride || homedir();
|
|
655
674
|
const deny = (sub) => absoluteToolDeny(permissionPath(join(home, sub), platform));
|
|
675
|
+
const hostReadAllows = hostReads.map((dir) => absoluteToolDeny(permissionPath(dir, platform)));
|
|
676
|
+
// Claude Code applies a deny before any allow, so a grant inside ~/.commonly
|
|
677
|
+
// (only ~/.commonly/logs passes the check) would be refused by the
|
|
678
|
+
// ~/.commonly deny. Then that deny becomes one per other entry in the folder.
|
|
679
|
+
// An entry created after the spawn is not named here; the jail still
|
|
680
|
+
// refuses it, as it refuses everything not granted.
|
|
681
|
+
const commonlyHome = join(home, '.commonly');
|
|
682
|
+
const folded = (p) => p.toLowerCase();
|
|
683
|
+
const grantsInsideCommonly = hostReads.some((dir) => folded(dir).startsWith(`${folded(commonlyHome)}/`));
|
|
684
|
+
const commonlyDenies = () => {
|
|
685
|
+
if (!grantsInsideCommonly) return [deny('.commonly')];
|
|
686
|
+
try {
|
|
687
|
+
return readdirSync(commonlyHome)
|
|
688
|
+
.filter((name) => !hostReads.some((dir) => {
|
|
689
|
+
const entry = folded(join(commonlyHome, name));
|
|
690
|
+
return folded(dir) === entry || folded(dir).startsWith(`${entry}/`);
|
|
691
|
+
}))
|
|
692
|
+
// A file such as admin-token is matched by its own name, a folder by
|
|
693
|
+
// what is under it: each entry is denied both ways.
|
|
694
|
+
.flatMap((name) => {
|
|
695
|
+
const entry = permissionPath(join(commonlyHome, name), platform);
|
|
696
|
+
return [`Read(/${entry})`, `Read(/${entry}/**)`];
|
|
697
|
+
});
|
|
698
|
+
} catch {
|
|
699
|
+
return [deny('.commonly')];
|
|
700
|
+
}
|
|
701
|
+
};
|
|
656
702
|
// `allow` is already narrowed to a workspace seat's grants (workspaceGrants).
|
|
657
703
|
// With no OS jail (native Windows, --unsandboxed) a shell would run
|
|
658
704
|
// with the user's whole access and could read the seat's own token from its
|
|
@@ -663,7 +709,7 @@ const buildPublicClaudePolicyArgs = (mcpToolPatterns, {
|
|
|
663
709
|
.filter((tool) => !(noShell && SHELL_TOOLS.has(tool)))
|
|
664
710
|
.map((tool) => (noShell && (tool === 'Edit' || tool === 'Write') ? `${tool}(./**)` : tool));
|
|
665
711
|
const deniedReads = [
|
|
666
|
-
|
|
712
|
+
...commonlyDenies(),
|
|
667
713
|
deny('.claude'),
|
|
668
714
|
deny('.codex'),
|
|
669
715
|
deny('.ssh'),
|
|
@@ -716,7 +762,7 @@ const buildPublicClaudePolicyArgs = (mcpToolPatterns, {
|
|
|
716
762
|
'--strict-mcp-config',
|
|
717
763
|
'--no-chrome',
|
|
718
764
|
'--permission-mode', 'dontAsk',
|
|
719
|
-
'--allowedTools', 'Read(./**)', ...granted, ...mcpToolPatterns,
|
|
765
|
+
'--allowedTools', 'Read(./**)', ...hostReadAllows, ...granted, ...mcpToolPatterns,
|
|
720
766
|
'--disallowedTools', ...PUBLIC_DENIED_TOOLS.filter((tool) => !granted.some((g) => g === tool || g.startsWith(`${tool}(`))),
|
|
721
767
|
...deniedReads, ...toolDenies,
|
|
722
768
|
];
|
|
@@ -1597,10 +1643,15 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1597
1643
|
if (!ctx.publicClaudeState) {
|
|
1598
1644
|
throw new Error('public Claude state was not prepared before argv construction');
|
|
1599
1645
|
}
|
|
1646
|
+
// F122: checked and resolved once; the policy and the profile get the same list.
|
|
1647
|
+
const hostReads = sandboxTrust === 'workspace'
|
|
1648
|
+
? resolveHostReadDirectories(workspaceReadOutside(env))
|
|
1649
|
+
: [];
|
|
1600
1650
|
innerArgv = [
|
|
1601
1651
|
...innerArgv,
|
|
1602
1652
|
...buildPublicClaudePolicyArgs(allowedPatterns, {
|
|
1603
1653
|
trust: sandboxTrust, allow: grants, memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken,
|
|
1654
|
+
hostReads,
|
|
1604
1655
|
}),
|
|
1605
1656
|
...(ctx.publicSkillArgs || []),
|
|
1606
1657
|
];
|
|
@@ -1644,6 +1695,10 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1644
1695
|
...(ctx.workspaceGit?.readDirectories || []),
|
|
1645
1696
|
],
|
|
1646
1697
|
readOnlyPaths: ctx.workspaceGit?.readPaths || [],
|
|
1698
|
+
// F122: a workspace seat reads the host folders it names, as it does
|
|
1699
|
+
// under bwrap on Linux, so an Ops-type seat can read the logs it watches
|
|
1700
|
+
// without running unconfined. A public seat names none: strangers drive it.
|
|
1701
|
+
hostReadDirectories: hostReads,
|
|
1647
1702
|
});
|
|
1648
1703
|
return {
|
|
1649
1704
|
cmd: wrapped[0],
|
|
@@ -1668,7 +1723,17 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1668
1723
|
innerArgv = [
|
|
1669
1724
|
...innerArgv,
|
|
1670
1725
|
...buildPublicClaudePolicyArgs(allowedPatterns, workspaceBwrapSandbox
|
|
1671
|
-
? {
|
|
1726
|
+
? {
|
|
1727
|
+
trust: sandboxTrust,
|
|
1728
|
+
allow: grants,
|
|
1729
|
+
memoryWithheld: ctx.memoryWithheld === true,
|
|
1730
|
+
ownerWoken: ctx.ownerWoken,
|
|
1731
|
+
// F493: the folders bwrap binds for this seat, checked the same way
|
|
1732
|
+
// wrapArgvWithBwrap checks them, so its Read tool can reach them.
|
|
1733
|
+
hostReads: resolveHostReadDirectories(workspaceReadOutside(env), homedir(), {
|
|
1734
|
+
fold: false, only: HOST_READ_DOT_ALLOW,
|
|
1735
|
+
}),
|
|
1736
|
+
}
|
|
1672
1737
|
: { memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken }),
|
|
1673
1738
|
...(ctx.publicSkillArgs || []),
|
|
1674
1739
|
];
|
|
@@ -476,10 +476,8 @@ export default {
|
|
|
476
476
|
const available = (ctx._detectBwrap || detectBwrap)();
|
|
477
477
|
if (!available.available) throw new Error(`goose adapter: bwrap unavailable: ${available.error}`);
|
|
478
478
|
[executable, ...spawnArgs] = (ctx._wrapArgvWithBwrap || wrapArgvWithBwrap)([binary, ...args], {
|
|
479
|
-
...ctx.environment, sandbox
|
|
480
|
-
|
|
481
|
-
} },
|
|
482
|
-
}, { workspacePath: turnWorkspace, homePath: home,
|
|
479
|
+
...ctx.environment, sandbox,
|
|
480
|
+
}, { workspacePath: turnWorkspace, homePath: home, homeWritablePaths: [home],
|
|
483
481
|
readOnlyPaths: [tempDir, binary, process.execPath, ...mcpReadDirectories] });
|
|
484
482
|
} else {
|
|
485
483
|
if ((ctx._platform || process.platform) !== 'darwin') throw new Error('goose adapter: Seatbelt requires macOS');
|
|
@@ -1686,17 +1686,12 @@ export default {
|
|
|
1686
1686
|
sandbox: {
|
|
1687
1687
|
...sandbox,
|
|
1688
1688
|
network: { ...sandbox?.network, policy: 'restricted' },
|
|
1689
|
-
filesystem: {
|
|
1690
|
-
...(sandbox?.filesystem || {}),
|
|
1691
|
-
'write-outside': [
|
|
1692
|
-
...(Array.isArray(sandbox?.filesystem?.['write-outside'])
|
|
1693
|
-
? sandbox.filesystem['write-outside'] : []),
|
|
1694
|
-
openCodeHome.root,
|
|
1695
|
-
],
|
|
1696
|
-
},
|
|
1697
1689
|
},
|
|
1698
1690
|
}, {
|
|
1699
1691
|
workspacePath: ctx.cwd,
|
|
1692
|
+
// Its own home, bound writable through opts: the spec's lists are
|
|
1693
|
+
// the server's, and a public seat's are refused (F493).
|
|
1694
|
+
homeWritablePaths: [openCodeHome.root],
|
|
1700
1695
|
readOnlyPaths: [
|
|
1701
1696
|
tempDir,
|
|
1702
1697
|
binary,
|
package/src/lib/adapters/qwen.js
CHANGED
|
@@ -456,17 +456,11 @@ export default {
|
|
|
456
456
|
if (!bwrap.available) throw new Error(`public Qwen seats require bwrap: ${bwrap.error}`);
|
|
457
457
|
[cmd, ...spawnArgs] = (ctx._wrapArgvWithBwrap || wrapArgvWithBwrap)([bwrapEntry, ...args], {
|
|
458
458
|
...ctx.environment,
|
|
459
|
-
sandbox
|
|
460
|
-
...sandbox,
|
|
461
|
-
filesystem: {
|
|
462
|
-
...(sandbox?.filesystem || {}),
|
|
463
|
-
'write-outside': [
|
|
464
|
-
...(sandbox?.filesystem?.['write-outside'] || []), home,
|
|
465
|
-
],
|
|
466
|
-
},
|
|
467
|
-
},
|
|
459
|
+
sandbox,
|
|
468
460
|
}, {
|
|
469
461
|
workspacePath: ctx.cwd,
|
|
462
|
+
// Its own home, bound writable through opts (F493).
|
|
463
|
+
homeWritablePaths: [home],
|
|
470
464
|
homePath: home,
|
|
471
465
|
readOnlyPaths: [tempDir, bwrapEntry, packageDir, process.execPath, ...mcpReadDirectories].filter(Boolean),
|
|
472
466
|
});
|
package/src/lib/sandbox/bwrap.js
CHANGED
|
@@ -18,6 +18,9 @@ import { existsSync, readFileSync } from 'fs';
|
|
|
18
18
|
import { isAbsolute, join } from 'path';
|
|
19
19
|
import { homedir } from 'os';
|
|
20
20
|
|
|
21
|
+
import { effectiveSandboxTrust } from '../environment.js';
|
|
22
|
+
import { HOST_READ_DOT_ALLOW, resolveHostReadDirectories } from './seatbelt.js';
|
|
23
|
+
|
|
21
24
|
// Tilde-expansion lives here (and not in environment.js's expandHome) because
|
|
22
25
|
// bwrap reads OS-level paths verbatim — `~` is a shell construct, not a
|
|
23
26
|
// kernel one, so any `~/foo` entry in `read-outside` / `write-outside` would
|
|
@@ -282,20 +285,51 @@ export const wrapArgvWithBwrap = (innerArgv, env, opts = {}) => {
|
|
|
282
285
|
'--tmpfs', '/tmp',
|
|
283
286
|
];
|
|
284
287
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
// F493: the spec's binds are the server's to write, so a confined seat's are
|
|
289
|
+
// held to what the jail can keep safe.
|
|
290
|
+
// - public: neither list. Strangers drive the seat; an adapter's own
|
|
291
|
+
// folders come through opts (writablePaths), never the spec.
|
|
292
|
+
// - workspace: read-outside only inside HOST_READ_DOT_ALLOW (bwrap cannot
|
|
293
|
+
// hide the .env files beneath a wider bind, as Seatbelt's denies do),
|
|
294
|
+
// resolved once and bound at the resolved path; write-outside refused, as
|
|
295
|
+
// on macOS (a writable project lets a seat plant a git hook the host runs).
|
|
296
|
+
// - none (a seat of your own): as declared. It is not confined, and names
|
|
297
|
+
// folders such as ~/.local/bin on purpose.
|
|
298
|
+
const trust = effectiveSandboxTrust(env?.sandbox?.trust);
|
|
299
|
+
const declaredBinds = (key) => (Array.isArray(env?.sandbox?.filesystem?.[key])
|
|
300
|
+
? env.sandbox.filesystem[key].map(expandHome) : []);
|
|
301
|
+
for (const key of ['read-outside', 'write-outside']) {
|
|
302
|
+
if (trust === 'public' && declaredBinds(key).length) {
|
|
303
|
+
throw new Error(`refusing sandbox.filesystem.${key}: a public seat binds nothing outside its own folders`);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (trust === 'workspace' && declaredBinds('write-outside').length) {
|
|
307
|
+
throw new Error('refusing sandbox.filesystem.write-outside: a workspace seat writes only its project, '
|
|
308
|
+
+ 'as on macOS');
|
|
309
|
+
}
|
|
310
|
+
const userReadOutside = trust === 'workspace'
|
|
311
|
+
? resolveHostReadDirectories(declaredBinds('read-outside'), opts.hostReadHome || homedir(), {
|
|
312
|
+
fold: false, only: HOST_READ_DOT_ALLOW,
|
|
313
|
+
})
|
|
314
|
+
: declaredBinds('read-outside');
|
|
288
315
|
const roBinds = [...new Set([...DEFAULT_RO_BINDS, ...userReadOutside])];
|
|
289
316
|
for (const p of roBinds) {
|
|
290
317
|
flags.push('--ro-bind-try', p, p);
|
|
291
318
|
}
|
|
292
319
|
|
|
293
|
-
const userWriteOutside =
|
|
294
|
-
? env.sandbox.filesystem['write-outside'].map(expandHome)
|
|
295
|
-
: [];
|
|
320
|
+
const userWriteOutside = declaredBinds('write-outside');
|
|
296
321
|
for (const p of userWriteOutside) {
|
|
297
322
|
flags.push('--bind-try', p, p);
|
|
298
323
|
}
|
|
324
|
+
// A public adapter's own home (F493: it used to ride in the spec's
|
|
325
|
+
// write-outside). bwrap stacks later binds on top, so it binds here, before
|
|
326
|
+
// the read-only inputs below: an input inside the home stays read-only.
|
|
327
|
+
for (const p of opts.homeWritablePaths || []) {
|
|
328
|
+
if (!p || !isAbsolute(p)) {
|
|
329
|
+
throw new Error('wrapArgvWithBwrap opts.homeWritablePaths entries must be absolute paths');
|
|
330
|
+
}
|
|
331
|
+
flags.push('--bind-try', p, p);
|
|
332
|
+
}
|
|
299
333
|
|
|
300
334
|
// Adapter-owned transient inputs (for example Claude's per-spawn MCP
|
|
301
335
|
// config) live outside the workspace so model-visible Read(./**) cannot
|
|
@@ -23,7 +23,7 @@ import { spawnSync } from 'child_process';
|
|
|
23
23
|
import { lstatSync, realpathSync } from 'fs';
|
|
24
24
|
import { homedir } from 'os';
|
|
25
25
|
import {
|
|
26
|
-
basename, dirname, isAbsolute, join, resolve,
|
|
26
|
+
basename, dirname, isAbsolute, join, relative, resolve,
|
|
27
27
|
} from 'path';
|
|
28
28
|
|
|
29
29
|
const SANDBOX_EXEC = '/usr/bin/sandbox-exec';
|
|
@@ -480,6 +480,118 @@ export const detectSeatbelt = () => {
|
|
|
480
480
|
}
|
|
481
481
|
};
|
|
482
482
|
|
|
483
|
+
// F122: which host folders a workspace seat may read through its
|
|
484
|
+
// sandbox.filesystem.read-outside. An allowlist, not a list of where
|
|
485
|
+
// credentials live: such a list lags every new token file (an Opus review found
|
|
486
|
+
// eleven under ~/.commonly that one missed). Inside the home folder:
|
|
487
|
+
// - a folder whose first name under home starts with a dot is refused, except
|
|
488
|
+
// HOST_READ_DOT_ALLOW (the CLI's logs);
|
|
489
|
+
// - ~/Library is refused (keychains, browser and app data);
|
|
490
|
+
// - the home folder itself, and any folder that holds it (`/`, /Users), are
|
|
491
|
+
// refused.
|
|
492
|
+
// Anything else in home (a project tree) is admitted read-only, with the
|
|
493
|
+
// workspace's own credential denies (.env*, .commonly, .codex, .npmrc, .yarnrc)
|
|
494
|
+
// applied beneath it. Outside home only HOST_READ_SYSTEM_ALLOW is admitted: the
|
|
495
|
+
// temp folders hold every seat's per-turn runtime token (same uid, so their
|
|
496
|
+
// 0700 mode is no fence), and /System/Volumes/Data firmlink spellings of home
|
|
497
|
+
// are refused with everything else not on the list (second Opus review).
|
|
498
|
+
//
|
|
499
|
+
// Paths are compared canonically and case-folded. APFS is case-insensitive and
|
|
500
|
+
// so is Seatbelt's subpath match, while path.relative and the JS realpathSync
|
|
501
|
+
// keep the case they were given: `~/.SSH` would otherwise pass a check for
|
|
502
|
+
// `.ssh` and still read ~/.ssh.
|
|
503
|
+
export const HOST_READ_DOT_ALLOW = Object.freeze(['.commonly/logs']);
|
|
504
|
+
export const HOST_READ_SYSTEM_ALLOW = Object.freeze(['/var/log', '/private/var/log', '/Library/Logs']);
|
|
505
|
+
|
|
506
|
+
// The real path, with the real case, of the longest prefix that exists, plus
|
|
507
|
+
// the rest as given. Resolved once: the result is both checked and granted.
|
|
508
|
+
const canonicalPath = (path) => {
|
|
509
|
+
const absolute = resolve(path);
|
|
510
|
+
let existing = absolute;
|
|
511
|
+
const rest = [];
|
|
512
|
+
for (;;) {
|
|
513
|
+
try {
|
|
514
|
+
return join(realpathSync.native(existing), ...rest);
|
|
515
|
+
} catch {
|
|
516
|
+
const parent = dirname(existing);
|
|
517
|
+
if (parent === existing) return absolute;
|
|
518
|
+
rest.unshift(basename(existing));
|
|
519
|
+
existing = parent;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
// Case is folded where the filesystem ignores it (macOS); on Linux the names
|
|
525
|
+
// are compared as they are, so `/VAR/LOG` is not taken for `/var/log`.
|
|
526
|
+
let foldCase = (p) => p.toLowerCase();
|
|
527
|
+
const foldedWithin = (outer, inner) => {
|
|
528
|
+
const rel = relative(foldCase(outer), foldCase(inner));
|
|
529
|
+
return rel === '' || (rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel));
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// A dot folder or dotfile anywhere along the path, not only directly under
|
|
533
|
+
// home: ~/Projects/repo/.commonly is a token folder too (CodeRabbit on #4111).
|
|
534
|
+
// The one exception is inside HOST_READ_DOT_ALLOW.
|
|
535
|
+
const dotComponent = (canonical, home) => {
|
|
536
|
+
if (HOST_READ_DOT_ALLOW.some((allowed) => foldedWithin(join(home, allowed), canonical))) {
|
|
537
|
+
const allowed = HOST_READ_DOT_ALLOW.find((a) => foldedWithin(join(home, a), canonical));
|
|
538
|
+
const below = relative(foldCase(join(home, allowed)), foldCase(canonical));
|
|
539
|
+
return below.split('/').find((name) => name.startsWith('.')) || null;
|
|
540
|
+
}
|
|
541
|
+
return canonical.split('/').find((name) => name.startsWith('.')) || null;
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
const hostReadRefusal = (canonical, home) => {
|
|
545
|
+
if (foldedWithin(canonical, home)) return 'it holds your home folder';
|
|
546
|
+
const dot = dotComponent(canonical, home);
|
|
547
|
+
if (dot) {
|
|
548
|
+
return `${dot} is a dot folder or dotfile, and those are not readable from a seat `
|
|
549
|
+
+ `(only ${HOST_READ_DOT_ALLOW.map((a) => `~/${a}`).join(', ')} is)`;
|
|
550
|
+
}
|
|
551
|
+
if (!foldedWithin(home, canonical)) {
|
|
552
|
+
return HOST_READ_SYSTEM_ALLOW.some((allowed) => foldedWithin(allowed, canonical))
|
|
553
|
+
? null
|
|
554
|
+
: `outside your home folder only ${HOST_READ_SYSTEM_ALLOW.join(', ')} are readable from a seat`;
|
|
555
|
+
}
|
|
556
|
+
const rel = relative(foldCase(home), foldCase(canonical));
|
|
557
|
+
const [first] = rel.split('/');
|
|
558
|
+
if (foldCase(first) === 'library') return '~/Library holds keychains and app data';
|
|
559
|
+
if (first.startsWith('.')
|
|
560
|
+
&& !HOST_READ_DOT_ALLOW.some((allowed) => foldedWithin(join(home, allowed), canonical))) {
|
|
561
|
+
return `the folders under ~/${first.split('/')[0]} are not readable from a seat `
|
|
562
|
+
+ `(of the dot folders, only ${HOST_READ_DOT_ALLOW.map((a) => `~/${a}`).join(', ')} is)`;
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
// Each entry resolved once, refused on the first that fails, in the order given.
|
|
568
|
+
// - fold: compare case-insensitively (macOS; default). Linux passes false.
|
|
569
|
+
// - only: folders under home the entry must also sit inside. bwrap cannot
|
|
570
|
+
// hide a credential file beneath a folder it binds, as Seatbelt's pattern
|
|
571
|
+
// denies do, so Linux admits only HOST_READ_DOT_ALLOW (F493 review).
|
|
572
|
+
export const resolveHostReadDirectories = (entries, home = homedir(), { fold = true, only = null } = {}) => {
|
|
573
|
+
const previousFold = foldCase;
|
|
574
|
+
foldCase = fold ? (p) => p.toLowerCase() : (p) => p;
|
|
575
|
+
try {
|
|
576
|
+
const canonicalHome = canonicalPath(home);
|
|
577
|
+
return entries.map((entry) => {
|
|
578
|
+
const canonical = canonicalPath(entry);
|
|
579
|
+
let reason = hostReadRefusal(canonical, canonicalHome);
|
|
580
|
+
if (!reason && only && !only.some((allowed) => foldedWithin(join(canonicalHome, allowed), canonical))) {
|
|
581
|
+
reason = `here only ${only.map((a) => `~/${a}`).join(', ')} can be named, because this sandbox `
|
|
582
|
+
+ 'cannot hide the credential files beneath a folder it binds';
|
|
583
|
+
}
|
|
584
|
+
if (reason) {
|
|
585
|
+
throw new Error(`refusing sandbox.filesystem.read-outside ${entry}: ${reason}.`);
|
|
586
|
+
}
|
|
587
|
+
return canonical;
|
|
588
|
+
});
|
|
589
|
+
} finally {
|
|
590
|
+
foldCase = previousFold;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
|
|
483
595
|
export const buildSeatbeltProfile = ({
|
|
484
596
|
workspacePath,
|
|
485
597
|
workspaceAccess = 'write',
|
|
@@ -489,6 +601,14 @@ export const buildSeatbeltProfile = ({
|
|
|
489
601
|
executablePaths = [],
|
|
490
602
|
readOnlyPaths = [],
|
|
491
603
|
readOnlyDirectories = [],
|
|
604
|
+
// F122: host folders a workspace seat names in sandbox.filesystem.read-outside,
|
|
605
|
+
// admitted read-only. Unlike readOnlyDirectories (folders the adapter itself
|
|
606
|
+
// prepared), these come from the seat's spec, which the server can write, so
|
|
607
|
+
// each passes resolveHostReadDirectories first and the turn is refused
|
|
608
|
+
// otherwise.
|
|
609
|
+
hostReadDirectories = [],
|
|
610
|
+
// The home folder those rules are judged against. Tests pass a temp one.
|
|
611
|
+
hostReadHome = homedir(),
|
|
492
612
|
loopbackNetworkPorts = [],
|
|
493
613
|
allowClaudeRuntimeAccess = false,
|
|
494
614
|
// 'open' (the default) or 'loopback': only the listed loopback ports.
|
|
@@ -533,6 +653,8 @@ export const buildSeatbeltProfile = ({
|
|
|
533
653
|
for (const path of denyWritePaths) assertAbsolutePath(path, 'denyWritePaths entry');
|
|
534
654
|
for (const path of readOnlyPaths) assertAbsolutePath(path, 'readOnlyPaths entry');
|
|
535
655
|
for (const path of readOnlyDirectories) assertAbsolutePath(path, 'readOnlyDirectories entry');
|
|
656
|
+
for (const path of hostReadDirectories) assertAbsolutePath(path, 'hostReadDirectories entry');
|
|
657
|
+
const grantedHostReads = [...new Set(resolveHostReadDirectories(hostReadDirectories, hostReadHome))];
|
|
536
658
|
for (const port of loopbackNetworkPorts) {
|
|
537
659
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
538
660
|
throw new Error('Seatbelt loopbackNetworkPorts entries must be valid TCP ports');
|
|
@@ -582,7 +704,10 @@ export const buildSeatbeltProfile = ({
|
|
|
582
704
|
const resolvedState = pinnedRealpath(statePath, 'state folder');
|
|
583
705
|
const resolvedMcpConfig = mcpConfigDir ? realpathOrSelf(mcpConfigDir) : null;
|
|
584
706
|
const resolvedReadOnlyPaths = [...new Set(readOnlyPaths.map(realpathOrSelf))];
|
|
585
|
-
const resolvedReadOnlyDirectories = [...new Set(
|
|
707
|
+
const resolvedReadOnlyDirectories = [...new Set([
|
|
708
|
+
...readOnlyDirectories.map(realpathOrSelf),
|
|
709
|
+
...grantedHostReads,
|
|
710
|
+
])];
|
|
586
711
|
const executables = [...new Set(
|
|
587
712
|
[resolvedExecutable, process.execPath, ...executablePaths]
|
|
588
713
|
.filter(Boolean)
|
|
@@ -619,6 +744,12 @@ export const buildSeatbeltProfile = ({
|
|
|
619
744
|
`(allow file-read* file-test-existence ${subpath(path)})`,
|
|
620
745
|
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(path)}"))`,
|
|
621
746
|
].join('\n'))).join('\n');
|
|
747
|
+
// The adapter's own read-only inputs, without the host read grants.
|
|
748
|
+
const adapterReadOnlyRules = resolvedReadOnlyPaths.map((path) => (
|
|
749
|
+
`(allow file-read* file-test-existence ${literal(path)})`
|
|
750
|
+
)).concat(resolvedReadOnlyDirectories.filter((path) => !grantedHostReads.includes(path)).map((path) => (
|
|
751
|
+
`(allow file-read* file-test-existence ${subpath(path)})`
|
|
752
|
+
))).join('\n');
|
|
622
753
|
// A symlinked entry is held at both its name and its target, so the write
|
|
623
754
|
// cannot land through whichever path the link resolves to.
|
|
624
755
|
const readOnlyWorkspaceRules = [...new Set(readOnlyWorkspaceEntries.flatMap((entry) => {
|
|
@@ -654,6 +785,16 @@ export const buildSeatbeltProfile = ({
|
|
|
654
785
|
loopbackNetworkRules,
|
|
655
786
|
mcpRule,
|
|
656
787
|
readOnlyRules,
|
|
788
|
+
// Beneath a host read folder, every dot folder and dotfile is denied, the
|
|
789
|
+
// same rule its request passed: a project tree holds other repos' .env
|
|
790
|
+
// files, .commonly token folders, .ssh keys and .aws credentials. One rule
|
|
791
|
+
// on the leading dot covers every name, in any case (CodeRabbit on #4129).
|
|
792
|
+
...grantedHostReads.map((dir) => `(deny file-read* file-write* ${regexUnder(dir, '\\.[^/]*(/.*)?$')})`),
|
|
793
|
+
// Later rules win, so a grant that holds the workspace, or a folder the
|
|
794
|
+
// adapter itself prepared, would hide its .git and dotfiles. Those allows
|
|
795
|
+
// are stated again here, and the workspace's credential denies follow them
|
|
796
|
+
// (CodeRabbit on #4111).
|
|
797
|
+
...(grantedHostReads.length ? [workspaceRule, adapterReadOnlyRules] : []),
|
|
657
798
|
// The workspace is intentionally readable, but credential-like nested
|
|
658
799
|
// paths are not. Explicit deny wins over the broad workspace allow.
|
|
659
800
|
`(deny file-read* file-write* ${subpath(join(resolvedWorkspace, '.commonly'))})`,
|