@glassbox-ai/engine 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +33 -2
- package/dist/action/acc.d.ts +48 -0
- package/dist/action/acc.js +117 -0
- package/dist/action/builtin-tools.d.ts +5 -0
- package/dist/action/builtin-tools.js +74 -0
- package/dist/action/inline.d.ts +14 -0
- package/dist/action/inline.js +54 -0
- package/dist/action/paths.d.ts +71 -0
- package/dist/action/paths.js +398 -0
- package/dist/action/powershell.d.ts +9 -0
- package/dist/action/powershell.js +848 -0
- package/dist/action/protected-write.d.ts +11 -0
- package/dist/action/protected-write.js +113 -0
- package/dist/action/schedule.d.ts +43 -0
- package/dist/action/schedule.js +213 -0
- package/dist/action/shell/analyze.d.ts +28 -0
- package/dist/action/shell/analyze.js +2057 -0
- package/dist/action/shell/parse.d.ts +74 -0
- package/dist/action/shell/parse.js +1037 -0
- package/dist/action/shell/view.d.ts +6 -0
- package/dist/action/shell/view.js +89 -0
- package/dist/action/sql.d.ts +3 -0
- package/dist/action/sql.js +259 -0
- package/dist/action/tools.d.ts +20 -0
- package/dist/action/tools.js +305 -0
- package/dist/action/upload.d.ts +17 -0
- package/dist/action/upload.js +72 -0
- package/dist/analysis/fields.d.ts +14 -0
- package/dist/analysis/fields.js +136 -0
- package/dist/analysis/findings.d.ts +25 -0
- package/dist/analysis/findings.js +82 -0
- package/dist/analysis/gate.d.ts +16 -0
- package/dist/analysis/gate.js +662 -0
- package/dist/analysis/manifest.d.ts +3 -0
- package/dist/analysis/manifest.js +369 -0
- package/dist/analysis/match.d.ts +54 -0
- package/dist/analysis/match.js +352 -0
- package/dist/analysis/scan.d.ts +17 -0
- package/dist/analysis/scan.js +97 -0
- package/dist/canon/confusables.generated.d.ts +3 -0
- package/dist/canon/confusables.generated.js +6 -0
- package/dist/canon/decode.d.ts +11 -0
- package/dist/canon/decode.js +147 -0
- package/dist/canon/views.d.ts +36 -0
- package/dist/canon/views.js +283 -0
- package/dist/evidence/evidence.d.ts +12 -0
- package/dist/evidence/evidence.js +149 -0
- package/dist/fingerprint/diff.d.ts +3 -0
- package/dist/fingerprint/diff.js +273 -0
- package/dist/fingerprint/fingerprint.d.ts +4 -0
- package/dist/fingerprint/fingerprint.js +77 -0
- package/dist/grade/score.d.ts +19 -0
- package/dist/grade/score.js +89 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +152 -0
- package/dist/intake/json.d.ts +17 -0
- package/dist/intake/json.js +284 -0
- package/dist/intake/snapshot.d.ts +14 -0
- package/dist/intake/snapshot.js +130 -0
- package/dist/limits.d.ts +4 -0
- package/dist/limits.js +30 -0
- package/dist/policy/decide.d.ts +32 -0
- package/dist/policy/decide.js +105 -0
- package/dist/rules/ids.d.ts +2 -0
- package/dist/rules/ids.js +99 -0
- package/dist/ruleset/baseline-tests.generated.d.ts +6 -0
- package/dist/ruleset/baseline-tests.generated.js +2935 -0
- package/dist/ruleset/baseline.d.ts +3 -0
- package/dist/ruleset/baseline.generated.d.ts +3 -0
- package/dist/ruleset/baseline.generated.js +5 -0
- package/dist/ruleset/baseline.js +44 -0
- package/dist/ruleset/fakes.d.ts +3 -0
- package/dist/ruleset/fakes.js +26 -0
- package/dist/ruleset/load.d.ts +13 -0
- package/dist/ruleset/load.js +187 -0
- package/dist/ruleset/schema.d.ts +120 -0
- package/dist/ruleset/schema.js +54 -0
- package/dist/ruleset/selftest.d.ts +18 -0
- package/dist/ruleset/selftest.js +42 -0
- package/dist/ruleset-entry.d.ts +5 -0
- package/dist/ruleset-entry.js +7 -0
- package/dist/secrets/detect.d.ts +17 -0
- package/dist/secrets/detect.js +236 -0
- package/dist/secrets/redact.d.ts +19 -0
- package/dist/secrets/redact.js +116 -0
- package/dist/types.d.ts +455 -0
- package/dist/types.js +10 -0
- package/dist/util/hash.d.ts +4 -0
- package/dist/util/hash.js +16 -0
- package/dist/util/initclock.d.ts +3 -0
- package/dist/util/initclock.js +17 -0
- package/dist/util/jcs.d.ts +4 -0
- package/dist/util/jcs.js +91 -0
- package/dist/util/misc.d.ts +17 -0
- package/dist/util/misc.js +77 -0
- package/dist/util/re.d.ts +14 -0
- package/dist/util/re.js +47 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +57 -4
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// Path normalization and the protected / protected-read / sensitive sets.
|
|
2
|
+
// Purely lexical: the engine can't see the filesystem.
|
|
3
|
+
import { trimEndChars } from "../util/misc.js";
|
|
4
|
+
import { JOB_LABEL } from "./schedule.js";
|
|
5
|
+
export function fold(s, ci) {
|
|
6
|
+
return ci ? s.toLowerCase() : s;
|
|
7
|
+
}
|
|
8
|
+
export function normalizeSlashes(p, win) {
|
|
9
|
+
let s = p;
|
|
10
|
+
if (win) {
|
|
11
|
+
s = s.replace(/\\/g, "/");
|
|
12
|
+
if (s.startsWith("//?/") || s.startsWith("//./"))
|
|
13
|
+
s = s.slice(4);
|
|
14
|
+
const m = /^\/\/(localhost|127\.0\.0\.1)\/([a-zA-Z])\$\//i.exec(s.slice(0, 40));
|
|
15
|
+
if (m)
|
|
16
|
+
s = `${m[2]}:/` + s.slice(m[0].length);
|
|
17
|
+
}
|
|
18
|
+
return s;
|
|
19
|
+
}
|
|
20
|
+
/** Collapse //, ., .. (lexically, never above root); strip Windows segment tricks. */
|
|
21
|
+
function collapse(p, win) {
|
|
22
|
+
let root = "";
|
|
23
|
+
let rest = p;
|
|
24
|
+
const drive = /^([a-zA-Z]):(\/|$)/.exec(p.slice(0, 3));
|
|
25
|
+
if (win && drive) {
|
|
26
|
+
root = drive[1].toLowerCase() + ":/";
|
|
27
|
+
rest = p.slice(drive[0].length);
|
|
28
|
+
}
|
|
29
|
+
else if (p.startsWith("/")) {
|
|
30
|
+
root = "/";
|
|
31
|
+
rest = p.slice(1);
|
|
32
|
+
}
|
|
33
|
+
const out = [];
|
|
34
|
+
const segs = rest.split("/");
|
|
35
|
+
segs.forEach((seg0, idx) => {
|
|
36
|
+
let seg = seg0;
|
|
37
|
+
if (win) {
|
|
38
|
+
if (idx === segs.length - 1)
|
|
39
|
+
seg = seg.replace(/::\$DATA$/i, "").replace(/:[^:/]*$/, "");
|
|
40
|
+
seg = seg === "." || seg === ".." ? seg : trimEndChars(seg, ". ");
|
|
41
|
+
}
|
|
42
|
+
if (seg === "" || seg === ".")
|
|
43
|
+
return;
|
|
44
|
+
if (seg === "..") {
|
|
45
|
+
out.pop();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
out.push(seg);
|
|
49
|
+
});
|
|
50
|
+
return root + out.join("/");
|
|
51
|
+
}
|
|
52
|
+
function expandHome(p, home) {
|
|
53
|
+
const h = trimEndChars(home, "\\/");
|
|
54
|
+
for (const pre of ["$HOME", "${HOME}", "%USERPROFILE%", "$env:USERPROFILE", "${env:USERPROFILE}", "%HOMEDRIVE%%HOMEPATH%"]) {
|
|
55
|
+
if (p === pre || p.startsWith(pre + "/") || p.startsWith(pre + "\\"))
|
|
56
|
+
return { s: h + p.slice(pre.length), unknownUser: false };
|
|
57
|
+
if (p.toLowerCase().startsWith(pre.toLowerCase()) && pre.startsWith("$env:")) {
|
|
58
|
+
const tail = p.slice(pre.length);
|
|
59
|
+
if (tail === "" || tail.startsWith("/") || tail.startsWith("\\"))
|
|
60
|
+
return { s: h + tail, unknownUser: false };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (p === "~" || p.startsWith("~/") || p.startsWith("~\\"))
|
|
64
|
+
return { s: h + p.slice(1), unknownUser: false };
|
|
65
|
+
if (p.startsWith("~"))
|
|
66
|
+
return { s: p, unknownUser: true };
|
|
67
|
+
return { s: p, unknownUser: false };
|
|
68
|
+
}
|
|
69
|
+
function isAbsolute(p, win) {
|
|
70
|
+
return p.startsWith("/") || (win && /^[a-zA-Z]:\//.test(p.slice(0, 3)));
|
|
71
|
+
}
|
|
72
|
+
export function normalizeFull(raw, ctx) {
|
|
73
|
+
const win = ctx.platform === "win32";
|
|
74
|
+
const { s: expanded, unknownUser } = expandHome(raw, ctx.homeDir);
|
|
75
|
+
if (unknownUser)
|
|
76
|
+
return null;
|
|
77
|
+
let s = normalizeSlashes(expanded, win);
|
|
78
|
+
if (!isAbsolute(s, win)) {
|
|
79
|
+
if (ctx.cwd === null)
|
|
80
|
+
return null;
|
|
81
|
+
s = trimEndChars(normalizeSlashes(ctx.cwd, win), "/") + "/" + s;
|
|
82
|
+
}
|
|
83
|
+
s = collapse(s, win);
|
|
84
|
+
s = s.normalize("NFC");
|
|
85
|
+
return fold(s, ctx.caseInsensitive);
|
|
86
|
+
}
|
|
87
|
+
export function normalizePath(raw, ctx) {
|
|
88
|
+
const win = ctx.platform === "win32";
|
|
89
|
+
const slashed = normalizeSlashes(raw, win);
|
|
90
|
+
const base = slashed.split("/").filter(Boolean).pop() ?? "";
|
|
91
|
+
const path = normalizeFull(raw, ctx);
|
|
92
|
+
const relativeUnknown = path === null && !raw.startsWith("~") && !isAbsolute(normalizeSlashes(expandHome(raw, ctx.homeDir).s, win), win);
|
|
93
|
+
let suffix = null;
|
|
94
|
+
if (path === null)
|
|
95
|
+
suffix = fold("/" + collapse(slashed.replace(/^~[^/]*\/?/, ""), win).replace(/^\/+/, ""), ctx.caseInsensitive);
|
|
96
|
+
return { path, suffix, relativeUnknown, basename: fold(trimEndChars(base, ". "), ctx.caseInsensitive) };
|
|
97
|
+
}
|
|
98
|
+
/** A path known only by its literal tail (e.g. "$(…)/.claude/settings.json"). */
|
|
99
|
+
export function suffixOnly(tail, ctx) {
|
|
100
|
+
const win = ctx.platform === "win32";
|
|
101
|
+
const t = collapse(normalizeSlashes(tail, win), win);
|
|
102
|
+
const suffix = fold(t.startsWith("/") ? t : "/" + t, ctx.caseInsensitive);
|
|
103
|
+
return { path: null, suffix, relativeUnknown: false, basename: suffix.split("/").pop() ?? "" };
|
|
104
|
+
}
|
|
105
|
+
export const ANYWHERE = ["/.claude/settings.json", "/.claude/settings.local.json", "/.mcp.json"];
|
|
106
|
+
const MANAGED = ["/etc/claude-code", "/library/application support/claudecode", "c:/program files/claudecode", "c:/programdata/claudecode"];
|
|
107
|
+
const PROTECTED_BASENAMES = ["settings.json", "settings.local.json", ".mcp.json", ".claude.json"];
|
|
108
|
+
export function entries(ctx) {
|
|
109
|
+
const n = (p) => normalizeFull(p, { ...ctx, cwd: "/" });
|
|
110
|
+
const out = [];
|
|
111
|
+
const add = (p, dir) => { if (p)
|
|
112
|
+
out.push({ p, dir }); };
|
|
113
|
+
for (const d of ctx.glassboxDirs)
|
|
114
|
+
add(n(d), true);
|
|
115
|
+
const configDirs = [ctx.claudeConfigDir, `${ctx.homeDir}/.claude`].filter((x) => typeof x === "string" && x.length > 0);
|
|
116
|
+
for (const c of configDirs) {
|
|
117
|
+
add(n(`${c}/settings.json`), false);
|
|
118
|
+
add(n(`${c}/settings.local.json`), false);
|
|
119
|
+
add(n(`${c}/hooks`), true);
|
|
120
|
+
add(n(`${c}/plugins`), true);
|
|
121
|
+
}
|
|
122
|
+
add(n(`${ctx.homeDir}/.claude.json`), false);
|
|
123
|
+
for (const x of ctx.extraProtected) {
|
|
124
|
+
const dir = x.endsWith("/**") || x.endsWith("\\**");
|
|
125
|
+
add(n(dir ? x.slice(0, -3) : x), dir);
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
export function readProtectedEntries(ctx) {
|
|
130
|
+
const n = (p) => normalizeFull(p, { ...ctx, cwd: "/" });
|
|
131
|
+
const out = [];
|
|
132
|
+
for (const d of ctx.glassboxDirs) {
|
|
133
|
+
const p = n(d);
|
|
134
|
+
if (p)
|
|
135
|
+
out.push({ p: p + "/*.key", dir: false });
|
|
136
|
+
}
|
|
137
|
+
const gb = n(`${ctx.homeDir}/.glassbox`);
|
|
138
|
+
if (gb)
|
|
139
|
+
out.push({ p: gb + "/*.key", dir: false });
|
|
140
|
+
for (const s of ctx.secretPaths) {
|
|
141
|
+
const p = n(s);
|
|
142
|
+
if (p)
|
|
143
|
+
out.push({ p, dir: false });
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
function under(path, e) {
|
|
148
|
+
if (e.p.endsWith("/*.key")) {
|
|
149
|
+
const dir = e.p.slice(0, -6);
|
|
150
|
+
return path.startsWith(dir + "/") && path.endsWith(".key");
|
|
151
|
+
}
|
|
152
|
+
return path === e.p || (e.dir && path.startsWith(e.p.endsWith("/") ? e.p : e.p + "/"));
|
|
153
|
+
}
|
|
154
|
+
/** 8.3 short-name segments (e.g. CLAUDE~1) that could stand for a protected segment. */
|
|
155
|
+
function shortNameMatch(path, ents) {
|
|
156
|
+
const segs = path.split("/");
|
|
157
|
+
const k = segs.findIndex((s) => /~\d/.test(s));
|
|
158
|
+
if (k < 0)
|
|
159
|
+
return false;
|
|
160
|
+
const short = segs[k].toLowerCase().split("~")[0] ?? "";
|
|
161
|
+
for (const e of ents) {
|
|
162
|
+
const es = e.p.split("/");
|
|
163
|
+
if (es.length <= k)
|
|
164
|
+
continue;
|
|
165
|
+
if (segs.slice(0, k).join("/").toLowerCase() !== es.slice(0, k).join("/").toLowerCase())
|
|
166
|
+
continue;
|
|
167
|
+
const target = es[k].toLowerCase().replace(/^\.+/, "").replace(/[^a-z0-9]/g, "").slice(0, 6);
|
|
168
|
+
if (short.length > 0 && target.startsWith(short.slice(0, 6)))
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
export function isProtected(np, ctx) {
|
|
174
|
+
const ents = entries(ctx);
|
|
175
|
+
const win = ctx.platform === "win32";
|
|
176
|
+
// Managed-settings directories are matched case-insensitively on every platform.
|
|
177
|
+
const managed = (p) => { const l = p.toLowerCase(); return MANAGED.some((m) => l === m || l.startsWith(m + "/")); };
|
|
178
|
+
const check = (p) => ents.some((e) => under(p, e)) || managed(p) || ANYWHERE.some((a) => p.endsWith(fold(a, ctx.caseInsensitive))) || (win && shortNameMatch(p, ents));
|
|
179
|
+
if (np.path !== null) {
|
|
180
|
+
if (check(np.path))
|
|
181
|
+
return true;
|
|
182
|
+
const r = ctx.resolved?.[np.path];
|
|
183
|
+
if (r) {
|
|
184
|
+
const rp = normalizeFull(r, ctx);
|
|
185
|
+
if (rp && check(rp))
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (np.suffix !== null) {
|
|
191
|
+
const suf = np.suffix;
|
|
192
|
+
if (ANYWHERE.some((a) => suf.endsWith(fold(a, ctx.caseInsensitive))))
|
|
193
|
+
return true;
|
|
194
|
+
if (ents.some((e) => suf.endsWith(e.p.slice(e.p.lastIndexOf("/"))) && !e.dir))
|
|
195
|
+
return true;
|
|
196
|
+
if (suf.includes("/.glassbox/") || suf.endsWith("/.glassbox") || suf.includes("/.claude/hooks") || suf.includes("/.claude/plugins"))
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (np.relativeUnknown) {
|
|
200
|
+
const gbNames = ctx.glassboxDirs.map((d) => fold(d.split(/[\\/]/).filter(Boolean).pop() ?? "", ctx.caseInsensitive));
|
|
201
|
+
if (PROTECTED_BASENAMES.includes(np.basename) || gbNames.includes(np.basename))
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
export function isProtectedRead(np, ctx) {
|
|
207
|
+
const ents = readProtectedEntries(ctx);
|
|
208
|
+
if (np.path !== null) {
|
|
209
|
+
if (ents.some((e) => under(np.path, e)))
|
|
210
|
+
return true;
|
|
211
|
+
const r = ctx.resolved?.[np.path];
|
|
212
|
+
if (r) {
|
|
213
|
+
const rp = normalizeFull(r, ctx);
|
|
214
|
+
if (rp && ents.some((e) => under(rp, e)))
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
if (np.suffix !== null)
|
|
220
|
+
return np.suffix.endsWith("/device.key") || (np.suffix.includes("/.glassbox/") && np.suffix.endsWith(".key"));
|
|
221
|
+
return np.relativeUnknown && np.basename === "device.key";
|
|
222
|
+
}
|
|
223
|
+
/** A directory-wide read rooted at `np` covers a protected-read path. */
|
|
224
|
+
export function coversProtectedRead(np, ctx) {
|
|
225
|
+
if (isProtectedRead(np, ctx))
|
|
226
|
+
return true;
|
|
227
|
+
if (np.path === null)
|
|
228
|
+
return np.suffix !== null && (np.suffix.endsWith("/.glassbox") || np.suffix.includes("/.glassbox/"));
|
|
229
|
+
const root = trimEndChars(np.path, "/");
|
|
230
|
+
const ents = readProtectedEntries(ctx);
|
|
231
|
+
return ents.some((e) => {
|
|
232
|
+
const target = e.p.endsWith("/*.key") ? e.p.slice(0, -6) : e.p;
|
|
233
|
+
return target === root || target.startsWith(root === "" ? "/" : root + "/") || root === "/";
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/** A glob pattern (e.g. Glob tool) that could match a protected-read path. */
|
|
237
|
+
export function globCoversProtectedRead(pattern, base, ctx) {
|
|
238
|
+
const full = base ? `${trimEndChars(base, "\\/")}/${pattern}` : pattern;
|
|
239
|
+
const literalPrefix = full.split(/[*?[{]/)[0] ?? "";
|
|
240
|
+
const np = normalizePath(literalPrefix.length > 0 ? literalPrefix : ".", ctx);
|
|
241
|
+
if (coversProtectedRead(np, ctx))
|
|
242
|
+
return true;
|
|
243
|
+
const lower = full.toLowerCase();
|
|
244
|
+
return lower.includes(".glassbox") || (lower.includes("*.key") && np.path !== null && coversProtectedRead(np, ctx));
|
|
245
|
+
}
|
|
246
|
+
// ── Sensitive (reads) ────────────────────────────────────────────────────
|
|
247
|
+
const HOME_DIRS = [
|
|
248
|
+
[".ssh", "ssh-keys"], [".aws", "cloud-credentials"], [".config/gcloud", "cloud-credentials"], [".azure", "cloud-credentials"],
|
|
249
|
+
[".gnupg", "gpg-keys"], [".config/google-chrome", "browser-profile"], [".mozilla/firefox", "browser-profile"],
|
|
250
|
+
["library/application support/google/chrome", "browser-profile"], ["appdata/local/google/chrome/user data", "browser-profile"],
|
|
251
|
+
["appdata/roaming/microsoft/credentials", "os-credentials"], ["appdata/local/microsoft/credentials", "os-credentials"],
|
|
252
|
+
];
|
|
253
|
+
const HOME_FILES = [
|
|
254
|
+
[".kube/config", "cloud-credentials"], [".docker/config.json", "registry-credentials"], [".netrc", "credentials"], [".npmrc", "registry-credentials"],
|
|
255
|
+
[".pypirc", "registry-credentials"], [".git-credentials", "credentials"], [".config/gh/hosts.yml", "credentials"],
|
|
256
|
+
];
|
|
257
|
+
// Persistence locations (spec rev 6, Q3; rev 7; rev 9): files that make code run later (login,
|
|
258
|
+
// boot, a schedule, every shell or git command) or grant remote access.
|
|
259
|
+
// - "deny": remote access (SSH) and library preloading (CP-SELF-004, protected, every mode).
|
|
260
|
+
// - "job": scheduled jobs, services, boot scripts and autostart (CP-SELF-006): ask, deny in
|
|
261
|
+
// autopilot; the ask shows the schedule and the command (rev 9).
|
|
262
|
+
// - "ask": shell and PowerShell startup files and global git config (CP-SELF-005).
|
|
263
|
+
const DENY_HOME_FILES = [".ssh/rc", ".ssh/authorized_keys", ".ssh/authorized_keys2", ".ssh/config"];
|
|
264
|
+
const DENY_SYSTEM = ["/etc/ld.so.preload"];
|
|
265
|
+
const ASK_HOME_FILES = [
|
|
266
|
+
".bashrc", ".shrc", ".bash_profile", ".bash_login", ".bash_logout", ".profile", ".zshrc", ".zprofile", ".zshenv", ".zlogin", ".zlogout",
|
|
267
|
+
".kshrc", ".cshrc", ".tcshrc", ".xprofile", ".xinitrc", ".xsessionrc", ".config/fish/config.fish", ".gitconfig", ".config/git/config",
|
|
268
|
+
];
|
|
269
|
+
const ASK_HOME_DIRS = [".config/fish/conf.d", ".config/git/hooks", ".config/powershell", "documents/windowspowershell", "documents/powershell"];
|
|
270
|
+
const ASK_SYSTEM = ["/etc/profile", "/etc/bash.bashrc", "/etc/zshrc", "/etc/zsh/"];
|
|
271
|
+
const JOB_HOME_DIRS = [
|
|
272
|
+
[".config/systemd/user", "systemd"], [".config/autostart", "autostart"], ["library/launchagents", "launchd"],
|
|
273
|
+
["appdata/roaming/microsoft/windows/start menu/programs/startup", "startup-folder"],
|
|
274
|
+
];
|
|
275
|
+
const JOB_SYSTEM = [
|
|
276
|
+
["/etc/cron", "cron"], ["/var/spool/cron/", "cron"], ["/etc/systemd/system/", "systemd"], ["/lib/systemd/system/", "systemd"],
|
|
277
|
+
["/usr/lib/systemd/system/", "systemd"], ["/library/launchagents/", "launchd"], ["/library/launchdaemons/", "launchd"],
|
|
278
|
+
["/etc/rc.local", "boot-script"], ["/etc/init.d/", "boot-script"], ["/etc/xdg/autostart/", "autostart"],
|
|
279
|
+
["c:/programdata/microsoft/windows/start menu/programs/startup/", "startup-folder"],
|
|
280
|
+
];
|
|
281
|
+
const SSH = "SSH access or startup file";
|
|
282
|
+
const STARTUP = "shell, PowerShell or git startup file";
|
|
283
|
+
const job = (k) => ({ kind: "job", label: JOB_LABEL[k], job: k });
|
|
284
|
+
/** Where writing `np` would install persistence or change remote access, else null. */
|
|
285
|
+
export function persistenceHit(np, ctx) {
|
|
286
|
+
const lower = trimEndChars((np.path ?? np.suffix ?? "").toLowerCase(), "/");
|
|
287
|
+
if (lower === "")
|
|
288
|
+
return null;
|
|
289
|
+
const under = (base, d) => lower === `${base}/${d}` || lower.startsWith(`${base}/${d}/`);
|
|
290
|
+
if (np.path !== null) {
|
|
291
|
+
const home = (normalizeFull(ctx.homeDir, { ...ctx, cwd: "/" }) ?? "").toLowerCase();
|
|
292
|
+
if (home) {
|
|
293
|
+
for (const f of DENY_HOME_FILES)
|
|
294
|
+
if (lower === `${home}/${f}`)
|
|
295
|
+
return { kind: "deny", label: SSH };
|
|
296
|
+
for (const [d, k] of JOB_HOME_DIRS)
|
|
297
|
+
if (under(home, d))
|
|
298
|
+
return job(k);
|
|
299
|
+
for (const f of ASK_HOME_FILES)
|
|
300
|
+
if (lower === `${home}/${f}`)
|
|
301
|
+
return { kind: "ask", label: STARTUP };
|
|
302
|
+
for (const d of ASK_HOME_DIRS)
|
|
303
|
+
if (under(home, d))
|
|
304
|
+
return { kind: "ask", label: STARTUP };
|
|
305
|
+
}
|
|
306
|
+
for (const s of DENY_SYSTEM)
|
|
307
|
+
if (lower === s)
|
|
308
|
+
return { kind: "deny", label: "library preload file" };
|
|
309
|
+
for (const [s, k] of JOB_SYSTEM)
|
|
310
|
+
if (lower.startsWith(s) || lower === trimEndChars(s, "/"))
|
|
311
|
+
return job(k);
|
|
312
|
+
for (const s of ASK_SYSTEM)
|
|
313
|
+
if (lower.startsWith(s) || lower === trimEndChars(s, "/"))
|
|
314
|
+
return { kind: "ask", label: STARTUP };
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
// Only the suffix is known (e.g. $SOMEDIR/.bashrc): match on the file name.
|
|
318
|
+
for (const f of DENY_HOME_FILES)
|
|
319
|
+
if (lower.endsWith("/" + f))
|
|
320
|
+
return { kind: "deny", label: SSH };
|
|
321
|
+
for (const [d, k] of JOB_HOME_DIRS)
|
|
322
|
+
if (lower.includes("/" + d + "/") || lower.endsWith("/" + d))
|
|
323
|
+
return job(k);
|
|
324
|
+
for (const f of ASK_HOME_FILES)
|
|
325
|
+
if (lower.endsWith("/" + f))
|
|
326
|
+
return { kind: "ask", label: STARTUP };
|
|
327
|
+
for (const d of ASK_HOME_DIRS)
|
|
328
|
+
if (lower.includes("/" + d + "/") || lower.endsWith("/" + d))
|
|
329
|
+
return { kind: "ask", label: STARTUP };
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
// Regenerable caches one level under home: deleting them is routine cleanup, not data loss.
|
|
333
|
+
const HOME_CACHES = new Set([".cache", ".npm", ".yarn", ".pnpm-store", ".node-gyp", ".gradle", ".m2", ".ivy2", ".bun", ".deno", ".nuget", ".pub-cache", ".expo", ".turbo"]);
|
|
334
|
+
/**
|
|
335
|
+
* True when deleting `path` recursively would remove the home directory itself, everything in
|
|
336
|
+
* it, or a whole folder one level under it (~/Documents, ~/Desktop, ~/.ssh, C:/Users/u/Pictures),
|
|
337
|
+
* other than a regenerable cache. `path` is a normalized path; null is false.
|
|
338
|
+
*/
|
|
339
|
+
export function homeTopLevel(path, ctx) {
|
|
340
|
+
if (path === null)
|
|
341
|
+
return false;
|
|
342
|
+
const home = (normalizeFull(ctx.homeDir, { ...ctx, cwd: "/" }) ?? "").toLowerCase();
|
|
343
|
+
if (home === "")
|
|
344
|
+
return false;
|
|
345
|
+
const lp = trimEndChars(path.toLowerCase(), "/");
|
|
346
|
+
if (lp === home || lp === home + "/*")
|
|
347
|
+
return true;
|
|
348
|
+
if (!lp.startsWith(home + "/"))
|
|
349
|
+
return false;
|
|
350
|
+
const rest = lp.slice(home.length + 1);
|
|
351
|
+
if (rest.includes("/"))
|
|
352
|
+
return false;
|
|
353
|
+
return rest !== "*" && !HOME_CACHES.has(rest);
|
|
354
|
+
}
|
|
355
|
+
/** Returns a label if `np` is a sensitive path, else null. */
|
|
356
|
+
export function sensitiveLabel(np, ctx) {
|
|
357
|
+
const p = np.path ?? np.suffix ?? "";
|
|
358
|
+
const lower = p.toLowerCase();
|
|
359
|
+
const home = (normalizeFull(ctx.homeDir, { ...ctx, cwd: "/" }) ?? "").toLowerCase();
|
|
360
|
+
if (np.path !== null && home) {
|
|
361
|
+
for (const [d, label] of HOME_DIRS)
|
|
362
|
+
if (lower === `${home}/${d}` || lower.startsWith(`${home}/${d}/`))
|
|
363
|
+
return label;
|
|
364
|
+
for (const [f, label] of HOME_FILES)
|
|
365
|
+
if (lower === `${home}/${f}`)
|
|
366
|
+
return label;
|
|
367
|
+
}
|
|
368
|
+
const base = (lower.split("/").pop() ?? "");
|
|
369
|
+
if (base === ".env" || (base.startsWith(".env.") && !/\.(example|sample|template|dist|defaults?)$/.test(base)))
|
|
370
|
+
return "env-file";
|
|
371
|
+
if (base.endsWith(".pem") || base.endsWith(".key") || base.endsWith(".p12") || base.endsWith(".pfx"))
|
|
372
|
+
return "private-key";
|
|
373
|
+
if (base.startsWith("id_rsa") || base.startsWith("id_ed25519") || base.startsWith("id_ecdsa") || base.startsWith("id_dsa"))
|
|
374
|
+
return "ssh-private-key";
|
|
375
|
+
if (lower === "/etc/shadow" || lower === "/etc/sudoers")
|
|
376
|
+
return "system-credentials";
|
|
377
|
+
for (const x of ctx.extraSensitive) {
|
|
378
|
+
const n = normalizeFull(x.endsWith("/**") ? x.slice(0, -3) : x, { ...ctx, cwd: "/" });
|
|
379
|
+
if (n && np.path !== null && (np.path === n || np.path.startsWith(n + "/")))
|
|
380
|
+
return "user-sensitive";
|
|
381
|
+
}
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
export function pathCtxFrom(c) {
|
|
385
|
+
return {
|
|
386
|
+
platform: c.platform,
|
|
387
|
+
homeDir: c.homeDir,
|
|
388
|
+
cwd: c.cwd,
|
|
389
|
+
caseInsensitive: c.caseInsensitiveFs,
|
|
390
|
+
glassboxDirs: c.glassboxDirs,
|
|
391
|
+
claudeConfigDir: c.claudeConfigDir,
|
|
392
|
+
extraProtected: c.policy?.extraProtectedPaths ?? [],
|
|
393
|
+
extraSensitive: c.policy?.extraSensitivePaths ?? [],
|
|
394
|
+
secretPaths: c.glassboxSecretPaths ?? [],
|
|
395
|
+
resolved: c.resolvedPaths,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Acc } from "./acc.js";
|
|
2
|
+
import { type PathCtx } from "./paths.js";
|
|
3
|
+
export interface PsState {
|
|
4
|
+
pctx: PathCtx;
|
|
5
|
+
depth: number;
|
|
6
|
+
maxBytes: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function analyzePowerShell(src: string, st: PsState): Acc;
|
|
9
|
+
//# sourceMappingURL=powershell.d.ts.map
|