diff --git a/src/sandbox/sandbox-manager.ts b/src/sandbox/sandbox-manager.ts index 3cf0d103..82cdc197 100644 --- a/src/sandbox/sandbox-manager.ts +++ b/src/sandbox/sandbox-manager.ts @@ -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, }) diff --git a/test/sandbox/wrap-with-sandbox.test.ts b/test/sandbox/wrap-with-sandbox.test.ts index a6371120..148f5cc4 100644 --- a/test/sandbox/wrap-with-sandbox.test.ts +++ b/test/sandbox/wrap-with-sandbox.test.ts @@ -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'