@anthropic-ai/sandbox-runtime 0.0.1
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/README.md +497 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/http-proxy.d.ts +7 -0
- package/dist/sandbox/http-proxy.d.ts.map +1 -0
- package/dist/sandbox/http-proxy.js +118 -0
- package/dist/sandbox/http-proxy.js.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts +60 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.js +333 -0
- package/dist/sandbox/linux-sandbox-utils.js.map +1 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts +53 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/macos-sandbox-utils.js +496 -0
- package/dist/sandbox/macos-sandbox-utils.js.map +1 -0
- package/dist/sandbox/sandbox-manager.d.ts +34 -0
- package/dist/sandbox/sandbox-manager.d.ts.map +1 -0
- package/dist/sandbox/sandbox-manager.js +655 -0
- package/dist/sandbox/sandbox-manager.js.map +1 -0
- package/dist/sandbox/sandbox-schemas.d.ts +93 -0
- package/dist/sandbox/sandbox-schemas.d.ts.map +1 -0
- package/dist/sandbox/sandbox-schemas.js +231 -0
- package/dist/sandbox/sandbox-schemas.js.map +1 -0
- package/dist/sandbox/sandbox-utils.d.ts +49 -0
- package/dist/sandbox/sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/sandbox-utils.js +345 -0
- package/dist/sandbox/sandbox-utils.js.map +1 -0
- package/dist/sandbox/sandbox-violation-store.d.ts +19 -0
- package/dist/sandbox/sandbox-violation-store.d.ts.map +1 -0
- package/dist/sandbox/sandbox-violation-store.js +54 -0
- package/dist/sandbox/sandbox-violation-store.js.map +1 -0
- package/dist/sandbox/socks-proxy.d.ts +13 -0
- package/dist/sandbox/socks-proxy.d.ts.map +1 -0
- package/dist/sandbox/socks-proxy.js +95 -0
- package/dist/sandbox/socks-proxy.js.map +1 -0
- package/dist/utils/debug.d.ts +7 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +22 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/exec.d.ts +13 -0
- package/dist/utils/exec.d.ts.map +1 -0
- package/dist/utils/exec.js +38 -0
- package/dist/utils/exec.js.map +1 -0
- package/dist/utils/platform.d.ts +6 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +16 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/ripgrep.d.ts +16 -0
- package/dist/utils/ripgrep.d.ts.map +1 -0
- package/dist/utils/ripgrep.js +57 -0
- package/dist/utils/ripgrep.js.map +1 -0
- package/dist/utils/settings.d.ts +147 -0
- package/dist/utils/settings.d.ts.map +1 -0
- package/dist/utils/settings.js +244 -0
- package/dist/utils/settings.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
import shellquote from 'shell-quote';
|
|
2
|
+
import { spawn, spawnSync } from 'child_process';
|
|
3
|
+
import { logForDebugging } from '../utils/debug.js';
|
|
4
|
+
import { normalizePathForSandbox, generateProxyEnvVars, getMandatoryDenyWithinAllow, encodeSandboxedCommand, decodeSandboxedCommand, containsGlobChars, } from './sandbox-utils.js';
|
|
5
|
+
// Cache for macOS sandbox dependencies check
|
|
6
|
+
let macosDepsCache;
|
|
7
|
+
/**
|
|
8
|
+
* Check if macOS sandbox dependencies are available (synchronous)
|
|
9
|
+
* Returns true if rg (ripgrep) is installed, false otherwise
|
|
10
|
+
* Cached to avoid repeated system calls
|
|
11
|
+
*/
|
|
12
|
+
export function hasMacOSSandboxDependenciesSync() {
|
|
13
|
+
if (macosDepsCache !== undefined) {
|
|
14
|
+
return macosDepsCache;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const rgResult = spawnSync('which', ['rg'], {
|
|
18
|
+
stdio: 'ignore',
|
|
19
|
+
timeout: 1000,
|
|
20
|
+
});
|
|
21
|
+
macosDepsCache = rgResult.status === 0;
|
|
22
|
+
return macosDepsCache;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
macosDepsCache = false;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const sessionSuffix = `_${Math.random().toString(36).slice(2, 11)}_SBX`;
|
|
30
|
+
/**
|
|
31
|
+
* Convert a glob pattern to a regular expression for macOS sandbox profiles
|
|
32
|
+
*
|
|
33
|
+
* This implements gitignore-style pattern matching to match the behavior of the
|
|
34
|
+
* `ignore` library used by the permission system/
|
|
35
|
+
*
|
|
36
|
+
* Supported patterns:
|
|
37
|
+
* - * matches any characters except / (e.g., *.ts matches foo.ts but not foo/bar.ts)
|
|
38
|
+
* - ** matches any characters including / (e.g., src/** /*.ts matches all .ts files in src/)
|
|
39
|
+
* - ? matches any single character except / (e.g., file?.txt matches file1.txt)
|
|
40
|
+
* - [abc] matches any character in the set (e.g., file[0-9].txt matches file3.txt)
|
|
41
|
+
*
|
|
42
|
+
* Note: This is designed for macOS sandbox (regex ...) syntax. The resulting regex
|
|
43
|
+
* will be used in sandbox profiles like: (deny file-write* (regex "pattern"))
|
|
44
|
+
*
|
|
45
|
+
* Exported for testing purposes.
|
|
46
|
+
*/
|
|
47
|
+
export function globToRegex(globPattern) {
|
|
48
|
+
return ('^' +
|
|
49
|
+
globPattern
|
|
50
|
+
// Escape regex special characters (except glob chars * ? [ ])
|
|
51
|
+
.replace(/[.^$+{}()|\\]/g, '\\$&')
|
|
52
|
+
// Escape unclosed brackets (no matching ])
|
|
53
|
+
.replace(/\[([^\]]*?)$/g, '\\[$1')
|
|
54
|
+
// Convert glob patterns to regex (order matters - ** before *)
|
|
55
|
+
.replace(/\*\*\//g, '__GLOBSTAR_SLASH__') // Placeholder for **/
|
|
56
|
+
.replace(/\*\*/g, '__GLOBSTAR__') // Placeholder for **
|
|
57
|
+
.replace(/\*/g, '[^/]*') // * matches anything except /
|
|
58
|
+
.replace(/\?/g, '[^/]') // ? matches single character except /
|
|
59
|
+
// Restore placeholders
|
|
60
|
+
.replace(/__GLOBSTAR_SLASH__/g, '(.*/)?') // **/ matches zero or more dirs
|
|
61
|
+
.replace(/__GLOBSTAR__/g, '.*') + // ** matches anything including /
|
|
62
|
+
'$');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Generate a unique log tag for sandbox monitoring
|
|
66
|
+
* @param command - The command being executed (will be base64 encoded)
|
|
67
|
+
*/
|
|
68
|
+
function generateLogTag(command) {
|
|
69
|
+
const encodedCommand = encodeSandboxedCommand(command);
|
|
70
|
+
return `CMD64_${encodedCommand}_END_${sessionSuffix}`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generate filesystem read rules for sandbox profile
|
|
74
|
+
*/
|
|
75
|
+
function generateReadRules(config, logTag) {
|
|
76
|
+
if (!config) {
|
|
77
|
+
return [`(allow file-read*)`];
|
|
78
|
+
}
|
|
79
|
+
const rules = [];
|
|
80
|
+
// Start by allowing everything
|
|
81
|
+
rules.push(`(allow file-read*)`);
|
|
82
|
+
// Then deny specific paths
|
|
83
|
+
for (const pathPattern of config.denyOnly || []) {
|
|
84
|
+
const normalizedPath = normalizePathForSandbox(pathPattern);
|
|
85
|
+
if (containsGlobChars(normalizedPath)) {
|
|
86
|
+
// Use regex matching for glob patterns
|
|
87
|
+
const regexPattern = globToRegex(normalizedPath);
|
|
88
|
+
rules.push(`(deny file-read*`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Use subpath matching for literal paths
|
|
92
|
+
rules.push(`(deny file-read*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return rules;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Generate filesystem write rules for sandbox profile
|
|
99
|
+
*/
|
|
100
|
+
async function generateWriteRules(config, logTag) {
|
|
101
|
+
if (!config) {
|
|
102
|
+
return [`(allow file-write*)`];
|
|
103
|
+
}
|
|
104
|
+
const rules = [];
|
|
105
|
+
// Automatically allow TMPDIR parent on macOS when write restrictions are enabled
|
|
106
|
+
const tmpdirParents = getTmpdirParentIfMacOSPattern();
|
|
107
|
+
for (const tmpdirParent of tmpdirParents) {
|
|
108
|
+
const normalizedPath = normalizePathForSandbox(tmpdirParent);
|
|
109
|
+
rules.push(`(allow file-write*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
|
|
110
|
+
}
|
|
111
|
+
// Generate allow rules
|
|
112
|
+
for (const pathPattern of config.allowOnly || []) {
|
|
113
|
+
const normalizedPath = normalizePathForSandbox(pathPattern);
|
|
114
|
+
if (containsGlobChars(normalizedPath)) {
|
|
115
|
+
// Use regex matching for glob patterns
|
|
116
|
+
const regexPattern = globToRegex(normalizedPath);
|
|
117
|
+
rules.push(`(allow file-write*`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Use subpath matching for literal paths
|
|
121
|
+
rules.push(`(allow file-write*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Combine user-specified and mandatory deny rules
|
|
125
|
+
const denyPaths = [
|
|
126
|
+
...(config.denyWithinAllow || []),
|
|
127
|
+
...(await getMandatoryDenyWithinAllow()),
|
|
128
|
+
];
|
|
129
|
+
for (const pathPattern of denyPaths) {
|
|
130
|
+
const normalizedPath = normalizePathForSandbox(pathPattern);
|
|
131
|
+
if (containsGlobChars(normalizedPath)) {
|
|
132
|
+
// Use regex matching for glob patterns
|
|
133
|
+
const regexPattern = globToRegex(normalizedPath);
|
|
134
|
+
rules.push(`(deny file-write*`, ` (regex ${escapePath(regexPattern)})`, ` (with message "${logTag}"))`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// Use subpath matching for literal paths
|
|
138
|
+
rules.push(`(deny file-write*`, ` (subpath ${escapePath(normalizedPath)})`, ` (with message "${logTag}"))`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return rules;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Generate complete sandbox profile
|
|
145
|
+
*/
|
|
146
|
+
async function generateSandboxProfile({ readConfig, writeConfig, httpProxyPort, socksProxyPort, needsNetworkRestriction, allowUnixSockets, allowLocalBinding, logTag, }) {
|
|
147
|
+
const profile = [
|
|
148
|
+
'(version 1)',
|
|
149
|
+
`(deny default (with message "${logTag}"))`,
|
|
150
|
+
'',
|
|
151
|
+
`; LogTag: ${logTag}`,
|
|
152
|
+
'',
|
|
153
|
+
'; Essential permissions - based on Chrome sandbox policy',
|
|
154
|
+
'; Process permissions',
|
|
155
|
+
'(allow process-exec)',
|
|
156
|
+
'(allow process-fork)',
|
|
157
|
+
'(allow process-info* (target same-sandbox))',
|
|
158
|
+
'(allow signal (target same-sandbox))',
|
|
159
|
+
'(allow mach-priv-task-port (target same-sandbox))',
|
|
160
|
+
'',
|
|
161
|
+
'; User preferences',
|
|
162
|
+
'(allow user-preference-read)',
|
|
163
|
+
'',
|
|
164
|
+
'; Mach IPC - specific services only (no wildcard)',
|
|
165
|
+
'(allow mach-lookup',
|
|
166
|
+
' (global-name "com.apple.audio.systemsoundserver")',
|
|
167
|
+
' (global-name "com.apple.distributed_notifications@Uv3")',
|
|
168
|
+
' (global-name "com.apple.FontObjectsServer")',
|
|
169
|
+
' (global-name "com.apple.fonts")',
|
|
170
|
+
' (global-name "com.apple.logd")',
|
|
171
|
+
' (global-name "com.apple.lsd.mapdb")',
|
|
172
|
+
' (global-name "com.apple.PowerManagement.control")',
|
|
173
|
+
' (global-name "com.apple.system.logger")',
|
|
174
|
+
' (global-name "com.apple.system.notification_center")',
|
|
175
|
+
' (global-name "com.apple.trustd.agent")',
|
|
176
|
+
' (global-name "com.apple.system.opendirectoryd.libinfo")',
|
|
177
|
+
' (global-name "com.apple.system.opendirectoryd.membership")',
|
|
178
|
+
' (global-name "com.apple.bsd.dirhelper")',
|
|
179
|
+
' (global-name "com.apple.securityd.xpc")',
|
|
180
|
+
' (global-name "com.apple.coreservices.launchservicesd")',
|
|
181
|
+
')',
|
|
182
|
+
'',
|
|
183
|
+
'; POSIX IPC - shared memory',
|
|
184
|
+
'(allow ipc-posix-shm)',
|
|
185
|
+
'',
|
|
186
|
+
'; POSIX IPC - semaphores for Python multiprocessing',
|
|
187
|
+
'(allow ipc-posix-sem)',
|
|
188
|
+
'',
|
|
189
|
+
'; IOKit - specific operations only',
|
|
190
|
+
'(allow iokit-open',
|
|
191
|
+
' (iokit-registry-entry-class "IOSurfaceRootUserClient")',
|
|
192
|
+
' (iokit-registry-entry-class "RootDomainUserClient")',
|
|
193
|
+
' (iokit-user-client-class "IOSurfaceSendRight")',
|
|
194
|
+
')',
|
|
195
|
+
'',
|
|
196
|
+
'; IOKit properties',
|
|
197
|
+
'(allow iokit-get-properties)',
|
|
198
|
+
'',
|
|
199
|
+
"; Specific safe system-sockets, doesn't allow network access",
|
|
200
|
+
'(allow system-socket (require-all (socket-domain AF_SYSTEM) (socket-protocol 2)))',
|
|
201
|
+
'',
|
|
202
|
+
'; sysctl - specific sysctls only',
|
|
203
|
+
'(allow sysctl-read',
|
|
204
|
+
' (sysctl-name "hw.activecpu")',
|
|
205
|
+
' (sysctl-name "hw.busfrequency_compat")',
|
|
206
|
+
' (sysctl-name "hw.byteorder")',
|
|
207
|
+
' (sysctl-name "hw.cacheconfig")',
|
|
208
|
+
' (sysctl-name "hw.cachelinesize_compat")',
|
|
209
|
+
' (sysctl-name "hw.cpufamily")',
|
|
210
|
+
' (sysctl-name "hw.cpufrequency")',
|
|
211
|
+
' (sysctl-name "hw.cpufrequency_compat")',
|
|
212
|
+
' (sysctl-name "hw.cputype")',
|
|
213
|
+
' (sysctl-name "hw.l1dcachesize_compat")',
|
|
214
|
+
' (sysctl-name "hw.l1icachesize_compat")',
|
|
215
|
+
' (sysctl-name "hw.l2cachesize_compat")',
|
|
216
|
+
' (sysctl-name "hw.l3cachesize_compat")',
|
|
217
|
+
' (sysctl-name "hw.logicalcpu")',
|
|
218
|
+
' (sysctl-name "hw.logicalcpu_max")',
|
|
219
|
+
' (sysctl-name "hw.machine")',
|
|
220
|
+
' (sysctl-name "hw.memsize")',
|
|
221
|
+
' (sysctl-name "hw.ncpu")',
|
|
222
|
+
' (sysctl-name "hw.nperflevels")',
|
|
223
|
+
' (sysctl-name "hw.packages")',
|
|
224
|
+
' (sysctl-name "hw.pagesize_compat")',
|
|
225
|
+
' (sysctl-name "hw.pagesize")',
|
|
226
|
+
' (sysctl-name "hw.physicalcpu")',
|
|
227
|
+
' (sysctl-name "hw.physicalcpu_max")',
|
|
228
|
+
' (sysctl-name "hw.tbfrequency_compat")',
|
|
229
|
+
' (sysctl-name "hw.vectorunit")',
|
|
230
|
+
' (sysctl-name "kern.argmax")',
|
|
231
|
+
' (sysctl-name "kern.bootargs")',
|
|
232
|
+
' (sysctl-name "kern.hostname")',
|
|
233
|
+
' (sysctl-name "kern.maxfiles")',
|
|
234
|
+
' (sysctl-name "kern.maxfilesperproc")',
|
|
235
|
+
' (sysctl-name "kern.maxproc")',
|
|
236
|
+
' (sysctl-name "kern.ngroups")',
|
|
237
|
+
' (sysctl-name "kern.osproductversion")',
|
|
238
|
+
' (sysctl-name "kern.osrelease")',
|
|
239
|
+
' (sysctl-name "kern.ostype")',
|
|
240
|
+
' (sysctl-name "kern.osvariant_status")',
|
|
241
|
+
' (sysctl-name "kern.osversion")',
|
|
242
|
+
' (sysctl-name "kern.secure_kernel")',
|
|
243
|
+
' (sysctl-name "kern.tcsm_available")',
|
|
244
|
+
' (sysctl-name "kern.tcsm_enable")',
|
|
245
|
+
' (sysctl-name "kern.usrstack64")',
|
|
246
|
+
' (sysctl-name "kern.version")',
|
|
247
|
+
' (sysctl-name "kern.willshutdown")',
|
|
248
|
+
' (sysctl-name "machdep.cpu.brand_string")',
|
|
249
|
+
' (sysctl-name "machdep.ptrauth_enabled")',
|
|
250
|
+
' (sysctl-name "security.mac.lockdown_mode_state")',
|
|
251
|
+
' (sysctl-name "sysctl.proc_cputype")',
|
|
252
|
+
' (sysctl-name "vm.loadavg")',
|
|
253
|
+
' (sysctl-name-prefix "hw.optional.arm")',
|
|
254
|
+
' (sysctl-name-prefix "hw.optional.arm.")',
|
|
255
|
+
' (sysctl-name-prefix "hw.optional.armv8_")',
|
|
256
|
+
' (sysctl-name-prefix "hw.perflevel")',
|
|
257
|
+
' (sysctl-name-prefix "kern.proc.pgrp.")',
|
|
258
|
+
' (sysctl-name-prefix "kern.proc.pid.")',
|
|
259
|
+
' (sysctl-name-prefix "machdep.cpu.")',
|
|
260
|
+
' (sysctl-name-prefix "net.routetable.")',
|
|
261
|
+
')',
|
|
262
|
+
'',
|
|
263
|
+
'; V8 thread calculations',
|
|
264
|
+
'(allow sysctl-write',
|
|
265
|
+
' (sysctl-name "kern.tcsm_enable")',
|
|
266
|
+
')',
|
|
267
|
+
'',
|
|
268
|
+
'; Distributed notifications',
|
|
269
|
+
'(allow distributed-notification-post)',
|
|
270
|
+
'',
|
|
271
|
+
'; Specific mach-lookup permissions for security operations',
|
|
272
|
+
'(allow mach-lookup (global-name "com.apple.SecurityServer"))',
|
|
273
|
+
'',
|
|
274
|
+
'; File I/O on device files',
|
|
275
|
+
'(allow file-ioctl (literal "/dev/null"))',
|
|
276
|
+
'(allow file-ioctl (literal "/dev/zero"))',
|
|
277
|
+
'(allow file-ioctl (literal "/dev/random"))',
|
|
278
|
+
'(allow file-ioctl (literal "/dev/urandom"))',
|
|
279
|
+
'(allow file-ioctl (literal "/dev/dtracehelper"))',
|
|
280
|
+
'(allow file-ioctl (literal "/dev/tty"))',
|
|
281
|
+
'',
|
|
282
|
+
'(allow file-ioctl file-read-data file-write-data',
|
|
283
|
+
' (require-all',
|
|
284
|
+
' (literal "/dev/null")',
|
|
285
|
+
' (vnode-type CHARACTER-DEVICE)',
|
|
286
|
+
' )',
|
|
287
|
+
')',
|
|
288
|
+
'',
|
|
289
|
+
];
|
|
290
|
+
// Network rules
|
|
291
|
+
profile.push('; Network');
|
|
292
|
+
if (!needsNetworkRestriction) {
|
|
293
|
+
profile.push('(allow network*)');
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
// Allow local binding if requested
|
|
297
|
+
if (allowLocalBinding) {
|
|
298
|
+
profile.push('(allow network-bind (local ip "localhost:*"))');
|
|
299
|
+
profile.push('(allow network-inbound (local ip "localhost:*"))');
|
|
300
|
+
profile.push('(allow network-outbound (local ip "localhost:*"))');
|
|
301
|
+
}
|
|
302
|
+
// Unix domain sockets for local IPC (SSH agent, Docker, etc.)
|
|
303
|
+
if (allowUnixSockets && allowUnixSockets.length > 0) {
|
|
304
|
+
// Allow specific Unix socket paths
|
|
305
|
+
for (const socketPath of allowUnixSockets) {
|
|
306
|
+
const normalizedPath = normalizePathForSandbox(socketPath);
|
|
307
|
+
profile.push(`(allow network* (subpath ${escapePath(normalizedPath)}))`);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// If allowUnixSockets is undefined or empty array, Unix sockets are blocked by default
|
|
311
|
+
// Allow localhost TCP operations for the HTTP proxy
|
|
312
|
+
if (httpProxyPort !== undefined) {
|
|
313
|
+
profile.push(`(allow network-bind (local ip "localhost:${httpProxyPort}"))`);
|
|
314
|
+
profile.push(`(allow network-inbound (local ip "localhost:${httpProxyPort}"))`);
|
|
315
|
+
profile.push(`(allow network-outbound (remote ip "localhost:${httpProxyPort}"))`);
|
|
316
|
+
}
|
|
317
|
+
// Allow localhost TCP operations for the SOCKS proxy
|
|
318
|
+
if (socksProxyPort !== undefined) {
|
|
319
|
+
profile.push(`(allow network-bind (local ip "localhost:${socksProxyPort}"))`);
|
|
320
|
+
profile.push(`(allow network-inbound (local ip "localhost:${socksProxyPort}"))`);
|
|
321
|
+
profile.push(`(allow network-outbound (remote ip "localhost:${socksProxyPort}"))`);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
profile.push('');
|
|
325
|
+
// Read rules
|
|
326
|
+
profile.push('; File read');
|
|
327
|
+
profile.push(...generateReadRules(readConfig, logTag));
|
|
328
|
+
profile.push('');
|
|
329
|
+
// Write rules
|
|
330
|
+
profile.push('; File write');
|
|
331
|
+
profile.push(...(await generateWriteRules(writeConfig, logTag)));
|
|
332
|
+
return profile.join('\n');
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Escape path for sandbox profile using JSON.stringify for proper escaping
|
|
336
|
+
*/
|
|
337
|
+
function escapePath(pathStr) {
|
|
338
|
+
return JSON.stringify(pathStr);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Get TMPDIR parent directory if it matches macOS pattern /var/folders/XX/YYY/T/
|
|
342
|
+
* Returns both /var/ and /private/var/ versions since /var is a symlink
|
|
343
|
+
*/
|
|
344
|
+
function getTmpdirParentIfMacOSPattern() {
|
|
345
|
+
const tmpdir = process.env.TMPDIR;
|
|
346
|
+
if (!tmpdir)
|
|
347
|
+
return [];
|
|
348
|
+
const match = tmpdir.match(/^\/(private\/)?var\/folders\/[^/]{2}\/[^/]+\/T\/?$/);
|
|
349
|
+
if (!match)
|
|
350
|
+
return [];
|
|
351
|
+
const parent = tmpdir.replace(/\/T\/?$/, '');
|
|
352
|
+
// Return both /var/ and /private/var/ versions since /var is a symlink
|
|
353
|
+
if (parent.startsWith('/private/var/')) {
|
|
354
|
+
return [parent, parent.replace('/private', '')];
|
|
355
|
+
}
|
|
356
|
+
else if (parent.startsWith('/var/')) {
|
|
357
|
+
return [parent, '/private' + parent];
|
|
358
|
+
}
|
|
359
|
+
return [parent];
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Wrap command with macOS sandbox
|
|
363
|
+
*/
|
|
364
|
+
export async function wrapCommandWithSandboxMacOS(params) {
|
|
365
|
+
const { command, httpProxyPort, socksProxyPort, needsNetworkRestriction, allowUnixSockets, allowLocalBinding, readConfig, writeConfig, } = params;
|
|
366
|
+
// No sandboxing needed
|
|
367
|
+
if (!needsNetworkRestriction && !readConfig && !writeConfig) {
|
|
368
|
+
return command;
|
|
369
|
+
}
|
|
370
|
+
const logTag = generateLogTag(command);
|
|
371
|
+
const profile = await generateSandboxProfile({
|
|
372
|
+
readConfig,
|
|
373
|
+
writeConfig,
|
|
374
|
+
httpProxyPort,
|
|
375
|
+
socksProxyPort,
|
|
376
|
+
needsNetworkRestriction,
|
|
377
|
+
allowUnixSockets,
|
|
378
|
+
allowLocalBinding,
|
|
379
|
+
logTag,
|
|
380
|
+
});
|
|
381
|
+
// Generate proxy environment variables using shared utility
|
|
382
|
+
const proxyEnv = `export ${generateProxyEnvVars(httpProxyPort, socksProxyPort).join(' ')} && `;
|
|
383
|
+
const wrappedCommand = shellquote.quote([
|
|
384
|
+
'sandbox-exec',
|
|
385
|
+
'-p',
|
|
386
|
+
profile,
|
|
387
|
+
'bash',
|
|
388
|
+
'-c',
|
|
389
|
+
proxyEnv + command,
|
|
390
|
+
]);
|
|
391
|
+
logForDebugging(`[Sandbox macOS] Applied restrictions - network: ${!!(httpProxyPort || socksProxyPort)}, read: ${readConfig
|
|
392
|
+
? 'allowAllExcept' in readConfig
|
|
393
|
+
? 'allowAllExcept'
|
|
394
|
+
: 'denyAllExcept'
|
|
395
|
+
: 'none'}, write: ${writeConfig
|
|
396
|
+
? 'allowAllExcept' in writeConfig
|
|
397
|
+
? 'allowAllExcept'
|
|
398
|
+
: 'denyAllExcept'
|
|
399
|
+
: 'none'}`);
|
|
400
|
+
return wrappedCommand;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Start monitoring macOS system logs for sandbox violations
|
|
404
|
+
* Look for sandbox-related kernel deny events ending in {logTag}
|
|
405
|
+
*/
|
|
406
|
+
export function startMacOSSandboxLogMonitor(callback, ignoreViolations) {
|
|
407
|
+
// Pre-compile regex patterns for better performance
|
|
408
|
+
const cmdExtractRegex = /CMD64_(.+?)_END/;
|
|
409
|
+
const sandboxExtractRegex = /Sandbox:\s+(.+)$/;
|
|
410
|
+
// Pre-process ignore patterns for faster lookup
|
|
411
|
+
const wildcardPaths = ignoreViolations?.['*'] || [];
|
|
412
|
+
const commandPatterns = ignoreViolations
|
|
413
|
+
? Object.entries(ignoreViolations).filter(([pattern]) => pattern !== '*')
|
|
414
|
+
: [];
|
|
415
|
+
// Stream and filter kernel logs for all sandbox violations
|
|
416
|
+
// We can't filter by specific logTag since it's dynamic per command
|
|
417
|
+
const logProcess = spawn('log', [
|
|
418
|
+
'stream',
|
|
419
|
+
'--predicate',
|
|
420
|
+
`(eventMessage ENDSWITH "${sessionSuffix}")`,
|
|
421
|
+
'--style',
|
|
422
|
+
'compact',
|
|
423
|
+
]);
|
|
424
|
+
logProcess.stdout?.on('data', (data) => {
|
|
425
|
+
const lines = data.toString().split('\n');
|
|
426
|
+
// Get violation and command lines
|
|
427
|
+
const violationLine = lines.find(line => line.includes('Sandbox:') && line.includes('deny'));
|
|
428
|
+
const commandLine = lines.find(line => line.startsWith('CMD64_'));
|
|
429
|
+
if (!violationLine)
|
|
430
|
+
return;
|
|
431
|
+
// Extract violation details
|
|
432
|
+
const sandboxMatch = violationLine.match(sandboxExtractRegex);
|
|
433
|
+
if (!sandboxMatch?.[1])
|
|
434
|
+
return;
|
|
435
|
+
const violationDetails = sandboxMatch[1];
|
|
436
|
+
// Try to get command
|
|
437
|
+
let command;
|
|
438
|
+
let encodedCommand;
|
|
439
|
+
if (commandLine) {
|
|
440
|
+
const cmdMatch = commandLine.match(cmdExtractRegex);
|
|
441
|
+
encodedCommand = cmdMatch?.[1];
|
|
442
|
+
if (encodedCommand) {
|
|
443
|
+
try {
|
|
444
|
+
command = decodeSandboxedCommand(encodedCommand);
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
// Failed to decode, continue without command
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// Always filter out noisey violations
|
|
452
|
+
if (violationDetails.includes('mDNSResponder') ||
|
|
453
|
+
violationDetails.includes('mach-lookup com.apple.diagnosticd') ||
|
|
454
|
+
violationDetails.includes('mach-lookup com.apple.analyticsd')) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
// Check if we should ignore this violation
|
|
458
|
+
if (ignoreViolations && command) {
|
|
459
|
+
// Check wildcard patterns first
|
|
460
|
+
if (wildcardPaths.length > 0) {
|
|
461
|
+
const shouldIgnore = wildcardPaths.some(path => violationDetails.includes(path));
|
|
462
|
+
if (shouldIgnore)
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
// Check command-specific patterns
|
|
466
|
+
for (const [pattern, paths] of commandPatterns) {
|
|
467
|
+
if (command.includes(pattern)) {
|
|
468
|
+
const shouldIgnore = paths.some(path => violationDetails.includes(path));
|
|
469
|
+
if (shouldIgnore)
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
// Not ignored - report the violation
|
|
475
|
+
callback({
|
|
476
|
+
line: violationDetails,
|
|
477
|
+
command,
|
|
478
|
+
encodedCommand,
|
|
479
|
+
timestamp: new Date(), // We could parse the timestamp from the log but this feels more reliable
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
logProcess.stderr?.on('data', (data) => {
|
|
483
|
+
logForDebugging(`[Sandbox Monitor] Log stream stderr: ${data.toString()}`);
|
|
484
|
+
});
|
|
485
|
+
logProcess.on('error', (error) => {
|
|
486
|
+
logForDebugging(`[Sandbox Monitor] Failed to start log stream: ${error.message}`);
|
|
487
|
+
});
|
|
488
|
+
logProcess.on('exit', (code) => {
|
|
489
|
+
logForDebugging(`[Sandbox Monitor] Log stream exited with code: ${code}`);
|
|
490
|
+
});
|
|
491
|
+
return () => {
|
|
492
|
+
logForDebugging('[Sandbox Monitor] Stopping log monitor');
|
|
493
|
+
logProcess.kill('SIGTERM');
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
//# sourceMappingURL=macos-sandbox-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macos-sandbox-utils.js","sourceRoot":"","sources":["../../src/sandbox/macos-sandbox-utils.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,oBAAoB,CAAA;AAO3B,6CAA6C;AAC7C,IAAI,cAAmC,CAAA;AAEvC;;;;GAIG;AACH,MAAM,UAAU,+BAA+B;IAC7C,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,cAAc,CAAA;IACvB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE;YAC1C,KAAK,EAAE,QAAQ;YACf,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,cAAc,GAAG,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAA;QACtC,OAAO,cAAc,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,cAAc,GAAG,KAAK,CAAA;QACtB,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAyBD,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KA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eAAe,CACb,iDAAiD,KAAK,CAAC,OAAO,EAAE,CACjE,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAmB,EAAE,EAAE;QAC5C,eAAe,CAAC,kDAAkD,IAAI,EAAE,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,EAAE;QACV,eAAe,CAAC,wCAAwC,CAAC,CAAA;QACzD,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAC5B,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Platform } from '../utils/platform.js';
|
|
2
|
+
import type { SandboxAskCallback, IgnoreViolationsConfig, FsReadRestrictionConfig, FsWriteRestrictionConfig, NetworkRestrictionConfig } from './sandbox-schemas.js';
|
|
3
|
+
import { SandboxViolationStore } from './sandbox-violation-store.js';
|
|
4
|
+
/**
|
|
5
|
+
* Interface for the sandbox manager API
|
|
6
|
+
*/
|
|
7
|
+
export interface ISandboxManager {
|
|
8
|
+
initialize(sandboxAskCallback?: SandboxAskCallback, enableLogMonitor?: boolean): Promise<void>;
|
|
9
|
+
isSupportedPlatform(platform: Platform): boolean;
|
|
10
|
+
isSandboxingEnabled(): boolean;
|
|
11
|
+
getFsReadConfig(): FsReadRestrictionConfig;
|
|
12
|
+
getFsWriteConfig(): FsWriteRestrictionConfig;
|
|
13
|
+
getNetworkRestrictionConfig(): NetworkRestrictionConfig;
|
|
14
|
+
getAllowUnixSockets(): string[] | undefined;
|
|
15
|
+
getAllowLocalBinding(): boolean | undefined;
|
|
16
|
+
getIgnoreViolations(): IgnoreViolationsConfig | undefined;
|
|
17
|
+
getEnableWeakerNestedSandbox(): boolean | undefined;
|
|
18
|
+
getProxyPort(): number | undefined;
|
|
19
|
+
getSocksProxyPort(): number | undefined;
|
|
20
|
+
getLinuxHttpSocketPath(): string | undefined;
|
|
21
|
+
getLinuxSocksSocketPath(): string | undefined;
|
|
22
|
+
waitForNetworkInitialization(): Promise<boolean>;
|
|
23
|
+
wrapWithSandbox(command: string): Promise<string>;
|
|
24
|
+
getSandboxViolationStore(): SandboxViolationStore;
|
|
25
|
+
annotateStderrWithSandboxFailures(command: string, stderr: string): string;
|
|
26
|
+
getLinuxGlobPatternWarnings(): string[];
|
|
27
|
+
reset(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Global sandbox manager that handles both network and filesystem restrictions
|
|
31
|
+
* for this session. This runs outside of the sandbox, on the host machine.
|
|
32
|
+
*/
|
|
33
|
+
export declare const SandboxManager: ISandboxManager;
|
|
34
|
+
//# sourceMappingURL=sandbox-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox-manager.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAQjE,OAAO,KAAK,EACV,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,sBAAsB,CAAA;AAiB7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AA8vBpE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,CACR,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,gBAAgB,CAAC,EAAE,OAAO,GACzB,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAA;IAChD,mBAAmB,IAAI,OAAO,CAAA;IAC9B,eAAe,IAAI,uBAAuB,CAAA;IAC1C,gBAAgB,IAAI,wBAAwB,CAAA;IAC5C,2BAA2B,IAAI,wBAAwB,CAAA;IACvD,mBAAmB,IAAI,MAAM,EAAE,GAAG,SAAS,CAAA;IAC3C,oBAAoB,IAAI,OAAO,GAAG,SA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