@commonlyai/cli 0.1.340 → 0.1.341

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.340",
3
+ "version": "0.1.341",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -71,7 +71,7 @@ import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credent
71
71
  import { prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir } from '../mcp-home.js';
72
72
  import { removeCredentialFile, writeCredentialFile } from '../credential-file.js';
73
73
  import { resolvePublicSandboxMode } from '../sandbox/mode.js';
74
- import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
74
+ import { seatbeltSystemReadRoots, wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
75
75
  import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
76
76
  import { publicSeatWithheldTools } from '../public-withheld-tools.js';
77
77
  import { promptTokens } from '../session-recycle.js';
@@ -344,16 +344,29 @@ const sharedProviderKeyFile = async (environment, workspacePath) => {
344
344
 
345
345
  /**
346
346
  * The proxy reads a public seat's key file from this process, so the file stays
347
- * out of the jail, and nothing here admits it. The jail does admit these
348
- * directories, and the seat home is a stable path a key file could be put in,
349
- * so a key under one of them would be readable from inside.
347
+ * out of the jail, and nothing here admits it. The jail does admit the seat's
348
+ * own directories (the seat home is a stable path a key file could be put in),
349
+ * and the Seatbelt baseline admits system trees such as /etc, /opt/homebrew/lib
350
+ * and /usr/local/lib (seatbeltSystemReadRoots, read from the profile itself).
351
+ * A key under any of them would be readable from inside, so it is refused.
352
+ * Each root is compared as written and through its real path (/etc is
353
+ * /private/etc on macOS); a root that does not exist is compared as written.
350
354
  */
351
- const refuseKeyFileInJail = (keyFile, readableDirectories) => {
352
- for (const directory of readableDirectories) {
353
- const fromDirectory = relative(realpathSync(directory), keyFile);
354
- if (fromDirectory !== '..' && !fromDirectory.startsWith(`..${sep}`) && !isAbsolute(fromDirectory)) {
355
- throw new Error(`pi adapter: provider.keyFile ${keyFile} is inside the sandbox of a public seat; move it outside ${directory}`);
356
- }
355
+ const realOrSelf = (path) => { try { return realpathSync(path); } catch { return path; } };
356
+ const within = (root, path) => {
357
+ const fromRoot = relative(root, path);
358
+ return fromRoot !== '..' && !fromRoot.startsWith(`..${sep}`) && !isAbsolute(fromRoot);
359
+ };
360
+ export const refuseKeyFileInJail = (keyFile, readableDirectories, systemRoots = seatbeltSystemReadRoots()) => {
361
+ const refuse = (root) => {
362
+ throw new Error(`pi adapter: provider.keyFile ${keyFile} is inside the sandbox of a public seat; move it outside ${root}`);
363
+ };
364
+ const forms = (root) => [...new Set([root, realOrSelf(root)])];
365
+ for (const directory of [...readableDirectories, ...systemRoots.subpaths]) {
366
+ if (forms(directory).some((root) => within(root, keyFile))) refuse(directory);
367
+ }
368
+ for (const literal of systemRoots.literals) {
369
+ if (forms(literal).includes(keyFile)) refuse(literal);
357
370
  }
358
371
  };
359
372
 
@@ -299,6 +299,59 @@ const OPEN_NETWORK = String.raw`
299
299
  (global-name "com.apple.securityd.xpc"))
300
300
  `;
301
301
 
302
+ // The static paths the baseline lets a jail READ (file-read* or file-read-data),
303
+ // as `subpaths` (whole trees) and `literals` (one file or directory entry).
304
+ // Read from PLATFORM_BASELINE itself, so a caller keeping a secret out of the
305
+ // jail (a public seat's provider key file) checks what the profile actually
306
+ // admits rather than a copy that drifts. Metadata-only grants are not reads;
307
+ // regex grants cover /dev only and are left out. Dynamic per-turn paths
308
+ // (workspace, state, executables, read-only directories) are the caller's.
309
+ const READ_OPERATIONS = ['file-read*', 'file-read-data'];
310
+ export const parseSeatbeltReadRoots = (profile) => {
311
+ const subpaths = new Set();
312
+ const literals = new Set();
313
+ const text = profile.replace(/;[^\n]*/g, '');
314
+ let at = text.indexOf('(allow ');
315
+ while (at !== -1) {
316
+ // The rule's balanced s-expression; parentheses inside a string don't count.
317
+ let depth = 0;
318
+ let end = at;
319
+ let inString = false;
320
+ for (; end < text.length; end += 1) {
321
+ const ch = text[end];
322
+ if (inString) { if (ch === '\\') end += 1; else if (ch === '"') inString = false; continue; }
323
+ if (ch === '"') inString = true;
324
+ else if (ch === '(') depth += 1;
325
+ else if (ch === ')') { depth -= 1; if (depth === 0) break; }
326
+ }
327
+ const rule = text.slice(at, end + 1);
328
+ const operations = rule.slice('(allow '.length).split('(')[0].trim().split(/\s+/);
329
+ if (operations.some((op) => READ_OPERATIONS.includes(op))) {
330
+ for (const match of rule.matchAll(/\((subpath|literal) "([^"]+)"\)/g)) {
331
+ (match[1] === 'subpath' ? subpaths : literals).add(match[2]);
332
+ }
333
+ // Fail closed: a read filter this cannot turn into a root would be a
334
+ // readable path the key-file check never sees. Regex grants are known
335
+ // to cover /dev only, and are held to that.
336
+ for (const filter of rule.matchAll(/\((path|prefix|regex|home-subpath|home-literal|home-prefix)\s+(#?"[^"]*")/g)) {
337
+ if (filter[1] !== 'regex' || !/^#?"\^\/dev\//.test(filter[2])) {
338
+ throw new Error(`seatbeltSystemReadRoots: a read rule uses a filter it cannot check: (${filter[1]} ${filter[2]})`);
339
+ }
340
+ }
341
+ }
342
+ at = text.indexOf('(allow ', end + 1);
343
+ }
344
+ return Object.freeze({
345
+ subpaths: Object.freeze([...subpaths]),
346
+ literals: Object.freeze([...literals]),
347
+ });
348
+ };
349
+ let systemReadRoots = null;
350
+ export const seatbeltSystemReadRoots = () => {
351
+ if (!systemReadRoots) systemReadRoots = parseSeatbeltReadRoots(PLATFORM_BASELINE);
352
+ return systemReadRoots;
353
+ };
354
+
302
355
  // Both network modes. On macOS, c-ares (node's dns.Resolver and dns.resolve*)
303
356
  // reads the resolver list from configd's DNSConfiguration service while the
304
357
  // Resolver is constructed. Denied, that lookup does not always fail: at