@commonlyai/cli 0.1.387 → 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
|
@@ -95,6 +95,7 @@ import { closeHeldPaths, openHeldPath } from '../sandbox/bind-fd.js';
|
|
|
95
95
|
import { PUBLIC_SANDBOX_MODES, resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
96
96
|
import { UNSANDBOXED_FLAG } from '../sandbox/host-check.js';
|
|
97
97
|
import {
|
|
98
|
+
HOST_READ_DOT_ALLOW,
|
|
98
99
|
publicClaudeStateRoot,
|
|
99
100
|
resolveHostReadDirectories,
|
|
100
101
|
wrapArgvWithSeatbelt,
|
|
@@ -1722,7 +1723,17 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1722
1723
|
innerArgv = [
|
|
1723
1724
|
...innerArgv,
|
|
1724
1725
|
...buildPublicClaudePolicyArgs(allowedPatterns, workspaceBwrapSandbox
|
|
1725
|
-
? {
|
|
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
|
+
}
|
|
1726
1737
|
: { memoryWithheld: ctx.memoryWithheld === true, ownerWoken: ctx.ownerWoken }),
|
|
1727
1738
|
...(ctx.publicSkillArgs || []),
|
|
1728
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
|
|
@@ -521,8 +521,11 @@ const canonicalPath = (path) => {
|
|
|
521
521
|
}
|
|
522
522
|
};
|
|
523
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();
|
|
524
527
|
const foldedWithin = (outer, inner) => {
|
|
525
|
-
const rel = relative(outer
|
|
528
|
+
const rel = relative(foldCase(outer), foldCase(inner));
|
|
526
529
|
return rel === '' || (rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel));
|
|
527
530
|
};
|
|
528
531
|
|
|
@@ -532,7 +535,7 @@ const foldedWithin = (outer, inner) => {
|
|
|
532
535
|
const dotComponent = (canonical, home) => {
|
|
533
536
|
if (HOST_READ_DOT_ALLOW.some((allowed) => foldedWithin(join(home, allowed), canonical))) {
|
|
534
537
|
const allowed = HOST_READ_DOT_ALLOW.find((a) => foldedWithin(join(home, a), canonical));
|
|
535
|
-
const below = relative(join(home, allowed)
|
|
538
|
+
const below = relative(foldCase(join(home, allowed)), foldCase(canonical));
|
|
536
539
|
return below.split('/').find((name) => name.startsWith('.')) || null;
|
|
537
540
|
}
|
|
538
541
|
return canonical.split('/').find((name) => name.startsWith('.')) || null;
|
|
@@ -550,9 +553,9 @@ const hostReadRefusal = (canonical, home) => {
|
|
|
550
553
|
? null
|
|
551
554
|
: `outside your home folder only ${HOST_READ_SYSTEM_ALLOW.join(', ')} are readable from a seat`;
|
|
552
555
|
}
|
|
553
|
-
const rel = relative(home
|
|
556
|
+
const rel = relative(foldCase(home), foldCase(canonical));
|
|
554
557
|
const [first] = rel.split('/');
|
|
555
|
-
if (first === 'library') return '~/Library holds keychains and app data';
|
|
558
|
+
if (foldCase(first) === 'library') return '~/Library holds keychains and app data';
|
|
556
559
|
if (first.startsWith('.')
|
|
557
560
|
&& !HOST_READ_DOT_ALLOW.some((allowed) => foldedWithin(join(home, allowed), canonical))) {
|
|
558
561
|
return `the folders under ~/${first.split('/')[0]} are not readable from a seat `
|
|
@@ -562,18 +565,33 @@ const hostReadRefusal = (canonical, home) => {
|
|
|
562
565
|
};
|
|
563
566
|
|
|
564
567
|
// Each entry resolved once, refused on the first that fails, in the order given.
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
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
|
+
}
|
|
575
592
|
};
|
|
576
593
|
|
|
594
|
+
|
|
577
595
|
export const buildSeatbeltProfile = ({
|
|
578
596
|
workspacePath,
|
|
579
597
|
workspaceAccess = 'write',
|