fix(core): implement __read and __write commands in sandbox managers (#24283)

This commit is contained in:
Gal Zahavi
2026-03-31 12:39:51 -07:00
committed by GitHub
parent 7e117ac0ac
commit 554a5a36a3
7 changed files with 112 additions and 12 deletions
@@ -317,7 +317,7 @@ describe('LinuxSandboxManager', () => {
);
});
it('should not grant read-write access to allowedPaths inside the workspace when readonly mode is active', async () => {
it('should grant read-write access to allowedPaths inside the workspace even when readonly mode is active', async () => {
const manager = new LinuxSandboxManager({
workspace,
modeConfig: { readonly: true },
@@ -333,7 +333,7 @@ describe('LinuxSandboxManager', () => {
});
const bwrapArgs = result.args;
const bindIndex = bwrapArgs.indexOf(workspace + '/subdirectory');
expect(bwrapArgs[bindIndex - 1]).toBe('--ro-bind-try');
expect(bwrapArgs[bindIndex - 1]).toBe('--bind-try');
});
it('should not bind the workspace twice even if it has a trailing slash in allowedPaths', async () => {
@@ -40,6 +40,7 @@ import {
isDangerousCommand,
} from '../utils/commandSafety.js';
import { parsePosixSandboxDenials } from '../utils/sandboxDenialUtils.js';
import { handleReadWriteCommands } from '../utils/sandboxReadWriteUtils.js';
let cachedBpfPath: string | undefined;
@@ -211,6 +212,13 @@ export class LinuxSandboxManager implements SandboxManager {
false,
};
const { command: finalCommand, args: finalArgs } = handleReadWriteCommands(
req,
mergedAdditional,
this.options.workspace,
req.policy?.allowedPaths,
);
const sanitizationConfig = getSecureSanitizationConfig(
req.policy?.sanitizationConfig,
);
@@ -279,14 +287,7 @@ export class LinuxSandboxManager implements SandboxManager {
if (!fs.existsSync(resolved)) continue;
const normalizedAllowedPath = normalize(resolved).replace(/\/$/, '');
if (normalizedAllowedPath !== normalizedWorkspace) {
if (
!workspaceWrite &&
normalizedAllowedPath.startsWith(normalizedWorkspace + '/')
) {
bwrapArgs.push('--ro-bind-try', resolved, resolved);
} else {
bwrapArgs.push('--bind-try', resolved, resolved);
}
bwrapArgs.push('--bind-try', resolved, resolved);
}
}
@@ -362,7 +363,7 @@ export class LinuxSandboxManager implements SandboxManager {
const bpfPath = getSeccompBpfPath();
bwrapArgs.push('--seccomp', '9');
bwrapArgs.push('--', req.command, ...req.args);
bwrapArgs.push('--', finalCommand, ...finalArgs);
const shArgs = [
'-c',