minicode-ai 0.9.26
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/CHANGELOG.md +935 -0
- package/LICENSE +21 -0
- package/README.md +200 -0
- package/cli/args.ts +195 -0
- package/cli/auto-update.ts +108 -0
- package/cli/commands/auth.ts +166 -0
- package/cli/commands/config.ts +382 -0
- package/cli/commands/doctor.ts +128 -0
- package/cli/commands/exec.ts +179 -0
- package/cli/commands/mcp.ts +35 -0
- package/cli/commands/memory.ts +107 -0
- package/cli/commands/pricing.ts +100 -0
- package/cli/commands/providers.ts +162 -0
- package/cli/commands/sessions.ts +128 -0
- package/cli/commands/skills.ts +61 -0
- package/cli/commands/stats.ts +82 -0
- package/cli/commands.ts +317 -0
- package/cli/index.ts +539 -0
- package/cli/model-manager.ts +112 -0
- package/cli/provider-manager.ts +111 -0
- package/cli/repl.ts +734 -0
- package/cli/router.ts +124 -0
- package/cli/setup.ts +780 -0
- package/cli/wizard.ts +21 -0
- package/docs/ARCHITECTURE.html +1222 -0
- package/docs/README.md +109 -0
- package/docs/architecture.md +44 -0
- package/docs/changelog.md +3 -0
- package/package.json +91 -0
- package/src/agents/pool.ts +43 -0
- package/src/app/mentions.ts +50 -0
- package/src/app/provider-layer.ts +118 -0
- package/src/app/rag-layer.ts +105 -0
- package/src/app/session.ts +154 -0
- package/src/app/tool-layer.ts +56 -0
- package/src/config.ts +372 -0
- package/src/constants.ts +119 -0
- package/src/hooks/run.ts +89 -0
- package/src/lib/atomic-write.ts +88 -0
- package/src/lib/db-path.ts +36 -0
- package/src/lib/git-hardening.ts +91 -0
- package/src/lib/ignore.ts +58 -0
- package/src/lib/keystore.ts +202 -0
- package/src/lib/net.ts +70 -0
- package/src/lib/safe-open.ts +138 -0
- package/src/lib/session-id.ts +23 -0
- package/src/lib/trash.ts +38 -0
- package/src/lib/trusted-exec.ts +81 -0
- package/src/lsp/client.ts +395 -0
- package/src/mcp/client.ts +400 -0
- package/src/mcp/http-transport.ts +344 -0
- package/src/mcp/server.ts +538 -0
- package/src/mcp/transport.ts +150 -0
- package/src/memory/files.ts +159 -0
- package/src/memory/vector.ts +775 -0
- package/src/policy/allowlist.ts +67 -0
- package/src/policy/bash-guard.ts +465 -0
- package/src/policy/compaction.ts +271 -0
- package/src/policy/context.ts +161 -0
- package/src/policy/executor.ts +199 -0
- package/src/policy/jail.ts +127 -0
- package/src/policy/permission.ts +517 -0
- package/src/policy/pricing.ts +336 -0
- package/src/policy/ratelimit.ts +54 -0
- package/src/policy/sandbox-policy.ts +157 -0
- package/src/policy/scrub.ts +138 -0
- package/src/policy/update-check.ts +200 -0
- package/src/policy/usage.ts +292 -0
- package/src/policy/verifier.ts +181 -0
- package/src/providers/anthropic.ts +401 -0
- package/src/providers/auth-store.ts +139 -0
- package/src/providers/build.ts +136 -0
- package/src/providers/detect.ts +126 -0
- package/src/providers/effort.ts +165 -0
- package/src/providers/guards.ts +107 -0
- package/src/providers/oauth.ts +326 -0
- package/src/providers/presets.ts +122 -0
- package/src/providers/provision.ts +298 -0
- package/src/providers/responses.ts +371 -0
- package/src/providers/router.ts +247 -0
- package/src/repo/repomap.ts +470 -0
- package/src/sandbox/docker.ts +129 -0
- package/src/sandbox/os.ts +193 -0
- package/src/session/checkpoint.ts +543 -0
- package/src/session/journal.ts +1347 -0
- package/src/session/persistence.ts +446 -0
- package/src/session/shadow-git.ts +351 -0
- package/src/session/turn-marker.ts +118 -0
- package/src/skills/loader.ts +117 -0
- package/src/telemetry/trace.ts +283 -0
- package/src/tools/ask_user.ts +54 -0
- package/src/tools/bash.ts +400 -0
- package/src/tools/code_run.ts +96 -0
- package/src/tools/delete_file.ts +31 -0
- package/src/tools/edit.ts +204 -0
- package/src/tools/git.ts +301 -0
- package/src/tools/glob.ts +90 -0
- package/src/tools/grep.ts +281 -0
- package/src/tools/hashline.ts +66 -0
- package/src/tools/index.ts +103 -0
- package/src/tools/lsp.ts +346 -0
- package/src/tools/mcp_call.ts +163 -0
- package/src/tools/memory.ts +144 -0
- package/src/tools/move_file.ts +47 -0
- package/src/tools/patch.ts +86 -0
- package/src/tools/read_file.ts +130 -0
- package/src/tools/read_image.ts +80 -0
- package/src/tools/submit_result.ts +49 -0
- package/src/tools/task.ts +346 -0
- package/src/tools/todo.ts +201 -0
- package/src/tools/web_fetch.ts +161 -0
- package/src/tools/web_search.ts +156 -0
- package/src/tools/write_file.ts +42 -0
- package/src/ui/approval/prompt.ts +76 -0
- package/src/ui/assistant/simple.ts +568 -0
- package/src/ui/assistant/turn-status.ts +303 -0
- package/src/ui/contract.ts +55 -0
- package/src/ui/footer.ts +105 -0
- package/src/ui/input/input.ts +805 -0
- package/src/ui/input/prompt-engine.ts +606 -0
- package/src/ui/render/collapse.ts +84 -0
- package/src/ui/render/detail.ts +24 -0
- package/src/ui/render/diff.ts +181 -0
- package/src/ui/render/errors.ts +239 -0
- package/src/ui/render/format.ts +54 -0
- package/src/ui/render/highlight.ts +294 -0
- package/src/ui/render/markdown.ts +120 -0
- package/src/ui/render/money.ts +12 -0
- package/src/ui/render/reasoning.ts +20 -0
- package/src/ui/render/sanitize.ts +80 -0
- package/src/ui/render/table.ts +88 -0
- package/src/ui/render/theme.ts +339 -0
- package/src/ui/render/width.ts +256 -0
- package/src/ui/render/wrap.ts +120 -0
- package/src/ui/runtime/bus-debug.ts +83 -0
- package/src/ui/runtime/chrome.ts +301 -0
- package/src/ui/runtime/spinner.ts +77 -0
- package/src/ui/runtime/statusline.ts +227 -0
- package/src/ui/screens/model-manager.ts +434 -0
- package/src/ui/screens/overlay.ts +61 -0
- package/src/ui/screens/picker.ts +307 -0
- package/src/ui/screens/provider-manager.ts +450 -0
- package/src/ui/screens/wizard.ts +132 -0
- package/vendor/minicore/VENDOR.md +29 -0
- package/vendor/minicore/package.json +21 -0
- package/vendor/minicore/src/core/budget.ts +26 -0
- package/vendor/minicore/src/core/compact.ts +76 -0
- package/vendor/minicore/src/core/errors.ts +60 -0
- package/vendor/minicore/src/core/events.ts +74 -0
- package/vendor/minicore/src/core/executor.ts +139 -0
- package/vendor/minicore/src/core/history.ts +32 -0
- package/vendor/minicore/src/core/index.ts +42 -0
- package/vendor/minicore/src/core/loop.ts +344 -0
- package/vendor/minicore/src/core/permission.ts +24 -0
- package/vendor/minicore/src/core/provider.ts +39 -0
- package/vendor/minicore/src/core/recovery.ts +34 -0
- package/vendor/minicore/src/core/session.ts +327 -0
- package/vendor/minicore/src/core/snapshot.ts +142 -0
- package/vendor/minicore/src/core/tokens.ts +111 -0
- package/vendor/minicore/src/core/tool.ts +118 -0
- package/vendor/minicore/src/core/types.ts +50 -0
- package/vendor/minicore/src/providers/openai-compat.ts +366 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises"
|
|
2
|
+
import { homedir } from "node:os"
|
|
3
|
+
import { dirname, join, resolve } from "node:path"
|
|
4
|
+
import type { ToolCall } from "#minicore/core/types.ts"
|
|
5
|
+
import { atomicWriteText } from "../lib/atomic-write.ts"
|
|
6
|
+
|
|
7
|
+
export interface Allowlist {
|
|
8
|
+
allowed: string[] // entries like "bash:echo hi" or "write_file:.tmp/*"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const GLOBAL_ALLOW = join(homedir(), ".minicode", "allowlist.json")
|
|
12
|
+
const LOCAL_ALLOW = ".minicode/allowlist.json"
|
|
13
|
+
|
|
14
|
+
export async function loadAllowlist(
|
|
15
|
+
cwd?: string,
|
|
16
|
+
opts: { allowLocal?: boolean } = {},
|
|
17
|
+
): Promise<Allowlist> {
|
|
18
|
+
let globalList: Allowlist = { allowed: [] }
|
|
19
|
+
let localList: Allowlist = { allowed: [] }
|
|
20
|
+
try {
|
|
21
|
+
const txt = await readFile(GLOBAL_ALLOW, "utf8")
|
|
22
|
+
const parsed = JSON.parse(txt) as Allowlist
|
|
23
|
+
if (Array.isArray(parsed.allowed)) globalList = parsed
|
|
24
|
+
} catch {}
|
|
25
|
+
// Sama seperti config (audit #07 P0): allowlist lokal adalah input repo —
|
|
26
|
+
// repo yang memberi dirinya sendiri "always" = persetujuan palsu. Hanya
|
|
27
|
+
// dibaca bila operator opt-in; default = global saja.
|
|
28
|
+
if (opts.allowLocal) {
|
|
29
|
+
try {
|
|
30
|
+
const path = resolve(cwd ?? process.cwd(), LOCAL_ALLOW)
|
|
31
|
+
const txt = await readFile(path, "utf8")
|
|
32
|
+
const parsed = JSON.parse(txt) as Allowlist
|
|
33
|
+
if (Array.isArray(parsed.allowed)) localList = parsed
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
// merge global+local, dedup
|
|
37
|
+
const merged = new Set<string>([...globalList.allowed, ...localList.allowed])
|
|
38
|
+
return { allowed: [...merged] }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function saveAllowlist(entry: string, cwd?: string, opts: { global?: boolean } = {}) {
|
|
42
|
+
const path = opts.global ? GLOBAL_ALLOW : resolve(cwd ?? process.cwd(), LOCAL_ALLOW)
|
|
43
|
+
await mkdir(dirname(path), { recursive: true }).catch(() => {})
|
|
44
|
+
let list: Allowlist = { allowed: [] }
|
|
45
|
+
try {
|
|
46
|
+
const parsed = JSON.parse(await readFile(path, "utf8")) as Allowlist
|
|
47
|
+
if (Array.isArray(parsed.allowed)) list = parsed
|
|
48
|
+
} catch {}
|
|
49
|
+
if (!list.allowed.includes(entry)) list.allowed.push(entry)
|
|
50
|
+
await mkdir(dirname(path), { recursive: true }).catch(() => {})
|
|
51
|
+
await atomicWriteText(path, JSON.stringify(list, null, 2))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function matchAllowlist(call: ToolCall, allowlist: string[]): boolean {
|
|
55
|
+
// Tanpa pemotongan: kunci = nama + JSON ARG PENUH. Versi lama memakai
|
|
56
|
+
// `.slice(0, 200)` sehingga dua panggilan dengan 200-char prefix sama
|
|
57
|
+
// berbagi kunci — entri "always" untuk perintah jinak panjang otomatis
|
|
58
|
+
// me-allow perintah jahat dengan prefix sama (temuan audit #07, reproducer:
|
|
59
|
+
// prefix 'A'x195 + tail jinak vs tail jahat → kunci terpotong identik).
|
|
60
|
+
const key = `${call.name}:${JSON.stringify(call.args)}`
|
|
61
|
+
return allowlist.some((pat) => {
|
|
62
|
+
const safe = pat.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")
|
|
63
|
+
const re = new RegExp(`^${safe}$`)
|
|
64
|
+
if (pat.includes(":")) return re.test(key)
|
|
65
|
+
return re.test(call.name) || re.test(key)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// Analisis perintah shell untuk keputusan permission.
|
|
2
|
+
//
|
|
3
|
+
// Kenapa modul terpisah? Denylist regex lama diterapkan ke string MENTAH,
|
|
4
|
+
// sehingga trivially dilewati oleh hal-hal yang shell anggap setara:
|
|
5
|
+
//
|
|
6
|
+
// cat .e""nv → shell membaca .env, regex melihat `.e""nv`
|
|
7
|
+
// X=.env; cat $X → shell membaca .env, regex tak pernah melihat ".env"
|
|
8
|
+
// p=python3; $p -c 1 → interpreter jalan, regex tak melihat "python3 -c"
|
|
9
|
+
// node --eval "1" → sama dengan -e, tapi hanya `-e` yang di-regex
|
|
10
|
+
//
|
|
11
|
+
// Pendekatan di sini: NORMALISASI dulu (buang quote pemisah kata, substitusi
|
|
12
|
+
// assignment variabel sederhana), lalu periksa. Ini menutup seluruh kelas
|
|
13
|
+
// bypass, bukan satu-satu polanya.
|
|
14
|
+
//
|
|
15
|
+
// Batasan yang harus jujur: ini tetap analisis statis atas bahasa yang
|
|
16
|
+
// Turing-complete. Command substitution dinamis (`$(curl ...)`), aritmetika,
|
|
17
|
+
// dan indirection berlapis tak bisa diselesaikan tanpa mengeksekusi. Untuk
|
|
18
|
+
// isolasi sungguhan tetap perlu sandbox OS/container — modul ini menaikkan
|
|
19
|
+
// biaya serangan, bukan menghilangkannya.
|
|
20
|
+
|
|
21
|
+
import { isAbsolute, resolve } from "node:path"
|
|
22
|
+
import { isOwnedState, isRealPathOutsideRoot, isSensitive } from "./jail.ts"
|
|
23
|
+
|
|
24
|
+
export interface BashVerdict {
|
|
25
|
+
/** true = tolak */
|
|
26
|
+
denied: boolean
|
|
27
|
+
/** alasan singkat untuk pesan ke model/user */
|
|
28
|
+
reason?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ── Normalisasi ──
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Buang quote yang dipakai untuk memecah kata tanpa mengubah arti bagi shell.
|
|
35
|
+
* `.e""nv` → `.env`, `pyt"h"on3` → `python3`, `'.env'` → `.env`.
|
|
36
|
+
*
|
|
37
|
+
* Kita tidak mencoba meniru quoting shell sepenuhnya; tujuannya membuat
|
|
38
|
+
* bentuk-terpecah dan bentuk-utuh menghasilkan string pemeriksaan yang sama.
|
|
39
|
+
* Diekspor untuk test.
|
|
40
|
+
*/
|
|
41
|
+
export function stripQuotes(cmd: string): string {
|
|
42
|
+
return cmd.replace(/["']/g, "")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Substitusi assignment variabel sederhana dalam satu perintah.
|
|
47
|
+
* `X=.env; cat $X` → `X=.env; cat .env`
|
|
48
|
+
* `p=python3 && $p -c 1` → `p=python3 && python3 -c 1`
|
|
49
|
+
*
|
|
50
|
+
* Hanya nilai literal tanpa spasi/ekspansi yang disubstitusi — cukup untuk
|
|
51
|
+
* menutup indirection yang dipakai untuk lolos filter, tanpa berpura-pura
|
|
52
|
+
* mengevaluasi shell. Assignment di-scan ulang tiap lintasan agar rantai
|
|
53
|
+
* (`a=.env; b=$a; cat $b`) juga terselesaikan. Diekspor untuk test.
|
|
54
|
+
*/
|
|
55
|
+
export function inlineSimpleVars(cmd: string): string {
|
|
56
|
+
const ASSIGN = /(?:^|[;&|]\s*|\s)([A-Za-z_][A-Za-z0-9_]*)=([^\s;&|"'`$()]+)/g
|
|
57
|
+
let out = cmd
|
|
58
|
+
for (let pass = 0; pass < 3; pass++) {
|
|
59
|
+
// scan ulang: substitusi lintasan sebelumnya bisa memunculkan
|
|
60
|
+
// assignment literal baru (b=$a → b=.env)
|
|
61
|
+
const vars = new Map<string, string>()
|
|
62
|
+
ASSIGN.lastIndex = 0
|
|
63
|
+
let m: RegExpExecArray | null = ASSIGN.exec(out)
|
|
64
|
+
while (m !== null) {
|
|
65
|
+
vars.set(m[1]!, m[2]!)
|
|
66
|
+
m = ASSIGN.exec(out)
|
|
67
|
+
}
|
|
68
|
+
if (vars.size === 0) break
|
|
69
|
+
let changed = false
|
|
70
|
+
for (const [name, value] of vars) {
|
|
71
|
+
const ref = new RegExp(`\\$\\{${name}\\}|\\$${name}\\b`, "g")
|
|
72
|
+
const next = out.replace(ref, value)
|
|
73
|
+
if (next !== out) {
|
|
74
|
+
out = next
|
|
75
|
+
changed = true
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!changed) break
|
|
79
|
+
}
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Buang wrapper perintah yang tidak mengubah apa yang dijalankan.
|
|
85
|
+
*
|
|
86
|
+
* `command env`, `nice env`, `time env`, `exec env` semuanya menjalankan `env`,
|
|
87
|
+
* tapi wrapper-nya menggeser posisi kata sehingga pola yang ter-anchor ke awal
|
|
88
|
+
* perintah (mis. deteksi env-dump) tidak lagi cocok. Ditemukan oleh
|
|
89
|
+
* experiments/extreme-bash-fuzz.ts: `command env` lolos sementara `env` ditolak.
|
|
90
|
+
*
|
|
91
|
+
* Wrapper dibuang berulang karena bisa berlapis (`time nice env`).
|
|
92
|
+
* Diekspor untuk test.
|
|
93
|
+
*/
|
|
94
|
+
export function stripCommandWrappers(cmd: string): string {
|
|
95
|
+
const WRAPPER =
|
|
96
|
+
/(^|[;&|]\s*)(?:command|exec|builtin|eval|nice(?:\s+-n\s*-?\d+)?|nohup|time|timeout\s+[\d.]+[smhd]?|stdbuf(?:\s+-\S+)*|env(?=\s+[A-Za-z_][A-Za-z0-9_]*=)|setsid|ionice(?:\s+-\S+)*|xargs(?:\s+-\S+)*|sudo(?:\s+-\S+)*|doas)\s+/gi
|
|
97
|
+
// Wrapper privilese/konteks (audit 2026-09-16 B2): `su -c 'env'`,
|
|
98
|
+
// `runuser -u x -- printenv`, `cmd /c set` menyembunyikan perintah
|
|
99
|
+
// sebenarnya dari aturan konten yang ter-anchor ke awal (ENV_DUMP dkk).
|
|
100
|
+
// Dibuang BESERTA flag/argumen konteksnya (user/host/path, introducer
|
|
101
|
+
// -c/--//c) sehingga perintah DALAM dievaluasi aturan biasa — `su -c
|
|
102
|
+
// 'cat /etc/shadow'` tetap kena SENSITIVE_TARGET. Jangkar awal mencegah
|
|
103
|
+
// strip di tengah perintah (`echo su -c env` tak tersentuh).
|
|
104
|
+
const WRAPPER_SHELL =
|
|
105
|
+
/(^|[;&|]\s*)(?:(?:su|runuser|gosu|chroot|nsenter)(?:\s+(?:-[^\s;|]+|--[^\s;|]*|\/[^\s;|]*|[^-;\s|/][^;\s|]*))*\s+|cmd(?:\.exe)?(?:\s+\/[a-zA-Z]+)*\s+\/c\s+)/gi
|
|
106
|
+
let out = cmd
|
|
107
|
+
for (let pass = 0; pass < 4; pass++) {
|
|
108
|
+
const next = out.replace(WRAPPER, "$1").replace(WRAPPER_SHELL, "$1")
|
|
109
|
+
if (next === out) break
|
|
110
|
+
out = next
|
|
111
|
+
}
|
|
112
|
+
return out
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Bentuk kanonik untuk pemeriksaan: quote dibuang + variabel disubstitusi. */
|
|
116
|
+
export function normalizeCommand(cmd: string): string {
|
|
117
|
+
return stripCommandWrappers(inlineSimpleVars(stripQuotes(cmd)))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ── Aturan ──
|
|
121
|
+
|
|
122
|
+
/** Path/berkas kredensial, dicek pada bentuk ternormalisasi. */
|
|
123
|
+
const SENSITIVE_TARGET =
|
|
124
|
+
/(?:^|[\s/\\=@"'([:])(?:\.env(?:\.[\w.-]+)?|\.git-credentials|\.npmrc|\.netrc|id_(?:rsa|dsa|ecdsa|ed25519)|credentials(?:\.json)?|\.pem|\.p12|\.pfx|shadow|master\.key|config[/\\](?:sam|system|security|software|default)(?=[/\\]|$|[\s;"'&|])|ntds\.dit\b|hklm[/\\](?:sam|system|security)(?=[/\\]|$|[\s;"'&|]))\b/i
|
|
125
|
+
|
|
126
|
+
/** Direktori kredensial: ~/.ssh, $HOME/.aws, /etc/shadow, dst. */
|
|
127
|
+
const SENSITIVE_DIR = /(?:~|\$HOME|\$\{HOME\}|\/etc|\/root|\/proc\/self)[/\\](?:\.?[\w.-]+)/i
|
|
128
|
+
|
|
129
|
+
/** Export registry hive / salin shadow-copy — satu-satunya pemakaian di
|
|
130
|
+
* konteks agen adalah eksfiltrasi hive terkunci (SAM butuh SYSTEM/VSS).
|
|
131
|
+
* `reg query` diagnostik TIDAK kena (butuh kata kerja save|export). */
|
|
132
|
+
const REG_HIVE_EXPORT = /\breg(?:\.exe)?\s+(?:save|export)\b/i
|
|
133
|
+
|
|
134
|
+
/** Path hive dalam bentuk apa pun (file maupun key registry). Jaga sinkron
|
|
135
|
+
* dengan cabang config[/\\]…|ntds|hklm di SENSITIVE_TARGET di atas. */
|
|
136
|
+
const HIVE_PATH =
|
|
137
|
+
/config[/\\](?:sam|system|security|software|default)(?=[/\\]|$|[\s;"'&|])|ntds\.dit\b|hklm[/\\](?:sam|system|security)(?=[/\\]|$|[\s;"'&|])/i
|
|
138
|
+
|
|
139
|
+
/** Pembuatan/mount shadow copy + utilitas DS — di tangan agen hanya untuk
|
|
140
|
+
* membaca hive terkunci (kasus nyata: `type ...\system32\config\sam`).
|
|
141
|
+
* `vssadmin list` diagnostik tetap lolos (hanya create/delete yang ditahan). */
|
|
142
|
+
const VSS_SHADOW = /\bvssadmin\b[^\n]*\b(?:create\s+shadow|delete\s+shadows?)\b/i
|
|
143
|
+
const NTDSUTIL = /\bntdsutil\b/i
|
|
144
|
+
|
|
145
|
+
/** Perintah yang membaca/menyalin isi berkas. Daftar ini + ekstraktor argumen
|
|
146
|
+
* di inspectBashCommand WAJIB sinkron (audit 2026-09-16 B4: certutil/tac/
|
|
147
|
+
* findstr lolos karena hanya ada di satu sisi). Denylist takkan pernah
|
|
148
|
+
* komplet (residual arsitektural, lihat kepala berkas) — tiap entri di sini
|
|
149
|
+
* adalah kasus konkret terverifikasi, bukan tebakan. */
|
|
150
|
+
const READERS =
|
|
151
|
+
/\b(?:cat|bat|less|more|head|tail|nl|od|xxd|strings|type|Get-Content|certutil|tac|findstr|fc|comp|cp|copy|mv|move|scp|rsync|tar|zip|gzip|base64|openssl|awk|sed|grep|egrep|fgrep|rg|cut|sort|uniq|tee|dd|install)\b/i
|
|
152
|
+
|
|
153
|
+
/** Dump environment — `printenv` sudah lama diblok, sisanya belum. */
|
|
154
|
+
const ENV_DUMP =
|
|
155
|
+
// F-20: `\n` adalah pemisah perintah setara `;` — tanpa ini `echo hi\nenv`
|
|
156
|
+
// lolos (anchor lama hanya [;&|]). Berlaku untuk semua aturan ber-anchor
|
|
157
|
+
// awal-perintah di berkas ini.
|
|
158
|
+
/(?:^|[;&|\n]\s*)(?:printenv|env|set|export\s+-p|declare\s+-[xp]|compgen\s+-v)\s*(?:$|[;&|\n]|\|)/i
|
|
159
|
+
|
|
160
|
+
/** Referensi eksplisit ke variabel env yang berbau kredensial. */
|
|
161
|
+
const ENV_SECRET_REF =
|
|
162
|
+
/\$\{?[A-Z_]*(?:API_?KEY|SECRET|TOKEN|PASSWORD|PASSWD|CREDENTIAL|PRIVATE_?KEY|ACCESS_?KEY)[A-Z_]*\}?/
|
|
163
|
+
|
|
164
|
+
/** Flag upload berkas pada klien HTTP — jalur exfiltrasi paling langsung. */
|
|
165
|
+
const UPLOAD_FLAG =
|
|
166
|
+
/\b(?:curl|wget|http|httpie|nc|ncat|socat)\b[^\n]*(?:-F\s*\S*=@|--form\s*\S*=@|-d\s*@|--data(?:-binary|-raw)?\s*@|-T\s+|--upload-file|--post-file=|-b\s*@)/i
|
|
167
|
+
|
|
168
|
+
/** Interpreter dijalankan dengan kode inline (semua bentuk flag). */
|
|
169
|
+
const INLINE_INTERPRETER =
|
|
170
|
+
/\b(?:pyw?|python[\d.]*|pypy[\d.]*|sh|bash|dash|zsh|ksh|node|deno|bun|perl|ruby|php|Rscript)(?:\.exe)?\b\s+(?:-\w*\s+)*(?:-c|-e|-E|--eval|--print|-p|--command|-r|--execute)\b/i
|
|
171
|
+
// Residual jujur (audit 2026-09-16 B3): eksekusi via stdin/redirect TANPA
|
|
172
|
+
// flag inline (`bash -s < skrip`, `python3 < prog`, `... | python3 -`) tidak
|
|
173
|
+
// ditahan — menahan `| python3 -` mematahkan pipeline sah, dan `bash berkas`
|
|
174
|
+
// telanjang memang diizinkan (skrip workspace dieksekusi setara user
|
|
175
|
+
// menjalankannya; penanaman skrip dijaga permission write). Isolasi penuh
|
|
176
|
+
// tetap tugas sandbox OS/docker, bukan analisis statis.
|
|
177
|
+
|
|
178
|
+
/** Process substitution / here-string yang memasukkan output perintah lain. */
|
|
179
|
+
const PROCESS_SUB = /<\s*\(|>\s*\(|<<<|\bsource\s+<|\.\s+<\(/
|
|
180
|
+
|
|
181
|
+
/** Pipe ke shell/interpreter — bentuk apa pun sumbernya. */
|
|
182
|
+
const PIPE_TO_SHELL =
|
|
183
|
+
/\|\s*(?:sudo\s+)?(?:sh|bash|dash|zsh|ksh|python|python2|python3|pyw?|node|deno|bun|perl|ruby|php|iex|Invoke-Expression)(?:\.exe)?\b/i
|
|
184
|
+
|
|
185
|
+
/** Unduh ke berkas lalu jalankan berkas itu dalam satu baris. */
|
|
186
|
+
const DOWNLOAD_THEN_RUN =
|
|
187
|
+
/\b(?:curl|wget|Invoke-WebRequest|iwr)\b[^\n]*?(?:-o|-O|--output|-OutFile)\s*(\S+)[^\n]*[;&|][^\n]*\b(?:sh|bash|dash|zsh|node|pyw?|python3?|perl|ruby|php|\.\/)(?:\.exe)?\b/i
|
|
188
|
+
|
|
189
|
+
/** Container escape: mount host root / privileged. */
|
|
190
|
+
const CONTAINER_ESCAPE =
|
|
191
|
+
/\b(?:docker|podman|nerdctl)\b[^\n]*(?:--privileged|--pid[= ]host|--net(?:work)?[= ]host|-v\s*\/:|--volume\s*\/:|-v\s*\/etc|--cap-add[= ](?:ALL|SYS_ADMIN))/i
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Target redirect shell (`>`, `>>`, `<`) di luar quote. Heredoc `<<`/`<<-`
|
|
195
|
+
* dilewati (kata berikutnya delimiter, bukan path); target fd (`>&2`, `&-`)
|
|
196
|
+
* dilewati (bukan path). Diekspor untuk test.
|
|
197
|
+
*
|
|
198
|
+
* Kenapa scan RAW quote-aware, bukan bentuk ternormalisasi: stripQuotes
|
|
199
|
+
* membuat `echo "a > b"` (aman — shell tak me-redirect isi quote) terlihat
|
|
200
|
+
* persis seperti `echo a > b` (redirect nyata).
|
|
201
|
+
*/
|
|
202
|
+
export function findRedirectTargets(rawCmd: string): string[] {
|
|
203
|
+
const out: string[] = []
|
|
204
|
+
let sq = false
|
|
205
|
+
let dq = false
|
|
206
|
+
let i = 0
|
|
207
|
+
const n = rawCmd.length
|
|
208
|
+
const isTerm = (c: string): boolean => /[\s;|&<>()]/.test(c)
|
|
209
|
+
while (i < n) {
|
|
210
|
+
const c = rawCmd[i]!
|
|
211
|
+
if (c === "\\" && i + 1 < n) {
|
|
212
|
+
i += 2
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
if (c === "'" && !dq) {
|
|
216
|
+
sq = !sq
|
|
217
|
+
i++
|
|
218
|
+
continue
|
|
219
|
+
}
|
|
220
|
+
if (c === '"' && !sq) {
|
|
221
|
+
dq = !dq
|
|
222
|
+
i++
|
|
223
|
+
continue
|
|
224
|
+
}
|
|
225
|
+
if (sq || dq || (c !== ">" && c !== "<")) {
|
|
226
|
+
i++
|
|
227
|
+
continue
|
|
228
|
+
}
|
|
229
|
+
// Operator: serakah makan [<>|] (>, >>, >|, <>, <). `<<` = heredoc.
|
|
230
|
+
let j = i
|
|
231
|
+
let heredoc = false
|
|
232
|
+
while (j < n && (rawCmd[j] === ">" || rawCmd[j] === "<" || rawCmd[j] === "|")) {
|
|
233
|
+
j++
|
|
234
|
+
if (j - i > 3) break
|
|
235
|
+
}
|
|
236
|
+
const op = rawCmd.slice(i, j)
|
|
237
|
+
if (op.includes("<<")) heredoc = true
|
|
238
|
+
// Lewati spasi, baca satu kata target.
|
|
239
|
+
let k = j
|
|
240
|
+
while (k < n && /\s/.test(rawCmd[k]!)) k++
|
|
241
|
+
if (heredoc || (k < n && rawCmd[k] === "&")) {
|
|
242
|
+
// Delimiter heredoc / target fd (`>&2`, `&-`): bukan path.
|
|
243
|
+
while (k < n && !isTerm(rawCmd[k]!)) k++
|
|
244
|
+
i = k
|
|
245
|
+
continue
|
|
246
|
+
}
|
|
247
|
+
let e = k
|
|
248
|
+
while (e < n && !isTerm(rawCmd[e]!)) e++
|
|
249
|
+
if (e > k) out.push(rawCmd.slice(k, e))
|
|
250
|
+
i = e
|
|
251
|
+
}
|
|
252
|
+
return out
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Null sink lintas-OS — redirect ke sini selalu aman, jangan dihitung. */
|
|
256
|
+
function isNullSink(t: string): boolean {
|
|
257
|
+
return t === "/dev/null" || t.toUpperCase() === "NUL"
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Pencarian rekursif dari root filesystem. */
|
|
261
|
+
const ROOT_SCAN = /\b(?:find|fd|ls|dir|du|tree|grep|rg)\b[^\n]*\s\/(?:\s|$)/i
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* `rm` rekursif dengan target berbahaya.
|
|
265
|
+
*
|
|
266
|
+
* Dipisah dari denylist lama yang menganggap SETIAP `/` berbahaya — itu
|
|
267
|
+
* memblokir `rm -rf node_modules/.cache` yang sah. Yang berbahaya: target root,
|
|
268
|
+
* home, parent traversal, atau wildcard telanjang.
|
|
269
|
+
*
|
|
270
|
+
* Bentuk flag panjang (`--recursive`) ikut dikenali: fuzz menemukan
|
|
271
|
+
* `rm --recursive --force /` lolos karena pola lama hanya mencari `-[a-z]*r`.
|
|
272
|
+
*
|
|
273
|
+
* Traversal dicek di mana pun dalam argumen, bukan hanya di awal kata: target
|
|
274
|
+
* bisa dibungkus command substitution (`rm -rf $(pwd)/../..`) yang tidak bisa
|
|
275
|
+
* kita evaluasi, tapi `..` yang menaik tetap terlihat.
|
|
276
|
+
*
|
|
277
|
+
* Target `//` dan `/.X` ikut berbahaya (audit 2026-09-16 B5): slash ganda
|
|
278
|
+
* collapse ke root di POSIX (`rm -rf //` ≡ `rm -rf /`), dan `/.[!.]*` dengan
|
|
279
|
+
* -r menghapus isi dotfile root.
|
|
280
|
+
*/
|
|
281
|
+
const RM_RECURSIVE = /\brm\b[^\n]*(?:\s-[a-z]*[rR]|\s--recursive\b|\s--dir\b)/i
|
|
282
|
+
const RM_DANGEROUS_TARGET =
|
|
283
|
+
/(?:\s\/(?:\s|$|\*|;|&|\/|\.)|\s~(?:[/\\]\s*)?(?:\s|$|;|&)|\$\{?HOME\}?|\.\.(?:[/\\]|\s|$|;|&)|\s\*\s*(?:$|;|&)|--no-preserve-root)/
|
|
284
|
+
|
|
285
|
+
const STATIC_DENY: [RegExp, string][] = [
|
|
286
|
+
// Fork bomb: definisi fungsi rekursif yang memanggil dirinya lewat pipe.
|
|
287
|
+
// Pola longgar (bukan hanya `:(){ :|:& };:` literal) karena nama fungsi bisa
|
|
288
|
+
// apa saja dan spasi bebas — fuzz menemukan varian yang terpecah oleh
|
|
289
|
+
// substitusi variabel masih lolos bentuk ketat. `\}` opsional karena
|
|
290
|
+
// normalisasi bisa menghilangkan bagian setelah pipe.
|
|
291
|
+
[/(?:^|[;&|=\n]\s*)[\w:]+\s*\(\)\s*\{[^}]*\|[^}]*&/, "fork bomb"],
|
|
292
|
+
[/\bmkfs\b/i, "format filesystem"],
|
|
293
|
+
[/\bdd\s+if=/i, "raw disk write"],
|
|
294
|
+
[/\bchmod\s+(-R\s+)?777\b/i, "permission 777"],
|
|
295
|
+
[/\bshred\b/i, "secure delete"],
|
|
296
|
+
[/\btruncate\b/i, "truncate file"],
|
|
297
|
+
[/\bmv\s+[^;|]*\s+\/(?:etc|boot|usr|lib)\b/i, "overwrite system dir"],
|
|
298
|
+
[/\bsudo\b[^\n]*\brm\b/i, "sudo rm"],
|
|
299
|
+
// `pwsh`/`pwsh.exe` = nama biner PowerShell modern lintas-OS (audit
|
|
300
|
+
// 2026-09-16: varian encoded lolos karena aturan hanya kenal `powershell`).
|
|
301
|
+
[/\b(?:powershell|pwsh)\b[^\n]*-EncodedCommand/i, "encoded powershell"],
|
|
302
|
+
// Bentuk pendek -enc/-enco/... + blob base64 panjang. Aturan penuh di atas
|
|
303
|
+
// tak menangkap prefix; pola ini mensyaratkan blob (60+ byte, hitung padding
|
|
304
|
+
// `==`) sehingga -Encoding milik cmdlet dalam (-Command "... -Encoding
|
|
305
|
+
// utf8 ...") lolos: -enc* + blob panjang praktis hanya payload terenkode.
|
|
306
|
+
// -Command arbitrer tetap residual jujur (butuh sandbox OS/docker).
|
|
307
|
+
[
|
|
308
|
+
/\b(?:powershell|pwsh)(\.exe)?\b[^\n]*\s-e\w*\s+[A-Za-z0-9+/]{60,}={0,2}/i,
|
|
309
|
+
"encoded powershell payload",
|
|
310
|
+
],
|
|
311
|
+
[/>\s*\/dev\/(?:sda|nvme|hd[a-z])/i, "raw device write"],
|
|
312
|
+
[/\b(?:del|erase)\b[^\n]*\/[sfaq]/i, "windows recursive delete"],
|
|
313
|
+
[/\brmdir\b[^\n]*\/s/i, "windows recursive rmdir"],
|
|
314
|
+
[/\bRemove-Item\b[^\n]*-Recurse/i, "powershell recursive delete"],
|
|
315
|
+
[/\[System\.IO\.File\]::ReadAllText/i, "powershell file read"],
|
|
316
|
+
[/\b(?:Invoke-Expression|iex)\b/i, "powershell dynamic eval"],
|
|
317
|
+
[/\bawk\b[^\n]*\bsystem\s*\(/i, "awk system()"],
|
|
318
|
+
// git sebagai pelarian jail: `git diff --no-index A B` mencetak isi path
|
|
319
|
+
// filesystem ARBITRER (di luar workspace, abaikan file-jail — terkonfirmasi
|
|
320
|
+
// via inspectBashCommand, bukan teori); --exec-path/--upload-pack/
|
|
321
|
+
// --receive-pack/ext:: mengeksekusi helper eksternal. Bentuk global
|
|
322
|
+
// `git -c k=v <sub>` sebelum subcommand sudah gugur di allowlist (tak cocok
|
|
323
|
+
// pola ^git <sub>), tapi mode auto hanya dijaga guard ini. Alur sah agen
|
|
324
|
+
// (status/diff/log/branch/show dalam repo) tak memakai flag ini.
|
|
325
|
+
[/\bgit\b[^\n]*?--(?:no-index|exec-path|upload-pack|receive-pack)\b/, "git dangerous flag"],
|
|
326
|
+
[/\bext::/, "git ext transport"],
|
|
327
|
+
// Injeksi konfigurasi git via environment (`GIT_EXTERNAL_DIFF=x git diff`
|
|
328
|
+
// setara diff.external repo — repo-side adalah residual terdokumentasi, tapi
|
|
329
|
+
// env datang dari perintah model sendiri sehingga ditahan di sini).
|
|
330
|
+
[
|
|
331
|
+
/\bGIT_(?:EXTERNAL_DIFF|CONFIG_COUNT|CONFIG_KEY_\d+|CONFIG_VALUE_\d+)\s*=/,
|
|
332
|
+
"git config injection via env",
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
/(?:^|[;&|\n]\s*)(?:base64|xxd)[^\n]*\|\s*(?:sh|bash|python|python3|node|perl)\b/i,
|
|
336
|
+
"decode|shell",
|
|
337
|
+
],
|
|
338
|
+
// F-20: upload berkas via PowerShell — UPLOAD_FLAG hanya kenal
|
|
339
|
+
// curl/wget/nc. Bentuk eksfiltrasi: Invoke-WebRequest -Method POST -Body
|
|
340
|
+
// (Get-Content rahasia) atau -InFile <berkas>. Download polos (-OutFile)
|
|
341
|
+
// TETAP lolos (seperti curl tanpa -d @file): bukan upload.
|
|
342
|
+
[/\b(?:Invoke-WebRequest|iwr)\b[^\n]*?(?:-InFile\b|Get-Content)/i, "file upload to network"],
|
|
343
|
+
]
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Evaluasi satu perintah bash. Return alasan bila ditolak.
|
|
347
|
+
*
|
|
348
|
+
* Pemeriksaan dilakukan pada bentuk ternormalisasi DAN mentah: normalisasi
|
|
349
|
+
* menutup bypass, sementara bentuk mentah menangkap pola yang justru hilang
|
|
350
|
+
* saat quote dibuang (mis. `--upload-file "x"`).
|
|
351
|
+
*/
|
|
352
|
+
export function inspectBashCommand(rawCmd: string, cwd?: string): BashVerdict {
|
|
353
|
+
const raw = rawCmd
|
|
354
|
+
const norm = normalizeCommand(rawCmd)
|
|
355
|
+
const both = (re: RegExp): boolean => re.test(norm) || re.test(raw)
|
|
356
|
+
|
|
357
|
+
for (const [re, reason] of STATIC_DENY) {
|
|
358
|
+
if (both(re)) return { denied: true, reason }
|
|
359
|
+
}
|
|
360
|
+
if (both(RM_RECURSIVE) && both(RM_DANGEROUS_TARGET)) {
|
|
361
|
+
return { denied: true, reason: "destructive rm" }
|
|
362
|
+
}
|
|
363
|
+
if (both(PROCESS_SUB)) return { denied: true, reason: "process substitution" }
|
|
364
|
+
if (both(PIPE_TO_SHELL)) return { denied: true, reason: "pipe to interpreter" }
|
|
365
|
+
if (both(DOWNLOAD_THEN_RUN)) return { denied: true, reason: "download then execute" }
|
|
366
|
+
if (both(INLINE_INTERPRETER)) return { denied: true, reason: "inline interpreter code" }
|
|
367
|
+
if (both(CONTAINER_ESCAPE)) return { denied: true, reason: "container escape" }
|
|
368
|
+
if (both(ENV_DUMP)) return { denied: true, reason: "environment dump" }
|
|
369
|
+
if (both(ENV_SECRET_REF)) return { denied: true, reason: "credential env reference" }
|
|
370
|
+
if (both(UPLOAD_FLAG)) return { denied: true, reason: "file upload to network" }
|
|
371
|
+
// Hive Windows: `reg save HKLM\SAM` / `reg export ...\config\system` —
|
|
372
|
+
// `reg query` diagnostik tetap lolos (tanpa kata kerja destruktif).
|
|
373
|
+
if (both(REG_HIVE_EXPORT) && (HIVE_PATH.test(norm) || HIVE_PATH.test(raw)))
|
|
374
|
+
return { denied: true, reason: "registry hive export" }
|
|
375
|
+
if (both(VSS_SHADOW)) return { denied: true, reason: "shadow copy credential access" }
|
|
376
|
+
if (both(NTDSUTIL)) return { denied: true, reason: "directory services tool" }
|
|
377
|
+
if (both(ROOT_SCAN)) return { denied: true, reason: "filesystem-root scan" }
|
|
378
|
+
|
|
379
|
+
// Redirect keluar workspace (temuan audit eksternal: `echo x > ..\evil`
|
|
380
|
+
// lolos karena allowlist hanya menolak chaining `[;&|]` dan guard tak
|
|
381
|
+
// punya aturan redirect). Target di-resolve terhadap cwd pemanggil agar
|
|
382
|
+
// presisi (`> local.txt` dan `> /dev/null` tetap jalan); tanpa cwd,
|
|
383
|
+
// heuristik konservatif (`..`/absolut/sensitif) berlaku.
|
|
384
|
+
for (const t of findRedirectTargets(raw)) {
|
|
385
|
+
if (isNullSink(t)) continue
|
|
386
|
+
// Ekspansi %VAR% terjadi di cmd.exe SETELAH cek statis: `> "%TEMP%\x"`
|
|
387
|
+
// terlihat di dalam cwd secara literal lalu menulis ke luar. Target dengan
|
|
388
|
+
// pola %NAMA% tak bisa dipastikan aman → tolak; tulis ulang tanpa env var
|
|
389
|
+
// atau pakai path relatif. `%` tunggal (mis. `100%.txt`) tetap lolos
|
|
390
|
+
// karena bukan pola ekspansi.
|
|
391
|
+
if (/%[^%\s]+%/.test(t))
|
|
392
|
+
return { denied: true, reason: "redirect target with env expansion (%VAR%)" }
|
|
393
|
+
if (cwd != null) {
|
|
394
|
+
const abs = isAbsolute(t) ? resolve(t) : resolve(cwd, t)
|
|
395
|
+
// Owned-state (.minicode/config dkk) simetris dengan jail file tools:
|
|
396
|
+
// tulis lewat shell tak boleh lebih longgar dari write_file.
|
|
397
|
+
if (
|
|
398
|
+
isRealPathOutsideRoot(abs, cwd) ||
|
|
399
|
+
isSensitive(t) ||
|
|
400
|
+
isSensitive(abs) ||
|
|
401
|
+
isOwnedState(t) ||
|
|
402
|
+
isOwnedState(abs)
|
|
403
|
+
)
|
|
404
|
+
return { denied: true, reason: "redirect outside workspace" }
|
|
405
|
+
} else if (
|
|
406
|
+
/(^|[\\/])\.\.(?:[\\/]|$)|\b[a-zA-Z]:[\\/]|^\/(?!dev\/null$)|^~(?:[\\/]|$)/.test(t) ||
|
|
407
|
+
isSensitive(t) ||
|
|
408
|
+
isOwnedState(t)
|
|
409
|
+
) {
|
|
410
|
+
return { denied: true, reason: "redirect outside workspace" }
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Berkas sensitif: berbahaya bila dibaca/disalin ATAU dijadikan argumen
|
|
415
|
+
// perintah jaringan. Menyebut `.env` dalam `echo` saja tidak diblokir.
|
|
416
|
+
const touchesSensitive = both(SENSITIVE_TARGET) || both(SENSITIVE_DIR)
|
|
417
|
+
if (touchesSensitive && (both(READERS) || /\b(?:curl|wget|nc|ncat|socat|scp)\b/i.test(norm))) {
|
|
418
|
+
return { denied: true, reason: "sensitive file access" }
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// P0-2: READER tanpa filter path (cat * / type *) = bisa baca file sensitif
|
|
422
|
+
// atau di luar workspace walau cocok allowlist. Ekstrak argumen path untuk
|
|
423
|
+
// READER dan cek jail/sensitive. Wildcard `*` ditolak bila cwd tersedia
|
|
424
|
+
// (bisa mengembang ke .env / .minicode).
|
|
425
|
+
if (both(READERS)) {
|
|
426
|
+
const readerTargets = (() => {
|
|
427
|
+
const out: string[] = []
|
|
428
|
+
const re =
|
|
429
|
+
/\b(?:cat|bat|less|more|head|tail|nl|od|xxd|strings|type|Get-Content|certutil|tac|findstr|fc|comp|cp|copy|mv|move|scp|rsync|tar|zip|gzip|base64|openssl|awk|sed|grep|egrep|fgrep|rg|cut|sort|uniq|tee|dd|install)\b\s+([^\n;&|]+)/gi
|
|
430
|
+
for (const m of norm.matchAll(re)) {
|
|
431
|
+
const args = m[1]!.split(/\s+/)
|
|
432
|
+
for (const a of args) {
|
|
433
|
+
if (!a) continue
|
|
434
|
+
if (a.startsWith("-")) continue
|
|
435
|
+
const t = a.trim()
|
|
436
|
+
if (!t) continue
|
|
437
|
+
out.push(t)
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return out
|
|
441
|
+
})()
|
|
442
|
+
for (const t of readerTargets) {
|
|
443
|
+
if (t.includes("*")) {
|
|
444
|
+
// Wildcard di READER bisa mengembang ke .env/.minicode — tolak bila
|
|
445
|
+
// cwd tersedia (butuh path eksplisit). Tanpa cwd, heuristik sensitif.
|
|
446
|
+
if (cwd != null) return { denied: true, reason: "reader wildcard" }
|
|
447
|
+
if (isSensitive(t) || isOwnedState(t)) return { denied: true, reason: "reader wildcard" }
|
|
448
|
+
}
|
|
449
|
+
if (isSensitive(t) || isSensitive(resolve(cwd ?? ".", t))) {
|
|
450
|
+
return { denied: true, reason: "sensitive file access" }
|
|
451
|
+
}
|
|
452
|
+
if (isOwnedState(t) || isOwnedState(resolve(cwd ?? ".", t))) {
|
|
453
|
+
return { denied: true, reason: "owned state access" }
|
|
454
|
+
}
|
|
455
|
+
if (cwd != null) {
|
|
456
|
+
const abs = isAbsolute(t) ? resolve(t) : resolve(cwd, t)
|
|
457
|
+
if (isRealPathOutsideRoot(abs, cwd)) return { denied: true, reason: "outside workspace" }
|
|
458
|
+
} else if (/^\.\.(?:[\\/]|$)|\b[a-zA-Z]:[\\/]|^\/(?!dev\/null$)|^~(?:[\\/]|$)/.test(t)) {
|
|
459
|
+
return { denied: true, reason: "outside workspace" }
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
return { denied: false }
|
|
465
|
+
}
|