@node9/policy-engine 2.46.1 → 2.47.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +358 -239
- package/dist/index.mjs +377 -252
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -258,9 +258,6 @@ __export(src_exports, {
|
|
|
258
258
|
});
|
|
259
259
|
module.exports = __toCommonJS(src_exports);
|
|
260
260
|
|
|
261
|
-
// src/shell/derived-writes.ts
|
|
262
|
-
var import_mvdan_sh3 = __toESM(require("mvdan-sh"));
|
|
263
|
-
|
|
264
261
|
// src/files/protected-access.ts
|
|
265
262
|
var import_picomatch2 = __toESM(require("picomatch"));
|
|
266
263
|
|
|
@@ -3555,8 +3552,139 @@ function resolveCheckMap(settings) {
|
|
|
3555
3552
|
// src/rules/index.ts
|
|
3556
3553
|
var import_picomatch = __toESM(require("picomatch"));
|
|
3557
3554
|
|
|
3558
|
-
// src/shell/
|
|
3559
|
-
var
|
|
3555
|
+
// src/shell/mvdan.ts
|
|
3556
|
+
var import_module = require("module");
|
|
3557
|
+
var syntax = null;
|
|
3558
|
+
function getSyntax() {
|
|
3559
|
+
if (syntax === null) {
|
|
3560
|
+
const req = (0, import_module.createRequire)(__filename);
|
|
3561
|
+
syntax = req("mvdan-sh").syntax;
|
|
3562
|
+
}
|
|
3563
|
+
return syntax;
|
|
3564
|
+
}
|
|
3565
|
+
function lazy(compute) {
|
|
3566
|
+
let done = false;
|
|
3567
|
+
let value;
|
|
3568
|
+
return () => {
|
|
3569
|
+
if (!done) {
|
|
3570
|
+
value = compute();
|
|
3571
|
+
done = true;
|
|
3572
|
+
}
|
|
3573
|
+
return value;
|
|
3574
|
+
};
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
// src/shell/plain-tree.ts
|
|
3578
|
+
var KINDS = {
|
|
3579
|
+
File: { nodes: ["Stmts"] },
|
|
3580
|
+
Stmt: { nodes: ["Cmd", "Redirs"], scalars: ["Negated", "Background", "Coprocess"] },
|
|
3581
|
+
CallExpr: { nodes: ["Assigns", "Args"] },
|
|
3582
|
+
Assign: { nodes: ["Name", "Value", "Index", "Array"], scalars: ["Append", "Naked"] },
|
|
3583
|
+
Word: { nodes: ["Parts"] },
|
|
3584
|
+
Lit: { scalars: ["Value"] },
|
|
3585
|
+
SglQuoted: { scalars: ["Value", "Dollar"] },
|
|
3586
|
+
DblQuoted: { nodes: ["Parts"], scalars: ["Dollar"] },
|
|
3587
|
+
ParamExp: {
|
|
3588
|
+
nodes: ["Param", "Index", "Slice", "Repl", "Exp"],
|
|
3589
|
+
scalars: ["Short", "Excl", "Length", "Width"]
|
|
3590
|
+
},
|
|
3591
|
+
CmdSubst: { nodes: ["Stmts"], scalars: ["Backquotes", "TempFile", "ReplyVar"] },
|
|
3592
|
+
ArithmExp: { nodes: ["X"], scalars: ["Bracket", "Unsigned"] },
|
|
3593
|
+
ArithmCmd: { nodes: ["X"], scalars: ["Unsigned"] },
|
|
3594
|
+
ProcSubst: { nodes: ["Stmts"], scalars: ["Op"] },
|
|
3595
|
+
ExtGlob: { nodes: ["Pattern"], scalars: ["Op"] },
|
|
3596
|
+
BraceExp: { nodes: ["Elems"], scalars: ["Sequence"] },
|
|
3597
|
+
// only with SplitBraces, unused here
|
|
3598
|
+
BinaryCmd: { nodes: ["X", "Y"], scalars: ["Op"] },
|
|
3599
|
+
BinaryArithm: { nodes: ["X", "Y"], scalars: ["Op"] },
|
|
3600
|
+
UnaryArithm: { nodes: ["X"], scalars: ["Op", "Post"] },
|
|
3601
|
+
ParenArithm: { nodes: ["X"] },
|
|
3602
|
+
BinaryTest: { nodes: ["X", "Y"], scalars: ["Op"] },
|
|
3603
|
+
UnaryTest: { nodes: ["X"], scalars: ["Op"] },
|
|
3604
|
+
ParenTest: { nodes: ["X"] },
|
|
3605
|
+
Redirect: { nodes: ["N", "Word", "Hdoc"], scalars: ["Op"] },
|
|
3606
|
+
Block: { nodes: ["Stmts"] },
|
|
3607
|
+
Subshell: { nodes: ["Stmts"] },
|
|
3608
|
+
IfClause: { nodes: ["Cond", "Then", "Else"] },
|
|
3609
|
+
WhileClause: { nodes: ["Cond", "Do"], scalars: ["Until"] },
|
|
3610
|
+
ForClause: { nodes: ["Loop", "Do"], scalars: ["Select"] },
|
|
3611
|
+
WordIter: { nodes: ["Name", "Items"] },
|
|
3612
|
+
CStyleLoop: { nodes: ["Init", "Cond", "Post"] },
|
|
3613
|
+
CaseClause: { nodes: ["Word", "Items"] },
|
|
3614
|
+
CaseItem: { nodes: ["Patterns", "Stmts"], scalars: ["Op"] },
|
|
3615
|
+
FuncDecl: { nodes: ["Name", "Body"], scalars: ["RsrvWord"] },
|
|
3616
|
+
DeclClause: { nodes: ["Variant", "Args"], notWalked: ["Variant"] },
|
|
3617
|
+
LetClause: { nodes: ["Exprs"] },
|
|
3618
|
+
TimeClause: { nodes: ["Stmt"], scalars: ["PosixFormat"] },
|
|
3619
|
+
CoprocClause: { nodes: ["Name", "Stmt"] },
|
|
3620
|
+
TestClause: { nodes: ["X"] },
|
|
3621
|
+
TestDecl: { nodes: ["Description", "Body"] },
|
|
3622
|
+
ArrayExpr: { nodes: ["Elems"] },
|
|
3623
|
+
ArrayElem: { nodes: ["Index", "Value"] },
|
|
3624
|
+
Comment: { scalars: ["Text"] }
|
|
3625
|
+
};
|
|
3626
|
+
var STRUCTS = {
|
|
3627
|
+
"ParamExp.Slice": { nodes: ["Offset", "Length"], notWalked: ["Offset", "Length"] },
|
|
3628
|
+
"ParamExp.Repl": { nodes: ["Orig", "With"], scalars: ["All"] },
|
|
3629
|
+
"ParamExp.Exp": { nodes: ["Word"], scalars: ["Op"] }
|
|
3630
|
+
};
|
|
3631
|
+
var unknownKinds = /* @__PURE__ */ new Set();
|
|
3632
|
+
function isGoNode(v) {
|
|
3633
|
+
return v !== null && typeof v === "object" && typeof v.Pos === "function";
|
|
3634
|
+
}
|
|
3635
|
+
function toPlainTree(goNode) {
|
|
3636
|
+
const kind = getSyntax().NodeType(goNode);
|
|
3637
|
+
const out = { kind, pos: goNode.Pos().Offset(), end: goNode.End().Offset() };
|
|
3638
|
+
const spec = KINDS[kind];
|
|
3639
|
+
if (!spec) {
|
|
3640
|
+
unknownKinds.add(kind);
|
|
3641
|
+
return out;
|
|
3642
|
+
}
|
|
3643
|
+
convertFields(goNode, spec, out, kind);
|
|
3644
|
+
return out;
|
|
3645
|
+
}
|
|
3646
|
+
function convertFields(goNode, spec, out, kind) {
|
|
3647
|
+
for (const f of spec.scalars ?? []) out[f] = goNode[f];
|
|
3648
|
+
for (const f of spec.nodes ?? []) {
|
|
3649
|
+
const v = goNode[f];
|
|
3650
|
+
if (v === void 0 || v === null) {
|
|
3651
|
+
out[f] = null;
|
|
3652
|
+
} else if (Array.isArray(v)) {
|
|
3653
|
+
out[f] = v.map((c) => isGoNode(c) ? toPlainTree(c) : c);
|
|
3654
|
+
} else if (isGoNode(v)) {
|
|
3655
|
+
out[f] = toPlainTree(v);
|
|
3656
|
+
} else if (typeof v === "object" && STRUCTS[`${kind}.${f}`]) {
|
|
3657
|
+
const sub = { struct: `${kind}.${f}` };
|
|
3658
|
+
convertFields(v, STRUCTS[`${kind}.${f}`], sub, `${kind}.${f}`);
|
|
3659
|
+
out[f] = sub;
|
|
3660
|
+
} else {
|
|
3661
|
+
out[f] = v;
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
function childrenOf(n) {
|
|
3666
|
+
const spec = n.kind ? KINDS[n.kind] : STRUCTS[n.struct];
|
|
3667
|
+
if (!spec?.nodes) return [];
|
|
3668
|
+
const out = [];
|
|
3669
|
+
for (const f of spec.nodes) {
|
|
3670
|
+
if (spec.notWalked?.includes(f)) continue;
|
|
3671
|
+
const v = n[f];
|
|
3672
|
+
if (!v) continue;
|
|
3673
|
+
if (Array.isArray(v)) {
|
|
3674
|
+
for (const c of v) if (c) out.push(c);
|
|
3675
|
+
} else if (v.kind) {
|
|
3676
|
+
out.push(v);
|
|
3677
|
+
} else if (v.struct) {
|
|
3678
|
+
out.push(...childrenOf(v));
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3681
|
+
return out;
|
|
3682
|
+
}
|
|
3683
|
+
function walk(root, fn) {
|
|
3684
|
+
if (!root) return;
|
|
3685
|
+
if (!fn(root)) return;
|
|
3686
|
+
for (const c of childrenOf(root)) walk(c, fn);
|
|
3687
|
+
}
|
|
3560
3688
|
|
|
3561
3689
|
// src/dlp/normalize.ts
|
|
3562
3690
|
var INVISIBLE_RE = /[͏----︀-️]|[\u{E0000}-\u{E007F}]/gu;
|
|
@@ -4003,8 +4131,7 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
4003
4131
|
}
|
|
4004
4132
|
|
|
4005
4133
|
// src/shell/index.ts
|
|
4006
|
-
var
|
|
4007
|
-
var sharedParser = syntax.NewParser();
|
|
4134
|
+
var sharedParser = lazy(() => getSyntax().NewParser());
|
|
4008
4135
|
var MESSAGE_FLAGS = /* @__PURE__ */ new Set([
|
|
4009
4136
|
"-m",
|
|
4010
4137
|
"--message",
|
|
@@ -4037,7 +4164,7 @@ var DOWNLOAD_CMDS = /* @__PURE__ */ new Set([
|
|
|
4037
4164
|
]);
|
|
4038
4165
|
function isCatHeredocOrLit(part) {
|
|
4039
4166
|
if (!part) return false;
|
|
4040
|
-
const t =
|
|
4167
|
+
const t = part.kind;
|
|
4041
4168
|
if (t === "Lit") return true;
|
|
4042
4169
|
if (t !== "CmdSubst") return false;
|
|
4043
4170
|
const stmts = part.Stmts || [];
|
|
@@ -4047,15 +4174,15 @@ function isCatHeredocOrLit(part) {
|
|
|
4047
4174
|
const hasHeredoc = redirs.some((r) => r && r.Hdoc);
|
|
4048
4175
|
if (!hasHeredoc) return false;
|
|
4049
4176
|
const cmd = stmt.Cmd;
|
|
4050
|
-
if (!cmd ||
|
|
4177
|
+
if (!cmd || cmd.kind !== "CallExpr") return false;
|
|
4051
4178
|
const firstArg = cmd.Args?.[0]?.Parts || [];
|
|
4052
|
-
if (firstArg.length !== 1 ||
|
|
4179
|
+
if (firstArg.length !== 1 || firstArg[0].kind !== "Lit") return false;
|
|
4053
4180
|
return (firstArg[0].Value || "").toLowerCase() === "cat";
|
|
4054
4181
|
}
|
|
4055
4182
|
var NORMALIZE_CACHE_MAX = 5e3;
|
|
4056
4183
|
var normalizeCache = /* @__PURE__ */ new Map();
|
|
4057
4184
|
var codeBodiesCache = /* @__PURE__ */ new Map();
|
|
4058
|
-
var AST_CACHE_MAX =
|
|
4185
|
+
var AST_CACHE_MAX = 256;
|
|
4059
4186
|
var astCache = /* @__PURE__ */ new Map();
|
|
4060
4187
|
var PARSE_FAIL = /* @__PURE__ */ Symbol("parse-fail");
|
|
4061
4188
|
function parseShared(command) {
|
|
@@ -4067,7 +4194,7 @@ function parseShared(command) {
|
|
|
4067
4194
|
}
|
|
4068
4195
|
let parsed;
|
|
4069
4196
|
try {
|
|
4070
|
-
parsed = sharedParser.Parse(command, "cmd");
|
|
4197
|
+
parsed = toPlainTree(sharedParser().Parse(command, "cmd"));
|
|
4071
4198
|
} catch {
|
|
4072
4199
|
parsed = PARSE_FAIL;
|
|
4073
4200
|
}
|
|
@@ -4132,10 +4259,10 @@ function fileAccessViewImpl(command) {
|
|
|
4132
4259
|
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
4133
4260
|
const edits = [];
|
|
4134
4261
|
try {
|
|
4135
|
-
|
|
4262
|
+
walk(f, (node) => {
|
|
4136
4263
|
if (!node) return false;
|
|
4137
4264
|
const n = node;
|
|
4138
|
-
if (
|
|
4265
|
+
if (n.kind !== "CallExpr") return true;
|
|
4139
4266
|
const args = n.Args || [];
|
|
4140
4267
|
const words = args.map((a) => resolveWordLiteral(a));
|
|
4141
4268
|
const head = unwrapCommandHead(words);
|
|
@@ -4147,8 +4274,8 @@ function fileAccessViewImpl(command) {
|
|
|
4147
4274
|
if (!PROGRAM_DIR.test(word)) continue;
|
|
4148
4275
|
const name = word.split(/[\\/]/).pop() ?? "";
|
|
4149
4276
|
if (!name) continue;
|
|
4150
|
-
const s = at(args[i].
|
|
4151
|
-
const e = at(args[i].
|
|
4277
|
+
const s = at(args[i].pos);
|
|
4278
|
+
const e = at(args[i].end);
|
|
4152
4279
|
if (s < 0 || e < 0) continue;
|
|
4153
4280
|
edits.push([s, e, name]);
|
|
4154
4281
|
}
|
|
@@ -4177,10 +4304,10 @@ function literalPayloadsOf(command, depth) {
|
|
|
4177
4304
|
if (f === PARSE_FAIL) return [];
|
|
4178
4305
|
const out = [];
|
|
4179
4306
|
try {
|
|
4180
|
-
|
|
4307
|
+
walk(f, (node) => {
|
|
4181
4308
|
if (!node || out.length >= MAX_READING_PAYLOADS) return false;
|
|
4182
4309
|
const n = node;
|
|
4183
|
-
if (
|
|
4310
|
+
if (n.kind !== "CallExpr") return true;
|
|
4184
4311
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
4185
4312
|
if (words.length === 0) return true;
|
|
4186
4313
|
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
@@ -4200,23 +4327,23 @@ function foldCommandWords(reading) {
|
|
|
4200
4327
|
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
4201
4328
|
const edits = [];
|
|
4202
4329
|
try {
|
|
4203
|
-
|
|
4330
|
+
walk(f, (node) => {
|
|
4204
4331
|
if (!node) return false;
|
|
4205
4332
|
const n = node;
|
|
4206
|
-
if (
|
|
4333
|
+
if (n.kind !== "CallExpr") return true;
|
|
4207
4334
|
const args = n.Args || [];
|
|
4208
4335
|
const words = args.map((a) => resolveWordLiteral(a));
|
|
4209
4336
|
const folded = words.map((w) => w === null ? null : foldHomoglyphs(w));
|
|
4210
4337
|
const head = unwrapCommandHead(folded);
|
|
4211
4338
|
for (let i = 0; i <= head && i < args.length; i++) {
|
|
4212
4339
|
const parts = args[i].Parts || [];
|
|
4213
|
-
if (parts.length !== 1 ||
|
|
4340
|
+
if (parts.length !== 1 || parts[0].kind !== "Lit") continue;
|
|
4214
4341
|
const value = parts[0].Value ?? "";
|
|
4215
4342
|
const word = folded[i];
|
|
4216
4343
|
if (word === null || word === value || !/[^\x00-\x7f]/.test(value)) continue;
|
|
4217
4344
|
if (!/^[A-Za-z0-9._/-]+$/.test(word)) continue;
|
|
4218
|
-
const s = at(args[i].
|
|
4219
|
-
const e = at(args[i].
|
|
4345
|
+
const s = at(args[i].pos);
|
|
4346
|
+
const e = at(args[i].end);
|
|
4220
4347
|
if (s < 0 || e < 0) continue;
|
|
4221
4348
|
edits.push([s, e, word]);
|
|
4222
4349
|
}
|
|
@@ -4284,10 +4411,10 @@ function interpreterHeredocSpans(f, at) {
|
|
|
4284
4411
|
const stmts = f?.Stmts || [];
|
|
4285
4412
|
const candidates = [];
|
|
4286
4413
|
let unsafe = false;
|
|
4287
|
-
|
|
4414
|
+
walk(f, (node) => {
|
|
4288
4415
|
if (!node || unsafe) return false;
|
|
4289
4416
|
const n = node;
|
|
4290
|
-
const t =
|
|
4417
|
+
const t = n.kind;
|
|
4291
4418
|
if (t === "FuncDecl") {
|
|
4292
4419
|
unsafe = true;
|
|
4293
4420
|
return false;
|
|
@@ -4307,7 +4434,7 @@ function interpreterHeredocSpans(f, at) {
|
|
|
4307
4434
|
});
|
|
4308
4435
|
if (unsafe) return [];
|
|
4309
4436
|
for (const st of stmts) {
|
|
4310
|
-
if (!st?.Cmd ||
|
|
4437
|
+
if (!st?.Cmd || st.Cmd.kind !== "CallExpr") continue;
|
|
4311
4438
|
const words = (st.Cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
4312
4439
|
const name = (words[0] ?? "").toLowerCase();
|
|
4313
4440
|
if (!STDIN_CODE_INTERPRETERS.test(name)) continue;
|
|
@@ -4322,8 +4449,8 @@ function interpreterHeredocSpans(f, at) {
|
|
|
4322
4449
|
if (stdin.length !== 1 || others > 0) continue;
|
|
4323
4450
|
const r = stdin[0];
|
|
4324
4451
|
if (heredocText(r.Hdoc) === null) continue;
|
|
4325
|
-
const hs = at(r.Hdoc.
|
|
4326
|
-
const he = at(r.Hdoc.
|
|
4452
|
+
const hs = at(r.Hdoc.pos);
|
|
4453
|
+
const he = at(r.Hdoc.end);
|
|
4327
4454
|
if (hs < 0 || he < 0 || he <= hs) continue;
|
|
4328
4455
|
spans.push([hs, he]);
|
|
4329
4456
|
}
|
|
@@ -4343,24 +4470,24 @@ function normalizeCommandForPolicyImpl(command, codeBodies) {
|
|
|
4343
4470
|
strips.push([hs, he]);
|
|
4344
4471
|
msgSpans.add(`${hs}:${he}`);
|
|
4345
4472
|
}
|
|
4346
|
-
|
|
4473
|
+
walk(f, (node) => {
|
|
4347
4474
|
if (!node) return false;
|
|
4348
4475
|
const n = node;
|
|
4349
|
-
if (
|
|
4476
|
+
if (n.kind !== "CallExpr") return true;
|
|
4350
4477
|
const args = n.Args || [];
|
|
4351
4478
|
for (let i = 0; i < args.length - 1; i++) {
|
|
4352
4479
|
const argParts = args[i].Parts || [];
|
|
4353
|
-
if (argParts.length !== 1 ||
|
|
4480
|
+
if (argParts.length !== 1 || argParts[0].kind !== "Lit") continue;
|
|
4354
4481
|
const flagVal = argParts[0].Value || "";
|
|
4355
4482
|
if (!MESSAGE_FLAGS.has(flagVal.toLowerCase())) continue;
|
|
4356
4483
|
const next = args[i + 1];
|
|
4357
4484
|
const nextParts = next.Parts || [];
|
|
4358
4485
|
if (nextParts.length !== 1) continue;
|
|
4359
4486
|
const quotedNode = nextParts[0];
|
|
4360
|
-
const nt =
|
|
4487
|
+
const nt = quotedNode.kind;
|
|
4361
4488
|
const markStrip = () => {
|
|
4362
|
-
const s = at(next.
|
|
4363
|
-
const e = at(next.
|
|
4489
|
+
const s = at(next.pos);
|
|
4490
|
+
const e = at(next.end);
|
|
4364
4491
|
if (s < 0 || e < 0) return;
|
|
4365
4492
|
strips.push([s, e]);
|
|
4366
4493
|
msgSpans.add(`${s}:${e}`);
|
|
@@ -4369,7 +4496,7 @@ function normalizeCommandForPolicyImpl(command, codeBodies) {
|
|
|
4369
4496
|
markStrip();
|
|
4370
4497
|
} else if (nt === "DblQuoted") {
|
|
4371
4498
|
const innerParts = quotedNode.Parts || [];
|
|
4372
|
-
const allLit = innerParts.length === 0 || innerParts.every((p) =>
|
|
4499
|
+
const allLit = innerParts.length === 0 || innerParts.every((p) => p.kind === "Lit");
|
|
4373
4500
|
if (allLit) {
|
|
4374
4501
|
markStrip();
|
|
4375
4502
|
} else if (innerParts.every((p) => isCatHeredocOrLit(p))) {
|
|
@@ -4378,8 +4505,8 @@ function normalizeCommandForPolicyImpl(command, codeBodies) {
|
|
|
4378
4505
|
}
|
|
4379
4506
|
}
|
|
4380
4507
|
for (const arg of args) {
|
|
4381
|
-
const s = at(arg.
|
|
4382
|
-
const e = at(arg.
|
|
4508
|
+
const s = at(arg.pos);
|
|
4509
|
+
const e = at(arg.end);
|
|
4383
4510
|
if (s < 0 || e < 0) continue;
|
|
4384
4511
|
if (msgSpans.has(`${s}:${e}`)) continue;
|
|
4385
4512
|
const resolved = resolveWordLiteral(arg);
|
|
@@ -4419,10 +4546,10 @@ function scanArgsForDynamicExec(args, startIdx) {
|
|
|
4419
4546
|
let hasParamExp = false;
|
|
4420
4547
|
let hasCurl = false;
|
|
4421
4548
|
for (let i = startIdx; i < args.length; i++) {
|
|
4422
|
-
|
|
4549
|
+
walk(args[i], (inner) => {
|
|
4423
4550
|
if (!inner) return false;
|
|
4424
4551
|
const inn = inner;
|
|
4425
|
-
const it =
|
|
4552
|
+
const it = inn.kind;
|
|
4426
4553
|
if (it === "CmdSubst") hasCmdSubst = true;
|
|
4427
4554
|
if (it === "ParamExp") hasParamExp = true;
|
|
4428
4555
|
if (it === "Lit" && DOWNLOAD_CMDS.has(inn.Value?.toLowerCase())) hasCurl = true;
|
|
@@ -4435,15 +4562,16 @@ function scanArgsForDynamicExec(args, startIdx) {
|
|
|
4435
4562
|
}
|
|
4436
4563
|
function detectDangerousShellExec(command) {
|
|
4437
4564
|
try {
|
|
4438
|
-
const f =
|
|
4565
|
+
const f = parseShared(command);
|
|
4566
|
+
if (f === PARSE_FAIL) return null;
|
|
4439
4567
|
let result = null;
|
|
4440
4568
|
const assigned = assignedNames(f);
|
|
4441
|
-
|
|
4569
|
+
walk(f, (node) => {
|
|
4442
4570
|
if (!node || result === "block") return false;
|
|
4443
4571
|
const n = node;
|
|
4444
|
-
if (
|
|
4572
|
+
if (n.kind === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
4445
4573
|
const call = n.Y.Cmd;
|
|
4446
|
-
if (call &&
|
|
4574
|
+
if (call && call.kind === "CallExpr") {
|
|
4447
4575
|
const words = (call.Args || []).map((a) => resolveWordLiteral(a));
|
|
4448
4576
|
const head2 = unwrapCommandHead(words);
|
|
4449
4577
|
const name = (words[head2] ?? "").split("/").pop() ?? "";
|
|
@@ -4456,7 +4584,7 @@ function detectDangerousShellExec(command) {
|
|
|
4456
4584
|
result = "review";
|
|
4457
4585
|
}
|
|
4458
4586
|
}
|
|
4459
|
-
if (
|
|
4587
|
+
if (n.kind !== "CallExpr") return true;
|
|
4460
4588
|
const args = n.Args || [];
|
|
4461
4589
|
if (args.length === 0) return true;
|
|
4462
4590
|
const headWords = args.map(
|
|
@@ -4467,7 +4595,7 @@ function detectDangerousShellExec(command) {
|
|
|
4467
4595
|
if (!lookup && (opaqueExecutable(args[0], assigned) || opaqueExecutable(args[head], assigned)))
|
|
4468
4596
|
result = "review";
|
|
4469
4597
|
const firstParts = args[0].Parts || [];
|
|
4470
|
-
if (firstParts.length !== 1 ||
|
|
4598
|
+
if (firstParts.length !== 1 || firstParts[0].kind !== "Lit") return true;
|
|
4471
4599
|
const cmdName = firstParts[0].Value?.toLowerCase() ?? "";
|
|
4472
4600
|
if (cmdName === "eval") {
|
|
4473
4601
|
const v = scanArgsForDynamicExec(args, 1);
|
|
@@ -4475,7 +4603,7 @@ function detectDangerousShellExec(command) {
|
|
|
4475
4603
|
} else if (SHELL_INTERPRETERS.has(cmdName)) {
|
|
4476
4604
|
for (let i = 1; i < args.length - 1; i++) {
|
|
4477
4605
|
const flagParts = args[i].Parts || [];
|
|
4478
|
-
if (flagParts.length !== 1 ||
|
|
4606
|
+
if (flagParts.length !== 1 || flagParts[0].kind !== "Lit" || flagParts[0].Value !== "-c")
|
|
4479
4607
|
continue;
|
|
4480
4608
|
const v = scanArgsForDynamicExec(args, i + 1);
|
|
4481
4609
|
if (v === "block" || v === "review" && result === null) result = v;
|
|
@@ -4500,8 +4628,7 @@ function isDefaultExpansion(part) {
|
|
|
4500
4628
|
}
|
|
4501
4629
|
function lookupSubstitution(part) {
|
|
4502
4630
|
const stmts = part.Stmts ?? [];
|
|
4503
|
-
if (stmts.length !== 1 || !stmts[0].Cmd ||
|
|
4504
|
-
return null;
|
|
4631
|
+
if (stmts.length !== 1 || !stmts[0].Cmd || stmts[0].Cmd.kind !== "CallExpr") return null;
|
|
4505
4632
|
const words = (stmts[0].Cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
4506
4633
|
if (words.some((w) => w === null)) return null;
|
|
4507
4634
|
if (words.length === 2 && words[0] === "which") return words[1];
|
|
@@ -4523,9 +4650,9 @@ var VARIABLE_READERS = /* @__PURE__ */ new Set([
|
|
|
4523
4650
|
]);
|
|
4524
4651
|
function assignedNames(f) {
|
|
4525
4652
|
const names = /* @__PURE__ */ new Set();
|
|
4526
|
-
|
|
4653
|
+
walk(f, (node) => {
|
|
4527
4654
|
if (!node) return false;
|
|
4528
|
-
const kind =
|
|
4655
|
+
const kind = node.kind;
|
|
4529
4656
|
if (kind === "Assign" && node.Name?.Value) names.add(node.Name.Value);
|
|
4530
4657
|
if (kind === "ForClause" && node.Loop?.Name?.Value) names.add(node.Loop.Name.Value);
|
|
4531
4658
|
if (kind === "CallExpr") {
|
|
@@ -4540,7 +4667,7 @@ function assignedNames(f) {
|
|
|
4540
4667
|
}
|
|
4541
4668
|
function executableParts(word, assigned, quoted = false) {
|
|
4542
4669
|
return (word?.Parts ?? []).flatMap((part) => {
|
|
4543
|
-
const kind =
|
|
4670
|
+
const kind = part.kind;
|
|
4544
4671
|
if (kind === "DblQuoted") return executableParts(part, assigned, true);
|
|
4545
4672
|
if (kind === "Lit") return [{ kind: "Lit", value: part.Value ?? "", quoted }];
|
|
4546
4673
|
if (kind === "SglQuoted")
|
|
@@ -5264,10 +5391,10 @@ function chmodHasOpenPermMode(command) {
|
|
|
5264
5391
|
if (f === PARSE_FAIL) return false;
|
|
5265
5392
|
let found = false;
|
|
5266
5393
|
try {
|
|
5267
|
-
|
|
5394
|
+
walk(f, (node) => {
|
|
5268
5395
|
if (!node || found) return false;
|
|
5269
5396
|
const n = node;
|
|
5270
|
-
if (
|
|
5397
|
+
if (n.kind !== "CallExpr") return true;
|
|
5271
5398
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
5272
5399
|
if (words.length === 0) return true;
|
|
5273
5400
|
const name = (words[0] ?? "").toLowerCase();
|
|
@@ -5344,11 +5471,11 @@ function redirStdinOps() {
|
|
|
5344
5471
|
}
|
|
5345
5472
|
function deriveBinaryOp(sample) {
|
|
5346
5473
|
try {
|
|
5347
|
-
const f = sharedParser.Parse(sample, "cmd");
|
|
5474
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
5348
5475
|
let op = -1;
|
|
5349
|
-
|
|
5476
|
+
walk(f, (node) => {
|
|
5350
5477
|
const n = node;
|
|
5351
|
-
if (n &&
|
|
5478
|
+
if (n && n.kind === "BinaryCmd" && op < 0) op = n.Op;
|
|
5352
5479
|
return true;
|
|
5353
5480
|
});
|
|
5354
5481
|
return op;
|
|
@@ -5444,7 +5571,7 @@ function heredocText(word) {
|
|
|
5444
5571
|
const parts = word?.Parts ?? [];
|
|
5445
5572
|
let out = "";
|
|
5446
5573
|
for (const p of parts) {
|
|
5447
|
-
if (
|
|
5574
|
+
if (p.kind !== "Lit") return null;
|
|
5448
5575
|
out += p.Value ?? "";
|
|
5449
5576
|
}
|
|
5450
5577
|
return out;
|
|
@@ -5480,7 +5607,7 @@ function attachedCode(interp, flag) {
|
|
|
5480
5607
|
}
|
|
5481
5608
|
function inlineExecCall(stmt, pipeFed) {
|
|
5482
5609
|
const cmd = stmt?.Cmd;
|
|
5483
|
-
if (!cmd ||
|
|
5610
|
+
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
5484
5611
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
5485
5612
|
if (words.length === 0) return null;
|
|
5486
5613
|
const headIdx = unwrapCommandHead(words);
|
|
@@ -5563,10 +5690,10 @@ function shellPayloadNeedsReview(payload) {
|
|
|
5563
5690
|
let review = false;
|
|
5564
5691
|
payloadNesting++;
|
|
5565
5692
|
try {
|
|
5566
|
-
|
|
5693
|
+
walk(f, (node) => {
|
|
5567
5694
|
if (!node || review) return false;
|
|
5568
5695
|
const n = node;
|
|
5569
|
-
if (
|
|
5696
|
+
if (n.kind !== "CallExpr") return true;
|
|
5570
5697
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
5571
5698
|
if (words.length === 0) return true;
|
|
5572
5699
|
const h = unwrapCommandHead(words);
|
|
@@ -5601,10 +5728,10 @@ function inlineExecCalls(command) {
|
|
|
5601
5728
|
if (f === PARSE_FAIL) return PARSE_FAIL;
|
|
5602
5729
|
const calls = [];
|
|
5603
5730
|
try {
|
|
5604
|
-
|
|
5731
|
+
walk(f, (node) => {
|
|
5605
5732
|
if (!node || calls.length >= MAX_INLINE_CALLS) return false;
|
|
5606
5733
|
const n = node;
|
|
5607
|
-
const t =
|
|
5734
|
+
const t = n.kind;
|
|
5608
5735
|
if (t === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
5609
5736
|
const call = inlineExecCall(n.Y, true);
|
|
5610
5737
|
if (call) calls.push(call);
|
|
@@ -5749,7 +5876,7 @@ function shellScriptOperands(command) {
|
|
|
5749
5876
|
walkWithCalls(f, (node) => {
|
|
5750
5877
|
if (!node) return false;
|
|
5751
5878
|
const n = node;
|
|
5752
|
-
if (
|
|
5879
|
+
if (n.kind !== "CallExpr") return true;
|
|
5753
5880
|
const callArgs = n.Args || [];
|
|
5754
5881
|
if (callArgs.length === 0) return true;
|
|
5755
5882
|
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
@@ -5785,7 +5912,7 @@ function shellScriptOperands(command) {
|
|
|
5785
5912
|
}
|
|
5786
5913
|
function windowsDrivePathSpelling(word) {
|
|
5787
5914
|
const parts = word?.Parts || [];
|
|
5788
|
-
if (parts.length === 0 || !parts.every((p) =>
|
|
5915
|
+
if (parts.length === 0 || !parts.every((p) => p.kind === "Lit")) return null;
|
|
5789
5916
|
const raw = parts.map((p) => p.Value ?? "").join("");
|
|
5790
5917
|
return /^[A-Za-z]:\\[^\s'"$`]*$/.test(raw) ? raw : null;
|
|
5791
5918
|
}
|
|
@@ -5990,28 +6117,33 @@ function recordTopLevelAssignments(f) {
|
|
|
5990
6117
|
}
|
|
5991
6118
|
function probeBinOp(src) {
|
|
5992
6119
|
try {
|
|
5993
|
-
const cmd =
|
|
5994
|
-
if (cmd &&
|
|
6120
|
+
const cmd = toPlainTree(getSyntax().NewParser().Parse(src, "probe"))?.Stmts?.[0]?.Cmd;
|
|
6121
|
+
if (cmd && cmd.kind === "BinaryCmd") return cmd.Op;
|
|
5995
6122
|
} catch {
|
|
5996
6123
|
}
|
|
5997
6124
|
return null;
|
|
5998
6125
|
}
|
|
5999
|
-
var
|
|
6000
|
-
|
|
6001
|
-
|
|
6126
|
+
var andOrOps = lazy(() => {
|
|
6127
|
+
const and = probeBinOp("a && b");
|
|
6128
|
+
const or = probeBinOp("a || b");
|
|
6129
|
+
return {
|
|
6130
|
+
AND_OP: and,
|
|
6131
|
+
AND_OR_OPS: new Set([and, or].filter((o) => o !== null))
|
|
6132
|
+
};
|
|
6133
|
+
});
|
|
6002
6134
|
function recordTopLevelStmt(stmt) {
|
|
6003
6135
|
if (!stmt || !stmt.Cmd) return false;
|
|
6004
|
-
const t =
|
|
6136
|
+
const t = stmt.Cmd.kind;
|
|
6005
6137
|
if (t === "BinaryCmd") {
|
|
6006
|
-
if (!AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
6138
|
+
if (!andOrOps().AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
6007
6139
|
if (!recordTopLevelStmt(stmt.Cmd.X)) return false;
|
|
6008
|
-
if (stmt.Cmd.Op === AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
6140
|
+
if (stmt.Cmd.Op === andOrOps().AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
6009
6141
|
return true;
|
|
6010
6142
|
}
|
|
6011
6143
|
if (t !== "CallExpr" && t !== "DeclClause") return false;
|
|
6012
6144
|
let at = 0;
|
|
6013
6145
|
try {
|
|
6014
|
-
at = stmt.
|
|
6146
|
+
at = stmt.pos;
|
|
6015
6147
|
} catch {
|
|
6016
6148
|
at = 0;
|
|
6017
6149
|
}
|
|
@@ -6022,14 +6154,14 @@ function recordTopLevelStmt(stmt) {
|
|
|
6022
6154
|
}
|
|
6023
6155
|
function recordAssignments(n, at) {
|
|
6024
6156
|
if (!assignmentTable) return;
|
|
6025
|
-
const t =
|
|
6157
|
+
const t = n.kind;
|
|
6026
6158
|
let assigns = [];
|
|
6027
6159
|
if (t === "CallExpr") {
|
|
6028
6160
|
if ((n.Args || []).length > 0) return;
|
|
6029
6161
|
assigns = n.Assigns || [];
|
|
6030
6162
|
} else if (t === "DeclClause") {
|
|
6031
6163
|
if (!ASSIGNMENT_HEADS.has(n.Variant?.Value ?? "")) return;
|
|
6032
|
-
assigns = (n.Args || []).filter((a) =>
|
|
6164
|
+
assigns = (n.Args || []).filter((a) => a.kind === "Assign");
|
|
6033
6165
|
} else return;
|
|
6034
6166
|
for (const a of assigns) {
|
|
6035
6167
|
const name = a?.Name?.Value;
|
|
@@ -6038,13 +6170,13 @@ function recordAssignments(n, at) {
|
|
|
6038
6170
|
}
|
|
6039
6171
|
}
|
|
6040
6172
|
function resolveTrivialSubst(part) {
|
|
6041
|
-
if (
|
|
6173
|
+
if (part.kind !== "CmdSubst") return void 0;
|
|
6042
6174
|
const stmts = part.Stmts || [];
|
|
6043
6175
|
if (stmts.length !== 1) return void 0;
|
|
6044
6176
|
const st = stmts[0];
|
|
6045
6177
|
if ((st.Redirs || []).length > 0 || st.Negated || st.Background) return void 0;
|
|
6046
6178
|
const cmd = st.Cmd;
|
|
6047
|
-
if (!cmd ||
|
|
6179
|
+
if (!cmd || cmd.kind !== "CallExpr") return void 0;
|
|
6048
6180
|
if ((cmd.Assigns || []).length > 0) return void 0;
|
|
6049
6181
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
6050
6182
|
if (words.length === 0 || words.some((w) => w === null)) return void 0;
|
|
@@ -6069,7 +6201,7 @@ function recordedExpansion(name) {
|
|
|
6069
6201
|
return rec.value;
|
|
6070
6202
|
}
|
|
6071
6203
|
function isPlainParam(p) {
|
|
6072
|
-
if (
|
|
6204
|
+
if (p.kind !== "ParamExp") return false;
|
|
6073
6205
|
return !(p.Excl || p.Length || p.Width || p.Index || p.Slice || p.Repl || p.Exp);
|
|
6074
6206
|
}
|
|
6075
6207
|
function expandPlainParam(p) {
|
|
@@ -6085,9 +6217,9 @@ var callDepth = 0;
|
|
|
6085
6217
|
var callWalks = 0;
|
|
6086
6218
|
function functionBodies(f) {
|
|
6087
6219
|
const out = /* @__PURE__ */ new Map();
|
|
6088
|
-
|
|
6220
|
+
walk(f, (node) => {
|
|
6089
6221
|
const n = node;
|
|
6090
|
-
if (n &&
|
|
6222
|
+
if (n && n.kind === "FuncDecl" && n.Name?.Value && n.Body) {
|
|
6091
6223
|
const list = out.get(n.Name.Value) ?? [];
|
|
6092
6224
|
list.push(n.Body);
|
|
6093
6225
|
out.set(n.Name.Value, list);
|
|
@@ -6098,10 +6230,10 @@ function functionBodies(f) {
|
|
|
6098
6230
|
}
|
|
6099
6231
|
function rebindsPositionals(body) {
|
|
6100
6232
|
let found = false;
|
|
6101
|
-
|
|
6233
|
+
walk(body, (node) => {
|
|
6102
6234
|
const n = node;
|
|
6103
6235
|
if (found || !n) return false;
|
|
6104
|
-
if (
|
|
6236
|
+
if (n.kind === "CallExpr") {
|
|
6105
6237
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
6106
6238
|
if (words[0] === "shift") found = true;
|
|
6107
6239
|
else if (words[0] === "set" && words.slice(1).some((w) => w === null || w === "--" || !/^[-+]/.test(w)))
|
|
@@ -6121,7 +6253,7 @@ function tableBindings() {
|
|
|
6121
6253
|
function walkWithCalls(f, visit) {
|
|
6122
6254
|
const bodies = functionBodies(f);
|
|
6123
6255
|
if (bodies.size === 0) {
|
|
6124
|
-
|
|
6256
|
+
walk(f, visit);
|
|
6125
6257
|
return;
|
|
6126
6258
|
}
|
|
6127
6259
|
const seenCalls = /* @__PURE__ */ new Set();
|
|
@@ -6155,8 +6287,8 @@ function walkWithCalls(f, visit) {
|
|
|
6155
6287
|
currentStmtOffset = Number.MAX_SAFE_INTEGER;
|
|
6156
6288
|
callDepth++;
|
|
6157
6289
|
try {
|
|
6158
|
-
if (body.Cmd &&
|
|
6159
|
-
|
|
6290
|
+
if (body.Cmd && body.Cmd.kind === "Block") recordTopLevelAssignments(body.Cmd);
|
|
6291
|
+
walk(body, step);
|
|
6160
6292
|
} finally {
|
|
6161
6293
|
callDepth--;
|
|
6162
6294
|
assignmentTable = outerTable;
|
|
@@ -6167,10 +6299,10 @@ function walkWithCalls(f, visit) {
|
|
|
6167
6299
|
const step = (node) => {
|
|
6168
6300
|
if (!node) return false;
|
|
6169
6301
|
const go = visit(node);
|
|
6170
|
-
if (go !== false &&
|
|
6302
|
+
if (go !== false && node.kind === "CallExpr") inline(node);
|
|
6171
6303
|
return go;
|
|
6172
6304
|
};
|
|
6173
|
-
|
|
6305
|
+
walk(f, step);
|
|
6174
6306
|
}
|
|
6175
6307
|
function withAssignments(f, body) {
|
|
6176
6308
|
const outerTable = assignmentTable;
|
|
@@ -6195,7 +6327,7 @@ function walkCommandScope(command, visit) {
|
|
|
6195
6327
|
if (f === PARSE_FAIL) return "parse-fail";
|
|
6196
6328
|
withAssignments(f, () => {
|
|
6197
6329
|
walkWithCalls(f, (node) => {
|
|
6198
|
-
if (node &&
|
|
6330
|
+
if (node && node.kind === "Stmt") trackStatement(node);
|
|
6199
6331
|
return visit(node);
|
|
6200
6332
|
});
|
|
6201
6333
|
});
|
|
@@ -6203,7 +6335,7 @@ function walkCommandScope(command, visit) {
|
|
|
6203
6335
|
}
|
|
6204
6336
|
function trackStatement(n) {
|
|
6205
6337
|
try {
|
|
6206
|
-
currentStmtOffset = n.
|
|
6338
|
+
currentStmtOffset = n.pos;
|
|
6207
6339
|
} catch {
|
|
6208
6340
|
currentStmtOffset = Number.MAX_SAFE_INTEGER;
|
|
6209
6341
|
}
|
|
@@ -6219,11 +6351,11 @@ function resolveWordLiteral(w) {
|
|
|
6219
6351
|
return s;
|
|
6220
6352
|
}
|
|
6221
6353
|
function resolveWordPrefix(w) {
|
|
6222
|
-
const
|
|
6354
|
+
const walk3 = (parts) => {
|
|
6223
6355
|
let s = "";
|
|
6224
6356
|
for (const p of parts) {
|
|
6225
6357
|
if (p && typeof p === "object" && Array.isArray(p.Parts) && p.Dollar !== void 0) {
|
|
6226
|
-
const inner =
|
|
6358
|
+
const inner = walk3(p.Parts);
|
|
6227
6359
|
s += inner.prefix;
|
|
6228
6360
|
if (inner.dynamic) return { prefix: s, dynamic: true };
|
|
6229
6361
|
continue;
|
|
@@ -6234,10 +6366,10 @@ function resolveWordPrefix(w) {
|
|
|
6234
6366
|
}
|
|
6235
6367
|
return { prefix: s, dynamic: false };
|
|
6236
6368
|
};
|
|
6237
|
-
return
|
|
6369
|
+
return walk3(w?.Parts || []);
|
|
6238
6370
|
}
|
|
6239
6371
|
function resolvePart(p, inQuotes) {
|
|
6240
|
-
const t =
|
|
6372
|
+
const t = p.kind;
|
|
6241
6373
|
if (t === "Lit") {
|
|
6242
6374
|
const raw = p.Value ?? "";
|
|
6243
6375
|
if (!inQuotes) return raw.replace(/\\(.)/g, "$1");
|
|
@@ -6333,7 +6465,7 @@ function extractShellDestinations(command) {
|
|
|
6333
6465
|
() => walkWithCalls(f, (node) => {
|
|
6334
6466
|
if (!node) return false;
|
|
6335
6467
|
const n = node;
|
|
6336
|
-
if (
|
|
6468
|
+
if (n.kind === "Stmt") {
|
|
6337
6469
|
trackStatement(n);
|
|
6338
6470
|
for (const raw of redirectWords(n)) {
|
|
6339
6471
|
const host2 = devNetRedirectHost(raw);
|
|
@@ -6345,7 +6477,7 @@ function extractShellDestinations(command) {
|
|
|
6345
6477
|
out.push({ host: host2, binary, raw });
|
|
6346
6478
|
}
|
|
6347
6479
|
}
|
|
6348
|
-
if (
|
|
6480
|
+
if (n.kind !== "CallExpr") return true;
|
|
6349
6481
|
const callArgs = n.Args || [];
|
|
6350
6482
|
if (callArgs.length === 0) return true;
|
|
6351
6483
|
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
@@ -6380,7 +6512,7 @@ function extractShellDestTokens(command) {
|
|
|
6380
6512
|
() => walkWithCalls(f, (node) => {
|
|
6381
6513
|
if (!node) return false;
|
|
6382
6514
|
const n = node;
|
|
6383
|
-
if (
|
|
6515
|
+
if (n.kind === "Stmt") {
|
|
6384
6516
|
trackStatement(n);
|
|
6385
6517
|
for (const raw of redirectWords(n)) {
|
|
6386
6518
|
const host2 = devNetRedirectHost(raw);
|
|
@@ -6392,7 +6524,7 @@ function extractShellDestTokens(command) {
|
|
|
6392
6524
|
out.push({ token: host2, binary });
|
|
6393
6525
|
}
|
|
6394
6526
|
}
|
|
6395
|
-
if (
|
|
6527
|
+
if (n.kind !== "CallExpr") return true;
|
|
6396
6528
|
const callArgs = n.Args || [];
|
|
6397
6529
|
if (callArgs.length === 0) return true;
|
|
6398
6530
|
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
@@ -6463,11 +6595,11 @@ function isWaivableCleanupTarget(p) {
|
|
|
6463
6595
|
}
|
|
6464
6596
|
function deriveRedirOp(sample) {
|
|
6465
6597
|
try {
|
|
6466
|
-
const f = sharedParser.Parse(sample, "cmd");
|
|
6598
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
6467
6599
|
let op = -1;
|
|
6468
|
-
|
|
6600
|
+
walk(f, (node) => {
|
|
6469
6601
|
const n = node;
|
|
6470
|
-
if (n &&
|
|
6602
|
+
if (n && n.kind === "Redirect" && op < 0) op = n.Op;
|
|
6471
6603
|
return true;
|
|
6472
6604
|
});
|
|
6473
6605
|
return op;
|
|
@@ -6475,24 +6607,23 @@ function deriveRedirOp(sample) {
|
|
|
6475
6607
|
return -1;
|
|
6476
6608
|
}
|
|
6477
6609
|
}
|
|
6478
|
-
var REDIR_TRUNCATE_OPS = /* @__PURE__ */ new Set([deriveRedirOp(">_f")]);
|
|
6479
|
-
var REDIR_FILE_IN_OPS =
|
|
6480
|
-
[deriveRedirOp("cat < f"), deriveRedirOp("cat <> f")].filter((op) => op >= 0)
|
|
6610
|
+
var REDIR_TRUNCATE_OPS = lazy(() => /* @__PURE__ */ new Set([deriveRedirOp(">_f")]));
|
|
6611
|
+
var REDIR_FILE_IN_OPS = lazy(
|
|
6612
|
+
() => new Set([deriveRedirOp("cat < f"), deriveRedirOp("cat <> f")].filter((op) => op >= 0))
|
|
6613
|
+
);
|
|
6614
|
+
var REDIR_HEREDOC_OPS = lazy(
|
|
6615
|
+
() => /* @__PURE__ */ new Set([deriveRedirOp("cat <<X\nX"), deriveRedirOp("cat <<-X\nX")])
|
|
6481
6616
|
);
|
|
6482
|
-
var REDIR_HEREDOC_OPS = /* @__PURE__ */ new Set([
|
|
6483
|
-
deriveRedirOp("cat <<X\nX"),
|
|
6484
|
-
deriveRedirOp("cat <<-X\nX")
|
|
6485
|
-
]);
|
|
6486
6617
|
function collectSameCommandCreations(f) {
|
|
6487
6618
|
const created = /* @__PURE__ */ new Set();
|
|
6488
6619
|
try {
|
|
6489
6620
|
const stmts = Array.isArray(f?.Stmts) ? f.Stmts : [];
|
|
6490
6621
|
for (const stmt of stmts) {
|
|
6491
|
-
if (!stmt || !stmt.Cmd ||
|
|
6622
|
+
if (!stmt || !stmt.Cmd || stmt.Cmd.kind !== "CallExpr") continue;
|
|
6492
6623
|
const redirs = stmt.Redirs || [];
|
|
6493
|
-
if (!redirs.some((r) => r && REDIR_HEREDOC_OPS.has(r.Op))) continue;
|
|
6624
|
+
if (!redirs.some((r) => r && REDIR_HEREDOC_OPS().has(r.Op))) continue;
|
|
6494
6625
|
for (const r of redirs) {
|
|
6495
|
-
if (r && REDIR_TRUNCATE_OPS.has(r.Op) && r.N == null) {
|
|
6626
|
+
if (r && REDIR_TRUNCATE_OPS().has(r.Op) && r.N == null) {
|
|
6496
6627
|
const w = resolveWordLiteral(r.Word);
|
|
6497
6628
|
if (w) created.add(stripDotSlash(w));
|
|
6498
6629
|
}
|
|
@@ -6512,10 +6643,10 @@ function isRmCreatedInCommandCleanup(command) {
|
|
|
6512
6643
|
let sawRm = false;
|
|
6513
6644
|
let ok = true;
|
|
6514
6645
|
try {
|
|
6515
|
-
|
|
6646
|
+
walk(f, (node) => {
|
|
6516
6647
|
if (!node || !ok) return false;
|
|
6517
6648
|
const n = node;
|
|
6518
|
-
if (
|
|
6649
|
+
if (n.kind !== "CallExpr") return true;
|
|
6519
6650
|
const args = n.Args || [];
|
|
6520
6651
|
const name = (resolveWordLiteral(args[0]) ?? "").toLowerCase();
|
|
6521
6652
|
if (name !== "rm") return true;
|
|
@@ -6565,10 +6696,10 @@ function analyzeFsOperationImpl(command, depth = 0) {
|
|
|
6565
6696
|
walkWithCalls(f, (node) => {
|
|
6566
6697
|
if (!node || result?.verdict === "block") return false;
|
|
6567
6698
|
const n = node;
|
|
6568
|
-
const nodeType =
|
|
6699
|
+
const nodeType = n.kind;
|
|
6569
6700
|
if (nodeType === "Stmt") {
|
|
6570
6701
|
try {
|
|
6571
|
-
currentStmtOffset = n.
|
|
6702
|
+
currentStmtOffset = n.pos;
|
|
6572
6703
|
} catch {
|
|
6573
6704
|
currentStmtOffset = Number.MAX_SAFE_INTEGER;
|
|
6574
6705
|
}
|
|
@@ -7092,7 +7223,7 @@ function literalShellPayload(words, name) {
|
|
|
7092
7223
|
function jailedRedirectRead(stmt) {
|
|
7093
7224
|
const redirs = stmt.Redirs || [];
|
|
7094
7225
|
for (const r of redirs) {
|
|
7095
|
-
if (!r || !REDIR_FILE_IN_OPS.has(r.Op)) continue;
|
|
7226
|
+
if (!r || !REDIR_FILE_IN_OPS().has(r.Op)) continue;
|
|
7096
7227
|
const p = resolveWordLiteral(r.Word);
|
|
7097
7228
|
if (p === null || p === "") continue;
|
|
7098
7229
|
const hit = matchSensitivePath(p);
|
|
@@ -7111,11 +7242,12 @@ function analyzeShellCommand(command) {
|
|
|
7111
7242
|
if (lower2.startsWith("-")) allTokens.push(lower2.replace(/^-+/, ""));
|
|
7112
7243
|
};
|
|
7113
7244
|
try {
|
|
7114
|
-
const f =
|
|
7115
|
-
|
|
7245
|
+
const f = parseShared(command);
|
|
7246
|
+
if (f === PARSE_FAIL) throw new Error("parse failed");
|
|
7247
|
+
walk(f, (node) => {
|
|
7116
7248
|
if (!node) return false;
|
|
7117
7249
|
const n = node;
|
|
7118
|
-
if (
|
|
7250
|
+
if (n.kind !== "CallExpr") return true;
|
|
7119
7251
|
const wordValues2 = (n.Args || []).map((arg) => {
|
|
7120
7252
|
return (arg.Parts || []).map((p) => (p.Value ?? "").replace(/\\(.)/g, "$1")).join("");
|
|
7121
7253
|
}).filter((s) => s.length > 0);
|
|
@@ -7414,8 +7546,6 @@ function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
|
|
|
7414
7546
|
}
|
|
7415
7547
|
|
|
7416
7548
|
// src/shell/file-access.ts
|
|
7417
|
-
var import_mvdan_sh2 = __toESM(require("mvdan-sh"));
|
|
7418
|
-
var { syntax: syntax2 } = import_mvdan_sh2.default;
|
|
7419
7549
|
var MAX_ALTERNATIVES = 64;
|
|
7420
7550
|
var MAX_CALL_DEPTH2 = 4;
|
|
7421
7551
|
var MAX_CALL_WALKS2 = 256;
|
|
@@ -7432,7 +7562,7 @@ function runnablePrefix(command) {
|
|
|
7432
7562
|
let text = command;
|
|
7433
7563
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
7434
7564
|
try {
|
|
7435
|
-
return
|
|
7565
|
+
return toPlainTree(getSyntax().NewParser().Parse(text, ""));
|
|
7436
7566
|
} catch (error) {
|
|
7437
7567
|
const message = String(typeof error?.Error === "function" ? error.Error() : error?.message);
|
|
7438
7568
|
const line = Number(/^(\d+):/.exec(message)?.[1]);
|
|
@@ -7531,18 +7661,22 @@ function merge(a, b) {
|
|
|
7531
7661
|
function opOf(sample) {
|
|
7532
7662
|
return parseShared(sample).Stmts[0].Redirs[0].Op;
|
|
7533
7663
|
}
|
|
7534
|
-
var
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
|
|
7542
|
-
|
|
7543
|
-
|
|
7664
|
+
var ops = lazy(() => ({
|
|
7665
|
+
WRITES: new Set([">x", ">>x", ">|x", "&>x", "&>>x", "<>x"].map(opOf)),
|
|
7666
|
+
APPENDS: new Set([">>x", "&>>x"].map(opOf)),
|
|
7667
|
+
READS: new Set(["<x", "<>x"].map(opOf)),
|
|
7668
|
+
/** `>&word` with a non-numeric word is `&>word` in bash. */
|
|
7669
|
+
DUP_OUT: opOf(">&x"),
|
|
7670
|
+
HERE_STRING: opOf("<<<x"),
|
|
7671
|
+
AND: parseShared("a && b").Stmts[0].Cmd.Op,
|
|
7672
|
+
OR: parseShared("a || b").Stmts[0].Cmd.Op,
|
|
7673
|
+
/** `${x:-d}` `${x-d}` `${x:=d}` `${x=d}`: the default is the value when x is unset. */
|
|
7674
|
+
DEFAULT_OPS: new Set(
|
|
7675
|
+
["${x:-y}", "${x-y}", "${x:=y}", "${x=y}"].map(
|
|
7676
|
+
(s) => parseShared(`echo ${s}`).Stmts[0].Cmd.Args[1].Parts[0].Exp.Op
|
|
7677
|
+
)
|
|
7544
7678
|
)
|
|
7545
|
-
);
|
|
7679
|
+
}));
|
|
7546
7680
|
function wordValues(word, state) {
|
|
7547
7681
|
const toWords = (values, quoted) => values.map((value) => ({
|
|
7548
7682
|
value,
|
|
@@ -7554,7 +7688,7 @@ function wordValues(word, state) {
|
|
|
7554
7688
|
const name = node.Param?.Value;
|
|
7555
7689
|
const known = name === "PWD" ? state.cwd : state.vars.get(name);
|
|
7556
7690
|
if (node.Exp) {
|
|
7557
|
-
if (!DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7691
|
+
if (!ops().DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7558
7692
|
if (known && known.length) return toWords(known, quoted);
|
|
7559
7693
|
const fallback = expand(node.Exp.Word?.Parts ?? [], quoted);
|
|
7560
7694
|
return fallback.dynamic ? null : fallback.out.map(asWord);
|
|
@@ -7577,7 +7711,7 @@ function wordValues(word, state) {
|
|
|
7577
7711
|
out2 = next.slice(0, MAX_ALTERNATIVES);
|
|
7578
7712
|
};
|
|
7579
7713
|
for (const node of nodes) {
|
|
7580
|
-
const kind =
|
|
7714
|
+
const kind = node.kind;
|
|
7581
7715
|
let pieces;
|
|
7582
7716
|
if (kind === "ParamExp") pieces = paramValues(node, quoted);
|
|
7583
7717
|
else if (kind === "DblQuoted") {
|
|
@@ -7645,9 +7779,9 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7645
7779
|
}
|
|
7646
7780
|
function substitutions(word, state, depth) {
|
|
7647
7781
|
if (!word) return;
|
|
7648
|
-
|
|
7782
|
+
walk(word, (node) => {
|
|
7649
7783
|
if (!node) return false;
|
|
7650
|
-
if (["CmdSubst", "ProcSubst"].includes(
|
|
7784
|
+
if (["CmdSubst", "ProcSubst"].includes(node.kind)) {
|
|
7651
7785
|
statements(node.Stmts ?? [], clone(state), depth + 1);
|
|
7652
7786
|
return false;
|
|
7653
7787
|
}
|
|
@@ -8071,7 +8205,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8071
8205
|
}
|
|
8072
8206
|
function readsScriptFromStdin(stmt) {
|
|
8073
8207
|
const cmd = stmt?.Cmd;
|
|
8074
|
-
if (!cmd ||
|
|
8208
|
+
if (!cmd || cmd.kind !== "CallExpr") return false;
|
|
8075
8209
|
const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
8076
8210
|
const head = unwrapCommandHead(words);
|
|
8077
8211
|
return SHELL_INTERPRETERS.has(base(words[head])) && shellConsumesPipe(words.slice(head + 1));
|
|
@@ -8079,13 +8213,13 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8079
8213
|
function stdinText(stmt) {
|
|
8080
8214
|
for (const redir of stmt?.Redirs ?? []) {
|
|
8081
8215
|
if (redir.Hdoc) return resolveWordLiteral(redir.Hdoc);
|
|
8082
|
-
if (redir.Op === HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
8216
|
+
if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
8083
8217
|
}
|
|
8084
8218
|
return null;
|
|
8085
8219
|
}
|
|
8086
8220
|
function producedText(stmt) {
|
|
8087
8221
|
const cmd = stmt?.Cmd;
|
|
8088
|
-
if (!cmd ||
|
|
8222
|
+
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
8089
8223
|
const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
8090
8224
|
if (words.some((w) => w === null)) return null;
|
|
8091
8225
|
const head = unwrapCommandHead(words);
|
|
@@ -8104,15 +8238,15 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8104
8238
|
if (!stmt || depth > MAX_DEPTH) return;
|
|
8105
8239
|
state.onSuccess = void 0;
|
|
8106
8240
|
if (stmt.Background) state = clone(state);
|
|
8107
|
-
const headWord = stmt.Cmd &&
|
|
8241
|
+
const headWord = stmt.Cmd && stmt.Cmd.kind === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
|
|
8108
8242
|
const sends = SENDING_STDIN.has(headWord);
|
|
8109
8243
|
for (const redir of stmt.Redirs ?? []) {
|
|
8110
8244
|
substitutions(redir.Word, state, depth);
|
|
8111
8245
|
for (const word of wordValues(redir.Word, state)) {
|
|
8112
|
-
if (WRITES.has(redir.Op))
|
|
8113
|
-
add("write", word, state, APPENDS.has(redir.Op) ? { append: true } : {});
|
|
8114
|
-
if (READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
8115
|
-
if (redir.Op === DUP_OUT && word.value && !/^\d+$/.test(word.value))
|
|
8246
|
+
if (ops().WRITES.has(redir.Op))
|
|
8247
|
+
add("write", word, state, ops().APPENDS.has(redir.Op) ? { append: true } : {});
|
|
8248
|
+
if (ops().READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
8249
|
+
if (redir.Op === ops().DUP_OUT && word.value && !/^\d+$/.test(word.value))
|
|
8116
8250
|
add("write", word, state);
|
|
8117
8251
|
}
|
|
8118
8252
|
substitutions(redir.Hdoc, state, depth);
|
|
@@ -8120,7 +8254,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8120
8254
|
const cmd = stmt.Cmd;
|
|
8121
8255
|
if (!cmd) return;
|
|
8122
8256
|
stdinScript(stmt, state, depth);
|
|
8123
|
-
switch (
|
|
8257
|
+
switch (cmd.kind) {
|
|
8124
8258
|
case "CallExpr":
|
|
8125
8259
|
call(cmd, state, depth);
|
|
8126
8260
|
break;
|
|
@@ -8134,7 +8268,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8134
8268
|
for (; ; ) {
|
|
8135
8269
|
segments2.unshift({ op: node.Op, part: node.Y });
|
|
8136
8270
|
const left = node.X;
|
|
8137
|
-
if (left?.Cmd &&
|
|
8271
|
+
if (left?.Cmd && left.Cmd.kind === "BinaryCmd" && !left.Redirs?.length && !left.Negated && !left.Background)
|
|
8138
8272
|
node = left.Cmd;
|
|
8139
8273
|
else {
|
|
8140
8274
|
segments2.unshift({ op: node.Op, part: left });
|
|
@@ -8144,16 +8278,17 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8144
8278
|
const seen = clone(state);
|
|
8145
8279
|
let pureAnd = true;
|
|
8146
8280
|
segments2.forEach(({ op, part }, i) => {
|
|
8147
|
-
if (op === AND || op === OR) {
|
|
8148
|
-
if (i > 0 && op === AND && pureAnd && state.onSuccess)
|
|
8149
|
-
|
|
8281
|
+
if (op === ops().AND || op === ops().OR) {
|
|
8282
|
+
if (i > 0 && op === ops().AND && pureAnd && state.onSuccess)
|
|
8283
|
+
state.cwd = state.onSuccess;
|
|
8284
|
+
if (i > 0 && op === ops().OR) merge(state, seen);
|
|
8150
8285
|
statement(part, state, depth + 1);
|
|
8151
8286
|
} else {
|
|
8152
8287
|
statement(part, clone(state), depth + 1);
|
|
8153
8288
|
if (i > 0 && readsScriptFromStdin(part))
|
|
8154
8289
|
nestedPayload(producedText(segments2[i - 1].part), clone(state), depth);
|
|
8155
8290
|
}
|
|
8156
|
-
if (i > 0 && op !== AND) pureAnd = false;
|
|
8291
|
+
if (i > 0 && op !== ops().AND) pureAnd = false;
|
|
8157
8292
|
merge(seen, state);
|
|
8158
8293
|
});
|
|
8159
8294
|
merge(state, seen);
|
|
@@ -8409,18 +8544,17 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
8409
8544
|
}
|
|
8410
8545
|
|
|
8411
8546
|
// src/shell/derived-writes.ts
|
|
8412
|
-
var
|
|
8413
|
-
|
|
8414
|
-
const ops = /* @__PURE__ */ new Set();
|
|
8547
|
+
var SEQUENCE_OPS = lazy(() => {
|
|
8548
|
+
const ops2 = /* @__PURE__ */ new Set();
|
|
8415
8549
|
for (const text of ["x && y", "x || y"]) {
|
|
8416
8550
|
try {
|
|
8417
8551
|
const f = parseShared(text);
|
|
8418
|
-
if (typeof f !== "symbol")
|
|
8552
|
+
if (typeof f !== "symbol") ops2.add(f.Stmts[0].Cmd.Op);
|
|
8419
8553
|
} catch {
|
|
8420
8554
|
}
|
|
8421
8555
|
}
|
|
8422
|
-
return
|
|
8423
|
-
})
|
|
8556
|
+
return ops2;
|
|
8557
|
+
});
|
|
8424
8558
|
function offsetMapper(text) {
|
|
8425
8559
|
if (!/[^\u0000-\u007f]/.test(text)) return (b) => b;
|
|
8426
8560
|
const starts = [];
|
|
@@ -8448,13 +8582,13 @@ function pipelineTexts(command) {
|
|
|
8448
8582
|
const visit = (stmt, depth) => {
|
|
8449
8583
|
if (!stmt || depth > 64) return;
|
|
8450
8584
|
const cmd = stmt.Cmd;
|
|
8451
|
-
if (cmd &&
|
|
8585
|
+
if (cmd && cmd.kind === "BinaryCmd" && SEQUENCE_OPS().has(cmd.Op)) {
|
|
8452
8586
|
visit(cmd.X, depth + 1);
|
|
8453
8587
|
visit(cmd.Y, depth + 1);
|
|
8454
8588
|
return;
|
|
8455
8589
|
}
|
|
8456
|
-
const s = at(stmt.
|
|
8457
|
-
const e = at(stmt.
|
|
8590
|
+
const s = at(stmt.pos);
|
|
8591
|
+
const e = at(stmt.end);
|
|
8458
8592
|
const text = s >= 0 && e > s ? command.slice(s, e).replace(/[\s;&]+$/, "") : "";
|
|
8459
8593
|
if (text) out.push(text);
|
|
8460
8594
|
};
|
|
@@ -12794,15 +12928,13 @@ function writtenTexts(args) {
|
|
|
12794
12928
|
}
|
|
12795
12929
|
|
|
12796
12930
|
// src/shell/write-source.ts
|
|
12797
|
-
var
|
|
12798
|
-
var { syntax: syntax4 } = import_mvdan_sh4.default;
|
|
12799
|
-
var RDR_IN = (() => {
|
|
12931
|
+
var RDR_IN = lazy(() => {
|
|
12800
12932
|
try {
|
|
12801
12933
|
return parseShared("x <y").Stmts[0].Redirs[0].Op;
|
|
12802
12934
|
} catch {
|
|
12803
12935
|
return null;
|
|
12804
12936
|
}
|
|
12805
|
-
})
|
|
12937
|
+
});
|
|
12806
12938
|
var COPY_VERBS2 = /* @__PURE__ */ new Set([
|
|
12807
12939
|
"cp",
|
|
12808
12940
|
"mv",
|
|
@@ -12830,17 +12962,16 @@ function shellWriteUnseen(command, target) {
|
|
|
12830
12962
|
let unseen = false;
|
|
12831
12963
|
let seen = false;
|
|
12832
12964
|
try {
|
|
12833
|
-
|
|
12965
|
+
walk(f, (node) => {
|
|
12834
12966
|
if (!node || unseen) return false;
|
|
12835
12967
|
const n = node;
|
|
12836
|
-
if (
|
|
12837
|
-
return true;
|
|
12968
|
+
if (n.kind !== "Stmt" || !n.Cmd || n.Cmd.kind !== "CallExpr") return true;
|
|
12838
12969
|
const words = (n.Cmd.Args || []).map(
|
|
12839
12970
|
(a) => resolveWordLiteral(a)
|
|
12840
12971
|
);
|
|
12841
12972
|
const redirs = n.Redirs || [];
|
|
12842
12973
|
const redirectsTo = redirs.some((r) => r.Word && resolveWordLiteral(r.Word) === target);
|
|
12843
|
-
const readsFromFile = redirs.some((r) => r.Op === RDR_IN && r.Word && !r.Hdoc);
|
|
12974
|
+
const readsFromFile = redirs.some((r) => r.Op === RDR_IN() && r.Word && !r.Hdoc);
|
|
12844
12975
|
const named = words.includes(target);
|
|
12845
12976
|
if (!redirectsTo && !named) return true;
|
|
12846
12977
|
const head = unwrapCommandHead(words);
|
|
@@ -12864,8 +12995,6 @@ function shellWriteUnseen(command, target) {
|
|
|
12864
12995
|
}
|
|
12865
12996
|
|
|
12866
12997
|
// src/shell/git.ts
|
|
12867
|
-
var import_mvdan_sh5 = __toESM(require("mvdan-sh"));
|
|
12868
|
-
var { syntax: syntax5 } = import_mvdan_sh5.default;
|
|
12869
12998
|
var GIT_PRESCREEN_RE = /git|husky/i;
|
|
12870
12999
|
var MAX_PAYLOAD_DEPTH2 = 8;
|
|
12871
13000
|
var MAX_ALIAS_DEPTH = 5;
|
|
@@ -12891,11 +13020,11 @@ function analyzeGit(command) {
|
|
|
12891
13020
|
}
|
|
12892
13021
|
function gitInvocations(command) {
|
|
12893
13022
|
const out = [];
|
|
12894
|
-
const
|
|
13023
|
+
const walk3 = new GitWalk(
|
|
12895
13024
|
(inv) => out.push(inv),
|
|
12896
13025
|
() => void 0
|
|
12897
13026
|
);
|
|
12898
|
-
|
|
13027
|
+
walk3.run(command, 0);
|
|
12899
13028
|
return out;
|
|
12900
13029
|
}
|
|
12901
13030
|
function analyzeGitImpl(command) {
|
|
@@ -12907,8 +13036,8 @@ function analyzeGitImpl(command) {
|
|
|
12907
13036
|
seen.add(key);
|
|
12908
13037
|
findings.push(f);
|
|
12909
13038
|
};
|
|
12910
|
-
const
|
|
12911
|
-
const parsed =
|
|
13039
|
+
const walk3 = new GitWalk((inv) => classify(inv).forEach(found), found);
|
|
13040
|
+
const parsed = walk3.run(command, 0);
|
|
12912
13041
|
return { parsed, findings };
|
|
12913
13042
|
}
|
|
12914
13043
|
var PAYLOAD_SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh", "eval"]);
|
|
@@ -12974,7 +13103,7 @@ var GitWalk = class {
|
|
|
12974
13103
|
visit(node, depth) {
|
|
12975
13104
|
if (!node) return false;
|
|
12976
13105
|
const n = node;
|
|
12977
|
-
const type =
|
|
13106
|
+
const type = n.kind;
|
|
12978
13107
|
if (type === "Stmt") {
|
|
12979
13108
|
this.visitHeredocShell(n, depth);
|
|
12980
13109
|
return true;
|
|
@@ -12982,7 +13111,7 @@ var GitWalk = class {
|
|
|
12982
13111
|
if (type === "ForClause") {
|
|
12983
13112
|
const loop = n.Loop;
|
|
12984
13113
|
const name = loop?.Name?.Value;
|
|
12985
|
-
if (name &&
|
|
13114
|
+
if (name && loop.kind === "WordIter") {
|
|
12986
13115
|
const items = (loop.Items || []).map((w) => resolveWordLiteral(w));
|
|
12987
13116
|
const literal = items.length > 0 && items.every((v) => v !== null);
|
|
12988
13117
|
this.loopVars.set(name, literal ? items.slice(0, MAX_LOOP_ITEMS) : null);
|
|
@@ -13049,7 +13178,7 @@ var GitWalk = class {
|
|
|
13049
13178
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13050
13179
|
visitHeredocShell(stmt, depth) {
|
|
13051
13180
|
const cmd = stmt.Cmd;
|
|
13052
|
-
if (!cmd ||
|
|
13181
|
+
if (!cmd || cmd.kind !== "CallExpr" || depth >= MAX_PAYLOAD_DEPTH2) return;
|
|
13053
13182
|
const redirs = stmt.Redirs || [];
|
|
13054
13183
|
const hdoc = redirs.find((r) => r?.Hdoc && (r.N == null || r.N.Value === "0"));
|
|
13055
13184
|
if (!hdoc) return;
|
|
@@ -13199,8 +13328,8 @@ var GitWalk = class {
|
|
|
13199
13328
|
var POSITIONAL2 = "\0positional";
|
|
13200
13329
|
function isPositionalParam(word) {
|
|
13201
13330
|
let parts = word?.Parts || [];
|
|
13202
|
-
if (parts.length === 1 &&
|
|
13203
|
-
if (parts.length !== 1 ||
|
|
13331
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
13332
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp") return false;
|
|
13204
13333
|
return /^(\d+|@|\*)$/.test(parts[0].Param?.Value ?? "");
|
|
13205
13334
|
}
|
|
13206
13335
|
function boundPositionals() {
|
|
@@ -13214,11 +13343,11 @@ function boundPositionals() {
|
|
|
13214
13343
|
function plainParamName(word) {
|
|
13215
13344
|
let parts = word?.Parts || [];
|
|
13216
13345
|
let quoted = false;
|
|
13217
|
-
if (parts.length === 1 &&
|
|
13346
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") {
|
|
13218
13347
|
parts = parts[0].Parts || [];
|
|
13219
13348
|
quoted = true;
|
|
13220
13349
|
}
|
|
13221
|
-
if (parts.length !== 1 ||
|
|
13350
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp") return null;
|
|
13222
13351
|
const p = parts[0];
|
|
13223
13352
|
if (p.Excl || p.Length || p.Width || p.Index || p.Slice || p.Repl || p.Exp) return null;
|
|
13224
13353
|
const name = p.Param?.Value;
|
|
@@ -13243,7 +13372,7 @@ function resolveGitWords(word) {
|
|
|
13243
13372
|
}
|
|
13244
13373
|
const parts = word?.Parts || [];
|
|
13245
13374
|
const expansion = parts.some((p) => {
|
|
13246
|
-
const t =
|
|
13375
|
+
const t = p.kind;
|
|
13247
13376
|
return t === "ParamExp" || t === "CmdSubst";
|
|
13248
13377
|
});
|
|
13249
13378
|
return expansion ? splitFields(value) : [value];
|
|
@@ -13754,14 +13883,14 @@ function hookCommands(text) {
|
|
|
13754
13883
|
const root = parsed?.hooks;
|
|
13755
13884
|
if (!root || typeof root !== "object") return null;
|
|
13756
13885
|
const out = [];
|
|
13757
|
-
const
|
|
13886
|
+
const walk3 = (v, depth) => {
|
|
13758
13887
|
if (depth > 8 || !v || typeof v !== "object") return;
|
|
13759
13888
|
for (const [k, x] of Object.entries(v)) {
|
|
13760
13889
|
if (k === "command" && typeof x === "string") out.push(x);
|
|
13761
|
-
else
|
|
13890
|
+
else walk3(x, depth + 1);
|
|
13762
13891
|
}
|
|
13763
13892
|
};
|
|
13764
|
-
|
|
13893
|
+
walk3(root, 0);
|
|
13765
13894
|
return out;
|
|
13766
13895
|
}
|
|
13767
13896
|
function hooksDisarmed(text) {
|
|
@@ -13923,8 +14052,6 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
|
|
|
13923
14052
|
}
|
|
13924
14053
|
|
|
13925
14054
|
// src/shell/outbound.ts
|
|
13926
|
-
var import_mvdan_sh6 = __toESM(require("mvdan-sh"));
|
|
13927
|
-
var { syntax: syntax6 } = import_mvdan_sh6.default;
|
|
13928
14055
|
var SHELLS = /* @__PURE__ */ new Set([...SHELL_INTERPRETERS, "mksh", "ash", "csh", "tcsh"]);
|
|
13929
14056
|
var NETCATS = /* @__PURE__ */ new Set(["nc", "ncat", "netcat", "nc.traditional", "nc.openbsd"]);
|
|
13930
14057
|
var NET_CLIENTS = /* @__PURE__ */ new Set([...NETCATS, "telnet", "socat"]);
|
|
@@ -13964,9 +14091,9 @@ function isDupInOp(op) {
|
|
|
13964
14091
|
if (dupInOp === null) {
|
|
13965
14092
|
let found = -1;
|
|
13966
14093
|
try {
|
|
13967
|
-
|
|
14094
|
+
walk(parseShared("cat <&3"), (node) => {
|
|
13968
14095
|
const n = node;
|
|
13969
|
-
if (found === -1 && n &&
|
|
14096
|
+
if (found === -1 && n && n.kind === "Stmt" && n.Redirs?.[0]) {
|
|
13970
14097
|
found = n.Redirs[0].Op;
|
|
13971
14098
|
}
|
|
13972
14099
|
return true;
|
|
@@ -13987,10 +14114,10 @@ function analyzeOutbound(command) {
|
|
|
13987
14114
|
return hit;
|
|
13988
14115
|
}
|
|
13989
14116
|
const findings = [];
|
|
13990
|
-
const
|
|
13991
|
-
const parsed =
|
|
14117
|
+
const walk3 = new OutboundWalk(findings);
|
|
14118
|
+
const parsed = walk3.run(command, 0);
|
|
13992
14119
|
const envOut = findings.find((f) => f.checkId === "data.env-exfil");
|
|
13993
|
-
if (envOut) envOut.destinations =
|
|
14120
|
+
if (envOut) envOut.destinations = walk3.envDestinations();
|
|
13994
14121
|
const computed = { parsed, findings };
|
|
13995
14122
|
if (cache2.size >= CACHE_MAX2) {
|
|
13996
14123
|
const oldest = cache2.keys().next().value;
|
|
@@ -14008,7 +14135,7 @@ function wordShape(word) {
|
|
|
14008
14135
|
const parts = word?.Parts || [];
|
|
14009
14136
|
let out = "";
|
|
14010
14137
|
for (const p of parts) {
|
|
14011
|
-
const t =
|
|
14138
|
+
const t = p.kind;
|
|
14012
14139
|
if (t === "Lit" || t === "SglQuoted") out += p.Value ?? "";
|
|
14013
14140
|
else if (t === "DblQuoted") out += wordShape(p);
|
|
14014
14141
|
else out += "X";
|
|
@@ -14164,7 +14291,7 @@ var OutboundWalk = class {
|
|
|
14164
14291
|
const f = parseShared(command);
|
|
14165
14292
|
if (!f || typeof f !== "object" || !f.Stmts) return false;
|
|
14166
14293
|
try {
|
|
14167
|
-
|
|
14294
|
+
walk(f, (node) => this.visit(node, depth));
|
|
14168
14295
|
} catch {
|
|
14169
14296
|
return false;
|
|
14170
14297
|
}
|
|
@@ -14203,7 +14330,7 @@ var OutboundWalk = class {
|
|
|
14203
14330
|
}
|
|
14204
14331
|
visit(n, depth) {
|
|
14205
14332
|
if (!n) return false;
|
|
14206
|
-
const type =
|
|
14333
|
+
const type = n.kind;
|
|
14207
14334
|
if (type === "Stmt") {
|
|
14208
14335
|
this.visitStmt(n, depth);
|
|
14209
14336
|
return true;
|
|
@@ -14223,7 +14350,7 @@ var OutboundWalk = class {
|
|
|
14223
14350
|
const redirs = redirectWords(stmt);
|
|
14224
14351
|
const toSocket = redirs.some((w) => w !== null && DEV_NET_RE.test(w));
|
|
14225
14352
|
if (!cmd) return;
|
|
14226
|
-
const type =
|
|
14353
|
+
const type = cmd.kind;
|
|
14227
14354
|
if (type !== "CallExpr" || wordsOf(cmd).length > 0) {
|
|
14228
14355
|
if (this.readsNetFd(stmt) && runsCommandsIn(stmt)) {
|
|
14229
14356
|
this.reverseShell("commands are read from a network socket opened with exec");
|
|
@@ -14309,7 +14436,7 @@ var OutboundWalk = class {
|
|
|
14309
14436
|
const stages = [];
|
|
14310
14437
|
const flatten = (s) => {
|
|
14311
14438
|
const c = s?.Cmd;
|
|
14312
|
-
if (c &&
|
|
14439
|
+
if (c && c.kind === "BinaryCmd" && isPipeOp(c.Op)) {
|
|
14313
14440
|
flatten(c.X);
|
|
14314
14441
|
flatten(c.Y);
|
|
14315
14442
|
} else stages.push(s);
|
|
@@ -14331,8 +14458,8 @@ var OutboundWalk = class {
|
|
|
14331
14458
|
sinks.set(i, socketHosts(st));
|
|
14332
14459
|
}
|
|
14333
14460
|
if (!c) return;
|
|
14334
|
-
if (
|
|
14335
|
-
if (
|
|
14461
|
+
if (c.kind === "DeclClause" && declDumpsEnv(c) && dump < 0) dump = i;
|
|
14462
|
+
if (c.kind !== "CallExpr") {
|
|
14336
14463
|
if (runsCommandsIn(st)) shell = i;
|
|
14337
14464
|
return;
|
|
14338
14465
|
}
|
|
@@ -14373,10 +14500,10 @@ var OutboundWalk = class {
|
|
|
14373
14500
|
/** A word (or assignment value) whose text includes an env dump's output. */
|
|
14374
14501
|
carriesEnv(word) {
|
|
14375
14502
|
let hit = false;
|
|
14376
|
-
|
|
14503
|
+
walk(word, (node) => {
|
|
14377
14504
|
if (hit || !node) return false;
|
|
14378
14505
|
const n = node;
|
|
14379
|
-
const t =
|
|
14506
|
+
const t = n.kind;
|
|
14380
14507
|
if (t === "ParamExp" && n.Param?.Value && this.envVars.has(n.Param.Value)) {
|
|
14381
14508
|
hit = true;
|
|
14382
14509
|
return false;
|
|
@@ -14393,11 +14520,11 @@ var OutboundWalk = class {
|
|
|
14393
14520
|
stmtsDumpEnv(stmts) {
|
|
14394
14521
|
let hit = false;
|
|
14395
14522
|
for (const s of stmts) {
|
|
14396
|
-
|
|
14523
|
+
walk(s, (node) => {
|
|
14397
14524
|
if (hit || !node) return false;
|
|
14398
14525
|
const n = node;
|
|
14399
|
-
const t =
|
|
14400
|
-
if (t === "Stmt" && n.Cmd &&
|
|
14526
|
+
const t = n.kind;
|
|
14527
|
+
if (t === "Stmt" && n.Cmd && n.Cmd.kind === "CallExpr") {
|
|
14401
14528
|
const words = wordsOf(n.Cmd);
|
|
14402
14529
|
if (words.length > 0 && dumpsEnv(words, n)) hit = true;
|
|
14403
14530
|
}
|
|
@@ -14416,16 +14543,16 @@ var OutboundWalk = class {
|
|
|
14416
14543
|
};
|
|
14417
14544
|
function paramName(word) {
|
|
14418
14545
|
let parts = word?.Parts || [];
|
|
14419
|
-
if (parts.length === 1 &&
|
|
14420
|
-
if (parts.length !== 1 ||
|
|
14546
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
14547
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp") return null;
|
|
14421
14548
|
return parts[0].Param?.Value ?? null;
|
|
14422
14549
|
}
|
|
14423
14550
|
function refersTo(word, names) {
|
|
14424
14551
|
let hit = false;
|
|
14425
|
-
|
|
14552
|
+
walk(word, (node) => {
|
|
14426
14553
|
if (hit || !node) return false;
|
|
14427
14554
|
const n = node;
|
|
14428
|
-
if (
|
|
14555
|
+
if (n.kind === "ParamExp" && names.has(n.Param?.Value)) hit = true;
|
|
14429
14556
|
return !hit;
|
|
14430
14557
|
});
|
|
14431
14558
|
return hit;
|
|
@@ -14433,10 +14560,10 @@ function refersTo(word, names) {
|
|
|
14433
14560
|
function runsCommandsIn(stmt) {
|
|
14434
14561
|
const readVars = /* @__PURE__ */ new Set();
|
|
14435
14562
|
let hit = false;
|
|
14436
|
-
|
|
14563
|
+
walk(stmt, (node) => {
|
|
14437
14564
|
if (hit || !node) return false;
|
|
14438
14565
|
const n = node;
|
|
14439
|
-
if (
|
|
14566
|
+
if (n.kind !== "CallExpr") return true;
|
|
14440
14567
|
const words = wordsOf(n);
|
|
14441
14568
|
if (words.length === 0) return true;
|
|
14442
14569
|
const { head, at } = headOf(words);
|
|
@@ -14457,12 +14584,7 @@ function runsCommandsIn(stmt) {
|
|
|
14457
14584
|
return hit;
|
|
14458
14585
|
}
|
|
14459
14586
|
|
|
14460
|
-
// src/shell/package-registry.ts
|
|
14461
|
-
var import_mvdan_sh8 = __toESM(require("mvdan-sh"));
|
|
14462
|
-
|
|
14463
14587
|
// src/shell/package-install.ts
|
|
14464
|
-
var import_mvdan_sh7 = __toESM(require("mvdan-sh"));
|
|
14465
|
-
var { syntax: syntax7 } = import_mvdan_sh7.default;
|
|
14466
14588
|
var NPM_INSTALL_VERBS = /* @__PURE__ */ new Set([
|
|
14467
14589
|
"install",
|
|
14468
14590
|
"i",
|
|
@@ -15036,14 +15158,14 @@ var COMPOSER_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
15036
15158
|
"--add-repository"
|
|
15037
15159
|
]);
|
|
15038
15160
|
function composerPackages(words, from, manager, out) {
|
|
15039
|
-
const
|
|
15040
|
-
const specs = manager === "composer create-project" ?
|
|
15161
|
+
const ops2 = operands(words, from, COMPOSER_VALUE_FLAGS);
|
|
15162
|
+
const specs = manager === "composer create-project" ? ops2.slice(0, 1) : ops2;
|
|
15041
15163
|
for (const raw of specs) {
|
|
15042
15164
|
const sep = raw.search(/[:=]/);
|
|
15043
15165
|
const name = sep < 0 ? raw : raw.slice(0, sep);
|
|
15044
15166
|
if (!COMPOSER_NAME_RE.test(name)) continue;
|
|
15045
15167
|
let ver = sep < 0 ? void 0 : raw.slice(sep + 1);
|
|
15046
|
-
if (manager === "composer create-project" && ver === void 0) ver =
|
|
15168
|
+
if (manager === "composer create-project" && ver === void 0) ver = ops2[2] ?? void 0;
|
|
15047
15169
|
push(out, "Packagist", manager, name.toLowerCase(), exactVersion(ver), raw);
|
|
15048
15170
|
}
|
|
15049
15171
|
}
|
|
@@ -15401,7 +15523,7 @@ function localContexts(file) {
|
|
|
15401
15523
|
if (depth > 64) return null;
|
|
15402
15524
|
if (!stmt || stmt.Background || stmt.Negated || stmt.Redirs?.length) return null;
|
|
15403
15525
|
const cmd = stmt.Cmd;
|
|
15404
|
-
const kind =
|
|
15526
|
+
const kind = cmd.kind;
|
|
15405
15527
|
if (kind === "BinaryCmd" && cmd.Op === andOp) {
|
|
15406
15528
|
const next = visit(cmd.X, steps, depth + 1);
|
|
15407
15529
|
return next === null ? null : visit(cmd.Y, next, depth + 1);
|
|
@@ -15417,7 +15539,7 @@ function localContexts(file) {
|
|
|
15417
15539
|
)
|
|
15418
15540
|
))
|
|
15419
15541
|
return null;
|
|
15420
|
-
contexts.set(cmd.
|
|
15542
|
+
contexts.set(cmd.pos, steps);
|
|
15421
15543
|
return null;
|
|
15422
15544
|
}
|
|
15423
15545
|
if (file.Stmts?.length === 1) visit(file.Stmts[0], []);
|
|
@@ -15428,12 +15550,12 @@ function collect(command, out, depth) {
|
|
|
15428
15550
|
const f = parseShared(command);
|
|
15429
15551
|
if (typeof f === "symbol") return;
|
|
15430
15552
|
const contexts = depth === 0 ? localContexts(f) : /* @__PURE__ */ new Map();
|
|
15431
|
-
|
|
15432
|
-
if (node &&
|
|
15553
|
+
walk(f, (node) => {
|
|
15554
|
+
if (node && node.kind === "CallExpr") {
|
|
15433
15555
|
const words = (node.Args || []).map((a) => resolveWordLiteral(a));
|
|
15434
15556
|
const start = out.length;
|
|
15435
15557
|
if (words.length > 0) fromCall(words, out, depth);
|
|
15436
|
-
const steps = contexts.get(node.
|
|
15558
|
+
const steps = contexts.get(node.pos);
|
|
15437
15559
|
for (let i = start; i < out.length; i++) {
|
|
15438
15560
|
if (["npx", "bunx", "npm exec"].includes(out[i].manager)) {
|
|
15439
15561
|
if (!steps) out[i].localCwd = null;
|
|
@@ -15457,7 +15579,6 @@ function extractPackageInstalls(command) {
|
|
|
15457
15579
|
}
|
|
15458
15580
|
|
|
15459
15581
|
// src/shell/package-registry.ts
|
|
15460
|
-
var { syntax: syntax8 } = import_mvdan_sh8.default;
|
|
15461
15582
|
var NPM_FAMILY = /* @__PURE__ */ new Set(["npm", "pnpm", "yarn", "bun", "npx", "pnpx", "bunx"]);
|
|
15462
15583
|
var PIP_FAMILY = /* @__PURE__ */ new Set(["pip", "pip3", "uv", "uvx", "pipx", "pipenv"]);
|
|
15463
15584
|
var NPM_FETCH_VERBS = /* @__PURE__ */ new Set([
|
|
@@ -15548,7 +15669,7 @@ function collect2(command, out, depth) {
|
|
|
15548
15669
|
try {
|
|
15549
15670
|
walkCommandScope(command, (node) => {
|
|
15550
15671
|
const n = node;
|
|
15551
|
-
if (!n ||
|
|
15672
|
+
if (!n || n.kind !== "CallExpr") return true;
|
|
15552
15673
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
15553
15674
|
if (words.length === 0) return true;
|
|
15554
15675
|
const prefix = (n.Assigns || []).filter((a) => a?.Name?.Value).map(
|
|
@@ -17335,12 +17456,12 @@ function extractContentDestinations(text) {
|
|
|
17335
17456
|
function extractArgDestinations(args) {
|
|
17336
17457
|
const out = /* @__PURE__ */ new Set();
|
|
17337
17458
|
try {
|
|
17338
|
-
|
|
17459
|
+
walk2(args, void 0, out, 0);
|
|
17339
17460
|
} catch {
|
|
17340
17461
|
}
|
|
17341
17462
|
return [...out];
|
|
17342
17463
|
}
|
|
17343
|
-
function
|
|
17464
|
+
function walk2(value, key, out, depth) {
|
|
17344
17465
|
if (out.size >= MAX_DESTINATIONS || depth > 12) return;
|
|
17345
17466
|
if (typeof value === "string") {
|
|
17346
17467
|
const s = value.length > MAX_SCAN_CHARS ? value.slice(0, MAX_SCAN_CHARS) : value;
|
|
@@ -17359,12 +17480,12 @@ function walk(value, key, out, depth) {
|
|
|
17359
17480
|
return;
|
|
17360
17481
|
}
|
|
17361
17482
|
if (Array.isArray(value)) {
|
|
17362
|
-
for (const v of value)
|
|
17483
|
+
for (const v of value) walk2(v, key, out, depth + 1);
|
|
17363
17484
|
return;
|
|
17364
17485
|
}
|
|
17365
17486
|
if (value && typeof value === "object") {
|
|
17366
17487
|
for (const [k, v] of Object.entries(value))
|
|
17367
|
-
|
|
17488
|
+
walk2(v, k, out, depth + 1);
|
|
17368
17489
|
}
|
|
17369
17490
|
}
|
|
17370
17491
|
function destinationDomain(dest) {
|
|
@@ -17875,8 +17996,6 @@ function maskLeaf(value, key, depth) {
|
|
|
17875
17996
|
}
|
|
17876
17997
|
|
|
17877
17998
|
// src/exposure/shell.ts
|
|
17878
|
-
var import_mvdan_sh9 = __toESM(require("mvdan-sh"));
|
|
17879
|
-
var { syntax: syntax9 } = import_mvdan_sh9.default;
|
|
17880
17999
|
var EMPTY = {
|
|
17881
18000
|
fetches: false,
|
|
17882
18001
|
sends: false,
|
|
@@ -18290,9 +18409,9 @@ function classifyCall(head, args, prefixes, env, state, out) {
|
|
|
18290
18409
|
function walkCalls(command, out, depth, state) {
|
|
18291
18410
|
const f = parseShared(command);
|
|
18292
18411
|
if (typeof f === "symbol" || !f) return;
|
|
18293
|
-
|
|
18412
|
+
walk(f, (node) => {
|
|
18294
18413
|
if (!node) return false;
|
|
18295
|
-
const type =
|
|
18414
|
+
const type = node.kind;
|
|
18296
18415
|
if (type === "DeclClause") {
|
|
18297
18416
|
for (const a of node.Args || []) if (a?.Name?.Value) state.env.add(a.Name.Value);
|
|
18298
18417
|
return true;
|
|
@@ -18870,7 +18989,7 @@ function matchCanaryArgs(args, values) {
|
|
|
18870
18989
|
if (values.length === 0) return null;
|
|
18871
18990
|
const needles = prepare(values);
|
|
18872
18991
|
if (needles.length === 0) return null;
|
|
18873
|
-
const
|
|
18992
|
+
const walk3 = (v, depth, fieldPath) => {
|
|
18874
18993
|
if (depth > MAX_DEPTH4) return null;
|
|
18875
18994
|
if (typeof v === "string") {
|
|
18876
18995
|
const hit = matchPrepared(v, needles);
|
|
@@ -18879,31 +18998,31 @@ function matchCanaryArgs(args, values) {
|
|
|
18879
18998
|
const trimmed = v.trim();
|
|
18880
18999
|
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
18881
19000
|
try {
|
|
18882
|
-
return
|
|
19001
|
+
return walk3(JSON.parse(v), depth + 1, fieldPath);
|
|
18883
19002
|
} catch {
|
|
18884
19003
|
}
|
|
18885
19004
|
}
|
|
18886
19005
|
}
|
|
18887
19006
|
return null;
|
|
18888
19007
|
}
|
|
18889
|
-
if (typeof v === "number" && Number.isFinite(v)) return
|
|
19008
|
+
if (typeof v === "number" && Number.isFinite(v)) return walk3(String(v), depth, fieldPath);
|
|
18890
19009
|
if (Array.isArray(v)) {
|
|
18891
19010
|
for (let i = 0; i < v.length; i++) {
|
|
18892
|
-
const h =
|
|
19011
|
+
const h = walk3(v[i], depth + 1, `${fieldPath}[${i}]`);
|
|
18893
19012
|
if (h) return h;
|
|
18894
19013
|
}
|
|
18895
19014
|
return null;
|
|
18896
19015
|
}
|
|
18897
19016
|
if (v && typeof v === "object") {
|
|
18898
19017
|
for (const [k, child] of Object.entries(v)) {
|
|
18899
|
-
const h =
|
|
19018
|
+
const h = walk3(child, depth + 1, fieldPath ? `${fieldPath}.${k}` : k);
|
|
18900
19019
|
if (h) return h;
|
|
18901
19020
|
}
|
|
18902
19021
|
}
|
|
18903
19022
|
return null;
|
|
18904
19023
|
};
|
|
18905
19024
|
try {
|
|
18906
|
-
return
|
|
19025
|
+
return walk3(args, 0, "");
|
|
18907
19026
|
} catch (e) {
|
|
18908
19027
|
console.error(
|
|
18909
19028
|
"[node9 engine] canary args walk failed:",
|
|
@@ -18916,7 +19035,7 @@ function matchCanaryArgs(args, values) {
|
|
|
18916
19035
|
// src/scan/canonical.ts
|
|
18917
19036
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
18918
19037
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
|
|
18919
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
19038
|
+
var CANONICAL_EXTRACTOR_HASH = "8726a60ddd4bad7b";
|
|
18920
19039
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
18921
19040
|
function extractCanonicalFindings(call, ctx) {
|
|
18922
19041
|
const out = [];
|