opencode-sandbox 0.1.14 → 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 -1
- 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: {
|
package/package.json
CHANGED