@schuttdev/gigai 0.4.0-beta.0 → 0.4.0-beta.1
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/{chunk-WUAGWZNA.js → chunk-NFKBLW3D.js} +11 -4
- package/dist/{chunk-XL27JFUS.js → chunk-ROMGFLOH.js} +50 -1
- package/dist/{chunk-FR2BGYIC.js → chunk-VCFG6XXN.js} +5 -4
- package/dist/{dist-SDKK67CH.js → dist-XQICZQ57.js} +8 -7
- package/dist/{filesystem-FTLLT7JC-3DA3AAA7.js → filesystem-CVLQFP7T-VBJWEKEE.js} +2 -2
- package/dist/index.js +2 -2
- package/dist/{shell-F2MZGP6N-WUIBVJZF.js → shell-IBJTGIEW-UEOHS5M2.js} +2 -2
- package/package.json +1 -1
|
@@ -3,10 +3,12 @@ import {
|
|
|
3
3
|
ErrorCode,
|
|
4
4
|
GigaiError,
|
|
5
5
|
canExecuteCommand,
|
|
6
|
-
canUseSudo
|
|
7
|
-
|
|
6
|
+
canUseSudo,
|
|
7
|
+
expandTilde,
|
|
8
|
+
validateCommandArgs
|
|
9
|
+
} from "./chunk-ROMGFLOH.js";
|
|
8
10
|
|
|
9
|
-
// ../server/dist/chunk-
|
|
11
|
+
// ../server/dist/chunk-BO7QE6T2.mjs
|
|
10
12
|
import { spawn } from "child_process";
|
|
11
13
|
var MAX_OUTPUT_SIZE = 10 * 1024 * 1024;
|
|
12
14
|
async function execCommandSafe(command, args, config, tier = "strict") {
|
|
@@ -20,13 +22,18 @@ async function execCommandSafe(command, args, config, tier = "strict") {
|
|
|
20
22
|
if (!check.allowed) {
|
|
21
23
|
throw new GigaiError(ErrorCode.COMMAND_NOT_ALLOWED, check.reason);
|
|
22
24
|
}
|
|
25
|
+
const argCheck = validateCommandArgs(tier, command, args);
|
|
26
|
+
if (!argCheck.allowed) {
|
|
27
|
+
throw new GigaiError(ErrorCode.COMMAND_NOT_ALLOWED, argCheck.reason);
|
|
28
|
+
}
|
|
23
29
|
for (const arg of args) {
|
|
24
30
|
if (arg.includes("\0")) {
|
|
25
31
|
throw new GigaiError(ErrorCode.VALIDATION_ERROR, "Null byte in argument");
|
|
26
32
|
}
|
|
27
33
|
}
|
|
34
|
+
const expandedArgs = args.map(expandTilde);
|
|
28
35
|
return new Promise((resolve, reject) => {
|
|
29
|
-
const child = spawn(command,
|
|
36
|
+
const child = spawn(command, expandedArgs, {
|
|
30
37
|
shell: false,
|
|
31
38
|
stdio: ["ignore", "pipe", "pipe"]
|
|
32
39
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// ../server/dist/chunk-
|
|
3
|
+
// ../server/dist/chunk-NO4R43QM.mjs
|
|
4
4
|
import { resolve } from "path";
|
|
5
5
|
import { homedir } from "os";
|
|
6
6
|
var DEFAULT_SECURITY = { default: "strict", overrides: {} };
|
|
@@ -93,6 +93,48 @@ function canExecuteCommand(tier, command, allowlist) {
|
|
|
93
93
|
return { allowed: true };
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
var PROTECTED_PATHS = /* @__PURE__ */ new Set([
|
|
97
|
+
"/",
|
|
98
|
+
"/bin",
|
|
99
|
+
"/boot",
|
|
100
|
+
"/dev",
|
|
101
|
+
"/etc",
|
|
102
|
+
"/home",
|
|
103
|
+
"/lib",
|
|
104
|
+
"/opt",
|
|
105
|
+
"/proc",
|
|
106
|
+
"/root",
|
|
107
|
+
"/sbin",
|
|
108
|
+
"/sys",
|
|
109
|
+
"/usr",
|
|
110
|
+
"/var",
|
|
111
|
+
"/Users",
|
|
112
|
+
"/System",
|
|
113
|
+
"/Library",
|
|
114
|
+
"/Applications"
|
|
115
|
+
]);
|
|
116
|
+
function hasRecursiveFlag(args) {
|
|
117
|
+
for (const a of args) {
|
|
118
|
+
if (a === "--") break;
|
|
119
|
+
if (a === "-r" || a === "-R" || a === "--recursive") return true;
|
|
120
|
+
if (a.startsWith("-") && !a.startsWith("--") && /[rR]/.test(a)) return true;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
function validateCommandArgs(tier, command, args) {
|
|
125
|
+
if (tier === "unrestricted") return { allowed: true };
|
|
126
|
+
if (command === "rm" && hasRecursiveFlag(args)) {
|
|
127
|
+
const home = homedir();
|
|
128
|
+
for (const arg of args) {
|
|
129
|
+
if (arg.startsWith("-")) continue;
|
|
130
|
+
const resolved = resolve(arg);
|
|
131
|
+
if (PROTECTED_PATHS.has(resolved) || resolved === home) {
|
|
132
|
+
return { allowed: false, reason: `Refusing to recursively remove critical path: ${resolved}` };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return { allowed: true };
|
|
137
|
+
}
|
|
96
138
|
function canUseSudo(allowSudo) {
|
|
97
139
|
if (allowSudo === false) return { allowed: false, reason: "sudo is not allowed" };
|
|
98
140
|
return { allowed: true };
|
|
@@ -136,6 +178,11 @@ function canAccessPath(tier, resolvedPath, allowedPaths) {
|
|
|
136
178
|
return { allowed: true };
|
|
137
179
|
}
|
|
138
180
|
}
|
|
181
|
+
function expandTilde(p) {
|
|
182
|
+
if (p === "~") return homedir();
|
|
183
|
+
if (p.startsWith("~/")) return homedir() + p.slice(1);
|
|
184
|
+
return p;
|
|
185
|
+
}
|
|
139
186
|
function shouldInjectSeparator(tier) {
|
|
140
187
|
return tier === "strict";
|
|
141
188
|
}
|
|
@@ -408,8 +455,10 @@ var GigaiConfigSchema = z.object({
|
|
|
408
455
|
export {
|
|
409
456
|
getEffectiveTier,
|
|
410
457
|
canExecuteCommand,
|
|
458
|
+
validateCommandArgs,
|
|
411
459
|
canUseSudo,
|
|
412
460
|
canAccessPath,
|
|
461
|
+
expandTilde,
|
|
413
462
|
shouldInjectSeparator,
|
|
414
463
|
encrypt,
|
|
415
464
|
decrypt,
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import {
|
|
3
3
|
ErrorCode,
|
|
4
4
|
GigaiError,
|
|
5
|
-
canAccessPath
|
|
6
|
-
|
|
5
|
+
canAccessPath,
|
|
6
|
+
expandTilde
|
|
7
|
+
} from "./chunk-ROMGFLOH.js";
|
|
7
8
|
|
|
8
|
-
// ../server/dist/chunk-
|
|
9
|
+
// ../server/dist/chunk-HXHM5BKW.mjs
|
|
9
10
|
import {
|
|
10
11
|
readFile as fsReadFile,
|
|
11
12
|
writeFile as fsWriteFile,
|
|
@@ -17,7 +18,7 @@ import { spawn } from "child_process";
|
|
|
17
18
|
var MAX_OUTPUT_SIZE = 10 * 1024 * 1024;
|
|
18
19
|
var MAX_READ_SIZE = 2 * 1024 * 1024;
|
|
19
20
|
async function validatePath(targetPath, allowedPaths, tier = "strict") {
|
|
20
|
-
const resolved = resolve(targetPath);
|
|
21
|
+
const resolved = resolve(expandTilde(targetPath));
|
|
21
22
|
let real;
|
|
22
23
|
try {
|
|
23
24
|
real = await realpath(resolved);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
execCommandSafe
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NFKBLW3D.js";
|
|
5
5
|
import {
|
|
6
6
|
editBuiltin,
|
|
7
7
|
globBuiltin,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
readFileSafe,
|
|
12
12
|
searchFilesSafe,
|
|
13
13
|
writeBuiltin
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-VCFG6XXN.js";
|
|
15
15
|
import {
|
|
16
16
|
ErrorCode,
|
|
17
17
|
GigaiConfigSchema,
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
generateEncryptionKey,
|
|
22
22
|
getEffectiveTier,
|
|
23
23
|
shouldInjectSeparator
|
|
24
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-ROMGFLOH.js";
|
|
25
25
|
|
|
26
26
|
// ../server/dist/index.mjs
|
|
27
27
|
import { parseArgs } from "util";
|
|
@@ -48,7 +48,7 @@ import { nanoid as nanoid3 } from "nanoid";
|
|
|
48
48
|
import { dirname as dirname2 } from "path";
|
|
49
49
|
import { readFileSync } from "fs";
|
|
50
50
|
import { resolve as resolve2 } from "path";
|
|
51
|
-
import { platform, hostname as hostname2 } from "os";
|
|
51
|
+
import { platform, hostname as hostname2, userInfo } from "os";
|
|
52
52
|
import { platform as platform2 } from "os";
|
|
53
53
|
import { writeFile as writeFile2, readFile as readFile2, unlink, mkdir } from "fs/promises";
|
|
54
54
|
import { join } from "path";
|
|
@@ -800,7 +800,7 @@ var cronPlugin = fp5(async (server, opts) => {
|
|
|
800
800
|
const executor = async (tool, args) => {
|
|
801
801
|
const entry = server.registry.get(tool);
|
|
802
802
|
if (entry.type === "builtin") {
|
|
803
|
-
const { execCommandSafe: execCommandSafe2 } = await import("./shell-
|
|
803
|
+
const { execCommandSafe: execCommandSafe2 } = await import("./shell-IBJTGIEW-UEOHS5M2.js");
|
|
804
804
|
const {
|
|
805
805
|
readFileSafe: readFileSafe2,
|
|
806
806
|
listDirSafe: listDirSafe2,
|
|
@@ -810,7 +810,7 @@ var cronPlugin = fp5(async (server, opts) => {
|
|
|
810
810
|
editBuiltin: editBuiltin2,
|
|
811
811
|
globBuiltin: globBuiltin2,
|
|
812
812
|
grepBuiltin: grepBuiltin2
|
|
813
|
-
} = await import("./filesystem-
|
|
813
|
+
} = await import("./filesystem-CVLQFP7T-VBJWEKEE.js");
|
|
814
814
|
const builtinConfig = entry.config.config ?? {};
|
|
815
815
|
switch (entry.config.builtin) {
|
|
816
816
|
case "filesystem": {
|
|
@@ -891,7 +891,8 @@ async function healthRoutes(server) {
|
|
|
891
891
|
version: startupVersion,
|
|
892
892
|
uptime: Date.now() - startTime,
|
|
893
893
|
platform: platform(),
|
|
894
|
-
hostname: hostname2()
|
|
894
|
+
hostname: hostname2(),
|
|
895
|
+
homeDir: userInfo().homedir
|
|
895
896
|
};
|
|
896
897
|
});
|
|
897
898
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
import { defineCommand, runMain } from "citty";
|
|
5
5
|
|
|
6
6
|
// src/version.ts
|
|
7
|
-
var VERSION = "0.4.0-beta.
|
|
7
|
+
var VERSION = "0.4.0-beta.1";
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
async function requireServer() {
|
|
11
11
|
try {
|
|
12
|
-
return await import("./dist-
|
|
12
|
+
return await import("./dist-XQICZQ57.js");
|
|
13
13
|
} catch {
|
|
14
14
|
console.error("Server dependencies not installed.");
|
|
15
15
|
console.error("Run: npm install -g @schuttdev/gigai");
|