Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion packages/core/src/sandbox/linux/LinuxSandboxManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ export class LinuxSandboxManager implements SandboxManager {
workspaceWrite,
networkAccess: mergedAdditional.network ?? false,
maskFilePath: this.getMaskFilePath(),
isWriteCommand: req.command === '__write',
});

const bpfPath = getSeccompBpfPath();
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/sandbox/linux/bwrapArgsBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ describe.skipIf(os.platform() === 'win32')('buildBwrapArgs', () => {
workspaceWrite: false,
networkAccess: false,
maskFilePath: '/tmp/mask',
isWriteCommand: false,
};

it('should correctly format the base arguments', async () => {
Expand Down Expand Up @@ -188,7 +187,7 @@ describe.skipIf(os.platform() === 'win32')('buildBwrapArgs', () => {
expect(args[args.indexOf('/opt/tools') - 1]).toBe('--bind-try');
});

it('should bind the parent directory of a non-existent path', async () => {
it('should bind the parent directory of a non-existent path with --bind-try', async () => {
vi.mocked(fs.existsSync).mockImplementation((p) => {
if (p === '/home/user/workspace/new-file.txt') return false;
return true;
Expand All @@ -199,7 +198,6 @@ describe.skipIf(os.platform() === 'win32')('buildBwrapArgs', () => {
resolvedPaths: createResolvedPaths({
policyAllowed: ['/home/user/workspace/new-file.txt'],
}),
isWriteCommand: true,
});

const parentDir = '/home/user/workspace';
Expand Down
16 changes: 4 additions & 12 deletions packages/core/src/sandbox/linux/bwrapArgsBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface BwrapArgsOptions {
workspaceWrite: boolean;
networkAccess: boolean;
maskFilePath: string;
isWriteCommand: boolean;
}

/**
Expand All @@ -32,13 +31,8 @@ export interface BwrapArgsOptions {
export async function buildBwrapArgs(
options: BwrapArgsOptions,
): Promise<string[]> {
const {
resolvedPaths,
workspaceWrite,
networkAccess,
maskFilePath,
isWriteCommand,
} = options;
const { resolvedPaths, workspaceWrite, networkAccess, maskFilePath } =
options;
const { workspace } = resolvedPaths;

const bwrapArgs: string[] = [
Expand Down Expand Up @@ -78,11 +72,9 @@ export async function buildBwrapArgs(
if (fs.existsSync(allowedPath)) {
bwrapArgs.push('--bind-try', allowedPath, allowedPath);
} else {
// If the path doesn't exist, we still want to allow access to its parent
// to enable creating it. Since allowedPath is already resolved by resolveSandboxPaths,
// its parent is also correctly resolved.
// Bind the parent directory as read-write to allow creating the non-existent path.
const parent = dirname(allowedPath);
bwrapArgs.push(isWriteCommand ? '--bind-try' : bindFlag, parent, parent);
bwrapArgs.push('--bind-try', parent, parent);
}
}

Expand Down
Loading
Loading