@commonlyai/cli 0.1.388 → 0.1.390
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
|
@@ -148,7 +148,8 @@ const WORK_CUES = [PARALLEL_READS_CUE, ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE];
|
|
|
148
148
|
const RUNTIME_CREDENTIAL_PLACEHOLDER = '${COMMONLY_AGENT_TOKEN}';
|
|
149
149
|
|
|
150
150
|
// A workspace seat's sandbox.filesystem.read-outside, with `~` expanded the way
|
|
151
|
-
// bwrap.js expands it.
|
|
151
|
+
// bwrap.js expands it. resolveHostReadDirectories refuses anything still
|
|
152
|
+
// relative, naming the entry, before the turn spawns.
|
|
152
153
|
const workspaceReadOutside = (env) => {
|
|
153
154
|
const declared = env?.sandbox?.filesystem?.['read-outside'];
|
|
154
155
|
if (!Array.isArray(declared)) return [];
|
|
@@ -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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|
|
@@ -575,6 +625,11 @@ export const resolveHostReadDirectories = (entries, home = homedir(), { fold = t
|
|
|
575
625
|
try {
|
|
576
626
|
const canonicalHome = canonicalPath(home);
|
|
577
627
|
return entries.map((entry) => {
|
|
628
|
+
// A relative entry would resolve against the CLI's own folder, which is
|
|
629
|
+
// no folder the operator named (CodeRabbit on #4111). Callers expand ~/.
|
|
630
|
+
if (typeof entry !== 'string' || !isAbsolute(entry)) {
|
|
631
|
+
throw new Error(`refusing sandbox.filesystem.read-outside ${entry}: name a folder by its absolute path or by ~/.`);
|
|
632
|
+
}
|
|
578
633
|
const canonical = canonicalPath(entry);
|
|
579
634
|
let reason = hostReadRefusal(canonical, canonicalHome);
|
|
580
635
|
if (!reason && only && !only.some((allowed) => foldedWithin(join(canonicalHome, allowed), canonical))) {
|
|
@@ -623,6 +678,9 @@ export const buildSeatbeltProfile = ({
|
|
|
623
678
|
// a seat credential in memory, as a public pi does. Signals are not narrowed:
|
|
624
679
|
// a parent must still stop the children it started.
|
|
625
680
|
processInfo = 'same-sandbox',
|
|
681
|
+
// The developer folders xcode-select points at. Resolved on each profile by
|
|
682
|
+
// default; tests pass their own.
|
|
683
|
+
developerDirs = resolveDeveloperDirs(),
|
|
626
684
|
// Pin a writable workspace to its own name (see pinnedRealpath). Set it for
|
|
627
685
|
// a public seat. Its workspace is usually the scratch folder the CLI made;
|
|
628
686
|
// when it is an `environment.workspace.path` the operator gave and that path
|
|
@@ -744,10 +802,12 @@ export const buildSeatbeltProfile = ({
|
|
|
744
802
|
`(allow file-read* file-test-existence ${subpath(path)})`,
|
|
745
803
|
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(path)}"))`,
|
|
746
804
|
].join('\n'))).join('\n');
|
|
747
|
-
// The adapter's own read-only inputs,
|
|
805
|
+
// The adapter's own read-only inputs, stated again after the host dot denies.
|
|
806
|
+
// Built from the adapter's list itself, so a folder the seat also names keeps
|
|
807
|
+
// the adapter's view of it, dot files included (CodeRabbit on #4111).
|
|
748
808
|
const adapterReadOnlyRules = resolvedReadOnlyPaths.map((path) => (
|
|
749
809
|
`(allow file-read* file-test-existence ${literal(path)})`
|
|
750
|
-
)).concat(
|
|
810
|
+
)).concat([...new Set(readOnlyDirectories.map(realpathOrSelf))].map((path) => (
|
|
751
811
|
`(allow file-read* file-test-existence ${subpath(path)})`
|
|
752
812
|
))).join('\n');
|
|
753
813
|
// A symlinked entry is held at both its name and its target, so the write
|
|
@@ -776,6 +836,7 @@ export const buildSeatbeltProfile = ({
|
|
|
776
836
|
|
|
777
837
|
return [
|
|
778
838
|
`${PLATFORM_BASELINE}${RESOLVER_CONFIG}${network === 'open' ? OPEN_NETWORK : ''}`.trim(),
|
|
839
|
+
developerDirsRules(developerDirs),
|
|
779
840
|
executableRules,
|
|
780
841
|
executableSymlinkRules,
|
|
781
842
|
`(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(resolvedWorkspace)}"))`,
|