@node9/policy-engine 2.50.1 → 2.52.0
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.d.mts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +797 -53
- package/dist/index.mjs +796 -53
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2122,15 +2122,15 @@ function ssrfExemptMatches(entries, normalized) {
|
|
|
2122
2122
|
continue;
|
|
2123
2123
|
}
|
|
2124
2124
|
if (!target) continue;
|
|
2125
|
-
const
|
|
2125
|
+
const base3 = bitsOf(normalizeIpLiteral(entry.slice(0, slash)) ?? "");
|
|
2126
2126
|
const prefixText = entry.slice(slash + 1);
|
|
2127
2127
|
const prefix = /^\d+$/.test(prefixText) ? Number(prefixText) : NaN;
|
|
2128
|
-
if (!
|
|
2128
|
+
if (!base3 || !Number.isInteger(prefix) || prefix < 0 || // A v4 range never matches a v6 address, and the reverse: the widths
|
|
2129
2129
|
// differ, so `0.0.0.0/0` does not release `::1`.
|
|
2130
|
-
|
|
2130
|
+
base3.length !== target.length || prefix > base3.length) {
|
|
2131
2131
|
continue;
|
|
2132
2132
|
}
|
|
2133
|
-
if (
|
|
2133
|
+
if (base3.slice(0, prefix) === target.slice(0, prefix)) return true;
|
|
2134
2134
|
}
|
|
2135
2135
|
return false;
|
|
2136
2136
|
}
|
|
@@ -2427,7 +2427,7 @@ var CHECK_TEXT = {
|
|
|
2427
2427
|
advice: "Fixed at Review for now."
|
|
2428
2428
|
},
|
|
2429
2429
|
"commands.node9-disarm": {
|
|
2430
|
-
plain: "The agent
|
|
2430
|
+
plain: "The agent switches node9 off or weakens it: stops or kills the daemon, stops its service, uninstalls node9, changes files in ~/.node9, clears a session flag, trusts an address, pauses the gate, weakens a shield.",
|
|
2431
2431
|
example: "After reading a web page, the agent runs node9 session-exposure clear --all",
|
|
2432
2432
|
advice: "Keep Review: these are your commands to run. Block if the agent should never touch node9."
|
|
2433
2433
|
},
|
|
@@ -2480,6 +2480,10 @@ function reviewsEveryAgentFileWrite(mode) {
|
|
|
2480
2480
|
const level = levelOf(mode);
|
|
2481
2481
|
return level === "strict" || level === "block-all";
|
|
2482
2482
|
}
|
|
2483
|
+
function holdsSendsWithoutDaemon(mode) {
|
|
2484
|
+
const level = levelOf(mode);
|
|
2485
|
+
return level === "strict" || level === "block-all";
|
|
2486
|
+
}
|
|
2483
2487
|
function isBlockAll(mode) {
|
|
2484
2488
|
return levelOf(mode) === "block-all";
|
|
2485
2489
|
}
|
|
@@ -2849,7 +2853,7 @@ var PRODUCT_CHECKS = [
|
|
|
2849
2853
|
group: "commands",
|
|
2850
2854
|
owasp: "ASI10",
|
|
2851
2855
|
title: "node9 disarmed from the shell",
|
|
2852
|
-
catches: "a node9 command that clears a session flag, trusts a destination, pauses the gate or weakens a shield
|
|
2856
|
+
catches: "the agent stopping or killing the node9 daemon, stopping its service, uninstalling node9, changing files in ~/.node9, or running a node9 command that clears a session flag, trusts a destination, pauses the gate or weakens a shield",
|
|
2853
2857
|
values: ALL,
|
|
2854
2858
|
defaultValue: "review",
|
|
2855
2859
|
legacy: ["review-node9-disarm"]
|
|
@@ -5415,9 +5419,15 @@ function detectDangerousShellExec(command) {
|
|
|
5415
5419
|
if (f === PARSE_FAIL) return null;
|
|
5416
5420
|
let result = null;
|
|
5417
5421
|
const assigned = assignedNames(f);
|
|
5418
|
-
|
|
5422
|
+
const known = plainlyNamedPrograms(f);
|
|
5423
|
+
const calledByName = literallyCalledFunctions(f);
|
|
5424
|
+
const bodies = [];
|
|
5425
|
+
const inBody = (pos) => bodies.some(([a, b]) => pos >= a && pos < b);
|
|
5426
|
+
walkWithCalls(f, (node) => {
|
|
5419
5427
|
if (!node || result === "block") return false;
|
|
5420
5428
|
const n = node;
|
|
5429
|
+
if (n.kind === "FuncDecl" && n.Body && callDepth === 0 && calledByName.has(n.Name?.Value))
|
|
5430
|
+
bodies.push([n.Body.pos, n.Body.end]);
|
|
5421
5431
|
if (n.kind === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
5422
5432
|
const call = n.Y.Cmd;
|
|
5423
5433
|
if (call && call.kind === "CallExpr") {
|
|
@@ -5441,7 +5451,8 @@ function detectDangerousShellExec(command) {
|
|
|
5441
5451
|
);
|
|
5442
5452
|
const head = unwrapCommandHead(headWords, false, true);
|
|
5443
5453
|
const lookup = headWords[0]?.toLowerCase() === "command" && headWords.slice(1).some((w) => w === "-v" || w === "-V");
|
|
5444
|
-
|
|
5454
|
+
const unboundBody = callDepth === 0 && inBody(n.pos ?? -1);
|
|
5455
|
+
if (!lookup && !unboundBody && (opaqueExecutable(args[0], assigned, known) || opaqueExecutable(args[head], assigned, known)))
|
|
5445
5456
|
result = "review";
|
|
5446
5457
|
const firstParts = args[0].Parts || [];
|
|
5447
5458
|
if (firstParts.length !== 1 || firstParts[0].kind !== "Lit") return true;
|
|
@@ -5485,6 +5496,7 @@ function lookupSubstitution(part) {
|
|
|
5485
5496
|
if (words.length === 3 && words[0] === "type" && words[1] === "-p") return words[2];
|
|
5486
5497
|
return null;
|
|
5487
5498
|
}
|
|
5499
|
+
var EMPTY_NAMES = /* @__PURE__ */ new Set();
|
|
5488
5500
|
var VARIABLE_READERS = /* @__PURE__ */ new Set([
|
|
5489
5501
|
"read",
|
|
5490
5502
|
"mapfile",
|
|
@@ -5514,11 +5526,106 @@ function assignedNames(f) {
|
|
|
5514
5526
|
});
|
|
5515
5527
|
return names;
|
|
5516
5528
|
}
|
|
5517
|
-
function
|
|
5529
|
+
function literallyCalledFunctions(f) {
|
|
5530
|
+
const declared = /* @__PURE__ */ new Set();
|
|
5531
|
+
const called = /* @__PURE__ */ new Set();
|
|
5532
|
+
walk(f, (node) => {
|
|
5533
|
+
if (!node) return false;
|
|
5534
|
+
if (node.kind === "FuncDecl" && node.Name?.Value) declared.add(node.Name.Value);
|
|
5535
|
+
if (node.kind === "CallExpr") {
|
|
5536
|
+
const head = resolveWordLiteral(node.Args?.[0]);
|
|
5537
|
+
if (head) called.add(head);
|
|
5538
|
+
}
|
|
5539
|
+
return true;
|
|
5540
|
+
});
|
|
5541
|
+
return new Set([...declared].filter((name) => called.has(name)));
|
|
5542
|
+
}
|
|
5543
|
+
var PLAIN_PROGRAM_NAME = /^[A-Za-z_][\w.+-]*$/;
|
|
5544
|
+
function plainlyNamedPrograms(f) {
|
|
5545
|
+
const values = /* @__PURE__ */ new Map();
|
|
5546
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
5547
|
+
const give = (name, value) => {
|
|
5548
|
+
if (value === null || !PLAIN_PROGRAM_NAME.test(value)) {
|
|
5549
|
+
values.set(name, null);
|
|
5550
|
+
return;
|
|
5551
|
+
}
|
|
5552
|
+
const cur = values.get(name);
|
|
5553
|
+
if (cur === null) return;
|
|
5554
|
+
if (cur === void 0) values.set(name, /* @__PURE__ */ new Set([value]));
|
|
5555
|
+
else cur.add(value);
|
|
5556
|
+
};
|
|
5557
|
+
const literalOnly = (w) => {
|
|
5558
|
+
const parts = w?.Parts ?? [];
|
|
5559
|
+
if (parts.length !== 1) return null;
|
|
5560
|
+
const p = parts[0];
|
|
5561
|
+
if (p.kind === "Lit") return p.Value ?? null;
|
|
5562
|
+
if (p.kind === "ParamExp" && expansionName(p) === "FUNCNAME") return "FUNCNAME";
|
|
5563
|
+
if (p.kind === "SglQuoted" && !p.Dollar) return p.Value ?? null;
|
|
5564
|
+
if (p.kind === "DblQuoted") {
|
|
5565
|
+
const inner = p.Parts ?? [];
|
|
5566
|
+
return inner.length === 1 && inner[0].kind === "Lit" ? inner[0].Value ?? null : null;
|
|
5567
|
+
}
|
|
5568
|
+
return null;
|
|
5569
|
+
};
|
|
5570
|
+
let ifsTouched = false;
|
|
5571
|
+
walk(f, (node) => {
|
|
5572
|
+
if (!node) return false;
|
|
5573
|
+
const kind = node.kind;
|
|
5574
|
+
if (kind === "FuncDecl" && node.Name?.Value) give(node.Name.Value, node.Name.Value);
|
|
5575
|
+
if (kind === "Assign" && node.Name?.Value) {
|
|
5576
|
+
const name = node.Name.Value;
|
|
5577
|
+
if (name === "IFS") ifsTouched = true;
|
|
5578
|
+
if (node.Append) values.set(name, null);
|
|
5579
|
+
else if (node.Array) {
|
|
5580
|
+
arrays.add(name);
|
|
5581
|
+
for (const el of node.Array.Elems ?? []) give(name, literalOnly(el.Value));
|
|
5582
|
+
} else if (node.Index) {
|
|
5583
|
+
arrays.add(name);
|
|
5584
|
+
give(name, node.Value ? literalOnly(node.Value) : null);
|
|
5585
|
+
} else give(name, node.Value ? literalOnly(node.Value) : null);
|
|
5586
|
+
}
|
|
5587
|
+
if (kind === "ForClause" && node.Loop?.Name?.Value) values.set(node.Loop.Name.Value, null);
|
|
5588
|
+
if (kind === "CallExpr") {
|
|
5589
|
+
const words = (node.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
5590
|
+
if (VARIABLE_READERS.has(words[0] ?? "")) {
|
|
5591
|
+
for (const w of words.slice(1)) if (w && /^[A-Za-z_]\w*$/.test(w)) values.set(w, null);
|
|
5592
|
+
}
|
|
5593
|
+
}
|
|
5594
|
+
return true;
|
|
5595
|
+
});
|
|
5596
|
+
if (ifsTouched) return /* @__PURE__ */ new Set();
|
|
5597
|
+
const functions = /* @__PURE__ */ new Set();
|
|
5598
|
+
walk(f, (node) => {
|
|
5599
|
+
if (node && node.kind === "FuncDecl" && node.Name?.Value) functions.add(node.Name.Value);
|
|
5600
|
+
return true;
|
|
5601
|
+
});
|
|
5602
|
+
const callable = (v) => functions.has(v) || v === "FUNCNAME" || v === "true" || v === "false" || v === ":";
|
|
5603
|
+
for (const [name, vals] of values) {
|
|
5604
|
+
if (vals && ![...vals].every(callable)) values.set(name, null);
|
|
5605
|
+
}
|
|
5606
|
+
const known = /* @__PURE__ */ new Set();
|
|
5607
|
+
for (const [name, vals] of values)
|
|
5608
|
+
if (vals && (vals.size === 1 || arrays.has(name) && vals.size > 0)) known.add(name);
|
|
5609
|
+
return known;
|
|
5610
|
+
}
|
|
5611
|
+
function expansionName(part) {
|
|
5612
|
+
if (part.kind !== "ParamExp") return null;
|
|
5613
|
+
if (part.Excl || part.Length || part.Width || part.Slice || part.Repl || part.Exp) return null;
|
|
5614
|
+
return part.Param?.Value ?? null;
|
|
5615
|
+
}
|
|
5616
|
+
function executableParts(word, assigned, quoted = false, known = EMPTY_NAMES) {
|
|
5518
5617
|
return (word?.Parts ?? []).flatMap((part) => {
|
|
5519
5618
|
const kind = part.kind;
|
|
5520
|
-
if (kind === "DblQuoted") return executableParts(part, assigned, true);
|
|
5619
|
+
if (kind === "DblQuoted") return executableParts(part, assigned, true, known);
|
|
5521
5620
|
if (kind === "Lit") return [{ kind: "Lit", value: part.Value ?? "", quoted }];
|
|
5621
|
+
const name = expansionName(part);
|
|
5622
|
+
if (name !== null && (known.has(name) || name === "FUNCNAME"))
|
|
5623
|
+
return [{ kind: "Lit", value: name, quoted }];
|
|
5624
|
+
if (name !== null) {
|
|
5625
|
+
const bound = recordedExpansion(name === "@" || name === "*" ? "1" : name);
|
|
5626
|
+
if (typeof bound === "string" && PLAIN_PROGRAM_NAME.test(bound))
|
|
5627
|
+
return [{ kind: "Lit", value: bound, quoted }];
|
|
5628
|
+
}
|
|
5522
5629
|
if (kind === "SglQuoted")
|
|
5523
5630
|
return [{ kind: part.Dollar ? "Dynamic" : "Lit", value: part.Value ?? "", quoted: true }];
|
|
5524
5631
|
if (kind === "ParamExp" && isDefaultExpansion(part) && !assigned.has(part.Param?.Value)) {
|
|
@@ -5526,14 +5633,14 @@ function executableParts(word, assigned, quoted = false) {
|
|
|
5526
5633
|
if (fallback !== null) return [{ kind: "Lit", value: fallback, quoted }];
|
|
5527
5634
|
}
|
|
5528
5635
|
if (kind === "CmdSubst") {
|
|
5529
|
-
const
|
|
5530
|
-
if (
|
|
5636
|
+
const name2 = lookupSubstitution(part);
|
|
5637
|
+
if (name2 !== null) return [{ kind: "Lit", value: name2, quoted }];
|
|
5531
5638
|
}
|
|
5532
5639
|
return [{ kind: "Dynamic", value: "", quoted }];
|
|
5533
5640
|
});
|
|
5534
5641
|
}
|
|
5535
|
-
function opaqueExecutable(word, assigned) {
|
|
5536
|
-
const parts = executableParts(word, assigned);
|
|
5642
|
+
function opaqueExecutable(word, assigned, known = EMPTY_NAMES) {
|
|
5643
|
+
const parts = executableParts(word, assigned, false, known);
|
|
5537
5644
|
let lastSlash = -1;
|
|
5538
5645
|
parts.forEach((p, i) => {
|
|
5539
5646
|
if (p.kind === "Lit" && p.value.includes("/")) lastSlash = i;
|
|
@@ -6343,6 +6450,9 @@ var _listOps = null;
|
|
|
6343
6450
|
function isListOp(op) {
|
|
6344
6451
|
return listOps().has(op);
|
|
6345
6452
|
}
|
|
6453
|
+
function isPipeOp(op) {
|
|
6454
|
+
return pipeOps().has(op);
|
|
6455
|
+
}
|
|
6346
6456
|
function listOps() {
|
|
6347
6457
|
if (_listOps) return _listOps;
|
|
6348
6458
|
_listOps = new Set(
|
|
@@ -6618,6 +6728,33 @@ function isProtectedCodePath(p) {
|
|
|
6618
6728
|
if (matchSensitivePath(p) !== null) return true;
|
|
6619
6729
|
return SYSTEM_AUTH_FILES.includes(p) || SYSTEM_AUTH_DIRS.some((d) => p === d || p.startsWith(d + "/"));
|
|
6620
6730
|
}
|
|
6731
|
+
function isJailedCodePath(literal, jailPaths) {
|
|
6732
|
+
const value = trimTrailingSlashes(literal.replace(/\\/g, "/"));
|
|
6733
|
+
if (!value) return false;
|
|
6734
|
+
for (const raw of jailPaths) {
|
|
6735
|
+
const jail = trimTrailingSlashes(raw.trim().replace(/\\/g, "/"));
|
|
6736
|
+
if (!jail) continue;
|
|
6737
|
+
const home = homeTail(jail);
|
|
6738
|
+
if (home === null) {
|
|
6739
|
+
if (value === jail || value.startsWith(jail + "/")) return true;
|
|
6740
|
+
continue;
|
|
6741
|
+
}
|
|
6742
|
+
if (!home) continue;
|
|
6743
|
+
const tail = homeTail(value);
|
|
6744
|
+
if (tail !== null && (tail === home || tail.startsWith(home + "/"))) return true;
|
|
6745
|
+
}
|
|
6746
|
+
return false;
|
|
6747
|
+
}
|
|
6748
|
+
function trimTrailingSlashes(s) {
|
|
6749
|
+
let end = s.length;
|
|
6750
|
+
while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
|
|
6751
|
+
return s.slice(0, end);
|
|
6752
|
+
}
|
|
6753
|
+
function homeTail(p) {
|
|
6754
|
+
const m = /^(?:~|\$\{?HOME\}?|\/home\/[^/]+|\/Users\/[^/]+|\/root)(?:\/(.*))?$/.exec(p);
|
|
6755
|
+
if (!m) return null;
|
|
6756
|
+
return m[1] ?? "";
|
|
6757
|
+
}
|
|
6621
6758
|
function inlineExecDescription(r) {
|
|
6622
6759
|
const lead = r ? `The AI is running code directly from the command line: ${inlineExecReason(r).replace(/^This/, "this")}.` : "The AI is running code directly from the command line.";
|
|
6623
6760
|
return `${lead} Review the full script below before allowing it to execute.`;
|
|
@@ -6626,7 +6763,8 @@ function inlineExecReason(r) {
|
|
|
6626
6763
|
const who = r.interp ? `This inline ${r.interp} code` : "This inline code";
|
|
6627
6764
|
return r.evidence ? `${who} ${r.what} (${r.evidence})` : `${who} ${r.what}`;
|
|
6628
6765
|
}
|
|
6629
|
-
function inlineExecReview(command) {
|
|
6766
|
+
function inlineExecReview(command, jailPaths = []) {
|
|
6767
|
+
const isProtected = jailPaths.length === 0 ? isProtectedCodePath : (p) => isProtectedCodePath(p) || isJailedCodePath(p, jailPaths);
|
|
6630
6768
|
const calls = inlineExecCalls(command);
|
|
6631
6769
|
if (calls === PARSE_FAIL) {
|
|
6632
6770
|
return INLINE_EXEC_FALLBACK.test(command) ? { outcome: "unreadable", interp: "", what: "could not be parsed" } : null;
|
|
@@ -6649,7 +6787,7 @@ function inlineExecReview(command) {
|
|
|
6649
6787
|
what: `is ${call.interp} code, which node9 does not read`
|
|
6650
6788
|
};
|
|
6651
6789
|
} else {
|
|
6652
|
-
const judged = judgeInlineCode(language, code,
|
|
6790
|
+
const judged = judgeInlineCode(language, code, isProtected);
|
|
6653
6791
|
if (judged) finding = { ...judged, interp: call.interp };
|
|
6654
6792
|
}
|
|
6655
6793
|
if (finding?.outcome === "dangerous") return finding;
|
|
@@ -7008,6 +7146,13 @@ function recordTopLevelStmt(stmt) {
|
|
|
7008
7146
|
if (t === "DeclClause") return ASSIGNMENT_HEADS.has(stmt.Cmd.Variant?.Value ?? "");
|
|
7009
7147
|
return (stmt.Cmd.Args || []).length === 0 && (stmt.Cmd.Assigns || []).length > 0;
|
|
7010
7148
|
}
|
|
7149
|
+
var ARRAY_MARK = "array";
|
|
7150
|
+
var ARRAY_SEP = "";
|
|
7151
|
+
function arrayElements(value) {
|
|
7152
|
+
if (typeof value !== "string" || !value.startsWith(ARRAY_MARK)) return null;
|
|
7153
|
+
const body = value.slice(ARRAY_MARK.length);
|
|
7154
|
+
return body === "" ? [] : body.split(ARRAY_SEP);
|
|
7155
|
+
}
|
|
7011
7156
|
function recordAssignments(n, at) {
|
|
7012
7157
|
if (!assignmentTable) return;
|
|
7013
7158
|
const t = n.kind;
|
|
@@ -7021,7 +7166,19 @@ function recordAssignments(n, at) {
|
|
|
7021
7166
|
} else return;
|
|
7022
7167
|
for (const a of assigns) {
|
|
7023
7168
|
const name = a?.Name?.Value;
|
|
7024
|
-
if (!name
|
|
7169
|
+
if (!name) continue;
|
|
7170
|
+
if (a.Array) {
|
|
7171
|
+
const elems = (a.Array.Elems || []).map(
|
|
7172
|
+
(e) => e?.Index ? null : resolveWordLiteral(e?.Value)
|
|
7173
|
+
);
|
|
7174
|
+
const literal = elems.every((v) => v !== null);
|
|
7175
|
+
assignmentTable.set(name, {
|
|
7176
|
+
value: literal && !a.Append ? ARRAY_MARK + elems.join(ARRAY_SEP) : null,
|
|
7177
|
+
at
|
|
7178
|
+
});
|
|
7179
|
+
continue;
|
|
7180
|
+
}
|
|
7181
|
+
if (!a.Value || a.Append) continue;
|
|
7025
7182
|
assignmentTable.set(name, { value: resolveWordLiteral(a.Value), at });
|
|
7026
7183
|
}
|
|
7027
7184
|
}
|
|
@@ -7032,7 +7189,33 @@ function resolveTrivialSubst(part) {
|
|
|
7032
7189
|
const st = stmts[0];
|
|
7033
7190
|
if ((st.Redirs || []).length > 0 || st.Negated || st.Background) return void 0;
|
|
7034
7191
|
const cmd = st.Cmd;
|
|
7035
|
-
if (!cmd
|
|
7192
|
+
if (!cmd) return void 0;
|
|
7193
|
+
if (cmd.kind === "BinaryCmd" && pipeOps().has(cmd.Op)) {
|
|
7194
|
+
const left = cmd.X?.Cmd;
|
|
7195
|
+
const right = cmd.Y?.Cmd;
|
|
7196
|
+
if (!left || !right || left.kind !== "CallExpr" || right.kind !== "CallExpr") return void 0;
|
|
7197
|
+
if ((cmd.X.Redirs || []).length > 0 || (cmd.Y.Redirs || []).length > 0) return void 0;
|
|
7198
|
+
const input = trivialCallOutput(left);
|
|
7199
|
+
if (input === void 0) return void 0;
|
|
7200
|
+
const filter = (right.Args || []).map((a) => resolveWordLiteral(a));
|
|
7201
|
+
if (filter.some((w) => w === null)) return void 0;
|
|
7202
|
+
const f = baseWord(filter[0]);
|
|
7203
|
+
const flags = filter.slice(1);
|
|
7204
|
+
if (f === "base64" && flags.length === 1 && /^(-d|-D|--decode)$/.test(flags[0])) {
|
|
7205
|
+
try {
|
|
7206
|
+
const out = Buffer.from(input, "base64").toString("utf8");
|
|
7207
|
+
return /^[\x20-\x7e]*$/.test(out) ? out : void 0;
|
|
7208
|
+
} catch {
|
|
7209
|
+
return void 0;
|
|
7210
|
+
}
|
|
7211
|
+
}
|
|
7212
|
+
if (f === "rev" && flags.length === 0) return [...input].reverse().join("");
|
|
7213
|
+
return void 0;
|
|
7214
|
+
}
|
|
7215
|
+
if (cmd.kind !== "CallExpr") return void 0;
|
|
7216
|
+
return trivialCallOutput(cmd);
|
|
7217
|
+
}
|
|
7218
|
+
function trivialCallOutput(cmd) {
|
|
7036
7219
|
if ((cmd.Assigns || []).length > 0) return void 0;
|
|
7037
7220
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
7038
7221
|
if (words.length === 0 || words.some((w) => w === null)) return void 0;
|
|
@@ -7044,9 +7227,16 @@ function resolveTrivialSubst(part) {
|
|
|
7044
7227
|
return rest.slice(i).join(" ");
|
|
7045
7228
|
}
|
|
7046
7229
|
if (head === "printf") {
|
|
7230
|
+
if (rest.length === 1 && /^(?:\\(?:[0-7]{1,3}|x[0-9A-Fa-f]{1,2}))+$/.test(rest[0])) {
|
|
7231
|
+
return rest[0].replace(
|
|
7232
|
+
/\\(?:x([0-9A-Fa-f]{1,2})|([0-7]{1,3}))/g,
|
|
7233
|
+
(_, hex, oct) => String.fromCharCode(hex ? parseInt(hex, 16) : parseInt(oct, 8))
|
|
7234
|
+
);
|
|
7235
|
+
}
|
|
7047
7236
|
if (rest.length !== 2) return void 0;
|
|
7048
|
-
|
|
7049
|
-
return
|
|
7237
|
+
const m = /^([^%]*)%s([^%]*?)(\\n)?$/.exec(rest[0]);
|
|
7238
|
+
if (!m) return void 0;
|
|
7239
|
+
return m[1] + rest[1] + m[2];
|
|
7050
7240
|
}
|
|
7051
7241
|
return void 0;
|
|
7052
7242
|
}
|
|
@@ -7060,11 +7250,28 @@ function isPlainParam(p) {
|
|
|
7060
7250
|
if (p.kind !== "ParamExp") return false;
|
|
7061
7251
|
return !(p.Excl || p.Length || p.Width || p.Index || p.Slice || p.Repl || p.Exp);
|
|
7062
7252
|
}
|
|
7253
|
+
function indexedParam(p) {
|
|
7254
|
+
if (p.kind !== "ParamExp" || !p.Index) return null;
|
|
7255
|
+
if (p.Excl || p.Length || p.Width || p.Slice || p.Repl || p.Exp) return null;
|
|
7256
|
+
const index = resolveWordLiteral(p.Index);
|
|
7257
|
+
const name = p.Param?.Value;
|
|
7258
|
+
return name && index !== null ? { name, index } : null;
|
|
7259
|
+
}
|
|
7063
7260
|
function expandPlainParam(p) {
|
|
7064
7261
|
if (!assignmentTable) return void 0;
|
|
7262
|
+
const indexed = indexedParam(p);
|
|
7263
|
+
if (indexed) {
|
|
7264
|
+
const elems = arrayElements(recordedExpansion(indexed.name));
|
|
7265
|
+
if (elems === null) return void 0;
|
|
7266
|
+
if (indexed.index === "@" || indexed.index === "*") return elems.join(" ");
|
|
7267
|
+
return /^\d+$/.test(indexed.index) ? elems[Number(indexed.index)] ?? null : null;
|
|
7268
|
+
}
|
|
7065
7269
|
if (!isPlainParam(p)) return void 0;
|
|
7066
7270
|
const recorded = recordedExpansion(p.Param?.Value);
|
|
7067
|
-
if (recorded !== void 0)
|
|
7271
|
+
if (recorded !== void 0) {
|
|
7272
|
+
const elems = arrayElements(recorded);
|
|
7273
|
+
return elems === null ? recorded : elems[0] ?? "";
|
|
7274
|
+
}
|
|
7068
7275
|
return HOME_VARIABLES.has(p.Param?.Value) ? "~" : void 0;
|
|
7069
7276
|
}
|
|
7070
7277
|
var MAX_CALL_DEPTH2 = 4;
|
|
@@ -7470,8 +7677,8 @@ function analyzeFsOperation(command) {
|
|
|
7470
7677
|
}
|
|
7471
7678
|
var stripDotSlash = (p) => p.replace(/^\.\//, "");
|
|
7472
7679
|
function isSensitiveCleanupName(p) {
|
|
7473
|
-
const
|
|
7474
|
-
return /^\.env(\.|$)/i.test(
|
|
7680
|
+
const base3 = p.replace(/^.*[\\/]/, "");
|
|
7681
|
+
return /^\.env(\.|$)/i.test(base3) || /(?:^|[\\/])\.(?:ssh|aws|gnupg|git)(?:[\\/]|$)/i.test(p) || /\.(?:pem|key|p12|pfx|crt)$/i.test(base3) || /^\.?(?:netrc|npmrc|pgpass|htpasswd)$/i.test(base3) || /^id_(?:rsa|dsa|ecdsa|ed25519)/i.test(base3) || /credential/i.test(p) || /secret/i.test(base3);
|
|
7475
7682
|
}
|
|
7476
7683
|
function isWaivableCleanupTarget(p) {
|
|
7477
7684
|
if (/^[/~]/.test(p) || /^\$/.test(p)) return false;
|
|
@@ -8862,6 +9069,21 @@ function hits(access, paths, directories, context) {
|
|
|
8862
9069
|
}
|
|
8863
9070
|
return false;
|
|
8864
9071
|
}
|
|
9072
|
+
function hitsNode9Dir(access, dirs, context) {
|
|
9073
|
+
const home = context.homeDirs?.[0] ?? "~";
|
|
9074
|
+
if (access.glob) {
|
|
9075
|
+
const pattern = normalizeFilePath(access.glob, access.cwd ?? context.cwd, home);
|
|
9076
|
+
const magic = pattern.search(/[*?[{]/);
|
|
9077
|
+
const literal = magic < 0 ? pattern : pattern.slice(0, pattern.lastIndexOf("/", magic));
|
|
9078
|
+
return dirs.some((d) => within(literal, d));
|
|
9079
|
+
}
|
|
9080
|
+
const candidates = access.candidates ?? [
|
|
9081
|
+
normalizeFilePath(access.path, access.cwd ?? context.cwd, home)
|
|
9082
|
+
];
|
|
9083
|
+
return candidates.some(
|
|
9084
|
+
(p) => dirs.some((d) => within(p, d)) || access.recursive === true && dirs.some((d) => within(d, p))
|
|
9085
|
+
);
|
|
9086
|
+
}
|
|
8865
9087
|
var exempt = (p) => SYSTEM_DIRS_EXEMPT.some((d) => within(p, d));
|
|
8866
9088
|
function hitsSystemDir(access, context, dirs = SYSTEM_DIRS) {
|
|
8867
9089
|
const home = context.homeDirs?.[0] ?? "~";
|
|
@@ -8904,6 +9126,7 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
8904
9126
|
const consider = (result) => {
|
|
8905
9127
|
if (!best || RANK[result.decision] > RANK[best.decision]) best = result;
|
|
8906
9128
|
};
|
|
9129
|
+
const node9Dirs = homes.map((home) => `${home.replace(/\/$/, "")}/.node9`);
|
|
8907
9130
|
for (const access of accesses) {
|
|
8908
9131
|
const mutation = access.operation !== "read";
|
|
8909
9132
|
let kind;
|
|
@@ -8932,6 +9155,10 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
8932
9155
|
"files.system-dirs",
|
|
8933
9156
|
"review-root-home-read",
|
|
8934
9157
|
"Reading the root account's home requires approval"
|
|
9158
|
+
] : mutation && hitsNode9Dir(access, node9Dirs, context) ? [
|
|
9159
|
+
"commands.node9-disarm",
|
|
9160
|
+
"review-node9-disarm",
|
|
9161
|
+
"Changing node9's own files requires approval"
|
|
8935
9162
|
] : null;
|
|
8936
9163
|
} catch {
|
|
8937
9164
|
consider(incompleteFileVerdict(access.operation));
|
|
@@ -11936,9 +12163,9 @@ function validateBelgianNationalNumber(raw) {
|
|
|
11936
12163
|
if (!/^\d{11}$/.test(d)) return false;
|
|
11937
12164
|
const month = Number(d.slice(2, 4)) % 20;
|
|
11938
12165
|
if (month !== 0 && !plausibleDate(String(month).padStart(2, "0"), d.slice(4, 6))) return false;
|
|
11939
|
-
const
|
|
12166
|
+
const base3 = Number(d.slice(0, 9));
|
|
11940
12167
|
const check = Number(d.slice(9, 11));
|
|
11941
|
-
return 97 -
|
|
12168
|
+
return 97 - base3 % 97 === check || 97 - (2e9 + base3) % 97 === check;
|
|
11942
12169
|
}
|
|
11943
12170
|
function validateCuit(raw) {
|
|
11944
12171
|
const d = raw.replace(/-/g, "");
|
|
@@ -13502,7 +13729,22 @@ var GitWalk = class {
|
|
|
13502
13729
|
found;
|
|
13503
13730
|
/** Aliases defined earlier in this command: name -> value (null = dynamic). */
|
|
13504
13731
|
aliases = /* @__PURE__ */ new Map();
|
|
13732
|
+
/** node9Firewall#385: variables assigned a tree-top word (`scope="$PWD"`,
|
|
13733
|
+
* `root=$(git rev-parse --show-toplevel)`, `DIR=$(pwd)`), so the
|
|
13734
|
+
* variable reads as the top where it is used. */
|
|
13735
|
+
treeTopVars = /* @__PURE__ */ new Set();
|
|
13736
|
+
/** node9Firewall#385 (c): a string a script builds with `+=` from
|
|
13737
|
+
* literals (`mode=--ha; mode+=rd`). The jail's table does not follow an
|
|
13738
|
+
* append (JAIL-14a); the git rules read the built word, since a flag
|
|
13739
|
+
* spelled in two halves is still that flag. name -> value, null once a
|
|
13740
|
+
* half is unknown. */
|
|
13741
|
+
appended = /* @__PURE__ */ new Map();
|
|
13505
13742
|
payloads = /* @__PURE__ */ new Set();
|
|
13743
|
+
/** node9Firewall#385 (a): the text this command writes to each path
|
|
13744
|
+
* (`cat > /tmp/x.sh <<'SH' ... SH`, `echo '...' > f`, `>>` appends), so
|
|
13745
|
+
* a later statement that runs the path (`bash f`, `sh f`, `./f`) is
|
|
13746
|
+
* judged on what it runs. null once a write to the path is unknown. */
|
|
13747
|
+
written = /* @__PURE__ */ new Map();
|
|
13506
13748
|
/** `for NAME in a b c`: the literal items, or null when one is dynamic. */
|
|
13507
13749
|
loopVars = /* @__PURE__ */ new Map();
|
|
13508
13750
|
/** Walk one command string. Returns false when it did not parse. */
|
|
@@ -13521,6 +13763,25 @@ var GitWalk = class {
|
|
|
13521
13763
|
const type = n.kind;
|
|
13522
13764
|
if (type === "Stmt") {
|
|
13523
13765
|
this.visitHeredocShell(n, depth);
|
|
13766
|
+
this.visitPipeline(n, depth);
|
|
13767
|
+
this.visitHookWrite(n);
|
|
13768
|
+
this.recordScriptWrite(n);
|
|
13769
|
+
this.visitWrittenScript(n, depth);
|
|
13770
|
+
return true;
|
|
13771
|
+
}
|
|
13772
|
+
if (type === "Assign" && n.Name?.Value && n.Value) {
|
|
13773
|
+
const name = n.Name.Value;
|
|
13774
|
+
if (n.Append) {
|
|
13775
|
+
const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
|
|
13776
|
+
const base3 = prev === void 0 ? recordedExpansion(name) : prev;
|
|
13777
|
+
const piece = resolveWordLiteral(n.Value);
|
|
13778
|
+
this.appended.set(name, typeof base3 === "string" && piece !== null ? base3 + piece : null);
|
|
13779
|
+
this.treeTopVars.delete(name);
|
|
13780
|
+
return true;
|
|
13781
|
+
}
|
|
13782
|
+
this.appended.delete(name);
|
|
13783
|
+
if (treeTopWord(n.Value, this.treeTopVars)) this.treeTopVars.add(name);
|
|
13784
|
+
else this.treeTopVars.delete(name);
|
|
13524
13785
|
return true;
|
|
13525
13786
|
}
|
|
13526
13787
|
if (type === "ForClause") {
|
|
@@ -13549,13 +13810,13 @@ var GitWalk = class {
|
|
|
13549
13810
|
const param = plainParamName(rawArgs[loopArg]);
|
|
13550
13811
|
for (const item of this.loopVars.get(param.name)) {
|
|
13551
13812
|
const words2 = rawArgs.flatMap(
|
|
13552
|
-
(a, i) => i === loopArg ? param.quoted ? [item] : splitFields(item) : resolveGitWords(a)
|
|
13813
|
+
(a, i) => i === loopArg ? param.quoted ? [item] : splitFields(item) : resolveGitWords(a, this.treeTopVars, this.appended)
|
|
13553
13814
|
);
|
|
13554
13815
|
this.visitWords(words2, new Map(prefixEnv), depth, false);
|
|
13555
13816
|
}
|
|
13556
13817
|
return true;
|
|
13557
13818
|
}
|
|
13558
|
-
const words = rawArgs.flatMap((a) => resolveGitWords(a));
|
|
13819
|
+
const words = rawArgs.flatMap((a) => resolveGitWords(a, this.treeTopVars, this.appended));
|
|
13559
13820
|
this.visitWords(words, prefixEnv, depth, false);
|
|
13560
13821
|
return true;
|
|
13561
13822
|
}
|
|
@@ -13580,6 +13841,23 @@ var GitWalk = class {
|
|
|
13580
13841
|
if (f) this.found(f);
|
|
13581
13842
|
return;
|
|
13582
13843
|
}
|
|
13844
|
+
if (headWord === "rm" || headWord === "unlink") {
|
|
13845
|
+
if (words.slice(head + 1).some((w) => w !== null && isLiveHookFile(w)))
|
|
13846
|
+
this.found(hooksBypassed(shownOf(words)));
|
|
13847
|
+
return;
|
|
13848
|
+
}
|
|
13849
|
+
if (headWord === "mv") {
|
|
13850
|
+
const operands2 = words.slice(head + 1).filter((w) => w === null || !w.startsWith("-"));
|
|
13851
|
+
const src = operands2[0];
|
|
13852
|
+
if (typeof src === "string" && isLiveHookFile(src)) this.found(hooksBypassed(shownOf(words)));
|
|
13853
|
+
return;
|
|
13854
|
+
}
|
|
13855
|
+
if (headWord === "perl") {
|
|
13856
|
+
const code = words.slice(head + 1).find((w) => w !== null && /\brename\b/.test(w));
|
|
13857
|
+
const m = code ? /rename\s*\(?\s*q[qw]?\s*[(\[{<'"]([^)\]}>'"]+)/.exec(code) : null;
|
|
13858
|
+
if (m && isLiveHookFile(m[1])) this.found(hooksBypassed(shownOf(words)));
|
|
13859
|
+
return;
|
|
13860
|
+
}
|
|
13583
13861
|
if (depth < MAX_PAYLOAD_DEPTH2) {
|
|
13584
13862
|
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
13585
13863
|
if (payload !== null) this.runPayload(payload, depth);
|
|
@@ -13590,6 +13868,127 @@ var GitWalk = class {
|
|
|
13590
13868
|
this.payloads.add(payload);
|
|
13591
13869
|
this.run(payload, depth + 1);
|
|
13592
13870
|
}
|
|
13871
|
+
/**
|
|
13872
|
+
* node9Firewall#385: a pipeline whose last stage reads its pathspec from
|
|
13873
|
+
* stdin (`git add --pathspec-from-file=-`) or runs git over the names it
|
|
13874
|
+
* is fed (`xargs -0 git add --`), with a producer that is one literal
|
|
13875
|
+
* (`git rev-parse --show-toplevel`, `printf '%s\0' .`): the literal is
|
|
13876
|
+
* the operand, and the call is judged with it.
|
|
13877
|
+
*/
|
|
13878
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13879
|
+
visitPipeline(stmt, depth) {
|
|
13880
|
+
const cmd = stmt.Cmd;
|
|
13881
|
+
if (!cmd || cmd.kind !== "BinaryCmd" || !isPipeOp(cmd.Op)) return;
|
|
13882
|
+
const stages = [];
|
|
13883
|
+
let cur = cmd;
|
|
13884
|
+
while (cur?.kind === "BinaryCmd" && isPipeOp(cur.Op)) {
|
|
13885
|
+
stages.unshift(cur.Y);
|
|
13886
|
+
const left = cur.X;
|
|
13887
|
+
if (left?.Cmd?.kind === "BinaryCmd" && isPipeOp(left.Cmd.Op)) cur = left.Cmd;
|
|
13888
|
+
else {
|
|
13889
|
+
stages.unshift(left);
|
|
13890
|
+
break;
|
|
13891
|
+
}
|
|
13892
|
+
}
|
|
13893
|
+
if (stages.length < 2) return;
|
|
13894
|
+
const producer = stages[stages.length - 2]?.Cmd;
|
|
13895
|
+
const consumer = stages[stages.length - 1]?.Cmd;
|
|
13896
|
+
if (!producer || !consumer || producer.kind !== "CallExpr" || consumer.kind !== "CallExpr")
|
|
13897
|
+
return;
|
|
13898
|
+
const fed = producedLiteral(producer);
|
|
13899
|
+
if (fed === null) return;
|
|
13900
|
+
const words = (consumer.Args || []).flatMap(
|
|
13901
|
+
(a) => resolveGitWords(a, this.treeTopVars, this.appended)
|
|
13902
|
+
);
|
|
13903
|
+
const head = unwrapCommandHead(words);
|
|
13904
|
+
const viaXargs = words.slice(0, head).some((w) => baseWord(w) === "xargs");
|
|
13905
|
+
const fromFile = words.findIndex(
|
|
13906
|
+
(w) => w === "--pathspec-from-file=-" || w === "--pathspec-from-file"
|
|
13907
|
+
);
|
|
13908
|
+
if (!viaXargs && fromFile < 0) return;
|
|
13909
|
+
let fedWords;
|
|
13910
|
+
if (fromFile >= 0) {
|
|
13911
|
+
fedWords = words.filter(
|
|
13912
|
+
(w, k) => !(k === fromFile || w === "-" && words[k - 1] === "--pathspec-from-file")
|
|
13913
|
+
);
|
|
13914
|
+
fedWords.push(fed);
|
|
13915
|
+
} else fedWords = [...words, fed];
|
|
13916
|
+
this.visitWords(fedWords, /* @__PURE__ */ new Map(), depth, false);
|
|
13917
|
+
}
|
|
13918
|
+
/**
|
|
13919
|
+
* node9Firewall#385 (e): a hook file written with a body that checks
|
|
13920
|
+
* nothing (`cat > .githooks/pre-commit <<'SH' exit 0 SH`, `echo 'exit 0'
|
|
13921
|
+
* > .git/hooks/pre-push`, `: > .githooks/pre-commit`). A real body (a
|
|
13922
|
+
* test, a linter) is ordinary work on the hooks.
|
|
13923
|
+
*/
|
|
13924
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13925
|
+
visitHookWrite(stmt) {
|
|
13926
|
+
const cmd = stmt.Cmd;
|
|
13927
|
+
if (!cmd || cmd.kind !== "CallExpr") return;
|
|
13928
|
+
const redirs = stmt.Redirs || [];
|
|
13929
|
+
const target = redirs.find((r) => r?.Word && !r.Hdoc && (r.N == null || r.N.Value === "1"));
|
|
13930
|
+
if (!target) return;
|
|
13931
|
+
const path2 = resolveWordLiteral(target.Word);
|
|
13932
|
+
if (path2 === null || !isLiveHookFile(path2)) return;
|
|
13933
|
+
const hdoc = redirs.find((r) => r?.Hdoc);
|
|
13934
|
+
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
13935
|
+
const head = baseWord(words[0]);
|
|
13936
|
+
let body = null;
|
|
13937
|
+
if (hdoc) body = resolveWordLiteral(hdoc.Hdoc);
|
|
13938
|
+
else if (head === ":" || head === "true" || words.length === 0) body = "";
|
|
13939
|
+
else if (head === "echo" || head === "printf") {
|
|
13940
|
+
const rest = words.slice(1);
|
|
13941
|
+
body = rest.some((w) => w === null) ? null : rest.filter((w) => !/^-[neE]+$/.test(w)).join(" ");
|
|
13942
|
+
if (body !== null) body = body.replace(/\\n/g, "\n");
|
|
13943
|
+
}
|
|
13944
|
+
if (body !== null && hookBodyIsEmpty(body)) this.found(hooksBypassed(shownOf(words)));
|
|
13945
|
+
}
|
|
13946
|
+
/** A statement that writes a literal text to a path, by redirect. */
|
|
13947
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13948
|
+
recordScriptWrite(stmt) {
|
|
13949
|
+
const cmd = stmt.Cmd;
|
|
13950
|
+
if (!cmd || cmd.kind !== "CallExpr") return;
|
|
13951
|
+
const redirs = stmt.Redirs || [];
|
|
13952
|
+
const target = redirs.find((r) => r?.Word && !r.Hdoc && (r.N == null || r.N.Value === "1"));
|
|
13953
|
+
if (!target) return;
|
|
13954
|
+
const path2 = resolveWordLiteral(target.Word);
|
|
13955
|
+
if (path2 === null) return;
|
|
13956
|
+
const append = /^>>/.test(target.Op?.toString() ?? "") || redirOpIsAppend(target);
|
|
13957
|
+
const hdoc = redirs.find((r) => r?.Hdoc);
|
|
13958
|
+
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
13959
|
+
const head = baseWord(words[0]);
|
|
13960
|
+
let text = null;
|
|
13961
|
+
if (hdoc && (head === "cat" || head === "tee")) text = resolveWordLiteral(hdoc.Hdoc);
|
|
13962
|
+
else if (head === "echo" || head === "printf") {
|
|
13963
|
+
const rest = words.slice(1);
|
|
13964
|
+
text = rest.some((w) => w === null) ? null : rest.filter((w) => !/^-[neE]+$/.test(w)).join(" ");
|
|
13965
|
+
if (text !== null && head === "printf") text = text.replace(/\\n/g, "\n");
|
|
13966
|
+
} else return;
|
|
13967
|
+
const prev = this.written.get(path2);
|
|
13968
|
+
if (text === null || append && prev === null) this.written.set(path2, null);
|
|
13969
|
+
else this.written.set(path2, append && typeof prev === "string" ? `${prev}
|
|
13970
|
+
${text}` : text);
|
|
13971
|
+
}
|
|
13972
|
+
/** A statement that runs a path this command wrote: the text is the script. */
|
|
13973
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13974
|
+
visitWrittenScript(stmt, depth) {
|
|
13975
|
+
const cmd = stmt.Cmd;
|
|
13976
|
+
if (!cmd || cmd.kind !== "CallExpr" || this.written.size === 0 || depth >= MAX_PAYLOAD_DEPTH2)
|
|
13977
|
+
return;
|
|
13978
|
+
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
13979
|
+
const head = unwrapCommandHead(words);
|
|
13980
|
+
const name = baseWord(words[head]);
|
|
13981
|
+
let ran = null;
|
|
13982
|
+
if (PAYLOAD_SHELLS.has(name) && name !== "eval") {
|
|
13983
|
+
const operand = words.slice(head + 1).find((w) => w === null || !w.startsWith("-"));
|
|
13984
|
+
if (typeof operand === "string") ran = operand;
|
|
13985
|
+
} else if (typeof words[head] === "string" && this.written.has(words[head])) {
|
|
13986
|
+
ran = words[head];
|
|
13987
|
+
}
|
|
13988
|
+
if (ran === null) return;
|
|
13989
|
+
const text = this.written.get(ran);
|
|
13990
|
+
if (typeof text === "string") this.runPayload(text, depth);
|
|
13991
|
+
}
|
|
13593
13992
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13594
13993
|
visitHeredocShell(stmt, depth) {
|
|
13595
13994
|
const cmd = stmt.Cmd;
|
|
@@ -13778,7 +14177,61 @@ function dynamicOptionWord(word) {
|
|
|
13778
14177
|
if (/^--[a-z-]+=/.test(prefix) || /^-[cC]/.test(prefix)) return `${prefix}$\u2026`;
|
|
13779
14178
|
return null;
|
|
13780
14179
|
}
|
|
13781
|
-
|
|
14180
|
+
var NO_VARS = /* @__PURE__ */ new Set();
|
|
14181
|
+
var NO_APPENDS = /* @__PURE__ */ new Map();
|
|
14182
|
+
function arrayExpansionWords(word) {
|
|
14183
|
+
let parts = word?.Parts || [];
|
|
14184
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
14185
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp" || !parts[0].Index) return null;
|
|
14186
|
+
const index = resolveWordLiteral(parts[0].Index);
|
|
14187
|
+
if (index !== "@" && index !== "*") return null;
|
|
14188
|
+
const elems = arrayElements(recordedExpansion(parts[0].Param?.Value));
|
|
14189
|
+
return elems;
|
|
14190
|
+
}
|
|
14191
|
+
function producedLiteral(call) {
|
|
14192
|
+
if ((call.Assigns || []).length > 0) return null;
|
|
14193
|
+
const words = (call.Args || []).map((a) => resolveWordLiteral(a));
|
|
14194
|
+
if (words.length === 0 || words.some((w) => w === null)) return null;
|
|
14195
|
+
const head = baseWord(words[0]);
|
|
14196
|
+
const rest = words.slice(1);
|
|
14197
|
+
if (head === "git" && rest[0] === "rev-parse" && rest[1] === "--show-toplevel" && rest.length === 2)
|
|
14198
|
+
return ":/";
|
|
14199
|
+
if (head === "echo") {
|
|
14200
|
+
let i = 0;
|
|
14201
|
+
while (i < rest.length && /^-[neE]+$/.test(rest[i])) i++;
|
|
14202
|
+
return rest.length - i === 1 ? rest[i] : null;
|
|
14203
|
+
}
|
|
14204
|
+
if (head === "printf" && rest.length === 2 && /^%s(\\[0n])?$/.test(rest[0])) return rest[1];
|
|
14205
|
+
return null;
|
|
14206
|
+
}
|
|
14207
|
+
function treeTopWord(word, treeTopVars = NO_VARS) {
|
|
14208
|
+
let parts = word?.Parts || [];
|
|
14209
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
14210
|
+
if (parts.length !== 1) return false;
|
|
14211
|
+
const p = parts[0];
|
|
14212
|
+
if (p.kind === "ParamExp") {
|
|
14213
|
+
const name = plainParamName(word)?.name;
|
|
14214
|
+
return name === "PWD" || name !== void 0 && treeTopVars.has(name);
|
|
14215
|
+
}
|
|
14216
|
+
if (p.kind !== "CmdSubst") return false;
|
|
14217
|
+
const stmts = p.Stmts || [];
|
|
14218
|
+
if (stmts.length !== 1 || !stmts[0].Cmd || stmts[0].Cmd.kind !== "CallExpr") return false;
|
|
14219
|
+
const words = (stmts[0].Cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
14220
|
+
if (words.some((w) => w === null)) return false;
|
|
14221
|
+
const head = baseWord(words[0]);
|
|
14222
|
+
if (head === "pwd") return words.length === 1 || words[1] === "-P" || words[1] === "-L";
|
|
14223
|
+
return head === "git" && words[1] === "rev-parse" && words[2] === "--show-toplevel";
|
|
14224
|
+
}
|
|
14225
|
+
function resolveGitWords(word, treeTopVars = NO_VARS, appended = NO_APPENDS) {
|
|
14226
|
+
if (treeTopWord(word, treeTopVars)) return [":/"];
|
|
14227
|
+
const plain = plainParamName(word);
|
|
14228
|
+
if (plain && appended.has(plain.name)) {
|
|
14229
|
+
const v = appended.get(plain.name);
|
|
14230
|
+
if (v === null || v === void 0) return [null];
|
|
14231
|
+
return plain.quoted ? [v] : splitFields(v);
|
|
14232
|
+
}
|
|
14233
|
+
const elems = arrayExpansionWords(word);
|
|
14234
|
+
if (elems !== null) return elems;
|
|
13782
14235
|
const value = resolveWordLiteral(word);
|
|
13783
14236
|
if (value === null) {
|
|
13784
14237
|
if (isPositionalParam(word)) return boundPositionals() ?? [POSITIONAL2];
|
|
@@ -13944,6 +14397,8 @@ function classify(inv) {
|
|
|
13944
14397
|
if (o.flags.has("-n") || o.flags.has("--dry-run")) break;
|
|
13945
14398
|
const forced = o.flags.has("-f") || o.flags.has("--force") || o.flags.has("--force-with-lease") || o.flags.has("--force-if-includes") || o.flags.has("--mirror") || o.operands.some((r) => r.startsWith("+"));
|
|
13946
14399
|
if (forced) found(FORCE_PUSH);
|
|
14400
|
+
const deletes = o.flags.has("-d") || o.flags.has("--delete") || o.operands.some((r) => /^:[^:]/.test(r));
|
|
14401
|
+
if (deletes) found(DESTRUCTIVE);
|
|
13947
14402
|
break;
|
|
13948
14403
|
}
|
|
13949
14404
|
case "reset": {
|
|
@@ -13971,11 +14426,74 @@ function classify(inv) {
|
|
|
13971
14426
|
if (o.flags.has("-d") || o.flags.has("--delete")) found(DESTRUCTIVE);
|
|
13972
14427
|
break;
|
|
13973
14428
|
}
|
|
14429
|
+
// node9Firewall#385: history and work discarded through plumbing. A ref
|
|
14430
|
+
// deleted by hand, a stash dropped, the reflog expired or pruned: the
|
|
14431
|
+
// commits behind them are gone the way `branch -D` loses them.
|
|
14432
|
+
case "update-ref": {
|
|
14433
|
+
const o = parseOptions(inv.args, "m", /* @__PURE__ */ new Set());
|
|
14434
|
+
if (o.flags.has("-d") && (o.dynamic || o.operands.some(isHistoryRef))) found(DESTRUCTIVE);
|
|
14435
|
+
break;
|
|
14436
|
+
}
|
|
14437
|
+
case "reflog": {
|
|
14438
|
+
const o = parseOptions(inv.args, "", /* @__PURE__ */ new Set());
|
|
14439
|
+
if (o.operands[0] === "expire" || o.operands[0] === "delete") found(DESTRUCTIVE);
|
|
14440
|
+
break;
|
|
14441
|
+
}
|
|
14442
|
+
case "gc": {
|
|
14443
|
+
if (inv.config.get("gc.reflogexpire") === "now") found(DESTRUCTIVE);
|
|
14444
|
+
break;
|
|
14445
|
+
}
|
|
14446
|
+
case "stash": {
|
|
14447
|
+
const o = parseOptions(inv.args, "", /* @__PURE__ */ new Set());
|
|
14448
|
+
if (o.operands[0] === "clear" || o.operands[0] === "drop") found(DESTRUCTIVE);
|
|
14449
|
+
break;
|
|
14450
|
+
}
|
|
14451
|
+
case "worktree": {
|
|
14452
|
+
const o = parseOptions(inv.args, "", /* @__PURE__ */ new Set());
|
|
14453
|
+
if (o.operands[0] === "remove" && (o.flags.has("-f") || o.flags.has("--force")))
|
|
14454
|
+
found(DESTRUCTIVE);
|
|
14455
|
+
break;
|
|
14456
|
+
}
|
|
14457
|
+
// The working tree overwritten: `restore` from another ref, a forced
|
|
14458
|
+
// checkout, or `checkout -- .` (every local change dropped). A bare
|
|
14459
|
+
// `restore .` or `checkout .` stays an ordinary undo, as pinned.
|
|
14460
|
+
case "restore": {
|
|
14461
|
+
const o = parseOptions(inv.args, "s", RESTORE_LONG_VALUE);
|
|
14462
|
+
const src = restoreSource(inv.args);
|
|
14463
|
+
const whole = o.dynamic || o.operands.some(wholeTree);
|
|
14464
|
+
if (src !== null && src !== "HEAD" && whole) found(DESTRUCTIVE);
|
|
14465
|
+
break;
|
|
14466
|
+
}
|
|
14467
|
+
case "checkout": {
|
|
14468
|
+
const o = parseOptions(inv.args, "bB", CHECKOUT_LONG_VALUE);
|
|
14469
|
+
const forced = o.flags.has("-f") || o.flags.has("--force");
|
|
14470
|
+
const dropAll = inv.args.includes("--") && o.operands.some(wholeTree);
|
|
14471
|
+
if (forced || dropAll) found(DESTRUCTIVE);
|
|
14472
|
+
break;
|
|
14473
|
+
}
|
|
13974
14474
|
default:
|
|
13975
14475
|
break;
|
|
13976
14476
|
}
|
|
13977
14477
|
return out;
|
|
13978
14478
|
}
|
|
14479
|
+
function isExcludePathspec(operand) {
|
|
14480
|
+
return /^:[!^]/.test(operand) || /^:\([^)]*\bexclude\b[^)]*\)/.test(operand);
|
|
14481
|
+
}
|
|
14482
|
+
function restoreSource(args) {
|
|
14483
|
+
for (let i = 0; i < args.length; i++) {
|
|
14484
|
+
const w = args[i];
|
|
14485
|
+
if (w === null) continue;
|
|
14486
|
+
if (w.startsWith("--source=")) return w.slice("--source=".length);
|
|
14487
|
+
if (w === "--source" || w === "-s") return args[i + 1] ?? null;
|
|
14488
|
+
if (/^-s./.test(w)) return w.slice(2);
|
|
14489
|
+
}
|
|
14490
|
+
return null;
|
|
14491
|
+
}
|
|
14492
|
+
function isHistoryRef(ref) {
|
|
14493
|
+
return /^refs\/(heads|stash)(\/|$)/.test(ref);
|
|
14494
|
+
}
|
|
14495
|
+
var RESTORE_LONG_VALUE = /* @__PURE__ */ new Set(["--source", "--pathspec-from-file"]);
|
|
14496
|
+
var CHECKOUT_LONG_VALUE = /* @__PURE__ */ new Set(["--pathspec-from-file", "--orphan", "--conflict"]);
|
|
13979
14497
|
var HOOKS_BYPASS = {
|
|
13980
14498
|
checkId: "commands.git-hooks-bypass",
|
|
13981
14499
|
ruleName: "review-git-hooks-bypass",
|
|
@@ -14042,6 +14560,7 @@ function hooksBypass(inv) {
|
|
|
14042
14560
|
const o = parseOptions(inv.args, "mFCcut", COMMIT_LONG_VALUE);
|
|
14043
14561
|
return o.flags.has("-n") || o.flags.has("--no-verify");
|
|
14044
14562
|
}
|
|
14563
|
+
if (sub === "commit-tree") return true;
|
|
14045
14564
|
if (sub !== void 0 && NO_VERIFY_SUBS.has(sub)) {
|
|
14046
14565
|
return inv.args.some((a) => a === "--no-verify");
|
|
14047
14566
|
}
|
|
@@ -14094,7 +14613,20 @@ function configWritesHooksPath(args) {
|
|
|
14094
14613
|
return write;
|
|
14095
14614
|
}
|
|
14096
14615
|
function isHookPath(word) {
|
|
14097
|
-
return /(^|[\\/])(\.git[\\/]hooks|\.husky)([\\/]|$)/.test(word);
|
|
14616
|
+
return /(^|[\\/])(\.git[\\/]hooks|\.husky|\.githooks)([\\/]|$)/.test(word);
|
|
14617
|
+
}
|
|
14618
|
+
function isLiveHookFile(word) {
|
|
14619
|
+
if (!isHookPath(word)) return false;
|
|
14620
|
+
const m = /(^|[\\/])(\.git[\\/]hooks|\.husky|\.githooks)(?:[\\/](.*))?$/.exec(word);
|
|
14621
|
+
if (!m) return false;
|
|
14622
|
+
const rest = m[3] ?? "";
|
|
14623
|
+
if (rest === "" || rest === "_") return true;
|
|
14624
|
+
const leaf = rest.replace(/^_[\\/]/, "");
|
|
14625
|
+
return /^[a-z-]+$/.test(leaf);
|
|
14626
|
+
}
|
|
14627
|
+
function hookBodyIsEmpty(text) {
|
|
14628
|
+
const lines = text.split(/\r?\n/).map((l) => l.trim()).filter((l) => l !== "" && !l.startsWith("#"));
|
|
14629
|
+
return lines.every((l) => /^(exit(\s+0)?|true|:|set\s+-[a-zA-Z]+|set\s+-o\s+\w+)$/.test(l));
|
|
14098
14630
|
}
|
|
14099
14631
|
var CHMOD_OPTION_RE = /^-[RvcfHLP]+$/;
|
|
14100
14632
|
function modeRemovesExecute(mode) {
|
|
@@ -14104,6 +14636,23 @@ function modeRemovesExecute(mode) {
|
|
|
14104
14636
|
}
|
|
14105
14637
|
return mode.split(",").some((part) => /^[ugoa]*-[rwst]*x/.test(part));
|
|
14106
14638
|
}
|
|
14639
|
+
function redirOpIsAppend(redir) {
|
|
14640
|
+
return redir?.Op === appendOp();
|
|
14641
|
+
}
|
|
14642
|
+
var _appendOp = null;
|
|
14643
|
+
function appendOp() {
|
|
14644
|
+
if (_appendOp !== null) return _appendOp;
|
|
14645
|
+
try {
|
|
14646
|
+
const f = parseShared("echo x >> y");
|
|
14647
|
+
_appendOp = typeof f === "symbol" ? -1 : f.Stmts[0].Redirs[0].Op;
|
|
14648
|
+
} catch {
|
|
14649
|
+
_appendOp = -1;
|
|
14650
|
+
}
|
|
14651
|
+
return _appendOp;
|
|
14652
|
+
}
|
|
14653
|
+
function hooksBypassed(shown) {
|
|
14654
|
+
return { ...HOOKS_BYPASS, shown, reason: `${HOOKS_BYPASS.reason}: ${shown}` };
|
|
14655
|
+
}
|
|
14107
14656
|
function chmodDisarmsHook(args, shown) {
|
|
14108
14657
|
let i = 0;
|
|
14109
14658
|
while (i < args.length) {
|
|
@@ -14154,6 +14703,7 @@ function stagesEverything(inv) {
|
|
|
14154
14703
|
const sub = inv.sub?.toLowerCase();
|
|
14155
14704
|
const prefix = chdirPrefix(inv);
|
|
14156
14705
|
const judge = (operands2) => {
|
|
14706
|
+
if (operands2.length > 0 && operands2.every(isExcludePathspec)) return {};
|
|
14157
14707
|
let conditional = false;
|
|
14158
14708
|
for (const operand of operands2) {
|
|
14159
14709
|
if (!wholeTree(operand)) continue;
|
|
@@ -14257,9 +14807,9 @@ var INSTRUCTION_NAMES = /* @__PURE__ */ new Set([
|
|
|
14257
14807
|
var SETTINGS_RE = /\/(?:\.claude\/settings(?:\.local)?\.json|\.gemini\/settings\.json|\.codex\/hooks\.json|\.cursor\/hooks\.json)$/i;
|
|
14258
14808
|
function agentFileKind(p) {
|
|
14259
14809
|
const lower2 = p.toLowerCase();
|
|
14260
|
-
const
|
|
14261
|
-
if (INSTRUCTION_NAMES.has(
|
|
14262
|
-
if (
|
|
14810
|
+
const base3 = lower2.slice(lower2.lastIndexOf("/") + 1);
|
|
14811
|
+
if (INSTRUCTION_NAMES.has(base3)) return "instructions";
|
|
14812
|
+
if (base3 === "copilot-instructions.md" && lower2.endsWith("/.github/" + base3))
|
|
14263
14813
|
return "instructions";
|
|
14264
14814
|
if (/\/\.cursor\/rules(?:\/|$)/.test(lower2)) return "instructions";
|
|
14265
14815
|
if (/\/\.claude\/projects\/[^/]+\/memory(?:\/|$)/.test(lower2)) return "memory";
|
|
@@ -14429,7 +14979,7 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
|
|
|
14429
14979
|
skills: "agent skill",
|
|
14430
14980
|
settings: "agent settings"
|
|
14431
14981
|
};
|
|
14432
|
-
const
|
|
14982
|
+
const base3 = `${kindLabel[kind]} written: ${access.path}`;
|
|
14433
14983
|
if (!signal && !every) {
|
|
14434
14984
|
return {
|
|
14435
14985
|
decision: "allow",
|
|
@@ -14439,14 +14989,14 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
|
|
|
14439
14989
|
path: access.path,
|
|
14440
14990
|
operation: access.operation,
|
|
14441
14991
|
kind,
|
|
14442
|
-
reason:
|
|
14992
|
+
reason: base3,
|
|
14443
14993
|
ruleDescription: "The AI writes to a file every later agent session loads as instructions.",
|
|
14444
|
-
blockedByLabel: `Node9 Files: ${
|
|
14994
|
+
blockedByLabel: `Node9 Files: ${base3}`,
|
|
14445
14995
|
tier: 2
|
|
14446
14996
|
};
|
|
14447
14997
|
}
|
|
14448
14998
|
const ruleName = signal === "content" ? "review-agent-file-content" : signal === "hooks" ? "review-agent-hooks-change" : "review-agent-file-write";
|
|
14449
|
-
const reason = signal ? `${
|
|
14999
|
+
const reason = signal ? `${base3} (${detail})` : base3;
|
|
14450
15000
|
const description = signal === "content" ? "The AI writes an instruction into a file every later agent session loads: to hide something from you, to skip approvals or the guard, or to read or send a secret. It would persist past this session; confirm it is yours." : signal === "hooks" ? "The AI changes the hooks in the agent's settings. Hooks are how node9 and your other checks run before each tool call; a change here can disarm them." : "The AI writes to a file every later agent session loads as instructions (CLAUDE.md, AGENTS.md, memory, agents, commands). Confirm the change is yours.";
|
|
14451
15001
|
return {
|
|
14452
15002
|
decision: value === "log" ? "allow" : value,
|
|
@@ -14498,7 +15048,7 @@ var PRESCREEN_RE = /\/dev\/(?:tcp|udp)|\b(?:nc|ncat|netcat|telnet|socat|s_client
|
|
|
14498
15048
|
var MAX_PAYLOAD_DEPTH3 = 4;
|
|
14499
15049
|
var CACHE_MAX2 = 1e3;
|
|
14500
15050
|
var cache2 = /* @__PURE__ */ new Map();
|
|
14501
|
-
function
|
|
15051
|
+
function isPipeOp2(op) {
|
|
14502
15052
|
return !isListOp(op);
|
|
14503
15053
|
}
|
|
14504
15054
|
var dupInOp = null;
|
|
@@ -14750,7 +15300,7 @@ var OutboundWalk = class {
|
|
|
14750
15300
|
this.visitStmt(n, depth);
|
|
14751
15301
|
return true;
|
|
14752
15302
|
}
|
|
14753
|
-
if (type === "BinaryCmd" &&
|
|
15303
|
+
if (type === "BinaryCmd" && isPipeOp2(n.Op)) {
|
|
14754
15304
|
this.visitPipeline(n);
|
|
14755
15305
|
return true;
|
|
14756
15306
|
}
|
|
@@ -14851,7 +15401,7 @@ var OutboundWalk = class {
|
|
|
14851
15401
|
const stages = [];
|
|
14852
15402
|
const flatten = (s) => {
|
|
14853
15403
|
const c = s?.Cmd;
|
|
14854
|
-
if (c && c.kind === "BinaryCmd" &&
|
|
15404
|
+
if (c && c.kind === "BinaryCmd" && isPipeOp2(c.Op)) {
|
|
14855
15405
|
flatten(c.X);
|
|
14856
15406
|
flatten(c.Y);
|
|
14857
15407
|
} else stages.push(s);
|
|
@@ -17166,6 +17716,175 @@ function scanArgumentSecrets(args) {
|
|
|
17166
17716
|
} : null;
|
|
17167
17717
|
}
|
|
17168
17718
|
|
|
17719
|
+
// src/shell/node9-disarm.ts
|
|
17720
|
+
var RULE_NAME2 = "review-node9-disarm";
|
|
17721
|
+
var DESCRIPTION = "The AI wants to stop node9, remove it, or change its own files. These are your commands to run, not the agent's: with the daemon stopped the outside-content and taint checks are off.";
|
|
17722
|
+
var DAEMON_CMDLINES = [
|
|
17723
|
+
"node /usr/lib/node_modules/@node9/proxy/dist/cli.js daemon start",
|
|
17724
|
+
"node9 daemon start"
|
|
17725
|
+
];
|
|
17726
|
+
var DAEMON_NAMES = ["node", "node9"];
|
|
17727
|
+
var KILLALL_NAMES = /* @__PURE__ */ new Set(["node", "node9", "node.exe", "node9.exe"]);
|
|
17728
|
+
var STOP_SYSTEMCTL = /* @__PURE__ */ new Set(["stop", "disable", "mask", "kill"]);
|
|
17729
|
+
var STOP_LAUNCHCTL = /* @__PURE__ */ new Set(["unload", "bootout", "remove", "stop", "kill", "disable"]);
|
|
17730
|
+
var PKILL_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
17731
|
+
"-u",
|
|
17732
|
+
"-U",
|
|
17733
|
+
"-g",
|
|
17734
|
+
"-G",
|
|
17735
|
+
"-P",
|
|
17736
|
+
"-s",
|
|
17737
|
+
"-t",
|
|
17738
|
+
"-F",
|
|
17739
|
+
"--signal",
|
|
17740
|
+
"--euid",
|
|
17741
|
+
"--uid",
|
|
17742
|
+
"--pgroup",
|
|
17743
|
+
"--group",
|
|
17744
|
+
"--parent",
|
|
17745
|
+
"--session",
|
|
17746
|
+
"--terminal",
|
|
17747
|
+
"--pidfile",
|
|
17748
|
+
"--ns",
|
|
17749
|
+
"--nslist"
|
|
17750
|
+
]);
|
|
17751
|
+
var NAME_PRESCREEN_RE = /node9|kill|systemctl|launchctl|daemon/i;
|
|
17752
|
+
function patternSelects(pattern, targets) {
|
|
17753
|
+
const pieces = pattern.toLowerCase().split(/[\\^$.*+?()[\]{}|]+/).filter(Boolean);
|
|
17754
|
+
if (pieces.length === 0) return false;
|
|
17755
|
+
return targets.some((t) => pieces.every((p) => t.includes(p)));
|
|
17756
|
+
}
|
|
17757
|
+
function sourceText(bytes, pos, end) {
|
|
17758
|
+
if (typeof pos !== "number" || typeof end !== "number" || pos < 0 || end < pos) return "";
|
|
17759
|
+
return new TextDecoder().decode(bytes.subarray(pos, end));
|
|
17760
|
+
}
|
|
17761
|
+
var base2 = (w) => (w ?? "").split(/[\\/]/).pop()?.toLowerCase() ?? "";
|
|
17762
|
+
function nextOperand(words, from) {
|
|
17763
|
+
for (let i = from; i < words.length; i++) {
|
|
17764
|
+
const w = words[i];
|
|
17765
|
+
if (w !== null && w.startsWith("-")) continue;
|
|
17766
|
+
return i;
|
|
17767
|
+
}
|
|
17768
|
+
return -1;
|
|
17769
|
+
}
|
|
17770
|
+
function node9Command(words, h) {
|
|
17771
|
+
const head = base2(words[h]);
|
|
17772
|
+
if (head !== "node9" && head !== "node9.cmd" && words[h] !== "@node9/proxy") return null;
|
|
17773
|
+
const s = nextOperand(words, h + 1);
|
|
17774
|
+
const sub = s < 0 ? "" : (words[s] ?? "").toLowerCase();
|
|
17775
|
+
if (sub === "uninstall") return "node9 uninstall";
|
|
17776
|
+
if (sub !== "daemon") return null;
|
|
17777
|
+
const a = nextOperand(words, s + 1);
|
|
17778
|
+
const action = a < 0 ? "" : (words[a] ?? "").toLowerCase();
|
|
17779
|
+
return action === "stop" || action === "uninstall" ? `node9 daemon ${action}` : null;
|
|
17780
|
+
}
|
|
17781
|
+
var HOME_PID_FILE_RE = /(?:^|[\s"'(=`])(?:~|\$HOME|\$\{HOME\}|\/home\/[^/\s]+|\/Users\/[^/\s]+|\/root)\/\.node9\/daemon\.pid/;
|
|
17782
|
+
function killsDaemon(words, texts, h, daemonPid) {
|
|
17783
|
+
const head = base2(words[h]);
|
|
17784
|
+
const args = words.slice(h + 1);
|
|
17785
|
+
if (head === "kill") {
|
|
17786
|
+
for (let i = 0; i < args.length; i++) {
|
|
17787
|
+
const w = args[i];
|
|
17788
|
+
if (w === "-s" || w === "-n") {
|
|
17789
|
+
i++;
|
|
17790
|
+
continue;
|
|
17791
|
+
}
|
|
17792
|
+
if (w !== null && w.startsWith("-")) continue;
|
|
17793
|
+
if (w === null) {
|
|
17794
|
+
if (HOME_PID_FILE_RE.test(texts[h + 1 + i] ?? "")) return "kill of the pid in daemon.pid";
|
|
17795
|
+
continue;
|
|
17796
|
+
}
|
|
17797
|
+
if (daemonPid !== null && w === String(daemonPid)) return `kill ${w} (the node9 daemon)`;
|
|
17798
|
+
}
|
|
17799
|
+
return null;
|
|
17800
|
+
}
|
|
17801
|
+
if (head === "pkill") {
|
|
17802
|
+
let full = false;
|
|
17803
|
+
let pattern = null;
|
|
17804
|
+
for (let i = 0; i < args.length; i++) {
|
|
17805
|
+
const w = args[i];
|
|
17806
|
+
if (w === null) continue;
|
|
17807
|
+
if (PKILL_VALUE_FLAGS.has(w)) {
|
|
17808
|
+
i++;
|
|
17809
|
+
continue;
|
|
17810
|
+
}
|
|
17811
|
+
if (w === "--full") full = true;
|
|
17812
|
+
else if (/^-[a-zA-Z]+$/.test(w) && w.includes("f")) full = true;
|
|
17813
|
+
if (w.startsWith("-")) continue;
|
|
17814
|
+
pattern = w;
|
|
17815
|
+
}
|
|
17816
|
+
if (pattern === null) return null;
|
|
17817
|
+
return patternSelects(pattern, full ? DAEMON_CMDLINES : DAEMON_NAMES) ? `pkill ${full ? "-f " : ""}${pattern}` : null;
|
|
17818
|
+
}
|
|
17819
|
+
if (head === "killall") {
|
|
17820
|
+
const regex = args.some((w) => w === "-r" || w === "--regexp");
|
|
17821
|
+
for (const w of args) {
|
|
17822
|
+
if (w === null || w.startsWith("-")) continue;
|
|
17823
|
+
if (regex ? patternSelects(w, DAEMON_NAMES) : KILLALL_NAMES.has(w.toLowerCase()))
|
|
17824
|
+
return `killall ${w}`;
|
|
17825
|
+
}
|
|
17826
|
+
return null;
|
|
17827
|
+
}
|
|
17828
|
+
if (head === "taskkill" || head === "taskkill.exe") {
|
|
17829
|
+
for (let i = 0; i < args.length - 1; i++) {
|
|
17830
|
+
const flag = (args[i] ?? "").toLowerCase();
|
|
17831
|
+
const value = (args[i + 1] ?? "").toLowerCase();
|
|
17832
|
+
if ((flag === "/im" || flag === "-im") && KILLALL_NAMES.has(value))
|
|
17833
|
+
return `taskkill /IM ${value}`;
|
|
17834
|
+
if ((flag === "/pid" || flag === "-pid") && daemonPid !== null && value === String(daemonPid))
|
|
17835
|
+
return `taskkill /PID ${value} (the node9 daemon)`;
|
|
17836
|
+
}
|
|
17837
|
+
}
|
|
17838
|
+
return null;
|
|
17839
|
+
}
|
|
17840
|
+
function stopsService(words, h) {
|
|
17841
|
+
const head = base2(words[h]);
|
|
17842
|
+
const args = words.slice(h + 1).map((w) => (w ?? "").toLowerCase());
|
|
17843
|
+
if (head === "systemctl") {
|
|
17844
|
+
const action = args.find((w) => STOP_SYSTEMCTL.has(w));
|
|
17845
|
+
if (action && args.some((w) => /^node9-daemon(\.service)?$/.test(w)))
|
|
17846
|
+
return `systemctl ${action} node9-daemon`;
|
|
17847
|
+
}
|
|
17848
|
+
if (head === "launchctl") {
|
|
17849
|
+
const action = args.find((w) => STOP_LAUNCHCTL.has(w));
|
|
17850
|
+
if (action && args.some((w) => w.includes("ai.node9.daemon")))
|
|
17851
|
+
return `launchctl ${action} ai.node9.daemon`;
|
|
17852
|
+
}
|
|
17853
|
+
return null;
|
|
17854
|
+
}
|
|
17855
|
+
function analyzeNode9Disarm(command, daemonPid = null, depth = 0) {
|
|
17856
|
+
if (depth > 3 || !NAME_PRESCREEN_RE.test(command.replace(/[\\'"]/g, ""))) return null;
|
|
17857
|
+
let shown = null;
|
|
17858
|
+
const bytes = new TextEncoder().encode(command);
|
|
17859
|
+
try {
|
|
17860
|
+
walkCommandScope(command, (node) => {
|
|
17861
|
+
if (shown !== null) return false;
|
|
17862
|
+
const n = node;
|
|
17863
|
+
if (!n || n.kind !== "CallExpr") return true;
|
|
17864
|
+
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
17865
|
+
if (words.length === 0) return true;
|
|
17866
|
+
const texts = (n.Args || []).map((a) => sourceText(bytes, a.pos, a.end));
|
|
17867
|
+
const h = unwrapCommandHead(words);
|
|
17868
|
+
shown = node9Command(words, h) ?? killsDaemon(words, texts, h, daemonPid) ?? stopsService(words, h);
|
|
17869
|
+
if (shown === null) {
|
|
17870
|
+
const payload = literalShellPayload(words, base2(words[0]));
|
|
17871
|
+
if (payload) {
|
|
17872
|
+
const inner = analyzeNode9Disarm(payload, daemonPid, depth + 1);
|
|
17873
|
+
if (inner) shown = inner.reason.replace(/^node9 switched off by the agent: /, "");
|
|
17874
|
+
}
|
|
17875
|
+
}
|
|
17876
|
+
return true;
|
|
17877
|
+
});
|
|
17878
|
+
} catch {
|
|
17879
|
+
}
|
|
17880
|
+
if (shown === null) return null;
|
|
17881
|
+
return {
|
|
17882
|
+
ruleName: RULE_NAME2,
|
|
17883
|
+
reason: `node9 switched off by the agent: ${shown}`,
|
|
17884
|
+
description: DESCRIPTION
|
|
17885
|
+
};
|
|
17886
|
+
}
|
|
17887
|
+
|
|
17169
17888
|
// src/policy/index.ts
|
|
17170
17889
|
function catalogSettings(config) {
|
|
17171
17890
|
return catalogSettingsFromConfig(config.settings, config.policy);
|
|
@@ -17332,7 +18051,7 @@ async function evaluatePolicy(config, toolName, args, context = {}, hostHooks =
|
|
|
17332
18051
|
}
|
|
17333
18052
|
async function evaluatePolicyCore(config, toolName, args, context = {}, hooks = {}) {
|
|
17334
18053
|
const { agent, cwd, activeEnvironment } = context;
|
|
17335
|
-
const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop } = hooks;
|
|
18054
|
+
const { checkProvenance, isTrustedHost, isConfiguredRegistry, isGitWorkTreeTop, daemonPid } = hooks;
|
|
17336
18055
|
const settingsView = catalogSettings(config);
|
|
17337
18056
|
const layers = inspectionLayers(config.policy);
|
|
17338
18057
|
const cv = (id) => checkValue(settingsView, id);
|
|
@@ -17517,6 +18236,23 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
17517
18236
|
else if (v && !pendingAstReview) pendingAstReview = v;
|
|
17518
18237
|
}
|
|
17519
18238
|
}
|
|
18239
|
+
if (cv("commands.node9-disarm") !== "off") {
|
|
18240
|
+
const finding = analyzeNode9Disarm(bashCommand, daemonPid?.() ?? null);
|
|
18241
|
+
if (finding) {
|
|
18242
|
+
const v = applyCheckValue(cv("commands.node9-disarm"), {
|
|
18243
|
+
decision: "review",
|
|
18244
|
+
blockedByLabel: `Node9 (AST): ${finding.ruleName}`,
|
|
18245
|
+
reason: finding.reason,
|
|
18246
|
+
tier: 2,
|
|
18247
|
+
ruleName: finding.ruleName,
|
|
18248
|
+
ruleDescription: finding.description,
|
|
18249
|
+
checkId: "commands.node9-disarm"
|
|
18250
|
+
});
|
|
18251
|
+
if (v?.logged) noteLogged(v);
|
|
18252
|
+
else if (v?.decision === "block") return v;
|
|
18253
|
+
else if (v && !pendingAstReview) pendingAstReview = v;
|
|
18254
|
+
}
|
|
18255
|
+
}
|
|
17520
18256
|
}
|
|
17521
18257
|
if (config.policy.smartRules.length > 0) {
|
|
17522
18258
|
const rmCleanupWaiver = bashCommand !== null && isRmCreatedInCommandCleanup(bashCommand);
|
|
@@ -17626,7 +18362,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
17626
18362
|
if (v?.logged) noteLogged(v);
|
|
17627
18363
|
else if (v) candidates.push(v);
|
|
17628
18364
|
};
|
|
17629
|
-
const inline = reviewsEveryInline(config.settings.mode) ? detectInlineExec(shellCommand) ? void 0 : null : inlineExecReview(shellCommand);
|
|
18365
|
+
const inline = reviewsEveryInline(config.settings.mode) ? detectInlineExec(shellCommand) ? void 0 : null : inlineExecReview(shellCommand, config.policy.jailPaths);
|
|
17630
18366
|
if (inline !== null) {
|
|
17631
18367
|
consider("commands.inline-exec", {
|
|
17632
18368
|
decision: "review",
|
|
@@ -18108,12 +18844,12 @@ function hasRoutingNumber(text) {
|
|
|
18108
18844
|
return false;
|
|
18109
18845
|
}
|
|
18110
18846
|
var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
|
|
18111
|
-
function* validCardRuns(text,
|
|
18112
|
-
const re = new RegExp(
|
|
18847
|
+
function* validCardRuns(text, base3, exemptFractions = true) {
|
|
18848
|
+
const re = new RegExp(base3.source, "g");
|
|
18113
18849
|
let m;
|
|
18114
18850
|
while ((m = re.exec(text)) !== null) {
|
|
18115
18851
|
const digits = m[0].replace(/\D/g, "");
|
|
18116
|
-
const fraction = exemptFractions && isDecimalFraction(text, m.index, digits.length === m[0].length);
|
|
18852
|
+
const fraction = exemptFractions && (isDecimalFraction(text, m.index, digits.length === m[0].length) || isInteriorDotNumber(m[0]));
|
|
18117
18853
|
if (!fraction && validateLuhn(digits)) {
|
|
18118
18854
|
yield { index: m.index, length: m[0].length, digits };
|
|
18119
18855
|
} else {
|
|
@@ -18122,17 +18858,17 @@ function* validCardRuns(text, base2, exemptFractions = true) {
|
|
|
18122
18858
|
}
|
|
18123
18859
|
}
|
|
18124
18860
|
function hasValidCard(text) {
|
|
18125
|
-
for (const
|
|
18126
|
-
if (!validCardRuns(text,
|
|
18861
|
+
for (const base3 of CARD_PATTERNS) {
|
|
18862
|
+
if (!validCardRuns(text, base3).next().done) return true;
|
|
18127
18863
|
}
|
|
18128
18864
|
return false;
|
|
18129
18865
|
}
|
|
18130
18866
|
function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
|
|
18131
18867
|
let out = text;
|
|
18132
|
-
for (const
|
|
18868
|
+
for (const base3 of CARD_PATTERNS) {
|
|
18133
18869
|
let res = "";
|
|
18134
18870
|
let last = 0;
|
|
18135
|
-
for (const run of validCardRuns(out,
|
|
18871
|
+
for (const run of validCardRuns(out, base3, exemptFractions)) {
|
|
18136
18872
|
res += out.slice(last, run.index) + replace(run.digits);
|
|
18137
18873
|
last = run.index + run.length;
|
|
18138
18874
|
}
|
|
@@ -18140,6 +18876,12 @@ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
|
|
|
18140
18876
|
}
|
|
18141
18877
|
return out;
|
|
18142
18878
|
}
|
|
18879
|
+
function isInteriorDotNumber(run) {
|
|
18880
|
+
const first = run.indexOf(".");
|
|
18881
|
+
if (first <= 0 || first === run.length - 1) return false;
|
|
18882
|
+
if (run.indexOf(".", first + 1) !== -1) return false;
|
|
18883
|
+
return !/[-\s]/.test(run);
|
|
18884
|
+
}
|
|
18143
18885
|
function isDecimalFraction(text, index, unseparated) {
|
|
18144
18886
|
if (!unseparated) return false;
|
|
18145
18887
|
const sep = text[index - 1];
|
|
@@ -18415,9 +19157,9 @@ function maskLeaf(value, key, depth) {
|
|
|
18415
19157
|
const used = /* @__PURE__ */ new Set();
|
|
18416
19158
|
return Object.fromEntries(
|
|
18417
19159
|
Object.entries(value).map(([k, v]) => {
|
|
18418
|
-
const
|
|
18419
|
-
let name =
|
|
18420
|
-
for (let n = 2; used.has(name); n++) name = `${
|
|
19160
|
+
const base3 = maskPersonalData(k);
|
|
19161
|
+
let name = base3;
|
|
19162
|
+
for (let n = 2; used.has(name); n++) name = `${base3}#${n}`;
|
|
18421
19163
|
used.add(name);
|
|
18422
19164
|
return [name, maskLeaf(v, k, depth + 1)];
|
|
18423
19165
|
})
|
|
@@ -19465,8 +20207,8 @@ function matchCanaryArgs(args, values) {
|
|
|
19465
20207
|
|
|
19466
20208
|
// src/scan/canonical.ts
|
|
19467
20209
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
19468
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
19469
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20210
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v38";
|
|
20211
|
+
var CANONICAL_EXTRACTOR_HASH = "2d3dfcccff2c2f65";
|
|
19470
20212
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
19471
20213
|
function extractCanonicalFindings(call, ctx) {
|
|
19472
20214
|
const out = [];
|
|
@@ -20046,6 +20788,7 @@ export {
|
|
|
20046
20788
|
gitInvocations,
|
|
20047
20789
|
gitRepoPath,
|
|
20048
20790
|
hashDestination,
|
|
20791
|
+
holdsSendsWithoutDaemon,
|
|
20049
20792
|
hostMatches,
|
|
20050
20793
|
incompleteFileVerdict,
|
|
20051
20794
|
inlineExecDescription,
|