@node9/policy-engine 2.50.0 → 2.51.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 +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +558 -26
- package/dist/index.mjs +558 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5677,9 +5677,15 @@ function detectDangerousShellExec(command) {
|
|
|
5677
5677
|
if (f === PARSE_FAIL) return null;
|
|
5678
5678
|
let result = null;
|
|
5679
5679
|
const assigned = assignedNames(f);
|
|
5680
|
-
|
|
5680
|
+
const known = plainlyNamedPrograms(f);
|
|
5681
|
+
const calledByName = literallyCalledFunctions(f);
|
|
5682
|
+
const bodies = [];
|
|
5683
|
+
const inBody = (pos) => bodies.some(([a, b]) => pos >= a && pos < b);
|
|
5684
|
+
walkWithCalls(f, (node) => {
|
|
5681
5685
|
if (!node || result === "block") return false;
|
|
5682
5686
|
const n = node;
|
|
5687
|
+
if (n.kind === "FuncDecl" && n.Body && callDepth === 0 && calledByName.has(n.Name?.Value))
|
|
5688
|
+
bodies.push([n.Body.pos, n.Body.end]);
|
|
5683
5689
|
if (n.kind === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
5684
5690
|
const call = n.Y.Cmd;
|
|
5685
5691
|
if (call && call.kind === "CallExpr") {
|
|
@@ -5703,7 +5709,8 @@ function detectDangerousShellExec(command) {
|
|
|
5703
5709
|
);
|
|
5704
5710
|
const head = unwrapCommandHead(headWords, false, true);
|
|
5705
5711
|
const lookup = headWords[0]?.toLowerCase() === "command" && headWords.slice(1).some((w) => w === "-v" || w === "-V");
|
|
5706
|
-
|
|
5712
|
+
const unboundBody = callDepth === 0 && inBody(n.pos ?? -1);
|
|
5713
|
+
if (!lookup && !unboundBody && (opaqueExecutable(args[0], assigned, known) || opaqueExecutable(args[head], assigned, known)))
|
|
5707
5714
|
result = "review";
|
|
5708
5715
|
const firstParts = args[0].Parts || [];
|
|
5709
5716
|
if (firstParts.length !== 1 || firstParts[0].kind !== "Lit") return true;
|
|
@@ -5747,6 +5754,7 @@ function lookupSubstitution(part) {
|
|
|
5747
5754
|
if (words.length === 3 && words[0] === "type" && words[1] === "-p") return words[2];
|
|
5748
5755
|
return null;
|
|
5749
5756
|
}
|
|
5757
|
+
var EMPTY_NAMES = /* @__PURE__ */ new Set();
|
|
5750
5758
|
var VARIABLE_READERS = /* @__PURE__ */ new Set([
|
|
5751
5759
|
"read",
|
|
5752
5760
|
"mapfile",
|
|
@@ -5776,11 +5784,106 @@ function assignedNames(f) {
|
|
|
5776
5784
|
});
|
|
5777
5785
|
return names;
|
|
5778
5786
|
}
|
|
5779
|
-
function
|
|
5787
|
+
function literallyCalledFunctions(f) {
|
|
5788
|
+
const declared = /* @__PURE__ */ new Set();
|
|
5789
|
+
const called = /* @__PURE__ */ new Set();
|
|
5790
|
+
walk(f, (node) => {
|
|
5791
|
+
if (!node) return false;
|
|
5792
|
+
if (node.kind === "FuncDecl" && node.Name?.Value) declared.add(node.Name.Value);
|
|
5793
|
+
if (node.kind === "CallExpr") {
|
|
5794
|
+
const head = resolveWordLiteral(node.Args?.[0]);
|
|
5795
|
+
if (head) called.add(head);
|
|
5796
|
+
}
|
|
5797
|
+
return true;
|
|
5798
|
+
});
|
|
5799
|
+
return new Set([...declared].filter((name) => called.has(name)));
|
|
5800
|
+
}
|
|
5801
|
+
var PLAIN_PROGRAM_NAME = /^[A-Za-z_][\w.+-]*$/;
|
|
5802
|
+
function plainlyNamedPrograms(f) {
|
|
5803
|
+
const values = /* @__PURE__ */ new Map();
|
|
5804
|
+
const arrays = /* @__PURE__ */ new Set();
|
|
5805
|
+
const give = (name, value) => {
|
|
5806
|
+
if (value === null || !PLAIN_PROGRAM_NAME.test(value)) {
|
|
5807
|
+
values.set(name, null);
|
|
5808
|
+
return;
|
|
5809
|
+
}
|
|
5810
|
+
const cur = values.get(name);
|
|
5811
|
+
if (cur === null) return;
|
|
5812
|
+
if (cur === void 0) values.set(name, /* @__PURE__ */ new Set([value]));
|
|
5813
|
+
else cur.add(value);
|
|
5814
|
+
};
|
|
5815
|
+
const literalOnly = (w) => {
|
|
5816
|
+
const parts = w?.Parts ?? [];
|
|
5817
|
+
if (parts.length !== 1) return null;
|
|
5818
|
+
const p = parts[0];
|
|
5819
|
+
if (p.kind === "Lit") return p.Value ?? null;
|
|
5820
|
+
if (p.kind === "ParamExp" && expansionName(p) === "FUNCNAME") return "FUNCNAME";
|
|
5821
|
+
if (p.kind === "SglQuoted" && !p.Dollar) return p.Value ?? null;
|
|
5822
|
+
if (p.kind === "DblQuoted") {
|
|
5823
|
+
const inner = p.Parts ?? [];
|
|
5824
|
+
return inner.length === 1 && inner[0].kind === "Lit" ? inner[0].Value ?? null : null;
|
|
5825
|
+
}
|
|
5826
|
+
return null;
|
|
5827
|
+
};
|
|
5828
|
+
let ifsTouched = false;
|
|
5829
|
+
walk(f, (node) => {
|
|
5830
|
+
if (!node) return false;
|
|
5831
|
+
const kind = node.kind;
|
|
5832
|
+
if (kind === "FuncDecl" && node.Name?.Value) give(node.Name.Value, node.Name.Value);
|
|
5833
|
+
if (kind === "Assign" && node.Name?.Value) {
|
|
5834
|
+
const name = node.Name.Value;
|
|
5835
|
+
if (name === "IFS") ifsTouched = true;
|
|
5836
|
+
if (node.Append) values.set(name, null);
|
|
5837
|
+
else if (node.Array) {
|
|
5838
|
+
arrays.add(name);
|
|
5839
|
+
for (const el of node.Array.Elems ?? []) give(name, literalOnly(el.Value));
|
|
5840
|
+
} else if (node.Index) {
|
|
5841
|
+
arrays.add(name);
|
|
5842
|
+
give(name, node.Value ? literalOnly(node.Value) : null);
|
|
5843
|
+
} else give(name, node.Value ? literalOnly(node.Value) : null);
|
|
5844
|
+
}
|
|
5845
|
+
if (kind === "ForClause" && node.Loop?.Name?.Value) values.set(node.Loop.Name.Value, null);
|
|
5846
|
+
if (kind === "CallExpr") {
|
|
5847
|
+
const words = (node.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
5848
|
+
if (VARIABLE_READERS.has(words[0] ?? "")) {
|
|
5849
|
+
for (const w of words.slice(1)) if (w && /^[A-Za-z_]\w*$/.test(w)) values.set(w, null);
|
|
5850
|
+
}
|
|
5851
|
+
}
|
|
5852
|
+
return true;
|
|
5853
|
+
});
|
|
5854
|
+
if (ifsTouched) return /* @__PURE__ */ new Set();
|
|
5855
|
+
const functions = /* @__PURE__ */ new Set();
|
|
5856
|
+
walk(f, (node) => {
|
|
5857
|
+
if (node && node.kind === "FuncDecl" && node.Name?.Value) functions.add(node.Name.Value);
|
|
5858
|
+
return true;
|
|
5859
|
+
});
|
|
5860
|
+
const callable = (v) => functions.has(v) || v === "FUNCNAME" || v === "true" || v === "false" || v === ":";
|
|
5861
|
+
for (const [name, vals] of values) {
|
|
5862
|
+
if (vals && ![...vals].every(callable)) values.set(name, null);
|
|
5863
|
+
}
|
|
5864
|
+
const known = /* @__PURE__ */ new Set();
|
|
5865
|
+
for (const [name, vals] of values)
|
|
5866
|
+
if (vals && (vals.size === 1 || arrays.has(name) && vals.size > 0)) known.add(name);
|
|
5867
|
+
return known;
|
|
5868
|
+
}
|
|
5869
|
+
function expansionName(part) {
|
|
5870
|
+
if (part.kind !== "ParamExp") return null;
|
|
5871
|
+
if (part.Excl || part.Length || part.Width || part.Slice || part.Repl || part.Exp) return null;
|
|
5872
|
+
return part.Param?.Value ?? null;
|
|
5873
|
+
}
|
|
5874
|
+
function executableParts(word, assigned, quoted = false, known = EMPTY_NAMES) {
|
|
5780
5875
|
return (word?.Parts ?? []).flatMap((part) => {
|
|
5781
5876
|
const kind = part.kind;
|
|
5782
|
-
if (kind === "DblQuoted") return executableParts(part, assigned, true);
|
|
5877
|
+
if (kind === "DblQuoted") return executableParts(part, assigned, true, known);
|
|
5783
5878
|
if (kind === "Lit") return [{ kind: "Lit", value: part.Value ?? "", quoted }];
|
|
5879
|
+
const name = expansionName(part);
|
|
5880
|
+
if (name !== null && (known.has(name) || name === "FUNCNAME"))
|
|
5881
|
+
return [{ kind: "Lit", value: name, quoted }];
|
|
5882
|
+
if (name !== null) {
|
|
5883
|
+
const bound = recordedExpansion(name === "@" || name === "*" ? "1" : name);
|
|
5884
|
+
if (typeof bound === "string" && PLAIN_PROGRAM_NAME.test(bound))
|
|
5885
|
+
return [{ kind: "Lit", value: bound, quoted }];
|
|
5886
|
+
}
|
|
5784
5887
|
if (kind === "SglQuoted")
|
|
5785
5888
|
return [{ kind: part.Dollar ? "Dynamic" : "Lit", value: part.Value ?? "", quoted: true }];
|
|
5786
5889
|
if (kind === "ParamExp" && isDefaultExpansion(part) && !assigned.has(part.Param?.Value)) {
|
|
@@ -5788,14 +5891,14 @@ function executableParts(word, assigned, quoted = false) {
|
|
|
5788
5891
|
if (fallback !== null) return [{ kind: "Lit", value: fallback, quoted }];
|
|
5789
5892
|
}
|
|
5790
5893
|
if (kind === "CmdSubst") {
|
|
5791
|
-
const
|
|
5792
|
-
if (
|
|
5894
|
+
const name2 = lookupSubstitution(part);
|
|
5895
|
+
if (name2 !== null) return [{ kind: "Lit", value: name2, quoted }];
|
|
5793
5896
|
}
|
|
5794
5897
|
return [{ kind: "Dynamic", value: "", quoted }];
|
|
5795
5898
|
});
|
|
5796
5899
|
}
|
|
5797
|
-
function opaqueExecutable(word, assigned) {
|
|
5798
|
-
const parts = executableParts(word, assigned);
|
|
5900
|
+
function opaqueExecutable(word, assigned, known = EMPTY_NAMES) {
|
|
5901
|
+
const parts = executableParts(word, assigned, false, known);
|
|
5799
5902
|
let lastSlash = -1;
|
|
5800
5903
|
parts.forEach((p, i) => {
|
|
5801
5904
|
if (p.kind === "Lit" && p.value.includes("/")) lastSlash = i;
|
|
@@ -6605,6 +6708,9 @@ var _listOps = null;
|
|
|
6605
6708
|
function isListOp(op) {
|
|
6606
6709
|
return listOps().has(op);
|
|
6607
6710
|
}
|
|
6711
|
+
function isPipeOp(op) {
|
|
6712
|
+
return pipeOps().has(op);
|
|
6713
|
+
}
|
|
6608
6714
|
function listOps() {
|
|
6609
6715
|
if (_listOps) return _listOps;
|
|
6610
6716
|
_listOps = new Set(
|
|
@@ -6880,6 +6986,33 @@ function isProtectedCodePath(p) {
|
|
|
6880
6986
|
if (matchSensitivePath(p) !== null) return true;
|
|
6881
6987
|
return SYSTEM_AUTH_FILES.includes(p) || SYSTEM_AUTH_DIRS.some((d) => p === d || p.startsWith(d + "/"));
|
|
6882
6988
|
}
|
|
6989
|
+
function isJailedCodePath(literal, jailPaths) {
|
|
6990
|
+
const value = trimTrailingSlashes(literal.replace(/\\/g, "/"));
|
|
6991
|
+
if (!value) return false;
|
|
6992
|
+
for (const raw of jailPaths) {
|
|
6993
|
+
const jail = trimTrailingSlashes(raw.trim().replace(/\\/g, "/"));
|
|
6994
|
+
if (!jail) continue;
|
|
6995
|
+
const home = homeTail(jail);
|
|
6996
|
+
if (home === null) {
|
|
6997
|
+
if (value === jail || value.startsWith(jail + "/")) return true;
|
|
6998
|
+
continue;
|
|
6999
|
+
}
|
|
7000
|
+
if (!home) continue;
|
|
7001
|
+
const tail = homeTail(value);
|
|
7002
|
+
if (tail !== null && (tail === home || tail.startsWith(home + "/"))) return true;
|
|
7003
|
+
}
|
|
7004
|
+
return false;
|
|
7005
|
+
}
|
|
7006
|
+
function trimTrailingSlashes(s) {
|
|
7007
|
+
let end = s.length;
|
|
7008
|
+
while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
|
|
7009
|
+
return s.slice(0, end);
|
|
7010
|
+
}
|
|
7011
|
+
function homeTail(p) {
|
|
7012
|
+
const m = /^(?:~|\$\{?HOME\}?|\/home\/[^/]+|\/Users\/[^/]+|\/root)(?:\/(.*))?$/.exec(p);
|
|
7013
|
+
if (!m) return null;
|
|
7014
|
+
return m[1] ?? "";
|
|
7015
|
+
}
|
|
6883
7016
|
function inlineExecDescription(r) {
|
|
6884
7017
|
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.";
|
|
6885
7018
|
return `${lead} Review the full script below before allowing it to execute.`;
|
|
@@ -6888,7 +7021,8 @@ function inlineExecReason(r) {
|
|
|
6888
7021
|
const who = r.interp ? `This inline ${r.interp} code` : "This inline code";
|
|
6889
7022
|
return r.evidence ? `${who} ${r.what} (${r.evidence})` : `${who} ${r.what}`;
|
|
6890
7023
|
}
|
|
6891
|
-
function inlineExecReview(command) {
|
|
7024
|
+
function inlineExecReview(command, jailPaths = []) {
|
|
7025
|
+
const isProtected = jailPaths.length === 0 ? isProtectedCodePath : (p) => isProtectedCodePath(p) || isJailedCodePath(p, jailPaths);
|
|
6892
7026
|
const calls = inlineExecCalls(command);
|
|
6893
7027
|
if (calls === PARSE_FAIL) {
|
|
6894
7028
|
return INLINE_EXEC_FALLBACK.test(command) ? { outcome: "unreadable", interp: "", what: "could not be parsed" } : null;
|
|
@@ -6911,7 +7045,7 @@ function inlineExecReview(command) {
|
|
|
6911
7045
|
what: `is ${call.interp} code, which node9 does not read`
|
|
6912
7046
|
};
|
|
6913
7047
|
} else {
|
|
6914
|
-
const judged = judgeInlineCode(language, code,
|
|
7048
|
+
const judged = judgeInlineCode(language, code, isProtected);
|
|
6915
7049
|
if (judged) finding = { ...judged, interp: call.interp };
|
|
6916
7050
|
}
|
|
6917
7051
|
if (finding?.outcome === "dangerous") return finding;
|
|
@@ -7270,6 +7404,13 @@ function recordTopLevelStmt(stmt) {
|
|
|
7270
7404
|
if (t === "DeclClause") return ASSIGNMENT_HEADS.has(stmt.Cmd.Variant?.Value ?? "");
|
|
7271
7405
|
return (stmt.Cmd.Args || []).length === 0 && (stmt.Cmd.Assigns || []).length > 0;
|
|
7272
7406
|
}
|
|
7407
|
+
var ARRAY_MARK = "array";
|
|
7408
|
+
var ARRAY_SEP = "";
|
|
7409
|
+
function arrayElements(value) {
|
|
7410
|
+
if (typeof value !== "string" || !value.startsWith(ARRAY_MARK)) return null;
|
|
7411
|
+
const body = value.slice(ARRAY_MARK.length);
|
|
7412
|
+
return body === "" ? [] : body.split(ARRAY_SEP);
|
|
7413
|
+
}
|
|
7273
7414
|
function recordAssignments(n, at) {
|
|
7274
7415
|
if (!assignmentTable) return;
|
|
7275
7416
|
const t = n.kind;
|
|
@@ -7283,7 +7424,19 @@ function recordAssignments(n, at) {
|
|
|
7283
7424
|
} else return;
|
|
7284
7425
|
for (const a of assigns) {
|
|
7285
7426
|
const name = a?.Name?.Value;
|
|
7286
|
-
if (!name
|
|
7427
|
+
if (!name) continue;
|
|
7428
|
+
if (a.Array) {
|
|
7429
|
+
const elems = (a.Array.Elems || []).map(
|
|
7430
|
+
(e) => e?.Index ? null : resolveWordLiteral(e?.Value)
|
|
7431
|
+
);
|
|
7432
|
+
const literal = elems.every((v) => v !== null);
|
|
7433
|
+
assignmentTable.set(name, {
|
|
7434
|
+
value: literal && !a.Append ? ARRAY_MARK + elems.join(ARRAY_SEP) : null,
|
|
7435
|
+
at
|
|
7436
|
+
});
|
|
7437
|
+
continue;
|
|
7438
|
+
}
|
|
7439
|
+
if (!a.Value || a.Append) continue;
|
|
7287
7440
|
assignmentTable.set(name, { value: resolveWordLiteral(a.Value), at });
|
|
7288
7441
|
}
|
|
7289
7442
|
}
|
|
@@ -7294,7 +7447,33 @@ function resolveTrivialSubst(part) {
|
|
|
7294
7447
|
const st = stmts[0];
|
|
7295
7448
|
if ((st.Redirs || []).length > 0 || st.Negated || st.Background) return void 0;
|
|
7296
7449
|
const cmd = st.Cmd;
|
|
7297
|
-
if (!cmd
|
|
7450
|
+
if (!cmd) return void 0;
|
|
7451
|
+
if (cmd.kind === "BinaryCmd" && pipeOps().has(cmd.Op)) {
|
|
7452
|
+
const left = cmd.X?.Cmd;
|
|
7453
|
+
const right = cmd.Y?.Cmd;
|
|
7454
|
+
if (!left || !right || left.kind !== "CallExpr" || right.kind !== "CallExpr") return void 0;
|
|
7455
|
+
if ((cmd.X.Redirs || []).length > 0 || (cmd.Y.Redirs || []).length > 0) return void 0;
|
|
7456
|
+
const input = trivialCallOutput(left);
|
|
7457
|
+
if (input === void 0) return void 0;
|
|
7458
|
+
const filter = (right.Args || []).map((a) => resolveWordLiteral(a));
|
|
7459
|
+
if (filter.some((w) => w === null)) return void 0;
|
|
7460
|
+
const f = baseWord(filter[0]);
|
|
7461
|
+
const flags = filter.slice(1);
|
|
7462
|
+
if (f === "base64" && flags.length === 1 && /^(-d|-D|--decode)$/.test(flags[0])) {
|
|
7463
|
+
try {
|
|
7464
|
+
const out = Buffer.from(input, "base64").toString("utf8");
|
|
7465
|
+
return /^[\x20-\x7e]*$/.test(out) ? out : void 0;
|
|
7466
|
+
} catch {
|
|
7467
|
+
return void 0;
|
|
7468
|
+
}
|
|
7469
|
+
}
|
|
7470
|
+
if (f === "rev" && flags.length === 0) return [...input].reverse().join("");
|
|
7471
|
+
return void 0;
|
|
7472
|
+
}
|
|
7473
|
+
if (cmd.kind !== "CallExpr") return void 0;
|
|
7474
|
+
return trivialCallOutput(cmd);
|
|
7475
|
+
}
|
|
7476
|
+
function trivialCallOutput(cmd) {
|
|
7298
7477
|
if ((cmd.Assigns || []).length > 0) return void 0;
|
|
7299
7478
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
7300
7479
|
if (words.length === 0 || words.some((w) => w === null)) return void 0;
|
|
@@ -7306,9 +7485,16 @@ function resolveTrivialSubst(part) {
|
|
|
7306
7485
|
return rest.slice(i).join(" ");
|
|
7307
7486
|
}
|
|
7308
7487
|
if (head === "printf") {
|
|
7488
|
+
if (rest.length === 1 && /^(?:\\(?:[0-7]{1,3}|x[0-9A-Fa-f]{1,2}))+$/.test(rest[0])) {
|
|
7489
|
+
return rest[0].replace(
|
|
7490
|
+
/\\(?:x([0-9A-Fa-f]{1,2})|([0-7]{1,3}))/g,
|
|
7491
|
+
(_, hex, oct) => String.fromCharCode(hex ? parseInt(hex, 16) : parseInt(oct, 8))
|
|
7492
|
+
);
|
|
7493
|
+
}
|
|
7309
7494
|
if (rest.length !== 2) return void 0;
|
|
7310
|
-
|
|
7311
|
-
return
|
|
7495
|
+
const m = /^([^%]*)%s([^%]*?)(\\n)?$/.exec(rest[0]);
|
|
7496
|
+
if (!m) return void 0;
|
|
7497
|
+
return m[1] + rest[1] + m[2];
|
|
7312
7498
|
}
|
|
7313
7499
|
return void 0;
|
|
7314
7500
|
}
|
|
@@ -7322,11 +7508,28 @@ function isPlainParam(p) {
|
|
|
7322
7508
|
if (p.kind !== "ParamExp") return false;
|
|
7323
7509
|
return !(p.Excl || p.Length || p.Width || p.Index || p.Slice || p.Repl || p.Exp);
|
|
7324
7510
|
}
|
|
7511
|
+
function indexedParam(p) {
|
|
7512
|
+
if (p.kind !== "ParamExp" || !p.Index) return null;
|
|
7513
|
+
if (p.Excl || p.Length || p.Width || p.Slice || p.Repl || p.Exp) return null;
|
|
7514
|
+
const index = resolveWordLiteral(p.Index);
|
|
7515
|
+
const name = p.Param?.Value;
|
|
7516
|
+
return name && index !== null ? { name, index } : null;
|
|
7517
|
+
}
|
|
7325
7518
|
function expandPlainParam(p) {
|
|
7326
7519
|
if (!assignmentTable) return void 0;
|
|
7520
|
+
const indexed = indexedParam(p);
|
|
7521
|
+
if (indexed) {
|
|
7522
|
+
const elems = arrayElements(recordedExpansion(indexed.name));
|
|
7523
|
+
if (elems === null) return void 0;
|
|
7524
|
+
if (indexed.index === "@" || indexed.index === "*") return elems.join(" ");
|
|
7525
|
+
return /^\d+$/.test(indexed.index) ? elems[Number(indexed.index)] ?? null : null;
|
|
7526
|
+
}
|
|
7327
7527
|
if (!isPlainParam(p)) return void 0;
|
|
7328
7528
|
const recorded = recordedExpansion(p.Param?.Value);
|
|
7329
|
-
if (recorded !== void 0)
|
|
7529
|
+
if (recorded !== void 0) {
|
|
7530
|
+
const elems = arrayElements(recorded);
|
|
7531
|
+
return elems === null ? recorded : elems[0] ?? "";
|
|
7532
|
+
}
|
|
7330
7533
|
return HOME_VARIABLES.has(p.Param?.Value) ? "~" : void 0;
|
|
7331
7534
|
}
|
|
7332
7535
|
var MAX_CALL_DEPTH2 = 4;
|
|
@@ -13764,7 +13967,22 @@ var GitWalk = class {
|
|
|
13764
13967
|
found;
|
|
13765
13968
|
/** Aliases defined earlier in this command: name -> value (null = dynamic). */
|
|
13766
13969
|
aliases = /* @__PURE__ */ new Map();
|
|
13970
|
+
/** node9Firewall#385: variables assigned a tree-top word (`scope="$PWD"`,
|
|
13971
|
+
* `root=$(git rev-parse --show-toplevel)`, `DIR=$(pwd)`), so the
|
|
13972
|
+
* variable reads as the top where it is used. */
|
|
13973
|
+
treeTopVars = /* @__PURE__ */ new Set();
|
|
13974
|
+
/** node9Firewall#385 (c): a string a script builds with `+=` from
|
|
13975
|
+
* literals (`mode=--ha; mode+=rd`). The jail's table does not follow an
|
|
13976
|
+
* append (JAIL-14a); the git rules read the built word, since a flag
|
|
13977
|
+
* spelled in two halves is still that flag. name -> value, null once a
|
|
13978
|
+
* half is unknown. */
|
|
13979
|
+
appended = /* @__PURE__ */ new Map();
|
|
13767
13980
|
payloads = /* @__PURE__ */ new Set();
|
|
13981
|
+
/** node9Firewall#385 (a): the text this command writes to each path
|
|
13982
|
+
* (`cat > /tmp/x.sh <<'SH' ... SH`, `echo '...' > f`, `>>` appends), so
|
|
13983
|
+
* a later statement that runs the path (`bash f`, `sh f`, `./f`) is
|
|
13984
|
+
* judged on what it runs. null once a write to the path is unknown. */
|
|
13985
|
+
written = /* @__PURE__ */ new Map();
|
|
13768
13986
|
/** `for NAME in a b c`: the literal items, or null when one is dynamic. */
|
|
13769
13987
|
loopVars = /* @__PURE__ */ new Map();
|
|
13770
13988
|
/** Walk one command string. Returns false when it did not parse. */
|
|
@@ -13783,6 +14001,25 @@ var GitWalk = class {
|
|
|
13783
14001
|
const type = n.kind;
|
|
13784
14002
|
if (type === "Stmt") {
|
|
13785
14003
|
this.visitHeredocShell(n, depth);
|
|
14004
|
+
this.visitPipeline(n, depth);
|
|
14005
|
+
this.visitHookWrite(n);
|
|
14006
|
+
this.recordScriptWrite(n);
|
|
14007
|
+
this.visitWrittenScript(n, depth);
|
|
14008
|
+
return true;
|
|
14009
|
+
}
|
|
14010
|
+
if (type === "Assign" && n.Name?.Value && n.Value) {
|
|
14011
|
+
const name = n.Name.Value;
|
|
14012
|
+
if (n.Append) {
|
|
14013
|
+
const prev = this.appended.has(name) ? this.appended.get(name) : resolveWordLiteral(n.Value) === null ? null : void 0;
|
|
14014
|
+
const base2 = prev === void 0 ? recordedExpansion(name) : prev;
|
|
14015
|
+
const piece = resolveWordLiteral(n.Value);
|
|
14016
|
+
this.appended.set(name, typeof base2 === "string" && piece !== null ? base2 + piece : null);
|
|
14017
|
+
this.treeTopVars.delete(name);
|
|
14018
|
+
return true;
|
|
14019
|
+
}
|
|
14020
|
+
this.appended.delete(name);
|
|
14021
|
+
if (treeTopWord(n.Value, this.treeTopVars)) this.treeTopVars.add(name);
|
|
14022
|
+
else this.treeTopVars.delete(name);
|
|
13786
14023
|
return true;
|
|
13787
14024
|
}
|
|
13788
14025
|
if (type === "ForClause") {
|
|
@@ -13811,13 +14048,13 @@ var GitWalk = class {
|
|
|
13811
14048
|
const param = plainParamName(rawArgs[loopArg]);
|
|
13812
14049
|
for (const item of this.loopVars.get(param.name)) {
|
|
13813
14050
|
const words2 = rawArgs.flatMap(
|
|
13814
|
-
(a, i) => i === loopArg ? param.quoted ? [item] : splitFields(item) : resolveGitWords(a)
|
|
14051
|
+
(a, i) => i === loopArg ? param.quoted ? [item] : splitFields(item) : resolveGitWords(a, this.treeTopVars, this.appended)
|
|
13815
14052
|
);
|
|
13816
14053
|
this.visitWords(words2, new Map(prefixEnv), depth, false);
|
|
13817
14054
|
}
|
|
13818
14055
|
return true;
|
|
13819
14056
|
}
|
|
13820
|
-
const words = rawArgs.flatMap((a) => resolveGitWords(a));
|
|
14057
|
+
const words = rawArgs.flatMap((a) => resolveGitWords(a, this.treeTopVars, this.appended));
|
|
13821
14058
|
this.visitWords(words, prefixEnv, depth, false);
|
|
13822
14059
|
return true;
|
|
13823
14060
|
}
|
|
@@ -13842,6 +14079,23 @@ var GitWalk = class {
|
|
|
13842
14079
|
if (f) this.found(f);
|
|
13843
14080
|
return;
|
|
13844
14081
|
}
|
|
14082
|
+
if (headWord === "rm" || headWord === "unlink") {
|
|
14083
|
+
if (words.slice(head + 1).some((w) => w !== null && isLiveHookFile(w)))
|
|
14084
|
+
this.found(hooksBypassed(shownOf(words)));
|
|
14085
|
+
return;
|
|
14086
|
+
}
|
|
14087
|
+
if (headWord === "mv") {
|
|
14088
|
+
const operands2 = words.slice(head + 1).filter((w) => w === null || !w.startsWith("-"));
|
|
14089
|
+
const src = operands2[0];
|
|
14090
|
+
if (typeof src === "string" && isLiveHookFile(src)) this.found(hooksBypassed(shownOf(words)));
|
|
14091
|
+
return;
|
|
14092
|
+
}
|
|
14093
|
+
if (headWord === "perl") {
|
|
14094
|
+
const code = words.slice(head + 1).find((w) => w !== null && /\brename\b/.test(w));
|
|
14095
|
+
const m = code ? /rename\s*\(?\s*q[qw]?\s*[(\[{<'"]([^)\]}>'"]+)/.exec(code) : null;
|
|
14096
|
+
if (m && isLiveHookFile(m[1])) this.found(hooksBypassed(shownOf(words)));
|
|
14097
|
+
return;
|
|
14098
|
+
}
|
|
13845
14099
|
if (depth < MAX_PAYLOAD_DEPTH2) {
|
|
13846
14100
|
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
13847
14101
|
if (payload !== null) this.runPayload(payload, depth);
|
|
@@ -13852,6 +14106,127 @@ var GitWalk = class {
|
|
|
13852
14106
|
this.payloads.add(payload);
|
|
13853
14107
|
this.run(payload, depth + 1);
|
|
13854
14108
|
}
|
|
14109
|
+
/**
|
|
14110
|
+
* node9Firewall#385: a pipeline whose last stage reads its pathspec from
|
|
14111
|
+
* stdin (`git add --pathspec-from-file=-`) or runs git over the names it
|
|
14112
|
+
* is fed (`xargs -0 git add --`), with a producer that is one literal
|
|
14113
|
+
* (`git rev-parse --show-toplevel`, `printf '%s\0' .`): the literal is
|
|
14114
|
+
* the operand, and the call is judged with it.
|
|
14115
|
+
*/
|
|
14116
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14117
|
+
visitPipeline(stmt, depth) {
|
|
14118
|
+
const cmd = stmt.Cmd;
|
|
14119
|
+
if (!cmd || cmd.kind !== "BinaryCmd" || !isPipeOp(cmd.Op)) return;
|
|
14120
|
+
const stages = [];
|
|
14121
|
+
let cur = cmd;
|
|
14122
|
+
while (cur?.kind === "BinaryCmd" && isPipeOp(cur.Op)) {
|
|
14123
|
+
stages.unshift(cur.Y);
|
|
14124
|
+
const left = cur.X;
|
|
14125
|
+
if (left?.Cmd?.kind === "BinaryCmd" && isPipeOp(left.Cmd.Op)) cur = left.Cmd;
|
|
14126
|
+
else {
|
|
14127
|
+
stages.unshift(left);
|
|
14128
|
+
break;
|
|
14129
|
+
}
|
|
14130
|
+
}
|
|
14131
|
+
if (stages.length < 2) return;
|
|
14132
|
+
const producer = stages[stages.length - 2]?.Cmd;
|
|
14133
|
+
const consumer = stages[stages.length - 1]?.Cmd;
|
|
14134
|
+
if (!producer || !consumer || producer.kind !== "CallExpr" || consumer.kind !== "CallExpr")
|
|
14135
|
+
return;
|
|
14136
|
+
const fed = producedLiteral(producer);
|
|
14137
|
+
if (fed === null) return;
|
|
14138
|
+
const words = (consumer.Args || []).flatMap(
|
|
14139
|
+
(a) => resolveGitWords(a, this.treeTopVars, this.appended)
|
|
14140
|
+
);
|
|
14141
|
+
const head = unwrapCommandHead(words);
|
|
14142
|
+
const viaXargs = words.slice(0, head).some((w) => baseWord(w) === "xargs");
|
|
14143
|
+
const fromFile = words.findIndex(
|
|
14144
|
+
(w) => w === "--pathspec-from-file=-" || w === "--pathspec-from-file"
|
|
14145
|
+
);
|
|
14146
|
+
if (!viaXargs && fromFile < 0) return;
|
|
14147
|
+
let fedWords;
|
|
14148
|
+
if (fromFile >= 0) {
|
|
14149
|
+
fedWords = words.filter(
|
|
14150
|
+
(w, k) => !(k === fromFile || w === "-" && words[k - 1] === "--pathspec-from-file")
|
|
14151
|
+
);
|
|
14152
|
+
fedWords.push(fed);
|
|
14153
|
+
} else fedWords = [...words, fed];
|
|
14154
|
+
this.visitWords(fedWords, /* @__PURE__ */ new Map(), depth, false);
|
|
14155
|
+
}
|
|
14156
|
+
/**
|
|
14157
|
+
* node9Firewall#385 (e): a hook file written with a body that checks
|
|
14158
|
+
* nothing (`cat > .githooks/pre-commit <<'SH' exit 0 SH`, `echo 'exit 0'
|
|
14159
|
+
* > .git/hooks/pre-push`, `: > .githooks/pre-commit`). A real body (a
|
|
14160
|
+
* test, a linter) is ordinary work on the hooks.
|
|
14161
|
+
*/
|
|
14162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14163
|
+
visitHookWrite(stmt) {
|
|
14164
|
+
const cmd = stmt.Cmd;
|
|
14165
|
+
if (!cmd || cmd.kind !== "CallExpr") return;
|
|
14166
|
+
const redirs = stmt.Redirs || [];
|
|
14167
|
+
const target = redirs.find((r) => r?.Word && !r.Hdoc && (r.N == null || r.N.Value === "1"));
|
|
14168
|
+
if (!target) return;
|
|
14169
|
+
const path = resolveWordLiteral(target.Word);
|
|
14170
|
+
if (path === null || !isLiveHookFile(path)) return;
|
|
14171
|
+
const hdoc = redirs.find((r) => r?.Hdoc);
|
|
14172
|
+
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
14173
|
+
const head = baseWord(words[0]);
|
|
14174
|
+
let body = null;
|
|
14175
|
+
if (hdoc) body = resolveWordLiteral(hdoc.Hdoc);
|
|
14176
|
+
else if (head === ":" || head === "true" || words.length === 0) body = "";
|
|
14177
|
+
else if (head === "echo" || head === "printf") {
|
|
14178
|
+
const rest = words.slice(1);
|
|
14179
|
+
body = rest.some((w) => w === null) ? null : rest.filter((w) => !/^-[neE]+$/.test(w)).join(" ");
|
|
14180
|
+
if (body !== null) body = body.replace(/\\n/g, "\n");
|
|
14181
|
+
}
|
|
14182
|
+
if (body !== null && hookBodyIsEmpty(body)) this.found(hooksBypassed(shownOf(words)));
|
|
14183
|
+
}
|
|
14184
|
+
/** A statement that writes a literal text to a path, by redirect. */
|
|
14185
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14186
|
+
recordScriptWrite(stmt) {
|
|
14187
|
+
const cmd = stmt.Cmd;
|
|
14188
|
+
if (!cmd || cmd.kind !== "CallExpr") return;
|
|
14189
|
+
const redirs = stmt.Redirs || [];
|
|
14190
|
+
const target = redirs.find((r) => r?.Word && !r.Hdoc && (r.N == null || r.N.Value === "1"));
|
|
14191
|
+
if (!target) return;
|
|
14192
|
+
const path = resolveWordLiteral(target.Word);
|
|
14193
|
+
if (path === null) return;
|
|
14194
|
+
const append = /^>>/.test(target.Op?.toString() ?? "") || redirOpIsAppend(target);
|
|
14195
|
+
const hdoc = redirs.find((r) => r?.Hdoc);
|
|
14196
|
+
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
14197
|
+
const head = baseWord(words[0]);
|
|
14198
|
+
let text = null;
|
|
14199
|
+
if (hdoc && (head === "cat" || head === "tee")) text = resolveWordLiteral(hdoc.Hdoc);
|
|
14200
|
+
else if (head === "echo" || head === "printf") {
|
|
14201
|
+
const rest = words.slice(1);
|
|
14202
|
+
text = rest.some((w) => w === null) ? null : rest.filter((w) => !/^-[neE]+$/.test(w)).join(" ");
|
|
14203
|
+
if (text !== null && head === "printf") text = text.replace(/\\n/g, "\n");
|
|
14204
|
+
} else return;
|
|
14205
|
+
const prev = this.written.get(path);
|
|
14206
|
+
if (text === null || append && prev === null) this.written.set(path, null);
|
|
14207
|
+
else this.written.set(path, append && typeof prev === "string" ? `${prev}
|
|
14208
|
+
${text}` : text);
|
|
14209
|
+
}
|
|
14210
|
+
/** A statement that runs a path this command wrote: the text is the script. */
|
|
14211
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14212
|
+
visitWrittenScript(stmt, depth) {
|
|
14213
|
+
const cmd = stmt.Cmd;
|
|
14214
|
+
if (!cmd || cmd.kind !== "CallExpr" || this.written.size === 0 || depth >= MAX_PAYLOAD_DEPTH2)
|
|
14215
|
+
return;
|
|
14216
|
+
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
14217
|
+
const head = unwrapCommandHead(words);
|
|
14218
|
+
const name = baseWord(words[head]);
|
|
14219
|
+
let ran = null;
|
|
14220
|
+
if (PAYLOAD_SHELLS.has(name) && name !== "eval") {
|
|
14221
|
+
const operand = words.slice(head + 1).find((w) => w === null || !w.startsWith("-"));
|
|
14222
|
+
if (typeof operand === "string") ran = operand;
|
|
14223
|
+
} else if (typeof words[head] === "string" && this.written.has(words[head])) {
|
|
14224
|
+
ran = words[head];
|
|
14225
|
+
}
|
|
14226
|
+
if (ran === null) return;
|
|
14227
|
+
const text = this.written.get(ran);
|
|
14228
|
+
if (typeof text === "string") this.runPayload(text, depth);
|
|
14229
|
+
}
|
|
13855
14230
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13856
14231
|
visitHeredocShell(stmt, depth) {
|
|
13857
14232
|
const cmd = stmt.Cmd;
|
|
@@ -14040,7 +14415,61 @@ function dynamicOptionWord(word) {
|
|
|
14040
14415
|
if (/^--[a-z-]+=/.test(prefix) || /^-[cC]/.test(prefix)) return `${prefix}$\u2026`;
|
|
14041
14416
|
return null;
|
|
14042
14417
|
}
|
|
14043
|
-
|
|
14418
|
+
var NO_VARS = /* @__PURE__ */ new Set();
|
|
14419
|
+
var NO_APPENDS = /* @__PURE__ */ new Map();
|
|
14420
|
+
function arrayExpansionWords(word) {
|
|
14421
|
+
let parts = word?.Parts || [];
|
|
14422
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
14423
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp" || !parts[0].Index) return null;
|
|
14424
|
+
const index = resolveWordLiteral(parts[0].Index);
|
|
14425
|
+
if (index !== "@" && index !== "*") return null;
|
|
14426
|
+
const elems = arrayElements(recordedExpansion(parts[0].Param?.Value));
|
|
14427
|
+
return elems;
|
|
14428
|
+
}
|
|
14429
|
+
function producedLiteral(call) {
|
|
14430
|
+
if ((call.Assigns || []).length > 0) return null;
|
|
14431
|
+
const words = (call.Args || []).map((a) => resolveWordLiteral(a));
|
|
14432
|
+
if (words.length === 0 || words.some((w) => w === null)) return null;
|
|
14433
|
+
const head = baseWord(words[0]);
|
|
14434
|
+
const rest = words.slice(1);
|
|
14435
|
+
if (head === "git" && rest[0] === "rev-parse" && rest[1] === "--show-toplevel" && rest.length === 2)
|
|
14436
|
+
return ":/";
|
|
14437
|
+
if (head === "echo") {
|
|
14438
|
+
let i = 0;
|
|
14439
|
+
while (i < rest.length && /^-[neE]+$/.test(rest[i])) i++;
|
|
14440
|
+
return rest.length - i === 1 ? rest[i] : null;
|
|
14441
|
+
}
|
|
14442
|
+
if (head === "printf" && rest.length === 2 && /^%s(\\[0n])?$/.test(rest[0])) return rest[1];
|
|
14443
|
+
return null;
|
|
14444
|
+
}
|
|
14445
|
+
function treeTopWord(word, treeTopVars = NO_VARS) {
|
|
14446
|
+
let parts = word?.Parts || [];
|
|
14447
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
14448
|
+
if (parts.length !== 1) return false;
|
|
14449
|
+
const p = parts[0];
|
|
14450
|
+
if (p.kind === "ParamExp") {
|
|
14451
|
+
const name = plainParamName(word)?.name;
|
|
14452
|
+
return name === "PWD" || name !== void 0 && treeTopVars.has(name);
|
|
14453
|
+
}
|
|
14454
|
+
if (p.kind !== "CmdSubst") return false;
|
|
14455
|
+
const stmts = p.Stmts || [];
|
|
14456
|
+
if (stmts.length !== 1 || !stmts[0].Cmd || stmts[0].Cmd.kind !== "CallExpr") return false;
|
|
14457
|
+
const words = (stmts[0].Cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
14458
|
+
if (words.some((w) => w === null)) return false;
|
|
14459
|
+
const head = baseWord(words[0]);
|
|
14460
|
+
if (head === "pwd") return words.length === 1 || words[1] === "-P" || words[1] === "-L";
|
|
14461
|
+
return head === "git" && words[1] === "rev-parse" && words[2] === "--show-toplevel";
|
|
14462
|
+
}
|
|
14463
|
+
function resolveGitWords(word, treeTopVars = NO_VARS, appended = NO_APPENDS) {
|
|
14464
|
+
if (treeTopWord(word, treeTopVars)) return [":/"];
|
|
14465
|
+
const plain = plainParamName(word);
|
|
14466
|
+
if (plain && appended.has(plain.name)) {
|
|
14467
|
+
const v = appended.get(plain.name);
|
|
14468
|
+
if (v === null || v === void 0) return [null];
|
|
14469
|
+
return plain.quoted ? [v] : splitFields(v);
|
|
14470
|
+
}
|
|
14471
|
+
const elems = arrayExpansionWords(word);
|
|
14472
|
+
if (elems !== null) return elems;
|
|
14044
14473
|
const value = resolveWordLiteral(word);
|
|
14045
14474
|
if (value === null) {
|
|
14046
14475
|
if (isPositionalParam(word)) return boundPositionals() ?? [POSITIONAL2];
|
|
@@ -14206,6 +14635,8 @@ function classify(inv) {
|
|
|
14206
14635
|
if (o.flags.has("-n") || o.flags.has("--dry-run")) break;
|
|
14207
14636
|
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("+"));
|
|
14208
14637
|
if (forced) found(FORCE_PUSH);
|
|
14638
|
+
const deletes = o.flags.has("-d") || o.flags.has("--delete") || o.operands.some((r) => /^:[^:]/.test(r));
|
|
14639
|
+
if (deletes) found(DESTRUCTIVE);
|
|
14209
14640
|
break;
|
|
14210
14641
|
}
|
|
14211
14642
|
case "reset": {
|
|
@@ -14233,11 +14664,74 @@ function classify(inv) {
|
|
|
14233
14664
|
if (o.flags.has("-d") || o.flags.has("--delete")) found(DESTRUCTIVE);
|
|
14234
14665
|
break;
|
|
14235
14666
|
}
|
|
14667
|
+
// node9Firewall#385: history and work discarded through plumbing. A ref
|
|
14668
|
+
// deleted by hand, a stash dropped, the reflog expired or pruned: the
|
|
14669
|
+
// commits behind them are gone the way `branch -D` loses them.
|
|
14670
|
+
case "update-ref": {
|
|
14671
|
+
const o = parseOptions(inv.args, "m", /* @__PURE__ */ new Set());
|
|
14672
|
+
if (o.flags.has("-d") && (o.dynamic || o.operands.some(isHistoryRef))) found(DESTRUCTIVE);
|
|
14673
|
+
break;
|
|
14674
|
+
}
|
|
14675
|
+
case "reflog": {
|
|
14676
|
+
const o = parseOptions(inv.args, "", /* @__PURE__ */ new Set());
|
|
14677
|
+
if (o.operands[0] === "expire" || o.operands[0] === "delete") found(DESTRUCTIVE);
|
|
14678
|
+
break;
|
|
14679
|
+
}
|
|
14680
|
+
case "gc": {
|
|
14681
|
+
if (inv.config.get("gc.reflogexpire") === "now") found(DESTRUCTIVE);
|
|
14682
|
+
break;
|
|
14683
|
+
}
|
|
14684
|
+
case "stash": {
|
|
14685
|
+
const o = parseOptions(inv.args, "", /* @__PURE__ */ new Set());
|
|
14686
|
+
if (o.operands[0] === "clear" || o.operands[0] === "drop") found(DESTRUCTIVE);
|
|
14687
|
+
break;
|
|
14688
|
+
}
|
|
14689
|
+
case "worktree": {
|
|
14690
|
+
const o = parseOptions(inv.args, "", /* @__PURE__ */ new Set());
|
|
14691
|
+
if (o.operands[0] === "remove" && (o.flags.has("-f") || o.flags.has("--force")))
|
|
14692
|
+
found(DESTRUCTIVE);
|
|
14693
|
+
break;
|
|
14694
|
+
}
|
|
14695
|
+
// The working tree overwritten: `restore` from another ref, a forced
|
|
14696
|
+
// checkout, or `checkout -- .` (every local change dropped). A bare
|
|
14697
|
+
// `restore .` or `checkout .` stays an ordinary undo, as pinned.
|
|
14698
|
+
case "restore": {
|
|
14699
|
+
const o = parseOptions(inv.args, "s", RESTORE_LONG_VALUE);
|
|
14700
|
+
const src = restoreSource(inv.args);
|
|
14701
|
+
const whole = o.dynamic || o.operands.some(wholeTree);
|
|
14702
|
+
if (src !== null && src !== "HEAD" && whole) found(DESTRUCTIVE);
|
|
14703
|
+
break;
|
|
14704
|
+
}
|
|
14705
|
+
case "checkout": {
|
|
14706
|
+
const o = parseOptions(inv.args, "bB", CHECKOUT_LONG_VALUE);
|
|
14707
|
+
const forced = o.flags.has("-f") || o.flags.has("--force");
|
|
14708
|
+
const dropAll = inv.args.includes("--") && o.operands.some(wholeTree);
|
|
14709
|
+
if (forced || dropAll) found(DESTRUCTIVE);
|
|
14710
|
+
break;
|
|
14711
|
+
}
|
|
14236
14712
|
default:
|
|
14237
14713
|
break;
|
|
14238
14714
|
}
|
|
14239
14715
|
return out;
|
|
14240
14716
|
}
|
|
14717
|
+
function isExcludePathspec(operand) {
|
|
14718
|
+
return /^:[!^]/.test(operand) || /^:\([^)]*\bexclude\b[^)]*\)/.test(operand);
|
|
14719
|
+
}
|
|
14720
|
+
function restoreSource(args) {
|
|
14721
|
+
for (let i = 0; i < args.length; i++) {
|
|
14722
|
+
const w = args[i];
|
|
14723
|
+
if (w === null) continue;
|
|
14724
|
+
if (w.startsWith("--source=")) return w.slice("--source=".length);
|
|
14725
|
+
if (w === "--source" || w === "-s") return args[i + 1] ?? null;
|
|
14726
|
+
if (/^-s./.test(w)) return w.slice(2);
|
|
14727
|
+
}
|
|
14728
|
+
return null;
|
|
14729
|
+
}
|
|
14730
|
+
function isHistoryRef(ref) {
|
|
14731
|
+
return /^refs\/(heads|stash)(\/|$)/.test(ref);
|
|
14732
|
+
}
|
|
14733
|
+
var RESTORE_LONG_VALUE = /* @__PURE__ */ new Set(["--source", "--pathspec-from-file"]);
|
|
14734
|
+
var CHECKOUT_LONG_VALUE = /* @__PURE__ */ new Set(["--pathspec-from-file", "--orphan", "--conflict"]);
|
|
14241
14735
|
var HOOKS_BYPASS = {
|
|
14242
14736
|
checkId: "commands.git-hooks-bypass",
|
|
14243
14737
|
ruleName: "review-git-hooks-bypass",
|
|
@@ -14304,6 +14798,7 @@ function hooksBypass(inv) {
|
|
|
14304
14798
|
const o = parseOptions(inv.args, "mFCcut", COMMIT_LONG_VALUE);
|
|
14305
14799
|
return o.flags.has("-n") || o.flags.has("--no-verify");
|
|
14306
14800
|
}
|
|
14801
|
+
if (sub === "commit-tree") return true;
|
|
14307
14802
|
if (sub !== void 0 && NO_VERIFY_SUBS.has(sub)) {
|
|
14308
14803
|
return inv.args.some((a) => a === "--no-verify");
|
|
14309
14804
|
}
|
|
@@ -14356,7 +14851,20 @@ function configWritesHooksPath(args) {
|
|
|
14356
14851
|
return write;
|
|
14357
14852
|
}
|
|
14358
14853
|
function isHookPath(word) {
|
|
14359
|
-
return /(^|[\\/])(\.git[\\/]hooks|\.husky)([\\/]|$)/.test(word);
|
|
14854
|
+
return /(^|[\\/])(\.git[\\/]hooks|\.husky|\.githooks)([\\/]|$)/.test(word);
|
|
14855
|
+
}
|
|
14856
|
+
function isLiveHookFile(word) {
|
|
14857
|
+
if (!isHookPath(word)) return false;
|
|
14858
|
+
const m = /(^|[\\/])(\.git[\\/]hooks|\.husky|\.githooks)(?:[\\/](.*))?$/.exec(word);
|
|
14859
|
+
if (!m) return false;
|
|
14860
|
+
const rest = m[3] ?? "";
|
|
14861
|
+
if (rest === "" || rest === "_") return true;
|
|
14862
|
+
const leaf = rest.replace(/^_[\\/]/, "");
|
|
14863
|
+
return /^[a-z-]+$/.test(leaf);
|
|
14864
|
+
}
|
|
14865
|
+
function hookBodyIsEmpty(text) {
|
|
14866
|
+
const lines = text.split(/\r?\n/).map((l) => l.trim()).filter((l) => l !== "" && !l.startsWith("#"));
|
|
14867
|
+
return lines.every((l) => /^(exit(\s+0)?|true|:|set\s+-[a-zA-Z]+|set\s+-o\s+\w+)$/.test(l));
|
|
14360
14868
|
}
|
|
14361
14869
|
var CHMOD_OPTION_RE = /^-[RvcfHLP]+$/;
|
|
14362
14870
|
function modeRemovesExecute(mode) {
|
|
@@ -14366,6 +14874,23 @@ function modeRemovesExecute(mode) {
|
|
|
14366
14874
|
}
|
|
14367
14875
|
return mode.split(",").some((part) => /^[ugoa]*-[rwst]*x/.test(part));
|
|
14368
14876
|
}
|
|
14877
|
+
function redirOpIsAppend(redir) {
|
|
14878
|
+
return redir?.Op === appendOp();
|
|
14879
|
+
}
|
|
14880
|
+
var _appendOp = null;
|
|
14881
|
+
function appendOp() {
|
|
14882
|
+
if (_appendOp !== null) return _appendOp;
|
|
14883
|
+
try {
|
|
14884
|
+
const f = parseShared("echo x >> y");
|
|
14885
|
+
_appendOp = typeof f === "symbol" ? -1 : f.Stmts[0].Redirs[0].Op;
|
|
14886
|
+
} catch {
|
|
14887
|
+
_appendOp = -1;
|
|
14888
|
+
}
|
|
14889
|
+
return _appendOp;
|
|
14890
|
+
}
|
|
14891
|
+
function hooksBypassed(shown) {
|
|
14892
|
+
return { ...HOOKS_BYPASS, shown, reason: `${HOOKS_BYPASS.reason}: ${shown}` };
|
|
14893
|
+
}
|
|
14369
14894
|
function chmodDisarmsHook(args, shown) {
|
|
14370
14895
|
let i = 0;
|
|
14371
14896
|
while (i < args.length) {
|
|
@@ -14416,6 +14941,7 @@ function stagesEverything(inv) {
|
|
|
14416
14941
|
const sub = inv.sub?.toLowerCase();
|
|
14417
14942
|
const prefix = chdirPrefix(inv);
|
|
14418
14943
|
const judge = (operands2) => {
|
|
14944
|
+
if (operands2.length > 0 && operands2.every(isExcludePathspec)) return {};
|
|
14419
14945
|
let conditional = false;
|
|
14420
14946
|
for (const operand of operands2) {
|
|
14421
14947
|
if (!wholeTree(operand)) continue;
|
|
@@ -14760,7 +15286,7 @@ var PRESCREEN_RE = /\/dev\/(?:tcp|udp)|\b(?:nc|ncat|netcat|telnet|socat|s_client
|
|
|
14760
15286
|
var MAX_PAYLOAD_DEPTH3 = 4;
|
|
14761
15287
|
var CACHE_MAX2 = 1e3;
|
|
14762
15288
|
var cache2 = /* @__PURE__ */ new Map();
|
|
14763
|
-
function
|
|
15289
|
+
function isPipeOp2(op) {
|
|
14764
15290
|
return !isListOp(op);
|
|
14765
15291
|
}
|
|
14766
15292
|
var dupInOp = null;
|
|
@@ -15012,7 +15538,7 @@ var OutboundWalk = class {
|
|
|
15012
15538
|
this.visitStmt(n, depth);
|
|
15013
15539
|
return true;
|
|
15014
15540
|
}
|
|
15015
|
-
if (type === "BinaryCmd" &&
|
|
15541
|
+
if (type === "BinaryCmd" && isPipeOp2(n.Op)) {
|
|
15016
15542
|
this.visitPipeline(n);
|
|
15017
15543
|
return true;
|
|
15018
15544
|
}
|
|
@@ -15113,7 +15639,7 @@ var OutboundWalk = class {
|
|
|
15113
15639
|
const stages = [];
|
|
15114
15640
|
const flatten = (s) => {
|
|
15115
15641
|
const c = s?.Cmd;
|
|
15116
|
-
if (c && c.kind === "BinaryCmd" &&
|
|
15642
|
+
if (c && c.kind === "BinaryCmd" && isPipeOp2(c.Op)) {
|
|
15117
15643
|
flatten(c.X);
|
|
15118
15644
|
flatten(c.Y);
|
|
15119
15645
|
} else stages.push(s);
|
|
@@ -17888,7 +18414,7 @@ async function evaluatePolicyCore(config, toolName, args, context = {}, hooks =
|
|
|
17888
18414
|
if (v?.logged) noteLogged(v);
|
|
17889
18415
|
else if (v) candidates.push(v);
|
|
17890
18416
|
};
|
|
17891
|
-
const inline = reviewsEveryInline(config.settings.mode) ? detectInlineExec(shellCommand) ? void 0 : null : inlineExecReview(shellCommand);
|
|
18417
|
+
const inline = reviewsEveryInline(config.settings.mode) ? detectInlineExec(shellCommand) ? void 0 : null : inlineExecReview(shellCommand, config.policy.jailPaths);
|
|
17892
18418
|
if (inline !== null) {
|
|
17893
18419
|
consider("commands.inline-exec", {
|
|
17894
18420
|
decision: "review",
|
|
@@ -18375,7 +18901,7 @@ function* validCardRuns(text, base2, exemptFractions = true) {
|
|
|
18375
18901
|
let m;
|
|
18376
18902
|
while ((m = re.exec(text)) !== null) {
|
|
18377
18903
|
const digits = m[0].replace(/\D/g, "");
|
|
18378
|
-
const fraction = exemptFractions && isDecimalFraction(text, m.index, digits.length === m[0].length);
|
|
18904
|
+
const fraction = exemptFractions && (isDecimalFraction(text, m.index, digits.length === m[0].length) || isInteriorDotNumber(m[0]));
|
|
18379
18905
|
if (!fraction && validateLuhn(digits)) {
|
|
18380
18906
|
yield { index: m.index, length: m[0].length, digits };
|
|
18381
18907
|
} else {
|
|
@@ -18402,6 +18928,12 @@ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
|
|
|
18402
18928
|
}
|
|
18403
18929
|
return out;
|
|
18404
18930
|
}
|
|
18931
|
+
function isInteriorDotNumber(run) {
|
|
18932
|
+
const first = run.indexOf(".");
|
|
18933
|
+
if (first <= 0 || first === run.length - 1) return false;
|
|
18934
|
+
if (run.indexOf(".", first + 1) !== -1) return false;
|
|
18935
|
+
return !/[-\s]/.test(run);
|
|
18936
|
+
}
|
|
18405
18937
|
function isDecimalFraction(text, index, unseparated) {
|
|
18406
18938
|
if (!unseparated) return false;
|
|
18407
18939
|
const sep = text[index - 1];
|
|
@@ -19727,8 +20259,8 @@ function matchCanaryArgs(args, values) {
|
|
|
19727
20259
|
|
|
19728
20260
|
// src/scan/canonical.ts
|
|
19729
20261
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
19730
|
-
var CANONICAL_EXTRACTOR_VERSION = "canonical-
|
|
19731
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20262
|
+
var CANONICAL_EXTRACTOR_VERSION = "canonical-v37";
|
|
20263
|
+
var CANONICAL_EXTRACTOR_HASH = "2c9a0271d9c1dd57";
|
|
19732
20264
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
19733
20265
|
function extractCanonicalFindings(call, ctx) {
|
|
19734
20266
|
const out = [];
|