@voratiq/sandbox-runtime 0.7.0-voratiq1

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +11 -0
  4. package/README.md +17 -0
  5. package/dist/cli.d.ts +3 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +243 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/index.d.ts +8 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +7 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/sandbox/generate-seccomp-filter.d.ts +56 -0
  14. package/dist/sandbox/generate-seccomp-filter.d.ts.map +1 -0
  15. package/dist/sandbox/generate-seccomp-filter.js +158 -0
  16. package/dist/sandbox/generate-seccomp-filter.js.map +1 -0
  17. package/dist/sandbox/http-proxy.d.ts +12 -0
  18. package/dist/sandbox/http-proxy.d.ts.map +1 -0
  19. package/dist/sandbox/http-proxy.js +489 -0
  20. package/dist/sandbox/http-proxy.js.map +1 -0
  21. package/dist/sandbox/linux-sandbox-utils.d.ts +111 -0
  22. package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -0
  23. package/dist/sandbox/linux-sandbox-utils.js +518 -0
  24. package/dist/sandbox/linux-sandbox-utils.js.map +1 -0
  25. package/dist/sandbox/macos-sandbox-utils.d.ts +54 -0
  26. package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -0
  27. package/dist/sandbox/macos-sandbox-utils.js +559 -0
  28. package/dist/sandbox/macos-sandbox-utils.js.map +1 -0
  29. package/dist/sandbox/sandbox-config.d.ts +170 -0
  30. package/dist/sandbox/sandbox-config.d.ts.map +1 -0
  31. package/dist/sandbox/sandbox-config.js +126 -0
  32. package/dist/sandbox/sandbox-config.js.map +1 -0
  33. package/dist/sandbox/sandbox-manager.d.ts +35 -0
  34. package/dist/sandbox/sandbox-manager.d.ts.map +1 -0
  35. package/dist/sandbox/sandbox-manager.js +666 -0
  36. package/dist/sandbox/sandbox-manager.js.map +1 -0
  37. package/dist/sandbox/sandbox-schemas.d.ts +17 -0
  38. package/dist/sandbox/sandbox-schemas.d.ts.map +1 -0
  39. package/dist/sandbox/sandbox-schemas.js +2 -0
  40. package/dist/sandbox/sandbox-schemas.js.map +1 -0
  41. package/dist/sandbox/sandbox-utils.d.ts +53 -0
  42. package/dist/sandbox/sandbox-utils.d.ts.map +1 -0
  43. package/dist/sandbox/sandbox-utils.js +368 -0
  44. package/dist/sandbox/sandbox-utils.js.map +1 -0
  45. package/dist/sandbox/sandbox-violation-store.d.ts +19 -0
  46. package/dist/sandbox/sandbox-violation-store.d.ts.map +1 -0
  47. package/dist/sandbox/sandbox-violation-store.js +54 -0
  48. package/dist/sandbox/sandbox-violation-store.js.map +1 -0
  49. package/dist/sandbox/socks-proxy.d.ts +18 -0
  50. package/dist/sandbox/socks-proxy.d.ts.map +1 -0
  51. package/dist/sandbox/socks-proxy.js +242 -0
  52. package/dist/sandbox/socks-proxy.js.map +1 -0
  53. package/dist/utils/debug.d.ts +7 -0
  54. package/dist/utils/debug.d.ts.map +1 -0
  55. package/dist/utils/debug.js +22 -0
  56. package/dist/utils/debug.js.map +1 -0
  57. package/dist/utils/platform.d.ts +6 -0
  58. package/dist/utils/platform.d.ts.map +1 -0
  59. package/dist/utils/platform.js +16 -0
  60. package/dist/utils/platform.js.map +1 -0
  61. package/dist/utils/ripgrep.d.ts +20 -0
  62. package/dist/utils/ripgrep.d.ts.map +1 -0
  63. package/dist/utils/ripgrep.js +51 -0
  64. package/dist/utils/ripgrep.js.map +1 -0
  65. package/dist/utils/telemetry.d.ts +67 -0
  66. package/dist/utils/telemetry.d.ts.map +1 -0
  67. package/dist/utils/telemetry.js +249 -0
  68. package/dist/utils/telemetry.js.map +1 -0
  69. package/dist/vendor/seccomp/arm64/apply-seccomp +0 -0
  70. package/dist/vendor/seccomp/arm64/unix-block.bpf +0 -0
  71. package/dist/vendor/seccomp/x64/apply-seccomp +0 -0
  72. package/dist/vendor/seccomp/x64/unix-block.bpf +0 -0
  73. package/dist/vendor/seccomp-src/apply-seccomp.c +98 -0
  74. package/dist/vendor/seccomp-src/seccomp-unix-block.c +97 -0
  75. package/package.json +80 -0
  76. package/vendor/seccomp/arm64/apply-seccomp +0 -0
  77. package/vendor/seccomp/arm64/unix-block.bpf +0 -0
  78. package/vendor/seccomp/x64/apply-seccomp +0 -0
  79. package/vendor/seccomp/x64/unix-block.bpf +0 -0
  80. package/vendor/seccomp-src/apply-seccomp.c +98 -0
  81. package/vendor/seccomp-src/seccomp-unix-block.c +97 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linux-sandbox-utils.js","sourceRoot":"","sources":["../../src/sandbox/linux-sandbox-utils.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,oBAAoB,CAAA;AAK3B,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,8BAA8B,CAAA;AA2BrC,8DAA8D;AAC9D,MAAM,uBAAuB,GAAgB,IAAI,GAAG,EAAE,CAAA;AACtD,IAAI,qBAAqB,GAAG,KAAK,CAAA;AAEjC;;GAEG;AACH,SAAS,6BAA6B;IACpC,IAAI,qBAAqB,EAAE,CAAC;QAC1B,OAAM;IACR,CAAC;I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,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { FsReadRestrictionConfig, FsWriteRestrictionConfig } from './sandbox-schemas.js';
