@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.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
1
|
+
// ../../node_modules/tsup/assets/esm_shims.js
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
var getFilename = () => fileURLToPath(import.meta.url);
|
|
5
|
+
var __filename = /* @__PURE__ */ getFilename();
|
|
3
6
|
|
|
4
7
|
// src/files/protected-access.ts
|
|
5
8
|
import picomatch from "picomatch";
|
|
@@ -3295,8 +3298,139 @@ function resolveCheckMap(settings) {
|
|
|
3295
3298
|
// src/rules/index.ts
|
|
3296
3299
|
import pm from "picomatch";
|
|
3297
3300
|
|
|
3298
|
-
// src/shell/
|
|
3299
|
-
import
|
|
3301
|
+
// src/shell/mvdan.ts
|
|
3302
|
+
import { createRequire } from "module";
|
|
3303
|
+
var syntax = null;
|
|
3304
|
+
function getSyntax() {
|
|
3305
|
+
if (syntax === null) {
|
|
3306
|
+
const req = createRequire(__filename);
|
|
3307
|
+
syntax = req("mvdan-sh").syntax;
|
|
3308
|
+
}
|
|
3309
|
+
return syntax;
|
|
3310
|
+
}
|
|
3311
|
+
function lazy(compute) {
|
|
3312
|
+
let done = false;
|
|
3313
|
+
let value;
|
|
3314
|
+
return () => {
|
|
3315
|
+
if (!done) {
|
|
3316
|
+
value = compute();
|
|
3317
|
+
done = true;
|
|
3318
|
+
}
|
|
3319
|
+
return value;
|
|
3320
|
+
};
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
// src/shell/plain-tree.ts
|
|
3324
|
+
var KINDS = {
|
|
3325
|
+
File: { nodes: ["Stmts"] },
|
|
3326
|
+
Stmt: { nodes: ["Cmd", "Redirs"], scalars: ["Negated", "Background", "Coprocess"] },
|
|
3327
|
+
CallExpr: { nodes: ["Assigns", "Args"] },
|
|
3328
|
+
Assign: { nodes: ["Name", "Value", "Index", "Array"], scalars: ["Append", "Naked"] },
|
|
3329
|
+
Word: { nodes: ["Parts"] },
|
|
3330
|
+
Lit: { scalars: ["Value"] },
|
|
3331
|
+
SglQuoted: { scalars: ["Value", "Dollar"] },
|
|
3332
|
+
DblQuoted: { nodes: ["Parts"], scalars: ["Dollar"] },
|
|
3333
|
+
ParamExp: {
|
|
3334
|
+
nodes: ["Param", "Index", "Slice", "Repl", "Exp"],
|
|
3335
|
+
scalars: ["Short", "Excl", "Length", "Width"]
|
|
3336
|
+
},
|
|
3337
|
+
CmdSubst: { nodes: ["Stmts"], scalars: ["Backquotes", "TempFile", "ReplyVar"] },
|
|
3338
|
+
ArithmExp: { nodes: ["X"], scalars: ["Bracket", "Unsigned"] },
|
|
3339
|
+
ArithmCmd: { nodes: ["X"], scalars: ["Unsigned"] },
|
|
3340
|
+
ProcSubst: { nodes: ["Stmts"], scalars: ["Op"] },
|
|
3341
|
+
ExtGlob: { nodes: ["Pattern"], scalars: ["Op"] },
|
|
3342
|
+
BraceExp: { nodes: ["Elems"], scalars: ["Sequence"] },
|
|
3343
|
+
// only with SplitBraces, unused here
|
|
3344
|
+
BinaryCmd: { nodes: ["X", "Y"], scalars: ["Op"] },
|
|
3345
|
+
BinaryArithm: { nodes: ["X", "Y"], scalars: ["Op"] },
|
|
3346
|
+
UnaryArithm: { nodes: ["X"], scalars: ["Op", "Post"] },
|
|
3347
|
+
ParenArithm: { nodes: ["X"] },
|
|
3348
|
+
BinaryTest: { nodes: ["X", "Y"], scalars: ["Op"] },
|
|
3349
|
+
UnaryTest: { nodes: ["X"], scalars: ["Op"] },
|
|
3350
|
+
ParenTest: { nodes: ["X"] },
|
|
3351
|
+
Redirect: { nodes: ["N", "Word", "Hdoc"], scalars: ["Op"] },
|
|
3352
|
+
Block: { nodes: ["Stmts"] },
|
|
3353
|
+
Subshell: { nodes: ["Stmts"] },
|
|
3354
|
+
IfClause: { nodes: ["Cond", "Then", "Else"] },
|
|
3355
|
+
WhileClause: { nodes: ["Cond", "Do"], scalars: ["Until"] },
|
|
3356
|
+
ForClause: { nodes: ["Loop", "Do"], scalars: ["Select"] },
|
|
3357
|
+
WordIter: { nodes: ["Name", "Items"] },
|
|
3358
|
+
CStyleLoop: { nodes: ["Init", "Cond", "Post"] },
|
|
3359
|
+
CaseClause: { nodes: ["Word", "Items"] },
|
|
3360
|
+
CaseItem: { nodes: ["Patterns", "Stmts"], scalars: ["Op"] },
|
|
3361
|
+
FuncDecl: { nodes: ["Name", "Body"], scalars: ["RsrvWord"] },
|
|
3362
|
+
DeclClause: { nodes: ["Variant", "Args"], notWalked: ["Variant"] },
|
|
3363
|
+
LetClause: { nodes: ["Exprs"] },
|
|
3364
|
+
TimeClause: { nodes: ["Stmt"], scalars: ["PosixFormat"] },
|
|
3365
|
+
CoprocClause: { nodes: ["Name", "Stmt"] },
|
|
3366
|
+
TestClause: { nodes: ["X"] },
|
|
3367
|
+
TestDecl: { nodes: ["Description", "Body"] },
|
|
3368
|
+
ArrayExpr: { nodes: ["Elems"] },
|
|
3369
|
+
ArrayElem: { nodes: ["Index", "Value"] },
|
|
3370
|
+
Comment: { scalars: ["Text"] }
|
|
3371
|
+
};
|
|
3372
|
+
var STRUCTS = {
|
|
3373
|
+
"ParamExp.Slice": { nodes: ["Offset", "Length"], notWalked: ["Offset", "Length"] },
|
|
3374
|
+
"ParamExp.Repl": { nodes: ["Orig", "With"], scalars: ["All"] },
|
|
3375
|
+
"ParamExp.Exp": { nodes: ["Word"], scalars: ["Op"] }
|
|
3376
|
+
};
|
|
3377
|
+
var unknownKinds = /* @__PURE__ */ new Set();
|
|
3378
|
+
function isGoNode(v) {
|
|
3379
|
+
return v !== null && typeof v === "object" && typeof v.Pos === "function";
|
|
3380
|
+
}
|
|
3381
|
+
function toPlainTree(goNode) {
|
|
3382
|
+
const kind = getSyntax().NodeType(goNode);
|
|
3383
|
+
const out = { kind, pos: goNode.Pos().Offset(), end: goNode.End().Offset() };
|
|
3384
|
+
const spec = KINDS[kind];
|
|
3385
|
+
if (!spec) {
|
|
3386
|
+
unknownKinds.add(kind);
|
|
3387
|
+
return out;
|
|
3388
|
+
}
|
|
3389
|
+
convertFields(goNode, spec, out, kind);
|
|
3390
|
+
return out;
|
|
3391
|
+
}
|
|
3392
|
+
function convertFields(goNode, spec, out, kind) {
|
|
3393
|
+
for (const f of spec.scalars ?? []) out[f] = goNode[f];
|
|
3394
|
+
for (const f of spec.nodes ?? []) {
|
|
3395
|
+
const v = goNode[f];
|
|
3396
|
+
if (v === void 0 || v === null) {
|
|
3397
|
+
out[f] = null;
|
|
3398
|
+
} else if (Array.isArray(v)) {
|
|
3399
|
+
out[f] = v.map((c) => isGoNode(c) ? toPlainTree(c) : c);
|
|
3400
|
+
} else if (isGoNode(v)) {
|
|
3401
|
+
out[f] = toPlainTree(v);
|
|
3402
|
+
} else if (typeof v === "object" && STRUCTS[`${kind}.${f}`]) {
|
|
3403
|
+
const sub = { struct: `${kind}.${f}` };
|
|
3404
|
+
convertFields(v, STRUCTS[`${kind}.${f}`], sub, `${kind}.${f}`);
|
|
3405
|
+
out[f] = sub;
|
|
3406
|
+
} else {
|
|
3407
|
+
out[f] = v;
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
function childrenOf(n) {
|
|
3412
|
+
const spec = n.kind ? KINDS[n.kind] : STRUCTS[n.struct];
|
|
3413
|
+
if (!spec?.nodes) return [];
|
|
3414
|
+
const out = [];
|
|
3415
|
+
for (const f of spec.nodes) {
|
|
3416
|
+
if (spec.notWalked?.includes(f)) continue;
|
|
3417
|
+
const v = n[f];
|
|
3418
|
+
if (!v) continue;
|
|
3419
|
+
if (Array.isArray(v)) {
|
|
3420
|
+
for (const c of v) if (c) out.push(c);
|
|
3421
|
+
} else if (v.kind) {
|
|
3422
|
+
out.push(v);
|
|
3423
|
+
} else if (v.struct) {
|
|
3424
|
+
out.push(...childrenOf(v));
|
|
3425
|
+
}
|
|
3426
|
+
}
|
|
3427
|
+
return out;
|
|
3428
|
+
}
|
|
3429
|
+
function walk(root, fn) {
|
|
3430
|
+
if (!root) return;
|
|
3431
|
+
if (!fn(root)) return;
|
|
3432
|
+
for (const c of childrenOf(root)) walk(c, fn);
|
|
3433
|
+
}
|
|
3300
3434
|
|
|
3301
3435
|
// src/dlp/normalize.ts
|
|
3302
3436
|
var INVISIBLE_RE = /[͏----︀-️]|[\u{E0000}-\u{E007F}]/gu;
|
|
@@ -3726,12 +3860,12 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
3726
3860
|
category
|
|
3727
3861
|
};
|
|
3728
3862
|
}
|
|
3729
|
-
const
|
|
3730
|
-
if (
|
|
3863
|
+
const path2 = protectedLiteral(text, isProtected);
|
|
3864
|
+
if (path2) {
|
|
3731
3865
|
return {
|
|
3732
3866
|
outcome: "dangerous",
|
|
3733
3867
|
what: WHAT["reads-protected"],
|
|
3734
|
-
evidence:
|
|
3868
|
+
evidence: path2.slice(0, 60),
|
|
3735
3869
|
category: "reads-protected"
|
|
3736
3870
|
};
|
|
3737
3871
|
}
|
|
@@ -3743,8 +3877,7 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
3743
3877
|
}
|
|
3744
3878
|
|
|
3745
3879
|
// src/shell/index.ts
|
|
3746
|
-
var
|
|
3747
|
-
var sharedParser = syntax.NewParser();
|
|
3880
|
+
var sharedParser = lazy(() => getSyntax().NewParser());
|
|
3748
3881
|
var MESSAGE_FLAGS = /* @__PURE__ */ new Set([
|
|
3749
3882
|
"-m",
|
|
3750
3883
|
"--message",
|
|
@@ -3777,7 +3910,7 @@ var DOWNLOAD_CMDS = /* @__PURE__ */ new Set([
|
|
|
3777
3910
|
]);
|
|
3778
3911
|
function isCatHeredocOrLit(part) {
|
|
3779
3912
|
if (!part) return false;
|
|
3780
|
-
const t =
|
|
3913
|
+
const t = part.kind;
|
|
3781
3914
|
if (t === "Lit") return true;
|
|
3782
3915
|
if (t !== "CmdSubst") return false;
|
|
3783
3916
|
const stmts = part.Stmts || [];
|
|
@@ -3787,15 +3920,15 @@ function isCatHeredocOrLit(part) {
|
|
|
3787
3920
|
const hasHeredoc = redirs.some((r) => r && r.Hdoc);
|
|
3788
3921
|
if (!hasHeredoc) return false;
|
|
3789
3922
|
const cmd = stmt.Cmd;
|
|
3790
|
-
if (!cmd ||
|
|
3923
|
+
if (!cmd || cmd.kind !== "CallExpr") return false;
|
|
3791
3924
|
const firstArg = cmd.Args?.[0]?.Parts || [];
|
|
3792
|
-
if (firstArg.length !== 1 ||
|
|
3925
|
+
if (firstArg.length !== 1 || firstArg[0].kind !== "Lit") return false;
|
|
3793
3926
|
return (firstArg[0].Value || "").toLowerCase() === "cat";
|
|
3794
3927
|
}
|
|
3795
3928
|
var NORMALIZE_CACHE_MAX = 5e3;
|
|
3796
3929
|
var normalizeCache = /* @__PURE__ */ new Map();
|
|
3797
3930
|
var codeBodiesCache = /* @__PURE__ */ new Map();
|
|
3798
|
-
var AST_CACHE_MAX =
|
|
3931
|
+
var AST_CACHE_MAX = 256;
|
|
3799
3932
|
var astCache = /* @__PURE__ */ new Map();
|
|
3800
3933
|
var PARSE_FAIL = /* @__PURE__ */ Symbol("parse-fail");
|
|
3801
3934
|
function parseShared(command) {
|
|
@@ -3807,7 +3940,7 @@ function parseShared(command) {
|
|
|
3807
3940
|
}
|
|
3808
3941
|
let parsed;
|
|
3809
3942
|
try {
|
|
3810
|
-
parsed = sharedParser.Parse(command, "cmd");
|
|
3943
|
+
parsed = toPlainTree(sharedParser().Parse(command, "cmd"));
|
|
3811
3944
|
} catch {
|
|
3812
3945
|
parsed = PARSE_FAIL;
|
|
3813
3946
|
}
|
|
@@ -3872,10 +4005,10 @@ function fileAccessViewImpl(command) {
|
|
|
3872
4005
|
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
3873
4006
|
const edits = [];
|
|
3874
4007
|
try {
|
|
3875
|
-
|
|
4008
|
+
walk(f, (node) => {
|
|
3876
4009
|
if (!node) return false;
|
|
3877
4010
|
const n = node;
|
|
3878
|
-
if (
|
|
4011
|
+
if (n.kind !== "CallExpr") return true;
|
|
3879
4012
|
const args = n.Args || [];
|
|
3880
4013
|
const words = args.map((a) => resolveWordLiteral(a));
|
|
3881
4014
|
const head = unwrapCommandHead(words);
|
|
@@ -3887,8 +4020,8 @@ function fileAccessViewImpl(command) {
|
|
|
3887
4020
|
if (!PROGRAM_DIR.test(word)) continue;
|
|
3888
4021
|
const name = word.split(/[\\/]/).pop() ?? "";
|
|
3889
4022
|
if (!name) continue;
|
|
3890
|
-
const s = at(args[i].
|
|
3891
|
-
const e = at(args[i].
|
|
4023
|
+
const s = at(args[i].pos);
|
|
4024
|
+
const e = at(args[i].end);
|
|
3892
4025
|
if (s < 0 || e < 0) continue;
|
|
3893
4026
|
edits.push([s, e, name]);
|
|
3894
4027
|
}
|
|
@@ -3917,10 +4050,10 @@ function literalPayloadsOf(command, depth) {
|
|
|
3917
4050
|
if (f === PARSE_FAIL) return [];
|
|
3918
4051
|
const out = [];
|
|
3919
4052
|
try {
|
|
3920
|
-
|
|
4053
|
+
walk(f, (node) => {
|
|
3921
4054
|
if (!node || out.length >= MAX_READING_PAYLOADS) return false;
|
|
3922
4055
|
const n = node;
|
|
3923
|
-
if (
|
|
4056
|
+
if (n.kind !== "CallExpr") return true;
|
|
3924
4057
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
3925
4058
|
if (words.length === 0) return true;
|
|
3926
4059
|
const payload = literalShellPayload(words, baseWord(words[0]));
|
|
@@ -3940,23 +4073,23 @@ function foldCommandWords(reading) {
|
|
|
3940
4073
|
const at = (byteOffset) => toCharIndex === null ? byteOffset : toCharIndex(byteOffset);
|
|
3941
4074
|
const edits = [];
|
|
3942
4075
|
try {
|
|
3943
|
-
|
|
4076
|
+
walk(f, (node) => {
|
|
3944
4077
|
if (!node) return false;
|
|
3945
4078
|
const n = node;
|
|
3946
|
-
if (
|
|
4079
|
+
if (n.kind !== "CallExpr") return true;
|
|
3947
4080
|
const args = n.Args || [];
|
|
3948
4081
|
const words = args.map((a) => resolveWordLiteral(a));
|
|
3949
4082
|
const folded = words.map((w) => w === null ? null : foldHomoglyphs(w));
|
|
3950
4083
|
const head = unwrapCommandHead(folded);
|
|
3951
4084
|
for (let i = 0; i <= head && i < args.length; i++) {
|
|
3952
4085
|
const parts = args[i].Parts || [];
|
|
3953
|
-
if (parts.length !== 1 ||
|
|
4086
|
+
if (parts.length !== 1 || parts[0].kind !== "Lit") continue;
|
|
3954
4087
|
const value = parts[0].Value ?? "";
|
|
3955
4088
|
const word = folded[i];
|
|
3956
4089
|
if (word === null || word === value || !/[^\x00-\x7f]/.test(value)) continue;
|
|
3957
4090
|
if (!/^[A-Za-z0-9._/-]+$/.test(word)) continue;
|
|
3958
|
-
const s = at(args[i].
|
|
3959
|
-
const e = at(args[i].
|
|
4091
|
+
const s = at(args[i].pos);
|
|
4092
|
+
const e = at(args[i].end);
|
|
3960
4093
|
if (s < 0 || e < 0) continue;
|
|
3961
4094
|
edits.push([s, e, word]);
|
|
3962
4095
|
}
|
|
@@ -4024,10 +4157,10 @@ function interpreterHeredocSpans(f, at) {
|
|
|
4024
4157
|
const stmts = f?.Stmts || [];
|
|
4025
4158
|
const candidates = [];
|
|
4026
4159
|
let unsafe = false;
|
|
4027
|
-
|
|
4160
|
+
walk(f, (node) => {
|
|
4028
4161
|
if (!node || unsafe) return false;
|
|
4029
4162
|
const n = node;
|
|
4030
|
-
const t =
|
|
4163
|
+
const t = n.kind;
|
|
4031
4164
|
if (t === "FuncDecl") {
|
|
4032
4165
|
unsafe = true;
|
|
4033
4166
|
return false;
|
|
@@ -4047,7 +4180,7 @@ function interpreterHeredocSpans(f, at) {
|
|
|
4047
4180
|
});
|
|
4048
4181
|
if (unsafe) return [];
|
|
4049
4182
|
for (const st of stmts) {
|
|
4050
|
-
if (!st?.Cmd ||
|
|
4183
|
+
if (!st?.Cmd || st.Cmd.kind !== "CallExpr") continue;
|
|
4051
4184
|
const words = (st.Cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
4052
4185
|
const name = (words[0] ?? "").toLowerCase();
|
|
4053
4186
|
if (!STDIN_CODE_INTERPRETERS.test(name)) continue;
|
|
@@ -4062,8 +4195,8 @@ function interpreterHeredocSpans(f, at) {
|
|
|
4062
4195
|
if (stdin.length !== 1 || others > 0) continue;
|
|
4063
4196
|
const r = stdin[0];
|
|
4064
4197
|
if (heredocText(r.Hdoc) === null) continue;
|
|
4065
|
-
const hs = at(r.Hdoc.
|
|
4066
|
-
const he = at(r.Hdoc.
|
|
4198
|
+
const hs = at(r.Hdoc.pos);
|
|
4199
|
+
const he = at(r.Hdoc.end);
|
|
4067
4200
|
if (hs < 0 || he < 0 || he <= hs) continue;
|
|
4068
4201
|
spans.push([hs, he]);
|
|
4069
4202
|
}
|
|
@@ -4083,24 +4216,24 @@ function normalizeCommandForPolicyImpl(command, codeBodies) {
|
|
|
4083
4216
|
strips.push([hs, he]);
|
|
4084
4217
|
msgSpans.add(`${hs}:${he}`);
|
|
4085
4218
|
}
|
|
4086
|
-
|
|
4219
|
+
walk(f, (node) => {
|
|
4087
4220
|
if (!node) return false;
|
|
4088
4221
|
const n = node;
|
|
4089
|
-
if (
|
|
4222
|
+
if (n.kind !== "CallExpr") return true;
|
|
4090
4223
|
const args = n.Args || [];
|
|
4091
4224
|
for (let i = 0; i < args.length - 1; i++) {
|
|
4092
4225
|
const argParts = args[i].Parts || [];
|
|
4093
|
-
if (argParts.length !== 1 ||
|
|
4226
|
+
if (argParts.length !== 1 || argParts[0].kind !== "Lit") continue;
|
|
4094
4227
|
const flagVal = argParts[0].Value || "";
|
|
4095
4228
|
if (!MESSAGE_FLAGS.has(flagVal.toLowerCase())) continue;
|
|
4096
4229
|
const next = args[i + 1];
|
|
4097
4230
|
const nextParts = next.Parts || [];
|
|
4098
4231
|
if (nextParts.length !== 1) continue;
|
|
4099
4232
|
const quotedNode = nextParts[0];
|
|
4100
|
-
const nt =
|
|
4233
|
+
const nt = quotedNode.kind;
|
|
4101
4234
|
const markStrip = () => {
|
|
4102
|
-
const s = at(next.
|
|
4103
|
-
const e = at(next.
|
|
4235
|
+
const s = at(next.pos);
|
|
4236
|
+
const e = at(next.end);
|
|
4104
4237
|
if (s < 0 || e < 0) return;
|
|
4105
4238
|
strips.push([s, e]);
|
|
4106
4239
|
msgSpans.add(`${s}:${e}`);
|
|
@@ -4109,7 +4242,7 @@ function normalizeCommandForPolicyImpl(command, codeBodies) {
|
|
|
4109
4242
|
markStrip();
|
|
4110
4243
|
} else if (nt === "DblQuoted") {
|
|
4111
4244
|
const innerParts = quotedNode.Parts || [];
|
|
4112
|
-
const allLit = innerParts.length === 0 || innerParts.every((p) =>
|
|
4245
|
+
const allLit = innerParts.length === 0 || innerParts.every((p) => p.kind === "Lit");
|
|
4113
4246
|
if (allLit) {
|
|
4114
4247
|
markStrip();
|
|
4115
4248
|
} else if (innerParts.every((p) => isCatHeredocOrLit(p))) {
|
|
@@ -4118,8 +4251,8 @@ function normalizeCommandForPolicyImpl(command, codeBodies) {
|
|
|
4118
4251
|
}
|
|
4119
4252
|
}
|
|
4120
4253
|
for (const arg of args) {
|
|
4121
|
-
const s = at(arg.
|
|
4122
|
-
const e = at(arg.
|
|
4254
|
+
const s = at(arg.pos);
|
|
4255
|
+
const e = at(arg.end);
|
|
4123
4256
|
if (s < 0 || e < 0) continue;
|
|
4124
4257
|
if (msgSpans.has(`${s}:${e}`)) continue;
|
|
4125
4258
|
const resolved = resolveWordLiteral(arg);
|
|
@@ -4159,10 +4292,10 @@ function scanArgsForDynamicExec(args, startIdx) {
|
|
|
4159
4292
|
let hasParamExp = false;
|
|
4160
4293
|
let hasCurl = false;
|
|
4161
4294
|
for (let i = startIdx; i < args.length; i++) {
|
|
4162
|
-
|
|
4295
|
+
walk(args[i], (inner) => {
|
|
4163
4296
|
if (!inner) return false;
|
|
4164
4297
|
const inn = inner;
|
|
4165
|
-
const it =
|
|
4298
|
+
const it = inn.kind;
|
|
4166
4299
|
if (it === "CmdSubst") hasCmdSubst = true;
|
|
4167
4300
|
if (it === "ParamExp") hasParamExp = true;
|
|
4168
4301
|
if (it === "Lit" && DOWNLOAD_CMDS.has(inn.Value?.toLowerCase())) hasCurl = true;
|
|
@@ -4175,15 +4308,16 @@ function scanArgsForDynamicExec(args, startIdx) {
|
|
|
4175
4308
|
}
|
|
4176
4309
|
function detectDangerousShellExec(command) {
|
|
4177
4310
|
try {
|
|
4178
|
-
const f =
|
|
4311
|
+
const f = parseShared(command);
|
|
4312
|
+
if (f === PARSE_FAIL) return null;
|
|
4179
4313
|
let result = null;
|
|
4180
4314
|
const assigned = assignedNames(f);
|
|
4181
|
-
|
|
4315
|
+
walk(f, (node) => {
|
|
4182
4316
|
if (!node || result === "block") return false;
|
|
4183
4317
|
const n = node;
|
|
4184
|
-
if (
|
|
4318
|
+
if (n.kind === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
4185
4319
|
const call = n.Y.Cmd;
|
|
4186
|
-
if (call &&
|
|
4320
|
+
if (call && call.kind === "CallExpr") {
|
|
4187
4321
|
const words = (call.Args || []).map((a) => resolveWordLiteral(a));
|
|
4188
4322
|
const head2 = unwrapCommandHead(words);
|
|
4189
4323
|
const name = (words[head2] ?? "").split("/").pop() ?? "";
|
|
@@ -4196,7 +4330,7 @@ function detectDangerousShellExec(command) {
|
|
|
4196
4330
|
result = "review";
|
|
4197
4331
|
}
|
|
4198
4332
|
}
|
|
4199
|
-
if (
|
|
4333
|
+
if (n.kind !== "CallExpr") return true;
|
|
4200
4334
|
const args = n.Args || [];
|
|
4201
4335
|
if (args.length === 0) return true;
|
|
4202
4336
|
const headWords = args.map(
|
|
@@ -4207,7 +4341,7 @@ function detectDangerousShellExec(command) {
|
|
|
4207
4341
|
if (!lookup && (opaqueExecutable(args[0], assigned) || opaqueExecutable(args[head], assigned)))
|
|
4208
4342
|
result = "review";
|
|
4209
4343
|
const firstParts = args[0].Parts || [];
|
|
4210
|
-
if (firstParts.length !== 1 ||
|
|
4344
|
+
if (firstParts.length !== 1 || firstParts[0].kind !== "Lit") return true;
|
|
4211
4345
|
const cmdName = firstParts[0].Value?.toLowerCase() ?? "";
|
|
4212
4346
|
if (cmdName === "eval") {
|
|
4213
4347
|
const v = scanArgsForDynamicExec(args, 1);
|
|
@@ -4215,7 +4349,7 @@ function detectDangerousShellExec(command) {
|
|
|
4215
4349
|
} else if (SHELL_INTERPRETERS.has(cmdName)) {
|
|
4216
4350
|
for (let i = 1; i < args.length - 1; i++) {
|
|
4217
4351
|
const flagParts = args[i].Parts || [];
|
|
4218
|
-
if (flagParts.length !== 1 ||
|
|
4352
|
+
if (flagParts.length !== 1 || flagParts[0].kind !== "Lit" || flagParts[0].Value !== "-c")
|
|
4219
4353
|
continue;
|
|
4220
4354
|
const v = scanArgsForDynamicExec(args, i + 1);
|
|
4221
4355
|
if (v === "block" || v === "review" && result === null) result = v;
|
|
@@ -4240,8 +4374,7 @@ function isDefaultExpansion(part) {
|
|
|
4240
4374
|
}
|
|
4241
4375
|
function lookupSubstitution(part) {
|
|
4242
4376
|
const stmts = part.Stmts ?? [];
|
|
4243
|
-
if (stmts.length !== 1 || !stmts[0].Cmd ||
|
|
4244
|
-
return null;
|
|
4377
|
+
if (stmts.length !== 1 || !stmts[0].Cmd || stmts[0].Cmd.kind !== "CallExpr") return null;
|
|
4245
4378
|
const words = (stmts[0].Cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
4246
4379
|
if (words.some((w) => w === null)) return null;
|
|
4247
4380
|
if (words.length === 2 && words[0] === "which") return words[1];
|
|
@@ -4263,9 +4396,9 @@ var VARIABLE_READERS = /* @__PURE__ */ new Set([
|
|
|
4263
4396
|
]);
|
|
4264
4397
|
function assignedNames(f) {
|
|
4265
4398
|
const names = /* @__PURE__ */ new Set();
|
|
4266
|
-
|
|
4399
|
+
walk(f, (node) => {
|
|
4267
4400
|
if (!node) return false;
|
|
4268
|
-
const kind =
|
|
4401
|
+
const kind = node.kind;
|
|
4269
4402
|
if (kind === "Assign" && node.Name?.Value) names.add(node.Name.Value);
|
|
4270
4403
|
if (kind === "ForClause" && node.Loop?.Name?.Value) names.add(node.Loop.Name.Value);
|
|
4271
4404
|
if (kind === "CallExpr") {
|
|
@@ -4280,7 +4413,7 @@ function assignedNames(f) {
|
|
|
4280
4413
|
}
|
|
4281
4414
|
function executableParts(word, assigned, quoted = false) {
|
|
4282
4415
|
return (word?.Parts ?? []).flatMap((part) => {
|
|
4283
|
-
const kind =
|
|
4416
|
+
const kind = part.kind;
|
|
4284
4417
|
if (kind === "DblQuoted") return executableParts(part, assigned, true);
|
|
4285
4418
|
if (kind === "Lit") return [{ kind: "Lit", value: part.Value ?? "", quoted }];
|
|
4286
4419
|
if (kind === "SglQuoted")
|
|
@@ -5004,10 +5137,10 @@ function chmodHasOpenPermMode(command) {
|
|
|
5004
5137
|
if (f === PARSE_FAIL) return false;
|
|
5005
5138
|
let found = false;
|
|
5006
5139
|
try {
|
|
5007
|
-
|
|
5140
|
+
walk(f, (node) => {
|
|
5008
5141
|
if (!node || found) return false;
|
|
5009
5142
|
const n = node;
|
|
5010
|
-
if (
|
|
5143
|
+
if (n.kind !== "CallExpr") return true;
|
|
5011
5144
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
5012
5145
|
if (words.length === 0) return true;
|
|
5013
5146
|
const name = (words[0] ?? "").toLowerCase();
|
|
@@ -5084,11 +5217,11 @@ function redirStdinOps() {
|
|
|
5084
5217
|
}
|
|
5085
5218
|
function deriveBinaryOp(sample) {
|
|
5086
5219
|
try {
|
|
5087
|
-
const f = sharedParser.Parse(sample, "cmd");
|
|
5220
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
5088
5221
|
let op = -1;
|
|
5089
|
-
|
|
5222
|
+
walk(f, (node) => {
|
|
5090
5223
|
const n = node;
|
|
5091
|
-
if (n &&
|
|
5224
|
+
if (n && n.kind === "BinaryCmd" && op < 0) op = n.Op;
|
|
5092
5225
|
return true;
|
|
5093
5226
|
});
|
|
5094
5227
|
return op;
|
|
@@ -5184,7 +5317,7 @@ function heredocText(word) {
|
|
|
5184
5317
|
const parts = word?.Parts ?? [];
|
|
5185
5318
|
let out = "";
|
|
5186
5319
|
for (const p of parts) {
|
|
5187
|
-
if (
|
|
5320
|
+
if (p.kind !== "Lit") return null;
|
|
5188
5321
|
out += p.Value ?? "";
|
|
5189
5322
|
}
|
|
5190
5323
|
return out;
|
|
@@ -5220,7 +5353,7 @@ function attachedCode(interp, flag) {
|
|
|
5220
5353
|
}
|
|
5221
5354
|
function inlineExecCall(stmt, pipeFed) {
|
|
5222
5355
|
const cmd = stmt?.Cmd;
|
|
5223
|
-
if (!cmd ||
|
|
5356
|
+
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
5224
5357
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
5225
5358
|
if (words.length === 0) return null;
|
|
5226
5359
|
const headIdx = unwrapCommandHead(words);
|
|
@@ -5303,10 +5436,10 @@ function shellPayloadNeedsReview(payload) {
|
|
|
5303
5436
|
let review = false;
|
|
5304
5437
|
payloadNesting++;
|
|
5305
5438
|
try {
|
|
5306
|
-
|
|
5439
|
+
walk(f, (node) => {
|
|
5307
5440
|
if (!node || review) return false;
|
|
5308
5441
|
const n = node;
|
|
5309
|
-
if (
|
|
5442
|
+
if (n.kind !== "CallExpr") return true;
|
|
5310
5443
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
5311
5444
|
if (words.length === 0) return true;
|
|
5312
5445
|
const h = unwrapCommandHead(words);
|
|
@@ -5341,10 +5474,10 @@ function inlineExecCalls(command) {
|
|
|
5341
5474
|
if (f === PARSE_FAIL) return PARSE_FAIL;
|
|
5342
5475
|
const calls = [];
|
|
5343
5476
|
try {
|
|
5344
|
-
|
|
5477
|
+
walk(f, (node) => {
|
|
5345
5478
|
if (!node || calls.length >= MAX_INLINE_CALLS) return false;
|
|
5346
5479
|
const n = node;
|
|
5347
|
-
const t =
|
|
5480
|
+
const t = n.kind;
|
|
5348
5481
|
if (t === "BinaryCmd" && n.Y && !listOps().has(n.Op)) {
|
|
5349
5482
|
const call = inlineExecCall(n.Y, true);
|
|
5350
5483
|
if (call) calls.push(call);
|
|
@@ -5489,7 +5622,7 @@ function shellScriptOperands(command) {
|
|
|
5489
5622
|
walkWithCalls(f, (node) => {
|
|
5490
5623
|
if (!node) return false;
|
|
5491
5624
|
const n = node;
|
|
5492
|
-
if (
|
|
5625
|
+
if (n.kind !== "CallExpr") return true;
|
|
5493
5626
|
const callArgs = n.Args || [];
|
|
5494
5627
|
if (callArgs.length === 0) return true;
|
|
5495
5628
|
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
@@ -5525,7 +5658,7 @@ function shellScriptOperands(command) {
|
|
|
5525
5658
|
}
|
|
5526
5659
|
function windowsDrivePathSpelling(word) {
|
|
5527
5660
|
const parts = word?.Parts || [];
|
|
5528
|
-
if (parts.length === 0 || !parts.every((p) =>
|
|
5661
|
+
if (parts.length === 0 || !parts.every((p) => p.kind === "Lit")) return null;
|
|
5529
5662
|
const raw = parts.map((p) => p.Value ?? "").join("");
|
|
5530
5663
|
return /^[A-Za-z]:\\[^\s'"$`]*$/.test(raw) ? raw : null;
|
|
5531
5664
|
}
|
|
@@ -5730,28 +5863,33 @@ function recordTopLevelAssignments(f) {
|
|
|
5730
5863
|
}
|
|
5731
5864
|
function probeBinOp(src) {
|
|
5732
5865
|
try {
|
|
5733
|
-
const cmd =
|
|
5734
|
-
if (cmd &&
|
|
5866
|
+
const cmd = toPlainTree(getSyntax().NewParser().Parse(src, "probe"))?.Stmts?.[0]?.Cmd;
|
|
5867
|
+
if (cmd && cmd.kind === "BinaryCmd") return cmd.Op;
|
|
5735
5868
|
} catch {
|
|
5736
5869
|
}
|
|
5737
5870
|
return null;
|
|
5738
5871
|
}
|
|
5739
|
-
var
|
|
5740
|
-
|
|
5741
|
-
|
|
5872
|
+
var andOrOps = lazy(() => {
|
|
5873
|
+
const and = probeBinOp("a && b");
|
|
5874
|
+
const or = probeBinOp("a || b");
|
|
5875
|
+
return {
|
|
5876
|
+
AND_OP: and,
|
|
5877
|
+
AND_OR_OPS: new Set([and, or].filter((o) => o !== null))
|
|
5878
|
+
};
|
|
5879
|
+
});
|
|
5742
5880
|
function recordTopLevelStmt(stmt) {
|
|
5743
5881
|
if (!stmt || !stmt.Cmd) return false;
|
|
5744
|
-
const t =
|
|
5882
|
+
const t = stmt.Cmd.kind;
|
|
5745
5883
|
if (t === "BinaryCmd") {
|
|
5746
|
-
if (!AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
5884
|
+
if (!andOrOps().AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
5747
5885
|
if (!recordTopLevelStmt(stmt.Cmd.X)) return false;
|
|
5748
|
-
if (stmt.Cmd.Op === AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
5886
|
+
if (stmt.Cmd.Op === andOrOps().AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
5749
5887
|
return true;
|
|
5750
5888
|
}
|
|
5751
5889
|
if (t !== "CallExpr" && t !== "DeclClause") return false;
|
|
5752
5890
|
let at = 0;
|
|
5753
5891
|
try {
|
|
5754
|
-
at = stmt.
|
|
5892
|
+
at = stmt.pos;
|
|
5755
5893
|
} catch {
|
|
5756
5894
|
at = 0;
|
|
5757
5895
|
}
|
|
@@ -5762,14 +5900,14 @@ function recordTopLevelStmt(stmt) {
|
|
|
5762
5900
|
}
|
|
5763
5901
|
function recordAssignments(n, at) {
|
|
5764
5902
|
if (!assignmentTable) return;
|
|
5765
|
-
const t =
|
|
5903
|
+
const t = n.kind;
|
|
5766
5904
|
let assigns = [];
|
|
5767
5905
|
if (t === "CallExpr") {
|
|
5768
5906
|
if ((n.Args || []).length > 0) return;
|
|
5769
5907
|
assigns = n.Assigns || [];
|
|
5770
5908
|
} else if (t === "DeclClause") {
|
|
5771
5909
|
if (!ASSIGNMENT_HEADS.has(n.Variant?.Value ?? "")) return;
|
|
5772
|
-
assigns = (n.Args || []).filter((a) =>
|
|
5910
|
+
assigns = (n.Args || []).filter((a) => a.kind === "Assign");
|
|
5773
5911
|
} else return;
|
|
5774
5912
|
for (const a of assigns) {
|
|
5775
5913
|
const name = a?.Name?.Value;
|
|
@@ -5778,13 +5916,13 @@ function recordAssignments(n, at) {
|
|
|
5778
5916
|
}
|
|
5779
5917
|
}
|
|
5780
5918
|
function resolveTrivialSubst(part) {
|
|
5781
|
-
if (
|
|
5919
|
+
if (part.kind !== "CmdSubst") return void 0;
|
|
5782
5920
|
const stmts = part.Stmts || [];
|
|
5783
5921
|
if (stmts.length !== 1) return void 0;
|
|
5784
5922
|
const st = stmts[0];
|
|
5785
5923
|
if ((st.Redirs || []).length > 0 || st.Negated || st.Background) return void 0;
|
|
5786
5924
|
const cmd = st.Cmd;
|
|
5787
|
-
if (!cmd ||
|
|
5925
|
+
if (!cmd || cmd.kind !== "CallExpr") return void 0;
|
|
5788
5926
|
if ((cmd.Assigns || []).length > 0) return void 0;
|
|
5789
5927
|
const words = (cmd.Args || []).map((a) => resolveWordLiteral(a));
|
|
5790
5928
|
if (words.length === 0 || words.some((w) => w === null)) return void 0;
|
|
@@ -5809,7 +5947,7 @@ function recordedExpansion(name) {
|
|
|
5809
5947
|
return rec.value;
|
|
5810
5948
|
}
|
|
5811
5949
|
function isPlainParam(p) {
|
|
5812
|
-
if (
|
|
5950
|
+
if (p.kind !== "ParamExp") return false;
|
|
5813
5951
|
return !(p.Excl || p.Length || p.Width || p.Index || p.Slice || p.Repl || p.Exp);
|
|
5814
5952
|
}
|
|
5815
5953
|
function expandPlainParam(p) {
|
|
@@ -5825,9 +5963,9 @@ var callDepth = 0;
|
|
|
5825
5963
|
var callWalks = 0;
|
|
5826
5964
|
function functionBodies(f) {
|
|
5827
5965
|
const out = /* @__PURE__ */ new Map();
|
|
5828
|
-
|
|
5966
|
+
walk(f, (node) => {
|
|
5829
5967
|
const n = node;
|
|
5830
|
-
if (n &&
|
|
5968
|
+
if (n && n.kind === "FuncDecl" && n.Name?.Value && n.Body) {
|
|
5831
5969
|
const list = out.get(n.Name.Value) ?? [];
|
|
5832
5970
|
list.push(n.Body);
|
|
5833
5971
|
out.set(n.Name.Value, list);
|
|
@@ -5838,10 +5976,10 @@ function functionBodies(f) {
|
|
|
5838
5976
|
}
|
|
5839
5977
|
function rebindsPositionals(body) {
|
|
5840
5978
|
let found = false;
|
|
5841
|
-
|
|
5979
|
+
walk(body, (node) => {
|
|
5842
5980
|
const n = node;
|
|
5843
5981
|
if (found || !n) return false;
|
|
5844
|
-
if (
|
|
5982
|
+
if (n.kind === "CallExpr") {
|
|
5845
5983
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
5846
5984
|
if (words[0] === "shift") found = true;
|
|
5847
5985
|
else if (words[0] === "set" && words.slice(1).some((w) => w === null || w === "--" || !/^[-+]/.test(w)))
|
|
@@ -5861,7 +5999,7 @@ function tableBindings() {
|
|
|
5861
5999
|
function walkWithCalls(f, visit) {
|
|
5862
6000
|
const bodies = functionBodies(f);
|
|
5863
6001
|
if (bodies.size === 0) {
|
|
5864
|
-
|
|
6002
|
+
walk(f, visit);
|
|
5865
6003
|
return;
|
|
5866
6004
|
}
|
|
5867
6005
|
const seenCalls = /* @__PURE__ */ new Set();
|
|
@@ -5895,8 +6033,8 @@ function walkWithCalls(f, visit) {
|
|
|
5895
6033
|
currentStmtOffset = Number.MAX_SAFE_INTEGER;
|
|
5896
6034
|
callDepth++;
|
|
5897
6035
|
try {
|
|
5898
|
-
if (body.Cmd &&
|
|
5899
|
-
|
|
6036
|
+
if (body.Cmd && body.Cmd.kind === "Block") recordTopLevelAssignments(body.Cmd);
|
|
6037
|
+
walk(body, step);
|
|
5900
6038
|
} finally {
|
|
5901
6039
|
callDepth--;
|
|
5902
6040
|
assignmentTable = outerTable;
|
|
@@ -5907,10 +6045,10 @@ function walkWithCalls(f, visit) {
|
|
|
5907
6045
|
const step = (node) => {
|
|
5908
6046
|
if (!node) return false;
|
|
5909
6047
|
const go = visit(node);
|
|
5910
|
-
if (go !== false &&
|
|
6048
|
+
if (go !== false && node.kind === "CallExpr") inline(node);
|
|
5911
6049
|
return go;
|
|
5912
6050
|
};
|
|
5913
|
-
|
|
6051
|
+
walk(f, step);
|
|
5914
6052
|
}
|
|
5915
6053
|
function withAssignments(f, body) {
|
|
5916
6054
|
const outerTable = assignmentTable;
|
|
@@ -5935,7 +6073,7 @@ function walkCommandScope(command, visit) {
|
|
|
5935
6073
|
if (f === PARSE_FAIL) return "parse-fail";
|
|
5936
6074
|
withAssignments(f, () => {
|
|
5937
6075
|
walkWithCalls(f, (node) => {
|
|
5938
|
-
if (node &&
|
|
6076
|
+
if (node && node.kind === "Stmt") trackStatement(node);
|
|
5939
6077
|
return visit(node);
|
|
5940
6078
|
});
|
|
5941
6079
|
});
|
|
@@ -5943,7 +6081,7 @@ function walkCommandScope(command, visit) {
|
|
|
5943
6081
|
}
|
|
5944
6082
|
function trackStatement(n) {
|
|
5945
6083
|
try {
|
|
5946
|
-
currentStmtOffset = n.
|
|
6084
|
+
currentStmtOffset = n.pos;
|
|
5947
6085
|
} catch {
|
|
5948
6086
|
currentStmtOffset = Number.MAX_SAFE_INTEGER;
|
|
5949
6087
|
}
|
|
@@ -5959,11 +6097,11 @@ function resolveWordLiteral(w) {
|
|
|
5959
6097
|
return s;
|
|
5960
6098
|
}
|
|
5961
6099
|
function resolveWordPrefix(w) {
|
|
5962
|
-
const
|
|
6100
|
+
const walk3 = (parts) => {
|
|
5963
6101
|
let s = "";
|
|
5964
6102
|
for (const p of parts) {
|
|
5965
6103
|
if (p && typeof p === "object" && Array.isArray(p.Parts) && p.Dollar !== void 0) {
|
|
5966
|
-
const inner =
|
|
6104
|
+
const inner = walk3(p.Parts);
|
|
5967
6105
|
s += inner.prefix;
|
|
5968
6106
|
if (inner.dynamic) return { prefix: s, dynamic: true };
|
|
5969
6107
|
continue;
|
|
@@ -5974,10 +6112,10 @@ function resolveWordPrefix(w) {
|
|
|
5974
6112
|
}
|
|
5975
6113
|
return { prefix: s, dynamic: false };
|
|
5976
6114
|
};
|
|
5977
|
-
return
|
|
6115
|
+
return walk3(w?.Parts || []);
|
|
5978
6116
|
}
|
|
5979
6117
|
function resolvePart(p, inQuotes) {
|
|
5980
|
-
const t =
|
|
6118
|
+
const t = p.kind;
|
|
5981
6119
|
if (t === "Lit") {
|
|
5982
6120
|
const raw = p.Value ?? "";
|
|
5983
6121
|
if (!inQuotes) return raw.replace(/\\(.)/g, "$1");
|
|
@@ -6073,7 +6211,7 @@ function extractShellDestinations(command) {
|
|
|
6073
6211
|
() => walkWithCalls(f, (node) => {
|
|
6074
6212
|
if (!node) return false;
|
|
6075
6213
|
const n = node;
|
|
6076
|
-
if (
|
|
6214
|
+
if (n.kind === "Stmt") {
|
|
6077
6215
|
trackStatement(n);
|
|
6078
6216
|
for (const raw of redirectWords(n)) {
|
|
6079
6217
|
const host2 = devNetRedirectHost(raw);
|
|
@@ -6085,7 +6223,7 @@ function extractShellDestinations(command) {
|
|
|
6085
6223
|
out.push({ host: host2, binary, raw });
|
|
6086
6224
|
}
|
|
6087
6225
|
}
|
|
6088
|
-
if (
|
|
6226
|
+
if (n.kind !== "CallExpr") return true;
|
|
6089
6227
|
const callArgs = n.Args || [];
|
|
6090
6228
|
if (callArgs.length === 0) return true;
|
|
6091
6229
|
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
@@ -6120,7 +6258,7 @@ function extractShellDestTokens(command) {
|
|
|
6120
6258
|
() => walkWithCalls(f, (node) => {
|
|
6121
6259
|
if (!node) return false;
|
|
6122
6260
|
const n = node;
|
|
6123
|
-
if (
|
|
6261
|
+
if (n.kind === "Stmt") {
|
|
6124
6262
|
trackStatement(n);
|
|
6125
6263
|
for (const raw of redirectWords(n)) {
|
|
6126
6264
|
const host2 = devNetRedirectHost(raw);
|
|
@@ -6132,7 +6270,7 @@ function extractShellDestTokens(command) {
|
|
|
6132
6270
|
out.push({ token: host2, binary });
|
|
6133
6271
|
}
|
|
6134
6272
|
}
|
|
6135
|
-
if (
|
|
6273
|
+
if (n.kind !== "CallExpr") return true;
|
|
6136
6274
|
const callArgs = n.Args || [];
|
|
6137
6275
|
if (callArgs.length === 0) return true;
|
|
6138
6276
|
const words = callArgs.map((a) => resolveWordLiteral(a));
|
|
@@ -6203,11 +6341,11 @@ function isWaivableCleanupTarget(p) {
|
|
|
6203
6341
|
}
|
|
6204
6342
|
function deriveRedirOp(sample) {
|
|
6205
6343
|
try {
|
|
6206
|
-
const f = sharedParser.Parse(sample, "cmd");
|
|
6344
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
6207
6345
|
let op = -1;
|
|
6208
|
-
|
|
6346
|
+
walk(f, (node) => {
|
|
6209
6347
|
const n = node;
|
|
6210
|
-
if (n &&
|
|
6348
|
+
if (n && n.kind === "Redirect" && op < 0) op = n.Op;
|
|
6211
6349
|
return true;
|
|
6212
6350
|
});
|
|
6213
6351
|
return op;
|
|
@@ -6215,24 +6353,23 @@ function deriveRedirOp(sample) {
|
|
|
6215
6353
|
return -1;
|
|
6216
6354
|
}
|
|
6217
6355
|
}
|
|
6218
|
-
var REDIR_TRUNCATE_OPS = /* @__PURE__ */ new Set([deriveRedirOp(">_f")]);
|
|
6219
|
-
var REDIR_FILE_IN_OPS =
|
|
6220
|
-
[deriveRedirOp("cat < f"), deriveRedirOp("cat <> f")].filter((op) => op >= 0)
|
|
6356
|
+
var REDIR_TRUNCATE_OPS = lazy(() => /* @__PURE__ */ new Set([deriveRedirOp(">_f")]));
|
|
6357
|
+
var REDIR_FILE_IN_OPS = lazy(
|
|
6358
|
+
() => new Set([deriveRedirOp("cat < f"), deriveRedirOp("cat <> f")].filter((op) => op >= 0))
|
|
6359
|
+
);
|
|
6360
|
+
var REDIR_HEREDOC_OPS = lazy(
|
|
6361
|
+
() => /* @__PURE__ */ new Set([deriveRedirOp("cat <<X\nX"), deriveRedirOp("cat <<-X\nX")])
|
|
6221
6362
|
);
|
|
6222
|
-
var REDIR_HEREDOC_OPS = /* @__PURE__ */ new Set([
|
|
6223
|
-
deriveRedirOp("cat <<X\nX"),
|
|
6224
|
-
deriveRedirOp("cat <<-X\nX")
|
|
6225
|
-
]);
|
|
6226
6363
|
function collectSameCommandCreations(f) {
|
|
6227
6364
|
const created = /* @__PURE__ */ new Set();
|
|
6228
6365
|
try {
|
|
6229
6366
|
const stmts = Array.isArray(f?.Stmts) ? f.Stmts : [];
|
|
6230
6367
|
for (const stmt of stmts) {
|
|
6231
|
-
if (!stmt || !stmt.Cmd ||
|
|
6368
|
+
if (!stmt || !stmt.Cmd || stmt.Cmd.kind !== "CallExpr") continue;
|
|
6232
6369
|
const redirs = stmt.Redirs || [];
|
|
6233
|
-
if (!redirs.some((r) => r && REDIR_HEREDOC_OPS.has(r.Op))) continue;
|
|
6370
|
+
if (!redirs.some((r) => r && REDIR_HEREDOC_OPS().has(r.Op))) continue;
|
|
6234
6371
|
for (const r of redirs) {
|
|
6235
|
-
if (r && REDIR_TRUNCATE_OPS.has(r.Op) && r.N == null) {
|
|
6372
|
+
if (r && REDIR_TRUNCATE_OPS().has(r.Op) && r.N == null) {
|
|
6236
6373
|
const w = resolveWordLiteral(r.Word);
|
|
6237
6374
|
if (w) created.add(stripDotSlash(w));
|
|
6238
6375
|
}
|
|
@@ -6252,10 +6389,10 @@ function isRmCreatedInCommandCleanup(command) {
|
|
|
6252
6389
|
let sawRm = false;
|
|
6253
6390
|
let ok = true;
|
|
6254
6391
|
try {
|
|
6255
|
-
|
|
6392
|
+
walk(f, (node) => {
|
|
6256
6393
|
if (!node || !ok) return false;
|
|
6257
6394
|
const n = node;
|
|
6258
|
-
if (
|
|
6395
|
+
if (n.kind !== "CallExpr") return true;
|
|
6259
6396
|
const args = n.Args || [];
|
|
6260
6397
|
const name = (resolveWordLiteral(args[0]) ?? "").toLowerCase();
|
|
6261
6398
|
if (name !== "rm") return true;
|
|
@@ -6305,10 +6442,10 @@ function analyzeFsOperationImpl(command, depth = 0) {
|
|
|
6305
6442
|
walkWithCalls(f, (node) => {
|
|
6306
6443
|
if (!node || result?.verdict === "block") return false;
|
|
6307
6444
|
const n = node;
|
|
6308
|
-
const nodeType =
|
|
6445
|
+
const nodeType = n.kind;
|
|
6309
6446
|
if (nodeType === "Stmt") {
|
|
6310
6447
|
try {
|
|
6311
|
-
currentStmtOffset = n.
|
|
6448
|
+
currentStmtOffset = n.pos;
|
|
6312
6449
|
} catch {
|
|
6313
6450
|
currentStmtOffset = Number.MAX_SAFE_INTEGER;
|
|
6314
6451
|
}
|
|
@@ -6832,7 +6969,7 @@ function literalShellPayload(words, name) {
|
|
|
6832
6969
|
function jailedRedirectRead(stmt) {
|
|
6833
6970
|
const redirs = stmt.Redirs || [];
|
|
6834
6971
|
for (const r of redirs) {
|
|
6835
|
-
if (!r || !REDIR_FILE_IN_OPS.has(r.Op)) continue;
|
|
6972
|
+
if (!r || !REDIR_FILE_IN_OPS().has(r.Op)) continue;
|
|
6836
6973
|
const p = resolveWordLiteral(r.Word);
|
|
6837
6974
|
if (p === null || p === "") continue;
|
|
6838
6975
|
const hit = matchSensitivePath(p);
|
|
@@ -6851,11 +6988,12 @@ function analyzeShellCommand(command) {
|
|
|
6851
6988
|
if (lower2.startsWith("-")) allTokens.push(lower2.replace(/^-+/, ""));
|
|
6852
6989
|
};
|
|
6853
6990
|
try {
|
|
6854
|
-
const f =
|
|
6855
|
-
|
|
6991
|
+
const f = parseShared(command);
|
|
6992
|
+
if (f === PARSE_FAIL) throw new Error("parse failed");
|
|
6993
|
+
walk(f, (node) => {
|
|
6856
6994
|
if (!node) return false;
|
|
6857
6995
|
const n = node;
|
|
6858
|
-
if (
|
|
6996
|
+
if (n.kind !== "CallExpr") return true;
|
|
6859
6997
|
const wordValues2 = (n.Args || []).map((arg) => {
|
|
6860
6998
|
return (arg.Parts || []).map((p) => (p.Value ?? "").replace(/\\(.)/g, "$1")).join("");
|
|
6861
6999
|
}).filter((s) => s.length > 0);
|
|
@@ -6916,9 +7054,9 @@ function ruleServerMatches(rule, serverLabel) {
|
|
|
6916
7054
|
return true;
|
|
6917
7055
|
}
|
|
6918
7056
|
var FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
6919
|
-
function getNestedValue(obj,
|
|
7057
|
+
function getNestedValue(obj, path2) {
|
|
6920
7058
|
if (!obj || typeof obj !== "object") return null;
|
|
6921
|
-
const segments2 =
|
|
7059
|
+
const segments2 = path2.split(".");
|
|
6922
7060
|
for (const seg of segments2) {
|
|
6923
7061
|
if (FORBIDDEN_PATH_SEGMENTS.has(seg)) return null;
|
|
6924
7062
|
}
|
|
@@ -7154,8 +7292,6 @@ function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
|
|
|
7154
7292
|
}
|
|
7155
7293
|
|
|
7156
7294
|
// src/shell/file-access.ts
|
|
7157
|
-
import mvdanSh2 from "mvdan-sh";
|
|
7158
|
-
var { syntax: syntax2 } = mvdanSh2;
|
|
7159
7295
|
var MAX_ALTERNATIVES = 64;
|
|
7160
7296
|
var MAX_CALL_DEPTH2 = 4;
|
|
7161
7297
|
var MAX_CALL_WALKS2 = 256;
|
|
@@ -7172,7 +7308,7 @@ function runnablePrefix(command) {
|
|
|
7172
7308
|
let text = command;
|
|
7173
7309
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
7174
7310
|
try {
|
|
7175
|
-
return
|
|
7311
|
+
return toPlainTree(getSyntax().NewParser().Parse(text, ""));
|
|
7176
7312
|
} catch (error) {
|
|
7177
7313
|
const message = String(typeof error?.Error === "function" ? error.Error() : error?.message);
|
|
7178
7314
|
const line = Number(/^(\d+):/.exec(message)?.[1]);
|
|
@@ -7271,18 +7407,22 @@ function merge(a, b) {
|
|
|
7271
7407
|
function opOf(sample) {
|
|
7272
7408
|
return parseShared(sample).Stmts[0].Redirs[0].Op;
|
|
7273
7409
|
}
|
|
7274
|
-
var
|
|
7275
|
-
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7283
|
-
|
|
7410
|
+
var ops = lazy(() => ({
|
|
7411
|
+
WRITES: new Set([">x", ">>x", ">|x", "&>x", "&>>x", "<>x"].map(opOf)),
|
|
7412
|
+
APPENDS: new Set([">>x", "&>>x"].map(opOf)),
|
|
7413
|
+
READS: new Set(["<x", "<>x"].map(opOf)),
|
|
7414
|
+
/** `>&word` with a non-numeric word is `&>word` in bash. */
|
|
7415
|
+
DUP_OUT: opOf(">&x"),
|
|
7416
|
+
HERE_STRING: opOf("<<<x"),
|
|
7417
|
+
AND: parseShared("a && b").Stmts[0].Cmd.Op,
|
|
7418
|
+
OR: parseShared("a || b").Stmts[0].Cmd.Op,
|
|
7419
|
+
/** `${x:-d}` `${x-d}` `${x:=d}` `${x=d}`: the default is the value when x is unset. */
|
|
7420
|
+
DEFAULT_OPS: new Set(
|
|
7421
|
+
["${x:-y}", "${x-y}", "${x:=y}", "${x=y}"].map(
|
|
7422
|
+
(s) => parseShared(`echo ${s}`).Stmts[0].Cmd.Args[1].Parts[0].Exp.Op
|
|
7423
|
+
)
|
|
7284
7424
|
)
|
|
7285
|
-
);
|
|
7425
|
+
}));
|
|
7286
7426
|
function wordValues(word, state) {
|
|
7287
7427
|
const toWords = (values, quoted) => values.map((value) => ({
|
|
7288
7428
|
value,
|
|
@@ -7294,7 +7434,7 @@ function wordValues(word, state) {
|
|
|
7294
7434
|
const name = node.Param?.Value;
|
|
7295
7435
|
const known = name === "PWD" ? state.cwd : state.vars.get(name);
|
|
7296
7436
|
if (node.Exp) {
|
|
7297
|
-
if (!DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7437
|
+
if (!ops().DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7298
7438
|
if (known && known.length) return toWords(known, quoted);
|
|
7299
7439
|
const fallback = expand(node.Exp.Word?.Parts ?? [], quoted);
|
|
7300
7440
|
return fallback.dynamic ? null : fallback.out.map(asWord);
|
|
@@ -7317,7 +7457,7 @@ function wordValues(word, state) {
|
|
|
7317
7457
|
out2 = next.slice(0, MAX_ALTERNATIVES);
|
|
7318
7458
|
};
|
|
7319
7459
|
for (const node of nodes) {
|
|
7320
|
-
const kind =
|
|
7460
|
+
const kind = node.kind;
|
|
7321
7461
|
let pieces;
|
|
7322
7462
|
if (kind === "ParamExp") pieces = paramValues(node, quoted);
|
|
7323
7463
|
else if (kind === "DblQuoted") {
|
|
@@ -7385,9 +7525,9 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7385
7525
|
}
|
|
7386
7526
|
function substitutions(word, state, depth) {
|
|
7387
7527
|
if (!word) return;
|
|
7388
|
-
|
|
7528
|
+
walk(word, (node) => {
|
|
7389
7529
|
if (!node) return false;
|
|
7390
|
-
if (["CmdSubst", "ProcSubst"].includes(
|
|
7530
|
+
if (["CmdSubst", "ProcSubst"].includes(node.kind)) {
|
|
7391
7531
|
statements(node.Stmts ?? [], clone(state), depth + 1);
|
|
7392
7532
|
return false;
|
|
7393
7533
|
}
|
|
@@ -7811,7 +7951,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7811
7951
|
}
|
|
7812
7952
|
function readsScriptFromStdin(stmt) {
|
|
7813
7953
|
const cmd = stmt?.Cmd;
|
|
7814
|
-
if (!cmd ||
|
|
7954
|
+
if (!cmd || cmd.kind !== "CallExpr") return false;
|
|
7815
7955
|
const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
7816
7956
|
const head = unwrapCommandHead(words);
|
|
7817
7957
|
return SHELL_INTERPRETERS.has(base(words[head])) && shellConsumesPipe(words.slice(head + 1));
|
|
@@ -7819,13 +7959,13 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7819
7959
|
function stdinText(stmt) {
|
|
7820
7960
|
for (const redir of stmt?.Redirs ?? []) {
|
|
7821
7961
|
if (redir.Hdoc) return resolveWordLiteral(redir.Hdoc);
|
|
7822
|
-
if (redir.Op === HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
7962
|
+
if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
7823
7963
|
}
|
|
7824
7964
|
return null;
|
|
7825
7965
|
}
|
|
7826
7966
|
function producedText(stmt) {
|
|
7827
7967
|
const cmd = stmt?.Cmd;
|
|
7828
|
-
if (!cmd ||
|
|
7968
|
+
if (!cmd || cmd.kind !== "CallExpr") return null;
|
|
7829
7969
|
const words = (cmd.Args ?? []).map((a) => resolveWordLiteral(a));
|
|
7830
7970
|
if (words.some((w) => w === null)) return null;
|
|
7831
7971
|
const head = unwrapCommandHead(words);
|
|
@@ -7844,15 +7984,15 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7844
7984
|
if (!stmt || depth > MAX_DEPTH) return;
|
|
7845
7985
|
state.onSuccess = void 0;
|
|
7846
7986
|
if (stmt.Background) state = clone(state);
|
|
7847
|
-
const headWord = stmt.Cmd &&
|
|
7987
|
+
const headWord = stmt.Cmd && stmt.Cmd.kind === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
|
|
7848
7988
|
const sends = SENDING_STDIN.has(headWord);
|
|
7849
7989
|
for (const redir of stmt.Redirs ?? []) {
|
|
7850
7990
|
substitutions(redir.Word, state, depth);
|
|
7851
7991
|
for (const word of wordValues(redir.Word, state)) {
|
|
7852
|
-
if (WRITES.has(redir.Op))
|
|
7853
|
-
add("write", word, state, APPENDS.has(redir.Op) ? { append: true } : {});
|
|
7854
|
-
if (READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
7855
|
-
if (redir.Op === DUP_OUT && word.value && !/^\d+$/.test(word.value))
|
|
7992
|
+
if (ops().WRITES.has(redir.Op))
|
|
7993
|
+
add("write", word, state, ops().APPENDS.has(redir.Op) ? { append: true } : {});
|
|
7994
|
+
if (ops().READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
7995
|
+
if (redir.Op === ops().DUP_OUT && word.value && !/^\d+$/.test(word.value))
|
|
7856
7996
|
add("write", word, state);
|
|
7857
7997
|
}
|
|
7858
7998
|
substitutions(redir.Hdoc, state, depth);
|
|
@@ -7860,7 +8000,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7860
8000
|
const cmd = stmt.Cmd;
|
|
7861
8001
|
if (!cmd) return;
|
|
7862
8002
|
stdinScript(stmt, state, depth);
|
|
7863
|
-
switch (
|
|
8003
|
+
switch (cmd.kind) {
|
|
7864
8004
|
case "CallExpr":
|
|
7865
8005
|
call(cmd, state, depth);
|
|
7866
8006
|
break;
|
|
@@ -7874,7 +8014,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7874
8014
|
for (; ; ) {
|
|
7875
8015
|
segments2.unshift({ op: node.Op, part: node.Y });
|
|
7876
8016
|
const left = node.X;
|
|
7877
|
-
if (left?.Cmd &&
|
|
8017
|
+
if (left?.Cmd && left.Cmd.kind === "BinaryCmd" && !left.Redirs?.length && !left.Negated && !left.Background)
|
|
7878
8018
|
node = left.Cmd;
|
|
7879
8019
|
else {
|
|
7880
8020
|
segments2.unshift({ op: node.Op, part: left });
|
|
@@ -7884,16 +8024,17 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7884
8024
|
const seen = clone(state);
|
|
7885
8025
|
let pureAnd = true;
|
|
7886
8026
|
segments2.forEach(({ op, part }, i) => {
|
|
7887
|
-
if (op === AND || op === OR) {
|
|
7888
|
-
if (i > 0 && op === AND && pureAnd && state.onSuccess)
|
|
7889
|
-
|
|
8027
|
+
if (op === ops().AND || op === ops().OR) {
|
|
8028
|
+
if (i > 0 && op === ops().AND && pureAnd && state.onSuccess)
|
|
8029
|
+
state.cwd = state.onSuccess;
|
|
8030
|
+
if (i > 0 && op === ops().OR) merge(state, seen);
|
|
7890
8031
|
statement(part, state, depth + 1);
|
|
7891
8032
|
} else {
|
|
7892
8033
|
statement(part, clone(state), depth + 1);
|
|
7893
8034
|
if (i > 0 && readsScriptFromStdin(part))
|
|
7894
8035
|
nestedPayload(producedText(segments2[i - 1].part), clone(state), depth);
|
|
7895
8036
|
}
|
|
7896
|
-
if (i > 0 && op !== AND) pureAnd = false;
|
|
8037
|
+
if (i > 0 && op !== ops().AND) pureAnd = false;
|
|
7897
8038
|
merge(seen, state);
|
|
7898
8039
|
});
|
|
7899
8040
|
merge(state, seen);
|
|
@@ -8019,8 +8160,8 @@ function collectFileAccesses(tool, args, context = {}, inspection = {}) {
|
|
|
8019
8160
|
}
|
|
8020
8161
|
return out;
|
|
8021
8162
|
}
|
|
8022
|
-
function within(
|
|
8023
|
-
return
|
|
8163
|
+
function within(path2, root) {
|
|
8164
|
+
return path2 === root || path2.startsWith(root === "/" ? "/" : root + "/");
|
|
8024
8165
|
}
|
|
8025
8166
|
function hits(access, paths, directories, context) {
|
|
8026
8167
|
const home = context.homeDirs?.[0] ?? "~";
|
|
@@ -8149,18 +8290,17 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
8149
8290
|
}
|
|
8150
8291
|
|
|
8151
8292
|
// src/shell/derived-writes.ts
|
|
8152
|
-
var
|
|
8153
|
-
|
|
8154
|
-
const ops = /* @__PURE__ */ new Set();
|
|
8293
|
+
var SEQUENCE_OPS = lazy(() => {
|
|
8294
|
+
const ops2 = /* @__PURE__ */ new Set();
|
|
8155
8295
|
for (const text of ["x && y", "x || y"]) {
|
|
8156
8296
|
try {
|
|
8157
8297
|
const f = parseShared(text);
|
|
8158
|
-
if (typeof f !== "symbol")
|
|
8298
|
+
if (typeof f !== "symbol") ops2.add(f.Stmts[0].Cmd.Op);
|
|
8159
8299
|
} catch {
|
|
8160
8300
|
}
|
|
8161
8301
|
}
|
|
8162
|
-
return
|
|
8163
|
-
})
|
|
8302
|
+
return ops2;
|
|
8303
|
+
});
|
|
8164
8304
|
function offsetMapper(text) {
|
|
8165
8305
|
if (!/[^\u0000-\u007f]/.test(text)) return (b) => b;
|
|
8166
8306
|
const starts = [];
|
|
@@ -8188,13 +8328,13 @@ function pipelineTexts(command) {
|
|
|
8188
8328
|
const visit = (stmt, depth) => {
|
|
8189
8329
|
if (!stmt || depth > 64) return;
|
|
8190
8330
|
const cmd = stmt.Cmd;
|
|
8191
|
-
if (cmd &&
|
|
8331
|
+
if (cmd && cmd.kind === "BinaryCmd" && SEQUENCE_OPS().has(cmd.Op)) {
|
|
8192
8332
|
visit(cmd.X, depth + 1);
|
|
8193
8333
|
visit(cmd.Y, depth + 1);
|
|
8194
8334
|
return;
|
|
8195
8335
|
}
|
|
8196
|
-
const s = at(stmt.
|
|
8197
|
-
const e = at(stmt.
|
|
8336
|
+
const s = at(stmt.pos);
|
|
8337
|
+
const e = at(stmt.end);
|
|
8198
8338
|
const text = s >= 0 && e > s ? command.slice(s, e).replace(/[\s;&]+$/, "") : "";
|
|
8199
8339
|
if (text) out.push(text);
|
|
8200
8340
|
};
|
|
@@ -12534,15 +12674,13 @@ function writtenTexts(args) {
|
|
|
12534
12674
|
}
|
|
12535
12675
|
|
|
12536
12676
|
// src/shell/write-source.ts
|
|
12537
|
-
|
|
12538
|
-
var { syntax: syntax4 } = mvdanSh4;
|
|
12539
|
-
var RDR_IN = (() => {
|
|
12677
|
+
var RDR_IN = lazy(() => {
|
|
12540
12678
|
try {
|
|
12541
12679
|
return parseShared("x <y").Stmts[0].Redirs[0].Op;
|
|
12542
12680
|
} catch {
|
|
12543
12681
|
return null;
|
|
12544
12682
|
}
|
|
12545
|
-
})
|
|
12683
|
+
});
|
|
12546
12684
|
var COPY_VERBS2 = /* @__PURE__ */ new Set([
|
|
12547
12685
|
"cp",
|
|
12548
12686
|
"mv",
|
|
@@ -12570,17 +12708,16 @@ function shellWriteUnseen(command, target) {
|
|
|
12570
12708
|
let unseen = false;
|
|
12571
12709
|
let seen = false;
|
|
12572
12710
|
try {
|
|
12573
|
-
|
|
12711
|
+
walk(f, (node) => {
|
|
12574
12712
|
if (!node || unseen) return false;
|
|
12575
12713
|
const n = node;
|
|
12576
|
-
if (
|
|
12577
|
-
return true;
|
|
12714
|
+
if (n.kind !== "Stmt" || !n.Cmd || n.Cmd.kind !== "CallExpr") return true;
|
|
12578
12715
|
const words = (n.Cmd.Args || []).map(
|
|
12579
12716
|
(a) => resolveWordLiteral(a)
|
|
12580
12717
|
);
|
|
12581
12718
|
const redirs = n.Redirs || [];
|
|
12582
12719
|
const redirectsTo = redirs.some((r) => r.Word && resolveWordLiteral(r.Word) === target);
|
|
12583
|
-
const readsFromFile = redirs.some((r) => r.Op === RDR_IN && r.Word && !r.Hdoc);
|
|
12720
|
+
const readsFromFile = redirs.some((r) => r.Op === RDR_IN() && r.Word && !r.Hdoc);
|
|
12584
12721
|
const named = words.includes(target);
|
|
12585
12722
|
if (!redirectsTo && !named) return true;
|
|
12586
12723
|
const head = unwrapCommandHead(words);
|
|
@@ -12604,8 +12741,6 @@ function shellWriteUnseen(command, target) {
|
|
|
12604
12741
|
}
|
|
12605
12742
|
|
|
12606
12743
|
// src/shell/git.ts
|
|
12607
|
-
import mvdanSh5 from "mvdan-sh";
|
|
12608
|
-
var { syntax: syntax5 } = mvdanSh5;
|
|
12609
12744
|
var GIT_PRESCREEN_RE = /git|husky/i;
|
|
12610
12745
|
var MAX_PAYLOAD_DEPTH2 = 8;
|
|
12611
12746
|
var MAX_ALIAS_DEPTH = 5;
|
|
@@ -12631,11 +12766,11 @@ function analyzeGit(command) {
|
|
|
12631
12766
|
}
|
|
12632
12767
|
function gitInvocations(command) {
|
|
12633
12768
|
const out = [];
|
|
12634
|
-
const
|
|
12769
|
+
const walk3 = new GitWalk(
|
|
12635
12770
|
(inv) => out.push(inv),
|
|
12636
12771
|
() => void 0
|
|
12637
12772
|
);
|
|
12638
|
-
|
|
12773
|
+
walk3.run(command, 0);
|
|
12639
12774
|
return out;
|
|
12640
12775
|
}
|
|
12641
12776
|
function analyzeGitImpl(command) {
|
|
@@ -12647,8 +12782,8 @@ function analyzeGitImpl(command) {
|
|
|
12647
12782
|
seen.add(key);
|
|
12648
12783
|
findings.push(f);
|
|
12649
12784
|
};
|
|
12650
|
-
const
|
|
12651
|
-
const parsed =
|
|
12785
|
+
const walk3 = new GitWalk((inv) => classify(inv).forEach(found), found);
|
|
12786
|
+
const parsed = walk3.run(command, 0);
|
|
12652
12787
|
return { parsed, findings };
|
|
12653
12788
|
}
|
|
12654
12789
|
var PAYLOAD_SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh", "eval"]);
|
|
@@ -12714,7 +12849,7 @@ var GitWalk = class {
|
|
|
12714
12849
|
visit(node, depth) {
|
|
12715
12850
|
if (!node) return false;
|
|
12716
12851
|
const n = node;
|
|
12717
|
-
const type =
|
|
12852
|
+
const type = n.kind;
|
|
12718
12853
|
if (type === "Stmt") {
|
|
12719
12854
|
this.visitHeredocShell(n, depth);
|
|
12720
12855
|
return true;
|
|
@@ -12722,7 +12857,7 @@ var GitWalk = class {
|
|
|
12722
12857
|
if (type === "ForClause") {
|
|
12723
12858
|
const loop = n.Loop;
|
|
12724
12859
|
const name = loop?.Name?.Value;
|
|
12725
|
-
if (name &&
|
|
12860
|
+
if (name && loop.kind === "WordIter") {
|
|
12726
12861
|
const items = (loop.Items || []).map((w) => resolveWordLiteral(w));
|
|
12727
12862
|
const literal = items.length > 0 && items.every((v) => v !== null);
|
|
12728
12863
|
this.loopVars.set(name, literal ? items.slice(0, MAX_LOOP_ITEMS) : null);
|
|
@@ -12789,7 +12924,7 @@ var GitWalk = class {
|
|
|
12789
12924
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12790
12925
|
visitHeredocShell(stmt, depth) {
|
|
12791
12926
|
const cmd = stmt.Cmd;
|
|
12792
|
-
if (!cmd ||
|
|
12927
|
+
if (!cmd || cmd.kind !== "CallExpr" || depth >= MAX_PAYLOAD_DEPTH2) return;
|
|
12793
12928
|
const redirs = stmt.Redirs || [];
|
|
12794
12929
|
const hdoc = redirs.find((r) => r?.Hdoc && (r.N == null || r.N.Value === "0"));
|
|
12795
12930
|
if (!hdoc) return;
|
|
@@ -12939,8 +13074,8 @@ var GitWalk = class {
|
|
|
12939
13074
|
var POSITIONAL2 = "\0positional";
|
|
12940
13075
|
function isPositionalParam(word) {
|
|
12941
13076
|
let parts = word?.Parts || [];
|
|
12942
|
-
if (parts.length === 1 &&
|
|
12943
|
-
if (parts.length !== 1 ||
|
|
13077
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
13078
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp") return false;
|
|
12944
13079
|
return /^(\d+|@|\*)$/.test(parts[0].Param?.Value ?? "");
|
|
12945
13080
|
}
|
|
12946
13081
|
function boundPositionals() {
|
|
@@ -12954,11 +13089,11 @@ function boundPositionals() {
|
|
|
12954
13089
|
function plainParamName(word) {
|
|
12955
13090
|
let parts = word?.Parts || [];
|
|
12956
13091
|
let quoted = false;
|
|
12957
|
-
if (parts.length === 1 &&
|
|
13092
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") {
|
|
12958
13093
|
parts = parts[0].Parts || [];
|
|
12959
13094
|
quoted = true;
|
|
12960
13095
|
}
|
|
12961
|
-
if (parts.length !== 1 ||
|
|
13096
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp") return null;
|
|
12962
13097
|
const p = parts[0];
|
|
12963
13098
|
if (p.Excl || p.Length || p.Width || p.Index || p.Slice || p.Repl || p.Exp) return null;
|
|
12964
13099
|
const name = p.Param?.Value;
|
|
@@ -12983,7 +13118,7 @@ function resolveGitWords(word) {
|
|
|
12983
13118
|
}
|
|
12984
13119
|
const parts = word?.Parts || [];
|
|
12985
13120
|
const expansion = parts.some((p) => {
|
|
12986
|
-
const t =
|
|
13121
|
+
const t = p.kind;
|
|
12987
13122
|
return t === "ParamExp" || t === "CmdSubst";
|
|
12988
13123
|
});
|
|
12989
13124
|
return expansion ? splitFields(value) : [value];
|
|
@@ -13494,14 +13629,14 @@ function hookCommands(text) {
|
|
|
13494
13629
|
const root = parsed?.hooks;
|
|
13495
13630
|
if (!root || typeof root !== "object") return null;
|
|
13496
13631
|
const out = [];
|
|
13497
|
-
const
|
|
13632
|
+
const walk3 = (v, depth) => {
|
|
13498
13633
|
if (depth > 8 || !v || typeof v !== "object") return;
|
|
13499
13634
|
for (const [k, x] of Object.entries(v)) {
|
|
13500
13635
|
if (k === "command" && typeof x === "string") out.push(x);
|
|
13501
|
-
else
|
|
13636
|
+
else walk3(x, depth + 1);
|
|
13502
13637
|
}
|
|
13503
13638
|
};
|
|
13504
|
-
|
|
13639
|
+
walk3(root, 0);
|
|
13505
13640
|
return out;
|
|
13506
13641
|
}
|
|
13507
13642
|
function hooksDisarmed(text) {
|
|
@@ -13663,8 +13798,6 @@ function evaluateAgentFileWrite(args, accesses, context, settings, shell, hooks
|
|
|
13663
13798
|
}
|
|
13664
13799
|
|
|
13665
13800
|
// src/shell/outbound.ts
|
|
13666
|
-
import mvdanSh6 from "mvdan-sh";
|
|
13667
|
-
var { syntax: syntax6 } = mvdanSh6;
|
|
13668
13801
|
var SHELLS = /* @__PURE__ */ new Set([...SHELL_INTERPRETERS, "mksh", "ash", "csh", "tcsh"]);
|
|
13669
13802
|
var NETCATS = /* @__PURE__ */ new Set(["nc", "ncat", "netcat", "nc.traditional", "nc.openbsd"]);
|
|
13670
13803
|
var NET_CLIENTS = /* @__PURE__ */ new Set([...NETCATS, "telnet", "socat"]);
|
|
@@ -13704,9 +13837,9 @@ function isDupInOp(op) {
|
|
|
13704
13837
|
if (dupInOp === null) {
|
|
13705
13838
|
let found = -1;
|
|
13706
13839
|
try {
|
|
13707
|
-
|
|
13840
|
+
walk(parseShared("cat <&3"), (node) => {
|
|
13708
13841
|
const n = node;
|
|
13709
|
-
if (found === -1 && n &&
|
|
13842
|
+
if (found === -1 && n && n.kind === "Stmt" && n.Redirs?.[0]) {
|
|
13710
13843
|
found = n.Redirs[0].Op;
|
|
13711
13844
|
}
|
|
13712
13845
|
return true;
|
|
@@ -13727,10 +13860,10 @@ function analyzeOutbound(command) {
|
|
|
13727
13860
|
return hit;
|
|
13728
13861
|
}
|
|
13729
13862
|
const findings = [];
|
|
13730
|
-
const
|
|
13731
|
-
const parsed =
|
|
13863
|
+
const walk3 = new OutboundWalk(findings);
|
|
13864
|
+
const parsed = walk3.run(command, 0);
|
|
13732
13865
|
const envOut = findings.find((f) => f.checkId === "data.env-exfil");
|
|
13733
|
-
if (envOut) envOut.destinations =
|
|
13866
|
+
if (envOut) envOut.destinations = walk3.envDestinations();
|
|
13734
13867
|
const computed = { parsed, findings };
|
|
13735
13868
|
if (cache2.size >= CACHE_MAX2) {
|
|
13736
13869
|
const oldest = cache2.keys().next().value;
|
|
@@ -13748,7 +13881,7 @@ function wordShape(word) {
|
|
|
13748
13881
|
const parts = word?.Parts || [];
|
|
13749
13882
|
let out = "";
|
|
13750
13883
|
for (const p of parts) {
|
|
13751
|
-
const t =
|
|
13884
|
+
const t = p.kind;
|
|
13752
13885
|
if (t === "Lit" || t === "SglQuoted") out += p.Value ?? "";
|
|
13753
13886
|
else if (t === "DblQuoted") out += wordShape(p);
|
|
13754
13887
|
else out += "X";
|
|
@@ -13904,7 +14037,7 @@ var OutboundWalk = class {
|
|
|
13904
14037
|
const f = parseShared(command);
|
|
13905
14038
|
if (!f || typeof f !== "object" || !f.Stmts) return false;
|
|
13906
14039
|
try {
|
|
13907
|
-
|
|
14040
|
+
walk(f, (node) => this.visit(node, depth));
|
|
13908
14041
|
} catch {
|
|
13909
14042
|
return false;
|
|
13910
14043
|
}
|
|
@@ -13943,7 +14076,7 @@ var OutboundWalk = class {
|
|
|
13943
14076
|
}
|
|
13944
14077
|
visit(n, depth) {
|
|
13945
14078
|
if (!n) return false;
|
|
13946
|
-
const type =
|
|
14079
|
+
const type = n.kind;
|
|
13947
14080
|
if (type === "Stmt") {
|
|
13948
14081
|
this.visitStmt(n, depth);
|
|
13949
14082
|
return true;
|
|
@@ -13963,7 +14096,7 @@ var OutboundWalk = class {
|
|
|
13963
14096
|
const redirs = redirectWords(stmt);
|
|
13964
14097
|
const toSocket = redirs.some((w) => w !== null && DEV_NET_RE.test(w));
|
|
13965
14098
|
if (!cmd) return;
|
|
13966
|
-
const type =
|
|
14099
|
+
const type = cmd.kind;
|
|
13967
14100
|
if (type !== "CallExpr" || wordsOf(cmd).length > 0) {
|
|
13968
14101
|
if (this.readsNetFd(stmt) && runsCommandsIn(stmt)) {
|
|
13969
14102
|
this.reverseShell("commands are read from a network socket opened with exec");
|
|
@@ -14049,7 +14182,7 @@ var OutboundWalk = class {
|
|
|
14049
14182
|
const stages = [];
|
|
14050
14183
|
const flatten = (s) => {
|
|
14051
14184
|
const c = s?.Cmd;
|
|
14052
|
-
if (c &&
|
|
14185
|
+
if (c && c.kind === "BinaryCmd" && isPipeOp(c.Op)) {
|
|
14053
14186
|
flatten(c.X);
|
|
14054
14187
|
flatten(c.Y);
|
|
14055
14188
|
} else stages.push(s);
|
|
@@ -14071,8 +14204,8 @@ var OutboundWalk = class {
|
|
|
14071
14204
|
sinks.set(i, socketHosts(st));
|
|
14072
14205
|
}
|
|
14073
14206
|
if (!c) return;
|
|
14074
|
-
if (
|
|
14075
|
-
if (
|
|
14207
|
+
if (c.kind === "DeclClause" && declDumpsEnv(c) && dump < 0) dump = i;
|
|
14208
|
+
if (c.kind !== "CallExpr") {
|
|
14076
14209
|
if (runsCommandsIn(st)) shell = i;
|
|
14077
14210
|
return;
|
|
14078
14211
|
}
|
|
@@ -14113,10 +14246,10 @@ var OutboundWalk = class {
|
|
|
14113
14246
|
/** A word (or assignment value) whose text includes an env dump's output. */
|
|
14114
14247
|
carriesEnv(word) {
|
|
14115
14248
|
let hit = false;
|
|
14116
|
-
|
|
14249
|
+
walk(word, (node) => {
|
|
14117
14250
|
if (hit || !node) return false;
|
|
14118
14251
|
const n = node;
|
|
14119
|
-
const t =
|
|
14252
|
+
const t = n.kind;
|
|
14120
14253
|
if (t === "ParamExp" && n.Param?.Value && this.envVars.has(n.Param.Value)) {
|
|
14121
14254
|
hit = true;
|
|
14122
14255
|
return false;
|
|
@@ -14133,11 +14266,11 @@ var OutboundWalk = class {
|
|
|
14133
14266
|
stmtsDumpEnv(stmts) {
|
|
14134
14267
|
let hit = false;
|
|
14135
14268
|
for (const s of stmts) {
|
|
14136
|
-
|
|
14269
|
+
walk(s, (node) => {
|
|
14137
14270
|
if (hit || !node) return false;
|
|
14138
14271
|
const n = node;
|
|
14139
|
-
const t =
|
|
14140
|
-
if (t === "Stmt" && n.Cmd &&
|
|
14272
|
+
const t = n.kind;
|
|
14273
|
+
if (t === "Stmt" && n.Cmd && n.Cmd.kind === "CallExpr") {
|
|
14141
14274
|
const words = wordsOf(n.Cmd);
|
|
14142
14275
|
if (words.length > 0 && dumpsEnv(words, n)) hit = true;
|
|
14143
14276
|
}
|
|
@@ -14156,16 +14289,16 @@ var OutboundWalk = class {
|
|
|
14156
14289
|
};
|
|
14157
14290
|
function paramName(word) {
|
|
14158
14291
|
let parts = word?.Parts || [];
|
|
14159
|
-
if (parts.length === 1 &&
|
|
14160
|
-
if (parts.length !== 1 ||
|
|
14292
|
+
if (parts.length === 1 && parts[0].kind === "DblQuoted") parts = parts[0].Parts || [];
|
|
14293
|
+
if (parts.length !== 1 || parts[0].kind !== "ParamExp") return null;
|
|
14161
14294
|
return parts[0].Param?.Value ?? null;
|
|
14162
14295
|
}
|
|
14163
14296
|
function refersTo(word, names) {
|
|
14164
14297
|
let hit = false;
|
|
14165
|
-
|
|
14298
|
+
walk(word, (node) => {
|
|
14166
14299
|
if (hit || !node) return false;
|
|
14167
14300
|
const n = node;
|
|
14168
|
-
if (
|
|
14301
|
+
if (n.kind === "ParamExp" && names.has(n.Param?.Value)) hit = true;
|
|
14169
14302
|
return !hit;
|
|
14170
14303
|
});
|
|
14171
14304
|
return hit;
|
|
@@ -14173,10 +14306,10 @@ function refersTo(word, names) {
|
|
|
14173
14306
|
function runsCommandsIn(stmt) {
|
|
14174
14307
|
const readVars = /* @__PURE__ */ new Set();
|
|
14175
14308
|
let hit = false;
|
|
14176
|
-
|
|
14309
|
+
walk(stmt, (node) => {
|
|
14177
14310
|
if (hit || !node) return false;
|
|
14178
14311
|
const n = node;
|
|
14179
|
-
if (
|
|
14312
|
+
if (n.kind !== "CallExpr") return true;
|
|
14180
14313
|
const words = wordsOf(n);
|
|
14181
14314
|
if (words.length === 0) return true;
|
|
14182
14315
|
const { head, at } = headOf(words);
|
|
@@ -14197,12 +14330,7 @@ function runsCommandsIn(stmt) {
|
|
|
14197
14330
|
return hit;
|
|
14198
14331
|
}
|
|
14199
14332
|
|
|
14200
|
-
// src/shell/package-registry.ts
|
|
14201
|
-
import mvdanSh8 from "mvdan-sh";
|
|
14202
|
-
|
|
14203
14333
|
// src/shell/package-install.ts
|
|
14204
|
-
import mvdanSh7 from "mvdan-sh";
|
|
14205
|
-
var { syntax: syntax7 } = mvdanSh7;
|
|
14206
14334
|
var NPM_INSTALL_VERBS = /* @__PURE__ */ new Set([
|
|
14207
14335
|
"install",
|
|
14208
14336
|
"i",
|
|
@@ -14776,14 +14904,14 @@ var COMPOSER_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
14776
14904
|
"--add-repository"
|
|
14777
14905
|
]);
|
|
14778
14906
|
function composerPackages(words, from, manager, out) {
|
|
14779
|
-
const
|
|
14780
|
-
const specs = manager === "composer create-project" ?
|
|
14907
|
+
const ops2 = operands(words, from, COMPOSER_VALUE_FLAGS);
|
|
14908
|
+
const specs = manager === "composer create-project" ? ops2.slice(0, 1) : ops2;
|
|
14781
14909
|
for (const raw of specs) {
|
|
14782
14910
|
const sep = raw.search(/[:=]/);
|
|
14783
14911
|
const name = sep < 0 ? raw : raw.slice(0, sep);
|
|
14784
14912
|
if (!COMPOSER_NAME_RE.test(name)) continue;
|
|
14785
14913
|
let ver = sep < 0 ? void 0 : raw.slice(sep + 1);
|
|
14786
|
-
if (manager === "composer create-project" && ver === void 0) ver =
|
|
14914
|
+
if (manager === "composer create-project" && ver === void 0) ver = ops2[2] ?? void 0;
|
|
14787
14915
|
push(out, "Packagist", manager, name.toLowerCase(), exactVersion(ver), raw);
|
|
14788
14916
|
}
|
|
14789
14917
|
}
|
|
@@ -15141,7 +15269,7 @@ function localContexts(file) {
|
|
|
15141
15269
|
if (depth > 64) return null;
|
|
15142
15270
|
if (!stmt || stmt.Background || stmt.Negated || stmt.Redirs?.length) return null;
|
|
15143
15271
|
const cmd = stmt.Cmd;
|
|
15144
|
-
const kind =
|
|
15272
|
+
const kind = cmd.kind;
|
|
15145
15273
|
if (kind === "BinaryCmd" && cmd.Op === andOp) {
|
|
15146
15274
|
const next = visit(cmd.X, steps, depth + 1);
|
|
15147
15275
|
return next === null ? null : visit(cmd.Y, next, depth + 1);
|
|
@@ -15157,7 +15285,7 @@ function localContexts(file) {
|
|
|
15157
15285
|
)
|
|
15158
15286
|
))
|
|
15159
15287
|
return null;
|
|
15160
|
-
contexts.set(cmd.
|
|
15288
|
+
contexts.set(cmd.pos, steps);
|
|
15161
15289
|
return null;
|
|
15162
15290
|
}
|
|
15163
15291
|
if (file.Stmts?.length === 1) visit(file.Stmts[0], []);
|
|
@@ -15168,12 +15296,12 @@ function collect(command, out, depth) {
|
|
|
15168
15296
|
const f = parseShared(command);
|
|
15169
15297
|
if (typeof f === "symbol") return;
|
|
15170
15298
|
const contexts = depth === 0 ? localContexts(f) : /* @__PURE__ */ new Map();
|
|
15171
|
-
|
|
15172
|
-
if (node &&
|
|
15299
|
+
walk(f, (node) => {
|
|
15300
|
+
if (node && node.kind === "CallExpr") {
|
|
15173
15301
|
const words = (node.Args || []).map((a) => resolveWordLiteral(a));
|
|
15174
15302
|
const start = out.length;
|
|
15175
15303
|
if (words.length > 0) fromCall(words, out, depth);
|
|
15176
|
-
const steps = contexts.get(node.
|
|
15304
|
+
const steps = contexts.get(node.pos);
|
|
15177
15305
|
for (let i = start; i < out.length; i++) {
|
|
15178
15306
|
if (["npx", "bunx", "npm exec"].includes(out[i].manager)) {
|
|
15179
15307
|
if (!steps) out[i].localCwd = null;
|
|
@@ -15197,7 +15325,6 @@ function extractPackageInstalls(command) {
|
|
|
15197
15325
|
}
|
|
15198
15326
|
|
|
15199
15327
|
// src/shell/package-registry.ts
|
|
15200
|
-
var { syntax: syntax8 } = mvdanSh8;
|
|
15201
15328
|
var NPM_FAMILY = /* @__PURE__ */ new Set(["npm", "pnpm", "yarn", "bun", "npx", "pnpx", "bunx"]);
|
|
15202
15329
|
var PIP_FAMILY = /* @__PURE__ */ new Set(["pip", "pip3", "uv", "uvx", "pipx", "pipenv"]);
|
|
15203
15330
|
var NPM_FETCH_VERBS = /* @__PURE__ */ new Set([
|
|
@@ -15288,7 +15415,7 @@ function collect2(command, out, depth) {
|
|
|
15288
15415
|
try {
|
|
15289
15416
|
walkCommandScope(command, (node) => {
|
|
15290
15417
|
const n = node;
|
|
15291
|
-
if (!n ||
|
|
15418
|
+
if (!n || n.kind !== "CallExpr") return true;
|
|
15292
15419
|
const words = (n.Args || []).map((a) => resolveWordLiteral(a));
|
|
15293
15420
|
if (words.length === 0) return true;
|
|
15294
15421
|
const prefix = (n.Assigns || []).filter((a) => a?.Name?.Value).map(
|
|
@@ -16139,9 +16266,9 @@ function bareToolName(toolName) {
|
|
|
16139
16266
|
const parts = toolName.split("__");
|
|
16140
16267
|
return (parts.length >= 3 ? parts.slice(2).join("__") : toolName).toLowerCase();
|
|
16141
16268
|
}
|
|
16142
|
-
function valuesAt(args,
|
|
16269
|
+
function valuesAt(args, path2) {
|
|
16143
16270
|
let cursors = [args];
|
|
16144
|
-
for (const rawSegment of
|
|
16271
|
+
for (const rawSegment of path2.split(".")) {
|
|
16145
16272
|
const isArray = rawSegment.endsWith("[]");
|
|
16146
16273
|
const key = isArray ? rawSegment.slice(0, -2) : rawSegment;
|
|
16147
16274
|
const next = [];
|
|
@@ -16172,8 +16299,8 @@ function extractToolDestinations(toolName, args) {
|
|
|
16172
16299
|
try {
|
|
16173
16300
|
const out = [];
|
|
16174
16301
|
const paths = DESTINATION_ARGS.get(bareToolName(toolName)) ?? [];
|
|
16175
|
-
for (const
|
|
16176
|
-
for (const value of valuesAt(args,
|
|
16302
|
+
for (const path2 of paths) {
|
|
16303
|
+
for (const value of valuesAt(args, path2)) {
|
|
16177
16304
|
const host2 = hostOf(value);
|
|
16178
16305
|
if (host2) out.push({ host: host2, binary: toolName, raw: value });
|
|
16179
16306
|
}
|
|
@@ -16206,8 +16333,8 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
16206
16333
|
try {
|
|
16207
16334
|
const paths = DESTINATION_ARGS.get(bareToolName(toolName));
|
|
16208
16335
|
if (!paths) return null;
|
|
16209
|
-
for (const
|
|
16210
|
-
for (const value of valuesAt(args,
|
|
16336
|
+
for (const path2 of paths) {
|
|
16337
|
+
for (const value of valuesAt(args, path2)) {
|
|
16211
16338
|
const host2 = hostOf(value);
|
|
16212
16339
|
if (!host2) continue;
|
|
16213
16340
|
const m = classifySsrf(host2);
|
|
@@ -16216,7 +16343,7 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
16216
16343
|
const decision = ssrfFloorDecision(m, written, opts);
|
|
16217
16344
|
if (decision === null) continue;
|
|
16218
16345
|
const reason = decision === "review" ? ssrfDisguisedReason(m, written) : ssrfReason(m, host2);
|
|
16219
|
-
return { ...m, argPath:
|
|
16346
|
+
return { ...m, argPath: path2, host: host2, reason, decision };
|
|
16220
16347
|
}
|
|
16221
16348
|
}
|
|
16222
16349
|
return null;
|
|
@@ -17075,12 +17202,12 @@ function extractContentDestinations(text) {
|
|
|
17075
17202
|
function extractArgDestinations(args) {
|
|
17076
17203
|
const out = /* @__PURE__ */ new Set();
|
|
17077
17204
|
try {
|
|
17078
|
-
|
|
17205
|
+
walk2(args, void 0, out, 0);
|
|
17079
17206
|
} catch {
|
|
17080
17207
|
}
|
|
17081
17208
|
return [...out];
|
|
17082
17209
|
}
|
|
17083
|
-
function
|
|
17210
|
+
function walk2(value, key, out, depth) {
|
|
17084
17211
|
if (out.size >= MAX_DESTINATIONS || depth > 12) return;
|
|
17085
17212
|
if (typeof value === "string") {
|
|
17086
17213
|
const s = value.length > MAX_SCAN_CHARS ? value.slice(0, MAX_SCAN_CHARS) : value;
|
|
@@ -17099,12 +17226,12 @@ function walk(value, key, out, depth) {
|
|
|
17099
17226
|
return;
|
|
17100
17227
|
}
|
|
17101
17228
|
if (Array.isArray(value)) {
|
|
17102
|
-
for (const v of value)
|
|
17229
|
+
for (const v of value) walk2(v, key, out, depth + 1);
|
|
17103
17230
|
return;
|
|
17104
17231
|
}
|
|
17105
17232
|
if (value && typeof value === "object") {
|
|
17106
17233
|
for (const [k, v] of Object.entries(value))
|
|
17107
|
-
|
|
17234
|
+
walk2(v, k, out, depth + 1);
|
|
17108
17235
|
}
|
|
17109
17236
|
}
|
|
17110
17237
|
function destinationDomain(dest) {
|
|
@@ -17615,8 +17742,6 @@ function maskLeaf(value, key, depth) {
|
|
|
17615
17742
|
}
|
|
17616
17743
|
|
|
17617
17744
|
// src/exposure/shell.ts
|
|
17618
|
-
import mvdanSh9 from "mvdan-sh";
|
|
17619
|
-
var { syntax: syntax9 } = mvdanSh9;
|
|
17620
17745
|
var EMPTY = {
|
|
17621
17746
|
fetches: false,
|
|
17622
17747
|
sends: false,
|
|
@@ -18030,9 +18155,9 @@ function classifyCall(head, args, prefixes, env, state, out) {
|
|
|
18030
18155
|
function walkCalls(command, out, depth, state) {
|
|
18031
18156
|
const f = parseShared(command);
|
|
18032
18157
|
if (typeof f === "symbol" || !f) return;
|
|
18033
|
-
|
|
18158
|
+
walk(f, (node) => {
|
|
18034
18159
|
if (!node) return false;
|
|
18035
|
-
const type =
|
|
18160
|
+
const type = node.kind;
|
|
18036
18161
|
if (type === "DeclClause") {
|
|
18037
18162
|
for (const a of node.Args || []) if (a?.Name?.Value) state.env.add(a.Name.Value);
|
|
18038
18163
|
return true;
|
|
@@ -18610,7 +18735,7 @@ function matchCanaryArgs(args, values) {
|
|
|
18610
18735
|
if (values.length === 0) return null;
|
|
18611
18736
|
const needles = prepare(values);
|
|
18612
18737
|
if (needles.length === 0) return null;
|
|
18613
|
-
const
|
|
18738
|
+
const walk3 = (v, depth, fieldPath) => {
|
|
18614
18739
|
if (depth > MAX_DEPTH4) return null;
|
|
18615
18740
|
if (typeof v === "string") {
|
|
18616
18741
|
const hit = matchPrepared(v, needles);
|
|
@@ -18619,31 +18744,31 @@ function matchCanaryArgs(args, values) {
|
|
|
18619
18744
|
const trimmed = v.trim();
|
|
18620
18745
|
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
18621
18746
|
try {
|
|
18622
|
-
return
|
|
18747
|
+
return walk3(JSON.parse(v), depth + 1, fieldPath);
|
|
18623
18748
|
} catch {
|
|
18624
18749
|
}
|
|
18625
18750
|
}
|
|
18626
18751
|
}
|
|
18627
18752
|
return null;
|
|
18628
18753
|
}
|
|
18629
|
-
if (typeof v === "number" && Number.isFinite(v)) return
|
|
18754
|
+
if (typeof v === "number" && Number.isFinite(v)) return walk3(String(v), depth, fieldPath);
|
|
18630
18755
|
if (Array.isArray(v)) {
|
|
18631
18756
|
for (let i = 0; i < v.length; i++) {
|
|
18632
|
-
const h =
|
|
18757
|
+
const h = walk3(v[i], depth + 1, `${fieldPath}[${i}]`);
|
|
18633
18758
|
if (h) return h;
|
|
18634
18759
|
}
|
|
18635
18760
|
return null;
|
|
18636
18761
|
}
|
|
18637
18762
|
if (v && typeof v === "object") {
|
|
18638
18763
|
for (const [k, child] of Object.entries(v)) {
|
|
18639
|
-
const h =
|
|
18764
|
+
const h = walk3(child, depth + 1, fieldPath ? `${fieldPath}.${k}` : k);
|
|
18640
18765
|
if (h) return h;
|
|
18641
18766
|
}
|
|
18642
18767
|
}
|
|
18643
18768
|
return null;
|
|
18644
18769
|
};
|
|
18645
18770
|
try {
|
|
18646
|
-
return
|
|
18771
|
+
return walk3(args, 0, "");
|
|
18647
18772
|
} catch (e) {
|
|
18648
18773
|
console.error(
|
|
18649
18774
|
"[node9 engine] canary args walk failed:",
|
|
@@ -18656,7 +18781,7 @@ function matchCanaryArgs(args, values) {
|
|
|
18656
18781
|
// src/scan/canonical.ts
|
|
18657
18782
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
18658
18783
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
|
|
18659
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
18784
|
+
var CANONICAL_EXTRACTOR_HASH = "8726a60ddd4bad7b";
|
|
18660
18785
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
18661
18786
|
function extractCanonicalFindings(call, ctx) {
|
|
18662
18787
|
const out = [];
|