Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/sandbox/sandbox-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1673,16 +1673,21 @@ async function wrapWithSandbox(
unsetEnvVars: credentialRestrictions.unsetEnvVars,
setEnvVars: credentialRestrictions.setEnvVars,
maskedFileBinds: credentialRestrictions.maskedFileBinds,
allowUnixSockets: getAllowUnixSockets(),
allowUnixSockets:
customConfig?.network?.allowUnixSockets ?? getAllowUnixSockets(),
allowAllUnixSockets: getAllowAllUnixSockets(),
allowLocalBinding: getAllowLocalBinding(),
allowLocalBinding:
customConfig?.network?.allowLocalBinding ?? getAllowLocalBinding(),
allowMachLookup: getAllowMachLookup(),
ignoreViolations: getIgnoreViolations(),
allowPty,
allowGitConfig: getAllowGitConfig(),
gitSafeDirectories,
enableWeakerNetworkIsolation: getEnableWeakerNetworkIsolation(),
allowAppleEvents: getAllowAppleEvents(),
enableWeakerNetworkIsolation:
customConfig?.enableWeakerNetworkIsolation ??
getEnableWeakerNetworkIsolation(),
allowAppleEvents:
customConfig?.allowAppleEvents ?? getAllowAppleEvents(),
binShell,
})

Expand Down
30 changes: 30 additions & 0 deletions test/sandbox/wrap-with-sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,36 @@ describe.if(isSupportedPlatform)('wrapWithSandbox customConfig', () => {
})
})

it.if(isMacOS)('prefers customConfig macOS permissions', async () => {
const globalConfig = createTestConfig()
globalConfig.network.allowLocalBinding = true
globalConfig.network.allowUnixSockets = ['/global/socket']
globalConfig.allowAppleEvents = true
globalConfig.enableWeakerNetworkIsolation = true
SandboxManager.updateConfig(globalConfig)

const customConfig = createTestConfig()
customConfig.network.allowLocalBinding = false
customConfig.network.allowUnixSockets = []
customConfig.allowAppleEvents = false
customConfig.enableWeakerNetworkIsolation = false

try {
const wrapped = await SandboxManager.wrapWithSandbox(
'echo test',
undefined,
customConfig,
)

expect(wrapped).not.toContain('(allow network-bind (local ip "*:*"))')
expect(wrapped).not.toContain('/global/socket')
expect(wrapped).not.toContain('(allow lsopen)')
expect(wrapped).not.toContain('com.apple.trustd.agent')
} finally {
SandboxManager.updateConfig(createTestConfig())
}
})

describe('readonly mode simulation', () => {
it('can create a fully restricted sandbox config', async () => {
const command = 'ls -la'
Expand Down