2
+ import type { IgnoreViolationsConfig } from './sandbox-config.js';
3
+ export interface MacOSSandboxParams {
4
+ command: string;
5
+ httpProxyPort?: number;
6
+ socksProxyPort?: number;
7
+ needsNetworkRestriction: boolean;
8
+ allowUnixSockets?: string[];
9
+ allowAllUnixSockets?: boolean;
10
+ allowLocalBinding?: boolean;
11
+ readConfig: FsReadRestrictionConfig | undefined;
12
+ writeConfig: FsWriteRestrictionConfig | undefined;
13
+ ignoreViolations?: IgnoreViolationsConfig | undefined;
14
+ binShell?: string;
15
+ ripgrepConfig?: {
16
+ command: string;
17
+ args?: string[];
18
+ };
19
+ }
20
+ export interface SandboxViolationEvent {
21
+ line: string;
22
+ command?: string;
23
+ encodedCommand?: string;
24
+ timestamp: Date;
25
+ }
26
+ export type SandboxViolationCallback = (violation: SandboxViolationEvent) => void;
27
+ /**
28
+ * Convert a glob pattern to a regular expression for macOS sandbox profiles
29
+ *
30
+ * This implements gitignore-style pattern matching to match the behavior of the
31
+ * `ignore` library used by the permission system/
32
+ *
33
+ * Supported patterns:
34
+ * - * matches any characters except / (e.g., *.ts matches foo.ts but not foo/bar.ts)
35
+ * - ** matches any characters including / (e.g., src/** /*.ts matches all .ts files in src/)
36
+ * - ? matches any single character except / (e.g., file?.txt matches file1.txt)
37
+ * - [abc] matches any character in the set (e.g., file[0-9].txt matches file3.txt)
38
+ *
39
+ * Note: This is designed for macOS sandbox (regex ...) syntax. The resulting regex
40
+ * will be used in sandbox profiles like: (deny file-write* (regex "pattern"))
41
+ *
42
+ * Exported for testing purposes.
43
+ */
44
+ export declare function globToRegex(globPattern: string): string;
45
+ /**
46
+ * Wrap command with macOS sandbox
47
+ */
48
+ export declare function wrapCommandWithSandboxMacOS(params: MacOSSandboxParams): Promise<string>;
49
+ /**
50
+ * Start monitoring macOS system logs for sandbox violations
51
+ * Look for sandbox-related kernel deny events ending in {logTag}
52
+ */
53
+ export declare function startMacOSSandboxLogMonitor(callback: SandboxViolationCallback, ignoreViolations?: IgnoreViolationsConfig): () => void;
54
+ //# sourceMappingURL=macos-sandbox-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"macos-sandbox-utils.d.ts","sourceRoot":"","sources":["../../src/sandbox/macos-sandbox-utils.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACzB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAEjE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,uBAAuB,EAAE,OAAO,CAAA;IAChC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,UAAU,EAAE,uBAAuB,GAAG,SAAS,CAAA;IAC/C,WAAW,EAAE,wBAAwB,GAAG,SAAS,CAAA;IACjD,gBAAgB,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAA;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CACrD;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,MAAM,MAAM,wBAAwB,GAAG,CACrC,SAAS,EAAE,qBAAqB,KAC7B,IAAI,CAAA;AAIT;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAkBvD;AA0fD;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,MAAM,CAAC,CAyEjB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,wBAAwB,EAClC,gBAAgB,CAAC,EAAE,sBAAsB,GACxC,MAAM,IAAI,CA8GZ"}
@@ -0,0 +1,559 @@
1
+ import shellquote from 'shell-quote';
2
+ import { spawn, spawnSync } from 'child_process';
3
+ import * as path from 'path';
4
+ import { logForDebugging } from '../utils/debug.js';
5
+ import { normalizePathForSandbox, generateProxyEnvVars, getMandatoryDenyWithinAllow, encodeSandboxedCommand, decodeSandboxedCommand, containsGlobChars, } from './sandbox-utils.js';
6
+ const sessionSuffix = `_${Math.random().toString(36).slice(2, 11)}_SBX`;
7
+ /**
8
+ * Convert a glob pattern to a regular expression for macOS sandbox profiles
9
+ *
10
+ * This implements gitignore-style pattern matching to match the behavior of the
11
+ * `ignore` library used by the permission system/
12
+ *
13
+ * Supported patterns:
14
+ * - * matches any characters except / (e.g., *.ts matches foo.ts but not foo/bar.ts)
15
+ * - ** matches any characters including / (e.g., src/** /*.ts matches all .ts files in src/)
16
+ * - ? matches any single character except / (e.g., file?.txt matches file1.txt)
17
+ * - [abc] matches any character in the set (e.g., file[0-9].txt matches file3.txt)
18
+ *
19
+ * Note: This is designed for macOS sandbox (regex ...) syntax. The resulting regex
20
+ * will be used in sandbox profiles like: (deny file-write* (regex "pattern"))
21
+ *
22
+ * Exported for testing purposes.
23
+ */
24
+ export function globToRegex(globPattern) {
25
+ return ('^' +
26
+ globPattern
27
+ // Escape regex special characters (except glob chars * ? [ ])
28
+ .replace(/[.^$+{}()|\\]/g, '\\$&')
29
+ // Escape unclosed brackets (no matching ])
30
+ .replace(/\[([^\]]*?)$/g, '\\[$1')
31
+ // Convert glob patterns to regex (order matters - ** before *)
32
+ .replace(/\*\*\//g, '__GLOBSTAR_SLASH__') // Placeholder for **/
33
+ .replace(/\*\*/g, '__GLOBSTAR__') // Placeholder for **
34
+ .replace(/\*/g, '[^/]*') // * matches anything except /
35
+ .replace(/\?/g, '[^/]') // ? matches single character except /
36
+ // Restore placeholders
37
+ .replace(/__GLOBSTAR_SLASH__/g, '(.*/)?') // **/ matches zero or more dirs
38
+ .replace(/__GLOBSTAR__/g, '.*') + // ** matches anything including /
39
+ '$');
40
+ }
41
+ /**
42
+ * Generate a unique log tag for sandbox monitoring
43
+ * @param command - The command being executed (will be base64 encoded)
44
+ */
45
+ function generateLogTag(command) {
46
+ const encodedCommand = encodeSandboxedCommand(command);
47
+ return `CMD64_${encodedCommand}_END_${sessionSuffix}`;
48
+ }
49
+ /**
50
+ * Get all ancestor directories for a path, up to (but not including) root
51
+ * Example: /private/tmp/test/file.txt -> ["/private/tmp/test", "/private/tmp", "/private"]
52
+ */
53
+ function getAncestorDirectories(pathStr) {
54
+ const ancestors = [];
55
+ let currentPath = path.dirname(pathStr);
56
+ // Walk up the directory tree until we reach root
57
+ while (currentPath !== '/' && currentPath !== '.') {
58
+ ancestors.push(currentPath);
59
+ const parentPath = path.dirname(currentPath);
60
+ // Break if we've reached the top (path.dirname returns the same path for root)
61
+ if (parentPath === currentPath) {
62
+ break;
63
+ }
64
+ currentPath = parentPath;
65
+ }
66
+ return ancestors;
67
+ }
68
+ /**
69
+ * Generate deny rules for file movement (file-write-unlink) to protect paths
70
+ * This prevents bypassing read or write restrictions by moving files/directories
71
+ *
72
+ * @param pathPatterns - Array of path patterns to protect (can include globs)
73
+ * @param logTag - Log tag for sandbox violations
74
+ * @returns Array of sandbox profile rule lines
75
+ */
76
+ function generateMoveBlockingRules(pathPatterns, logTag) {
77
+ const rules = [];
78
+ for (const pathPattern of pathPatterns) {
79
+ const normalizedPath = normalizePathForSandbox(pathPattern);
80
+ if (containsGlobChars(normalizedPath)) {
81
+ // Use regex matching for glob patterns
82
+ const regexPattern = globToRegex(normalizedPath);
83
+ // Block moving/renaming files matching this pattern
84
+ rules.push(`(deny file-write-unlink`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
85
+ // For glob patterns, extract the static prefix and block ancestor moves
86
+ // Remove glob characters to get the directory prefix
87
+ const staticPrefix = normalizedPath.split(/[*?[\]]/)[0];
88
+ if (staticPrefix && staticPrefix !== '/') {
89
+ // Get the directory containing the glob pattern
90
+ const baseDir = staticPrefix.endsWith('/')
91
+ ? staticPrefix.slice(0, -1)
92
+ : path.dirname(staticPrefix);
93
+ // Block moves of the base directory itself
94
+ rules.push(`(deny file-write-unlink`, ` (literal ${escapePath(baseDir)})`, ` (with message "${logTag}"))`);
95
+ // Block moves of ancestor directories
96
+ for (const ancestorDir of getAncestorDirectories(baseDir)) {
97
+ rules.push(`(deny file-write-unlink`, ` (literal ${escapePath(ancestorDir)})`, ` (with message "${logTag}"))`);
98
+ }
99
+ }
100
+ }
101
+ else {
102
+ // Use subpath matching for literal paths
103
+ // Block moving/renaming the denied path itself
104
+ rules.push(`(deny file-write-unlink`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
105
+ // Block moves of ancestor directories
106
+ for (const ancestorDir of getAncestorDirectories(normalizedPath)) {
107
+ rules.push(`(deny file-write-unlink`, ` (literal ${escapePath(ancestorDir)})`, ` (with message "${logTag}"))`);
108
+ }
109
+ }
110
+ }
111
+ return rules;
112
+ }
113
+ /**
114
+ * Generate filesystem read rules for sandbox profile
115
+ */
116
+ function generateReadRules(config, logTag) {
117
+ if (!config) {
118
+ return [`(allow file-read*)`];
119
+ }
120
+ const rules = [];
121
+ // Start by allowing everything
122
+ rules.push(`(allow file-read*)`);
123
+ // Then deny specific paths
124
+ for (const pathPattern of config.denyOnly || []) {
125
+ const normalizedPath = normalizePathForSandbox(pathPattern);
126
+ if (containsGlobChars(normalizedPath)) {
127
+ // Use regex matching for glob patterns
128
+ const regexPattern = globToRegex(normalizedPath);
129
+ rules.push(`(deny file-read*`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
130
+ }
131
+ else {
132
+ // Use subpath matching for literal paths
133
+ rules.push(`(deny file-read*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
134
+ }
135
+ }
136
+ // Block file movement to prevent bypass via mv/rename
137
+ rules.push(...generateMoveBlockingRules(config.denyOnly || [], logTag));
138
+ return rules;
139
+ }
140
+ /**
141
+ * Generate filesystem write rules for sandbox profile
142
+ */
143
+ async function generateWriteRules(config, logTag, ripgrepConfig = { command: 'rg' }) {
144
+ if (!config) {
145
+ return [`(allow file-write*)`];
146
+ }
147
+ const rules = [];
148
+ // Automatically allow TMPDIR parent on macOS when write restrictions are enabled
149
+ const tmpdirParents = getTmpdirParentIfMacOSPattern();
150
+ for (const tmpdirParent of tmpdirParents) {
151
+ const normalizedPath = normalizePathForSandbox(tmpdirParent);
152
+ rules.push(`(allow file-write*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
153
+ }
154
+ // Generate allow rules
155
+ for (const pathPattern of config.allowOnly || []) {
156
+ const normalizedPath = normalizePathForSandbox(pathPattern);
157
+ if (containsGlobChars(normalizedPath)) {
158
+ // Use regex matching for glob patterns
159
+ const regexPattern = globToRegex(normalizedPath);
160
+ rules.push(`(allow file-write*`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
161
+ }
162
+ else {
163
+ // Use subpath matching for literal paths
164
+ rules.push(`(allow file-write*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
165
+ }
166
+ }
167
+ // Combine user-specified and mandatory deny rules
168
+ const denyPaths = [
169
+ ...(config.denyWithinAllow || []),
170
+ ...(await getMandatoryDenyWithinAllow(ripgrepConfig)),
171
+ ];
172
+ for (const pathPattern of denyPaths) {
173
+ const normalizedPath = normalizePathForSandbox(pathPattern);
174
+ if (containsGlobChars(normalizedPath)) {
175
+ // Use regex matching for glob patterns
176
+ const regexPattern = globToRegex(normalizedPath);
177
+ rules.push(`(deny file-write*`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
178
+ }
179
+ else {
180
+ // Use subpath matching for literal paths
181
+ rules.push(`(deny file-write*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
182
+ }
183
+ }
184
+ // Block file movement to prevent bypass via mv/rename
185
+ rules.push(...generateMoveBlockingRules(denyPaths, logTag));
186
+ return rules;
187
+ }
188
+ /**
189
+ * Generate complete sandbox profile
190
+ */
191
+ async function generateSandboxProfile({ readConfig, writeConfig, httpProxyPort, socksProxyPort, needsNetworkRestriction, allowUnixSockets, allowAllUnixSockets, allowLocalBinding, logTag, ripgrepConfig = { command: 'rg' }, }) {
192
+ const profile = [
193
+ '(version 1)',
194
+ `(deny default (with message "${logTag}"))`,
195
+ '',
196
+ `; LogTag: ${logTag}`,
197
+ '',
198
+ '; Essential permissions - based on Chrome sandbox policy',
199
+ '; Process permissions',
200
+ '(allow process-exec)',
201
+ '(allow process-fork)',
202
+ '(allow process-info* (target same-sandbox))',
203
+ '(allow signal (target same-sandbox))',
204
+ '(allow mach-priv-task-port (target same-sandbox))',
205
+ '',
206
+ '; User preferences',
207
+ '(allow user-preference-read)',
208
+ '',
209
+ '; Mach IPC - specific services only (no wildcard)',
210
+ '(allow mach-lookup',
211
+ ' (global-name "com.apple.audio.systemsoundserver")',
212
+ ' (global-name "com.apple.distributed_notifications@Uv3")',
213
+ ' (global-name "com.apple.FontObjectsServer")',
214
+ ' (global-name "com.apple.fonts")',
215
+ ' (global-name "com.apple.logd")',
216
+ ' (global-name "com.apple.lsd.mapdb")',
217
+ ' (global-name "com.apple.PowerManagement.control")',
218
+ ' (global-name "com.apple.system.logger")',
219
+ ' (global-name "com.apple.system.notification_center")',
220
+ ' (global-name "com.apple.trustd.agent")',
221
+ ' (global-name "com.apple.system.opendirectoryd.libinfo")',
222
+ ' (global-name "com.apple.system.opendirectoryd.membership")',
223
+ ' (global-name "com.apple.bsd.dirhelper")',
224
+ ' (global-name "com.apple.securityd.xpc")',
225
+ // Voratiq: allow configd for network queries
226
+ ' (global-name "com.apple.SystemConfiguration.configd")',
227
+ ' (global-name "com.apple.coreservices.launchservicesd")',
228
+ ')',
229
+ '',
230
+ '; POSIX IPC - shared memory',
231
+ '(allow ipc-posix-shm)',
232
+ '',
233
+ '; POSIX IPC - semaphores for Python multiprocessing',
234
+ '(allow ipc-posix-sem)',
235
+ '',
236
+ '; IOKit - specific operations only',
237
+ '(allow iokit-open',
238
+ ' (iokit-registry-entry-class "IOSurfaceRootUserClient")',
239
+ ' (iokit-registry-entry-class "RootDomainUserClient")',
240
+ ' (iokit-user-client-class "IOSurfaceSendRight")',
241
+ ')',
242
+ '',
243
+ '; IOKit properties',
244
+ '(allow iokit-get-properties)',
245
+ '',
246
+ "; Specific safe system-sockets, doesn't allow network access",
247
+ '(allow system-socket (require-all (socket-domain AF_SYSTEM) (socket-protocol 2)))',
248
+ '',
249
+ '; sysctl - specific sysctls only',
250
+ '(allow sysctl-read',
251
+ ' (sysctl-name "hw.activecpu")',
252
+ ' (sysctl-name "hw.busfrequency_compat")',
253
+ ' (sysctl-name "hw.byteorder")',
254
+ ' (sysctl-name "hw.cacheconfig")',
255
+ ' (sysctl-name "hw.cachelinesize_compat")',
256
+ ' (sysctl-name "hw.cpufamily")',
257
+ ' (sysctl-name "hw.cpufrequency")',
258
+ ' (sysctl-name "hw.cpufrequency_compat")',
259
+ ' (sysctl-name "hw.cputype")',
260
+ ' (sysctl-name "hw.l1dcachesize_compat")',
261
+ ' (sysctl-name "hw.l1icachesize_compat")',
262
+ ' (sysctl-name "hw.l2cachesize_compat")',
263
+ ' (sysctl-name "hw.l3cachesize_compat")',
264
+ ' (sysctl-name "hw.logicalcpu")',
265
+ ' (sysctl-name "hw.logicalcpu_max")',
266
+ ' (sysctl-name "hw.machine")',
267
+ ' (sysctl-name "hw.memsize")',
268
+ ' (sysctl-name "hw.ncpu")',
269
+ ' (sysctl-name "hw.nperflevels")',
270
+ ' (sysctl-name "hw.packages")',
271
+ ' (sysctl-name "hw.pagesize_compat")',
272
+ ' (sysctl-name "hw.pagesize")',
273
+ ' (sysctl-name "hw.physicalcpu")',
274
+ ' (sysctl-name "hw.physicalcpu_max")',
275
+ ' (sysctl-name "hw.tbfrequency_compat")',
276
+ ' (sysctl-name "hw.vectorunit")',
277
+ ' (sysctl-name "kern.argmax")',
278
+ ' (sysctl-name "kern.bootargs")',
279
+ ' (sysctl-name "kern.hostname")',
280
+ ' (sysctl-name "kern.maxfiles")',
281
+ ' (sysctl-name "kern.maxfilesperproc")',
282
+ ' (sysctl-name "kern.maxproc")',
283
+ ' (sysctl-name "kern.ngroups")',
284
+ ' (sysctl-name "kern.osproductversion")',
285
+ ' (sysctl-name "kern.osrelease")',
286
+ ' (sysctl-name "kern.ostype")',
287
+ ' (sysctl-name "kern.osvariant_status")',
288
+ ' (sysctl-name "kern.osversion")',
289
+ ' (sysctl-name "kern.secure_kernel")',
290
+ ' (sysctl-name "kern.tcsm_available")',
291
+ ' (sysctl-name "kern.tcsm_enable")',
292
+ ' (sysctl-name "kern.usrstack64")',
293
+ ' (sysctl-name "kern.version")',
294
+ ' (sysctl-name "kern.willshutdown")',
295
+ ' (sysctl-name "machdep.cpu.brand_string")',
296
+ ' (sysctl-name "machdep.ptrauth_enabled")',
297
+ ' (sysctl-name "security.mac.lockdown_mode_state")',
298
+ ' (sysctl-name "sysctl.proc_cputype")',
299
+ ' (sysctl-name "vm.loadavg")',
300
+ ' (sysctl-name-prefix "hw.optional.arm")',
301
+ ' (sysctl-name-prefix "hw.optional.arm.")',
302
+ ' (sysctl-name-prefix "hw.optional.armv8_")',
303
+ ' (sysctl-name-prefix "hw.perflevel")',
304
+ ' (sysctl-name-prefix "kern.proc.pgrp.")',
305
+ ' (sysctl-name-prefix "kern.proc.pid.")',
306
+ ' (sysctl-name-prefix "machdep.cpu.")',
307
+ ' (sysctl-name-prefix "net.routetable.")',
308
+ ')',
309
+ '',
310
+ '; V8 thread calculations',
311
+ '(allow sysctl-write',
312
+ ' (sysctl-name "kern.tcsm_enable")',
313
+ ')',
314
+ '',
315
+ '; Distributed notifications',
316
+ '(allow distributed-notification-post)',
317
+ '',
318
+ '; Specific mach-lookup permissions for security operations',
319
+ '(allow mach-lookup (global-name "com.apple.SecurityServer"))',
320
+ // Voratiq: allow configd for network queries
321
+ '(allow mach-lookup (global-name "com.apple.SystemConfiguration.configd"))',
322
+ '',
323
+ '; File I/O on device files',
324
+ '(allow file-ioctl (literal "/dev/null"))',
325
+ '(allow file-ioctl (literal "/dev/zero"))',
326
+ '(allow file-ioctl (literal "/dev/random"))',
327
+ '(allow file-ioctl (literal "/dev/urandom"))',
328
+ '(allow file-ioctl (literal "/dev/dtracehelper"))',
329
+ '(allow file-ioctl (literal "/dev/tty"))',
330
+ '',
331
+ '(allow file-ioctl file-read-data file-write-data',
332
+ ' (require-all',
333
+ ' (literal "/dev/null")',
334
+ ' (vnode-type CHARACTER-DEVICE)',
335
+ ' )',
336
+ ')',
337
+ '',
338
+ ];
339
+ // Network rules
340
+ profile.push('; Network');
341
+ if (!needsNetworkRestriction) {
342
+ profile.push('(allow network*)');
343
+ }
344
+ else {
345
+ // Allow local binding if requested
346
+ if (allowLocalBinding) {
347
+ profile.push('(allow network-bind (local ip "localhost:*"))');
348
+ profile.push('(allow network-inbound (local ip "localhost:*"))');
349
+ profile.push('(allow network-outbound (local ip "localhost:*"))');
350
+ }
351
+ // Unix domain sockets for local IPC (SSH agent, Docker, etc.)
352
+ if (allowAllUnixSockets) {
353
+ // Allow all Unix socket paths
354
+ profile.push('(allow network* (subpath "/"))');
355
+ }
356
+ else if (allowUnixSockets && allowUnixSockets.length > 0) {
357
+ // Allow specific Unix socket paths
358
+ for (const socketPath of allowUnixSockets) {
359
+ const normalizedPath = normalizePathForSandbox(socketPath);
360
+ profile.push(`(allow network* (subpath ${escapePath(normalizedPath)}))`);
361
+ }
362
+ }
363
+ // If both allowAllUnixSockets and allowUnixSockets are false/undefined/empty, Unix sockets are blocked by default
364
+ // Allow localhost TCP operations for the HTTP proxy
365
+ if (httpProxyPort !== undefined) {
366
+ profile.push(`(allow network-bind (local ip "localhost:${httpProxyPort}"))`);
367
+ profile.push(`(allow network-inbound (local ip "localhost:${httpProxyPort}"))`);
368
+ profile.push(`(allow network-outbound (remote ip "localhost:${httpProxyPort}"))`);
369
+ }
370
+ // Allow localhost TCP operations for the SOCKS proxy
371
+ if (socksProxyPort !== undefined) {
372
+ profile.push(`(allow network-bind (local ip "localhost:${socksProxyPort}"))`);
373
+ profile.push(`(allow network-inbound (local ip "localhost:${socksProxyPort}"))`);
374
+ profile.push(`(allow network-outbound (remote ip "localhost:${socksProxyPort}"))`);
375
+ }
376
+ }
377
+ profile.push('');
378
+ // Read rules
379
+ profile.push('; File read');
380
+ profile.push(...generateReadRules(readConfig, logTag));
381
+ profile.push('');
382
+ // Write rules
383
+ profile.push('; File write');
384
+ profile.push(...(await generateWriteRules(writeConfig, logTag, ripgrepConfig)));
385
+ return profile.join('\n');
386
+ }
387
+ /**
388
+ * Escape path for sandbox profile using JSON.stringify for proper escaping
389
+ */
390
+ function escapePath(pathStr) {
391
+ return JSON.stringify(pathStr);
392
+ }
393
+ /**
394
+ * Get TMPDIR parent directory if it matches macOS pattern /var/folders/XX/YYY/T/
395
+ * Returns both /var/ and /private/var/ versions since /var is a symlink
396
+ */
397
+ function getTmpdirParentIfMacOSPattern() {
398
+ const tmpdir = process.env.TMPDIR;
399
+ if (!tmpdir)
400
+ return [];
401
+ const match = tmpdir.match(/^\/(private\/)?var\/folders\/[^/]{2}\/[^/]+\/T\/?$/);
402
+ if (!match)
403
+ return [];
404
+ const parent = tmpdir.replace(/\/T\/?$/, '');
405
+ // Return both /var/ and /private/var/ versions since /var is a symlink
406
+ if (parent.startsWith('/private/var/')) {
407
+ return [parent, parent.replace('/private', '')];
408
+ }
409
+ else if (parent.startsWith('/var/')) {
410
+ return [parent, '/private' + parent];
411
+ }
412
+ return [parent];
413
+ }
414
+ /**
415
+ * Wrap command with macOS sandbox
416
+ */
417
+ export async function wrapCommandWithSandboxMacOS(params) {
418
+ const { command, httpProxyPort, socksProxyPort, needsNetworkRestriction, allowUnixSockets, allowAllUnixSockets, allowLocalBinding, readConfig, writeConfig, binShell, ripgrepConfig = { command: 'rg' }, } = params;
419
+ // No sandboxing needed
420
+ if (!needsNetworkRestriction && !readConfig && !writeConfig) {
421
+ return command;
422
+ }
423
+ const logTag = generateLogTag(command);
424
+ const profile = await generateSandboxProfile({
425
+ readConfig,
426
+ writeConfig,
427
+ httpProxyPort,
428
+ socksProxyPort,
429
+ needsNetworkRestriction,
430
+ allowUnixSockets,
431
+ allowAllUnixSockets,
432
+ allowLocalBinding,
433
+ logTag,
434
+ ripgrepConfig,
435
+ });
436
+ // Generate proxy environment variables using shared utility
437
+ const proxyEnv = `export ${generateProxyEnvVars(httpProxyPort, socksProxyPort).join(' ')} && `;
438
+ // Use the user's shell (zsh, bash, etc.) to ensure aliases/snapshots work
439
+ // Resolve the full path to the shell binary
440
+ const shellName = binShell || 'bash';
441
+ const shellPathResult = spawnSync('which', [shellName], { encoding: 'utf8' });
442
+ if (shellPathResult.status !== 0) {
443
+ throw new Error(`Shell '${shellName}' not found in PATH`);
444
+ }
445
+ const shell = shellPathResult.stdout.trim();
446
+ const wrappedCommand = shellquote.quote([
447
+ 'sandbox-exec',
448
+ '-p',
449
+ profile,
450
+ shell,
451
+ '-c',
452
+ proxyEnv + command,
453
+ ]);
454
+ logForDebugging(`[Sandbox macOS] Applied restrictions - network: ${!!(httpProxyPort || socksProxyPort)}, read: ${readConfig
455
+ ? 'allowAllExcept' in readConfig
456
+ ? 'allowAllExcept'
457
+ : 'denyAllExcept'
458
+ : 'none'}, write: ${writeConfig
459
+ ? 'allowAllExcept' in writeConfig
460
+ ? 'allowAllExcept'
461
+ : 'denyAllExcept'
462
+ : 'none'}`);
463
+ return wrappedCommand;
464
+ }
465
+ /**
466
+ * Start monitoring macOS system logs for sandbox violations
467
+ * Look for sandbox-related kernel deny events ending in {logTag}
468
+ */
469
+ export function startMacOSSandboxLogMonitor(callback, ignoreViolations) {
470
+ // Pre-compile regex patterns for better performance
471
+ const cmdExtractRegex = /CMD64_(.+?)_END/;
472
+ const sandboxExtractRegex = /Sandbox:\s+(.+)$/;
473
+ // Pre-process ignore patterns for faster lookup
474
+ const wildcardPaths = ignoreViolations?.['*'] || [];
475
+ const commandPatterns = ignoreViolations
476
+ ? Object.entries(ignoreViolations).filter(([pattern]) => pattern !== '*')
477
+ : [];
478
+ // Stream and filter kernel logs for all sandbox violations
479
+ // We can't filter by specific logTag since it's dynamic per command
480
+ const logProcess = spawn('log', [
481
+ 'stream',
482
+ '--predicate',
483
+ `(eventMessage ENDSWITH "${sessionSuffix}")`,
484
+ '--style',
485
+ 'compact',
486
+ ]);
487
+ logProcess.stdout?.on('data', (data) => {
488
+ const lines = data.toString().split('\n');
489
+ // Get violation and command lines
490
+ const violationLine = lines.find(line => line.includes('Sandbox:') && line.includes('deny'));
491
+ const commandLine = lines.find(line => line.startsWith('CMD64_'));
492
+ if (!violationLine)
493
+ return;
494
+ // Extract violation details
495
+ const sandboxMatch = violationLine.match(sandboxExtractRegex);
496
+ if (!sandboxMatch?.[1])
497
+ return;
498
+ const violationDetails = sandboxMatch[1];
499
+ // Try to get command
500
+ let command;
501
+ let encodedCommand;
502
+ if (commandLine) {
503
+ const cmdMatch = commandLine.match(cmdExtractRegex);
504
+ encodedCommand = cmdMatch?.[1];
505
+ if (encodedCommand) {
506
+ try {
507
+ command = decodeSandboxedCommand(encodedCommand);
508
+ }
509
+ catch {
510
+ // Failed to decode, continue without command
511
+ }
512
+ }
513
+ }
514
+ // Always filter out noisey violations
515
+ if (violationDetails.includes('mDNSResponder') ||
516
+ violationDetails.includes('mach-lookup com.apple.diagnosticd') ||
517
+ violationDetails.includes('mach-lookup com.apple.analyticsd')) {
518
+ return;
519
+ }
520
+ // Check if we should ignore this violation
521
+ if (ignoreViolations && command) {
522
+ // Check wildcard patterns first
523
+ if (wildcardPaths.length > 0) {
524
+ const shouldIgnore = wildcardPaths.some(path => violationDetails.includes(path));
525
+ if (shouldIgnore)
526
+ return;
527
+ }
528
+ // Check command-specific patterns
529
+ for (const [pattern, paths] of commandPatterns) {
530
+ if (command.includes(pattern)) {
531
+ const shouldIgnore = paths.some(path => violationDetails.includes(path));
532
+ if (shouldIgnore)
533
+ return;
534
+ }
535
+ }
536
+ }
537
+ // Not ignored - report the violation
538
+ callback({
539
+ line: violationDetails,
540
+ command,
541
+ encodedCommand,
542
+ timestamp: new Date(), // We could parse the timestamp from the log but this feels more reliable
543
+ });
544
+ });
545
+ logProcess.stderr?.on('data', (data) => {
546
+ logForDebugging(`[Sandbox Monitor] Log stream stderr: ${data.toString()}`);
547
+ });
548
+ logProcess.on('error', (error) => {
549
+ logForDebugging(`[Sandbox Monitor] Failed to start log stream: ${error.message}`);
550
+ });
551
+ logProcess.on('exit', (code) => {
552
+ logForDebugging(`[Sandbox Monitor] Log stream exited with code: ${code}`);
553
+ });
554
+ return () => {
555
+ logForDebugging('[Sandbox Monitor] Stopping log monitor');
556
+ logProcess.kill('SIGTERM');
557
+ };
558
+ }
559
+ //# sourceMappingURL=macos-sandbox-utils.js.map