@commonlyai/cli 0.1.388 → 0.1.389

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.388",
3
+ "version": "0.1.389",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -63,6 +63,12 @@ const PLATFORM_BASELINE = String.raw`
63
63
  (subpath "/private/var/db"))
64
64
  (allow file-read* file-test-existence
65
65
  (subpath "/System/Volumes/Preboot/Cryptexes/OS"))
66
+ ; The active developer tools, read-only. /usr/bin/git and the other /usr/bin
67
+ ; developer commands are xcrun shims: they read the xcode-select link, then run
68
+ ; the tool from the Command Line Tools, and git reads its own defaults there.
69
+ (allow file-read* file-test-existence
70
+ (literal "/private/var/select/developer_dir")
71
+ (subpath "/Library/Developer/CommandLineTools"))
66
72
 
67
73
  (allow file-map-executable
68
74
  (subpath "/Library/Apple/System/Library/Frameworks")
@@ -346,10 +352,24 @@ export const parseSeatbeltReadRoots = (profile) => {
346
352
  literals: Object.freeze([...literals]),
347
353
  });
348
354
  };
349
- let systemReadRoots = null;
350
- export const seatbeltSystemReadRoots = () => {
351
- if (!systemReadRoots) systemReadRoots = parseSeatbeltReadRoots(PLATFORM_BASELINE);
352
- return systemReadRoots;
355
+ // Only the static baseline is cached. The developer folder is resolved on
356
+ // every call, as each profile resolves it, so a key-file check never trusts a
357
+ // selection the next profile no longer has (CodeRabbit on #4205). The same
358
+ // selection returns the same object.
359
+ let baselineReadRoots = null;
360
+ const rootsByDeveloperRules = new Map();
361
+ export const seatbeltSystemReadRoots = ({ developerDirs = resolveDeveloperDirs() } = {}) => {
362
+ if (!baselineReadRoots) baselineReadRoots = parseSeatbeltReadRoots(PLATFORM_BASELINE);
363
+ const rules = developerDirsRules(developerDirs);
364
+ if (!rules) return baselineReadRoots;
365
+ if (!rootsByDeveloperRules.has(rules)) {
366
+ const extra = parseSeatbeltReadRoots(rules);
367
+ rootsByDeveloperRules.set(rules, Object.freeze({
368
+ subpaths: Object.freeze([...new Set([...baselineReadRoots.subpaths, ...extra.subpaths])]),
369
+ literals: Object.freeze([...new Set([...baselineReadRoots.literals, ...extra.literals])]),
370
+ }));
371
+ }
372
+ return rootsByDeveloperRules.get(rules);
353
373
  };
354
374
 
355
375
  // Both network modes. On macOS, c-ares (node's dns.Resolver and dns.resolve*)
@@ -411,6 +431,36 @@ const isSymlink = (path) => {
411
431
  }
412
432
  };
413
433
 
434
+ // The two xcode-select links. The xcrun shim reads developer_dir; both name
435
+ // the same folder on a normal install, and a turn admits each target.
436
+ const XCODE_SELECT_LINKS = Object.freeze(['/private/var/select/developer_dir', '/private/var/db/xcode_select_link']);
437
+ const COMMAND_LINE_TOOLS = '/Library/Developer/CommandLineTools';
438
+
439
+ /**
440
+ * The read-only rule for a developer folder xcode-select points at, when that
441
+ * isn't the Command Line Tools the baseline already admits. /usr/bin/git is an
442
+ * xcrun shim that runs git from that folder. Only a developer folder's shape
443
+ * is admitted: an Xcode bundle's Contents/Developer, or a folder under
444
+ * /Library/Developer. Anything else (/, a home folder, a link that did not
445
+ * resolve, a path holding a quote, backslash, `;` or line break) gets no
446
+ * rule, and git there fails closed. A `;` starts a comment to
447
+ * parseSeatbeltReadRoots, so such a path would drop out of the key-file roots.
448
+ */
449
+ export function developerDirRules(activeDeveloperDir) {
450
+ const dir = String(activeDeveloperDir || '');
451
+ if (!isAbsolute(dir) || XCODE_SELECT_LINKS.includes(dir) || /["\\;\r\n]/.test(dir)) return '';
452
+ if (dir === COMMAND_LINE_TOOLS || dir.startsWith(`${COMMAND_LINE_TOOLS}/`)) return '';
453
+ if (!dir.endsWith('.app/Contents/Developer') && !dir.startsWith('/Library/Developer/')) return '';
454
+ return [
455
+ `(allow file-read* file-test-existence ${subpath(dir)})`,
456
+ `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(dir)}"))`,
457
+ ].join('\n');
458
+ }
459
+
460
+ // What the links point at now; read once per profile and once per root check.
461
+ const resolveDeveloperDirs = () => [...new Set(XCODE_SELECT_LINKS.map(realpathOrSelf))];
462
+ const developerDirsRules = (dirs) => dirs.map(developerDirRules).filter(Boolean).join('\n');
463
+
414
464
  // A folder this profile lets the jail write is one the jail can also replace:
415
465
  // a write rule on a folder covers the folder's own name, so a process from an
416
466
  // earlier turn can move it aside and leave a link there. The profile grants
@@ -623,6 +673,9 @@ export const buildSeatbeltProfile = ({
623
673
  // a seat credential in memory, as a public pi does. Signals are not narrowed:
624
674
  // a parent must still stop the children it started.
625
675
  processInfo = 'same-sandbox',
676
+ // The developer folders xcode-select points at. Resolved on each profile by
677
+ // default; tests pass their own.
678
+ developerDirs = resolveDeveloperDirs(),
626
679
  // Pin a writable workspace to its own name (see pinnedRealpath). Set it for
627
680
  // a public seat. Its workspace is usually the scratch folder the CLI made;
628
681
  // when it is an `environment.workspace.path` the operator gave and that path
@@ -776,6 +829,7 @@ export const buildSeatbeltProfile = ({
776
829
 
777
830
  return [
778
831
  `${PLATFORM_BASELINE}${RESOLVER_CONFIG}${network === 'open' ? OPEN_NETWORK : ''}`.trim(),
832
+ developerDirsRules(developerDirs),
779
833
  executableRules,
780
834
  executableSymlinkRules,
781
835
  `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(resolvedWorkspace)}"))`,