opencode-sandbox 0.1.13 → 0.1.15
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/dist/index.js +20 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,12 +32,31 @@ var DEFAULT_ALLOWED_DOMAINS = [
|
|
|
32
32
|
"generativelanguage.googleapis.com",
|
|
33
33
|
"*.googleapis.com"
|
|
34
34
|
];
|
|
35
|
+
var UNSAFE_WRITE_PATHS = new Set(["/", "/home", "/usr", "/etc", "/var", "/opt"]);
|
|
36
|
+
function isSafeWritePath(p) {
|
|
37
|
+
const normalized = path.resolve(p);
|
|
38
|
+
if (UNSAFE_WRITE_PATHS.has(normalized)) {
|
|
39
|
+
console.warn(`[opencode-sandbox] Rejecting unsafe write path: ${normalized}`);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
35
44
|
function resolveConfig(projectDir, worktree, user) {
|
|
36
45
|
const homeDir = os.homedir();
|
|
46
|
+
const candidatePaths = [projectDir, worktree, os.tmpdir()].filter(Boolean);
|
|
47
|
+
const safePaths = candidatePaths.filter((p) => isSafeWritePath(p));
|
|
48
|
+
const seen = new Set;
|
|
49
|
+
const writePaths = user?.filesystem?.allowWrite ?? safePaths.filter((p) => {
|
|
50
|
+
const resolved = path.resolve(p);
|
|
51
|
+
if (seen.has(resolved))
|
|
52
|
+
return false;
|
|
53
|
+
seen.add(resolved);
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
37
56
|
return {
|
|
38
57
|
filesystem: {
|
|
39
58
|
denyRead: user?.filesystem?.denyRead ?? DEFAULT_DENY_READ_DIRS.map((p) => path.join(homeDir, p)),
|
|
40
|
-
allowWrite:
|
|
59
|
+
allowWrite: writePaths,
|
|
41
60
|
denyWrite: user?.filesystem?.denyWrite ?? []
|
|
42
61
|
},
|
|
43
62
|
network: {
|
|
@@ -109,16 +128,6 @@ var SandboxPlugin = async ({ directory, worktree }) => {
|
|
|
109
128
|
"tool.execute.after": async (input, output) => {
|
|
110
129
|
if (input.tool !== "bash")
|
|
111
130
|
return;
|
|
112
|
-
const text = output.output ?? "";
|
|
113
|
-
if (text.includes("Operation not permitted") || text.includes("Connection blocked by network allowlist")) {
|
|
114
|
-
const message = "⚠️ [opencode-sandbox] Command blocked or partially blocked by sandbox restrictions. " + "Adjust config in .opencode/sandbox.json or OPENCODE_SANDBOX_CONFIG.";
|
|
115
|
-
output.output = text + `
|
|
116
|
-
|
|
117
|
-
` + message;
|
|
118
|
-
if (output.metadata && typeof output.metadata.output === "string") {
|
|
119
|
-
output.metadata.output = message;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
131
|
if (lastOriginalCommand && input.args && typeof input.args.command === "string") {
|
|
123
132
|
input.args.command = lastOriginalCommand;
|
|
124
133
|
lastOriginalCommand = undefined;
|
package/package.json
CHANGED