@node9/policy-engine 2.47.0 → 2.47.2
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 +86 -63
- package/dist/index.mjs +106 -77
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2399,7 +2399,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
|
|
|
2399
2399
|
* files changed, this hash must change too, and you must consciously
|
|
2400
2400
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2401
2401
|
*/
|
|
2402
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2402
|
+
declare const CANONICAL_EXTRACTOR_HASH = "8726a60ddd4bad7b";
|
|
2403
2403
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2404
2404
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2405
2405
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -2399,7 +2399,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
|
|
|
2399
2399
|
* files changed, this hash must change too, and you must consciously
|
|
2400
2400
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2401
2401
|
*/
|
|
2402
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2402
|
+
declare const CANONICAL_EXTRACTOR_HASH = "8726a60ddd4bad7b";
|
|
2403
2403
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2404
2404
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2405
2405
|
/**
|
package/dist/index.js
CHANGED
|
@@ -3552,12 +3552,29 @@ function resolveCheckMap(settings) {
|
|
|
3552
3552
|
// src/rules/index.ts
|
|
3553
3553
|
var import_picomatch = __toESM(require("picomatch"));
|
|
3554
3554
|
|
|
3555
|
-
// src/shell/
|
|
3556
|
-
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
|
+
}
|
|
3557
3576
|
|
|
3558
3577
|
// src/shell/plain-tree.ts
|
|
3559
|
-
var import_mvdan_sh = __toESM(require("mvdan-sh"));
|
|
3560
|
-
var { syntax } = import_mvdan_sh.default;
|
|
3561
3578
|
var KINDS = {
|
|
3562
3579
|
File: { nodes: ["Stmts"] },
|
|
3563
3580
|
Stmt: { nodes: ["Cmd", "Redirs"], scalars: ["Negated", "Background", "Coprocess"] },
|
|
@@ -3616,7 +3633,7 @@ function isGoNode(v) {
|
|
|
3616
3633
|
return v !== null && typeof v === "object" && typeof v.Pos === "function";
|
|
3617
3634
|
}
|
|
3618
3635
|
function toPlainTree(goNode) {
|
|
3619
|
-
const kind =
|
|
3636
|
+
const kind = getSyntax().NodeType(goNode);
|
|
3620
3637
|
const out = { kind, pos: goNode.Pos().Offset(), end: goNode.End().Offset() };
|
|
3621
3638
|
const spec = KINDS[kind];
|
|
3622
3639
|
if (!spec) {
|
|
@@ -4114,8 +4131,7 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
4114
4131
|
}
|
|
4115
4132
|
|
|
4116
4133
|
// src/shell/index.ts
|
|
4117
|
-
var
|
|
4118
|
-
var sharedParser = syntax2.NewParser();
|
|
4134
|
+
var sharedParser = lazy(() => getSyntax().NewParser());
|
|
4119
4135
|
var MESSAGE_FLAGS = /* @__PURE__ */ new Set([
|
|
4120
4136
|
"-m",
|
|
4121
4137
|
"--message",
|
|
@@ -4178,7 +4194,7 @@ function parseShared(command) {
|
|
|
4178
4194
|
}
|
|
4179
4195
|
let parsed;
|
|
4180
4196
|
try {
|
|
4181
|
-
parsed = toPlainTree(sharedParser.Parse(command, "cmd"));
|
|
4197
|
+
parsed = toPlainTree(sharedParser().Parse(command, "cmd"));
|
|
4182
4198
|
} catch {
|
|
4183
4199
|
parsed = PARSE_FAIL;
|
|
4184
4200
|
}
|
|
@@ -5455,7 +5471,7 @@ function redirStdinOps() {
|
|
|
5455
5471
|
}
|
|
5456
5472
|
function deriveBinaryOp(sample) {
|
|
5457
5473
|
try {
|
|
5458
|
-
const f = toPlainTree(sharedParser.Parse(sample, "cmd"));
|
|
5474
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
5459
5475
|
let op = -1;
|
|
5460
5476
|
walk(f, (node) => {
|
|
5461
5477
|
const n = node;
|
|
@@ -6101,22 +6117,27 @@ function recordTopLevelAssignments(f) {
|
|
|
6101
6117
|
}
|
|
6102
6118
|
function probeBinOp(src) {
|
|
6103
6119
|
try {
|
|
6104
|
-
const cmd = toPlainTree(
|
|
6120
|
+
const cmd = toPlainTree(getSyntax().NewParser().Parse(src, "probe"))?.Stmts?.[0]?.Cmd;
|
|
6105
6121
|
if (cmd && cmd.kind === "BinaryCmd") return cmd.Op;
|
|
6106
6122
|
} catch {
|
|
6107
6123
|
}
|
|
6108
6124
|
return null;
|
|
6109
6125
|
}
|
|
6110
|
-
var
|
|
6111
|
-
|
|
6112
|
-
|
|
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
|
+
});
|
|
6113
6134
|
function recordTopLevelStmt(stmt) {
|
|
6114
6135
|
if (!stmt || !stmt.Cmd) return false;
|
|
6115
6136
|
const t = stmt.Cmd.kind;
|
|
6116
6137
|
if (t === "BinaryCmd") {
|
|
6117
|
-
if (!AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
6138
|
+
if (!andOrOps().AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
6118
6139
|
if (!recordTopLevelStmt(stmt.Cmd.X)) return false;
|
|
6119
|
-
if (stmt.Cmd.Op === AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
6140
|
+
if (stmt.Cmd.Op === andOrOps().AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
6120
6141
|
return true;
|
|
6121
6142
|
}
|
|
6122
6143
|
if (t !== "CallExpr" && t !== "DeclClause") return false;
|
|
@@ -6574,7 +6595,7 @@ function isWaivableCleanupTarget(p) {
|
|
|
6574
6595
|
}
|
|
6575
6596
|
function deriveRedirOp(sample) {
|
|
6576
6597
|
try {
|
|
6577
|
-
const f = toPlainTree(sharedParser.Parse(sample, "cmd"));
|
|
6598
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
6578
6599
|
let op = -1;
|
|
6579
6600
|
walk(f, (node) => {
|
|
6580
6601
|
const n = node;
|
|
@@ -6586,14 +6607,13 @@ function deriveRedirOp(sample) {
|
|
|
6586
6607
|
return -1;
|
|
6587
6608
|
}
|
|
6588
6609
|
}
|
|
6589
|
-
var REDIR_TRUNCATE_OPS = /* @__PURE__ */ new Set([deriveRedirOp(">_f")]);
|
|
6590
|
-
var REDIR_FILE_IN_OPS =
|
|
6591
|
-
[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")])
|
|
6592
6616
|
);
|
|
6593
|
-
var REDIR_HEREDOC_OPS = /* @__PURE__ */ new Set([
|
|
6594
|
-
deriveRedirOp("cat <<X\nX"),
|
|
6595
|
-
deriveRedirOp("cat <<-X\nX")
|
|
6596
|
-
]);
|
|
6597
6617
|
function collectSameCommandCreations(f) {
|
|
6598
6618
|
const created = /* @__PURE__ */ new Set();
|
|
6599
6619
|
try {
|
|
@@ -6601,9 +6621,9 @@ function collectSameCommandCreations(f) {
|
|
|
6601
6621
|
for (const stmt of stmts) {
|
|
6602
6622
|
if (!stmt || !stmt.Cmd || stmt.Cmd.kind !== "CallExpr") continue;
|
|
6603
6623
|
const redirs = stmt.Redirs || [];
|
|
6604
|
-
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;
|
|
6605
6625
|
for (const r of redirs) {
|
|
6606
|
-
if (r && REDIR_TRUNCATE_OPS.has(r.Op) && r.N == null) {
|
|
6626
|
+
if (r && REDIR_TRUNCATE_OPS().has(r.Op) && r.N == null) {
|
|
6607
6627
|
const w = resolveWordLiteral(r.Word);
|
|
6608
6628
|
if (w) created.add(stripDotSlash(w));
|
|
6609
6629
|
}
|
|
@@ -7203,7 +7223,7 @@ function literalShellPayload(words, name) {
|
|
|
7203
7223
|
function jailedRedirectRead(stmt) {
|
|
7204
7224
|
const redirs = stmt.Redirs || [];
|
|
7205
7225
|
for (const r of redirs) {
|
|
7206
|
-
if (!r || !REDIR_FILE_IN_OPS.has(r.Op)) continue;
|
|
7226
|
+
if (!r || !REDIR_FILE_IN_OPS().has(r.Op)) continue;
|
|
7207
7227
|
const p = resolveWordLiteral(r.Word);
|
|
7208
7228
|
if (p === null || p === "") continue;
|
|
7209
7229
|
const hit = matchSensitivePath(p);
|
|
@@ -7526,8 +7546,6 @@ function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
|
|
|
7526
7546
|
}
|
|
7527
7547
|
|
|
7528
7548
|
// src/shell/file-access.ts
|
|
7529
|
-
var import_mvdan_sh3 = __toESM(require("mvdan-sh"));
|
|
7530
|
-
var { syntax: syntax3 } = import_mvdan_sh3.default;
|
|
7531
7549
|
var MAX_ALTERNATIVES = 64;
|
|
7532
7550
|
var MAX_CALL_DEPTH2 = 4;
|
|
7533
7551
|
var MAX_CALL_WALKS2 = 256;
|
|
@@ -7544,7 +7562,7 @@ function runnablePrefix(command) {
|
|
|
7544
7562
|
let text = command;
|
|
7545
7563
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
7546
7564
|
try {
|
|
7547
|
-
return toPlainTree(
|
|
7565
|
+
return toPlainTree(getSyntax().NewParser().Parse(text, ""));
|
|
7548
7566
|
} catch (error) {
|
|
7549
7567
|
const message = String(typeof error?.Error === "function" ? error.Error() : error?.message);
|
|
7550
7568
|
const line = Number(/^(\d+):/.exec(message)?.[1]);
|
|
@@ -7643,18 +7661,22 @@ function merge(a, b) {
|
|
|
7643
7661
|
function opOf(sample) {
|
|
7644
7662
|
return parseShared(sample).Stmts[0].Redirs[0].Op;
|
|
7645
7663
|
}
|
|
7646
|
-
var
|
|
7647
|
-
|
|
7648
|
-
|
|
7649
|
-
|
|
7650
|
-
|
|
7651
|
-
|
|
7652
|
-
|
|
7653
|
-
|
|
7654
|
-
|
|
7655
|
-
|
|
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
|
+
)
|
|
7656
7678
|
)
|
|
7657
|
-
);
|
|
7679
|
+
}));
|
|
7658
7680
|
function wordValues(word, state) {
|
|
7659
7681
|
const toWords = (values, quoted) => values.map((value) => ({
|
|
7660
7682
|
value,
|
|
@@ -7666,7 +7688,7 @@ function wordValues(word, state) {
|
|
|
7666
7688
|
const name = node.Param?.Value;
|
|
7667
7689
|
const known = name === "PWD" ? state.cwd : state.vars.get(name);
|
|
7668
7690
|
if (node.Exp) {
|
|
7669
|
-
if (!DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7691
|
+
if (!ops().DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7670
7692
|
if (known && known.length) return toWords(known, quoted);
|
|
7671
7693
|
const fallback = expand(node.Exp.Word?.Parts ?? [], quoted);
|
|
7672
7694
|
return fallback.dynamic ? null : fallback.out.map(asWord);
|
|
@@ -8191,7 +8213,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8191
8213
|
function stdinText(stmt) {
|
|
8192
8214
|
for (const redir of stmt?.Redirs ?? []) {
|
|
8193
8215
|
if (redir.Hdoc) return resolveWordLiteral(redir.Hdoc);
|
|
8194
|
-
if (redir.Op === HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
8216
|
+
if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
8195
8217
|
}
|
|
8196
8218
|
return null;
|
|
8197
8219
|
}
|
|
@@ -8221,10 +8243,10 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8221
8243
|
for (const redir of stmt.Redirs ?? []) {
|
|
8222
8244
|
substitutions(redir.Word, state, depth);
|
|
8223
8245
|
for (const word of wordValues(redir.Word, state)) {
|
|
8224
|
-
if (WRITES.has(redir.Op))
|
|
8225
|
-
add("write", word, state, APPENDS.has(redir.Op) ? { append: true } : {});
|
|
8226
|
-
if (READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
8227
|
-
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))
|
|
8228
8250
|
add("write", word, state);
|
|
8229
8251
|
}
|
|
8230
8252
|
substitutions(redir.Hdoc, state, depth);
|
|
@@ -8256,16 +8278,17 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
8256
8278
|
const seen = clone(state);
|
|
8257
8279
|
let pureAnd = true;
|
|
8258
8280
|
segments2.forEach(({ op, part }, i) => {
|
|
8259
|
-
if (op === AND || op === OR) {
|
|
8260
|
-
if (i > 0 && op === AND && pureAnd && state.onSuccess)
|
|
8261
|
-
|
|
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);
|
|
8262
8285
|
statement(part, state, depth + 1);
|
|
8263
8286
|
} else {
|
|
8264
8287
|
statement(part, clone(state), depth + 1);
|
|
8265
8288
|
if (i > 0 && readsScriptFromStdin(part))
|
|
8266
8289
|
nestedPayload(producedText(segments2[i - 1].part), clone(state), depth);
|
|
8267
8290
|
}
|
|
8268
|
-
if (i > 0 && op !== AND) pureAnd = false;
|
|
8291
|
+
if (i > 0 && op !== ops().AND) pureAnd = false;
|
|
8269
8292
|
merge(seen, state);
|
|
8270
8293
|
});
|
|
8271
8294
|
merge(state, seen);
|
|
@@ -8521,17 +8544,17 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
8521
8544
|
}
|
|
8522
8545
|
|
|
8523
8546
|
// src/shell/derived-writes.ts
|
|
8524
|
-
var SEQUENCE_OPS = (() => {
|
|
8525
|
-
const
|
|
8547
|
+
var SEQUENCE_OPS = lazy(() => {
|
|
8548
|
+
const ops2 = /* @__PURE__ */ new Set();
|
|
8526
8549
|
for (const text of ["x && y", "x || y"]) {
|
|
8527
8550
|
try {
|
|
8528
8551
|
const f = parseShared(text);
|
|
8529
|
-
if (typeof f !== "symbol")
|
|
8552
|
+
if (typeof f !== "symbol") ops2.add(f.Stmts[0].Cmd.Op);
|
|
8530
8553
|
} catch {
|
|
8531
8554
|
}
|
|
8532
8555
|
}
|
|
8533
|
-
return
|
|
8534
|
-
})
|
|
8556
|
+
return ops2;
|
|
8557
|
+
});
|
|
8535
8558
|
function offsetMapper(text) {
|
|
8536
8559
|
if (!/[^\u0000-\u007f]/.test(text)) return (b) => b;
|
|
8537
8560
|
const starts = [];
|
|
@@ -8559,7 +8582,7 @@ function pipelineTexts(command) {
|
|
|
8559
8582
|
const visit = (stmt, depth) => {
|
|
8560
8583
|
if (!stmt || depth > 64) return;
|
|
8561
8584
|
const cmd = stmt.Cmd;
|
|
8562
|
-
if (cmd && cmd.kind === "BinaryCmd" && SEQUENCE_OPS.has(cmd.Op)) {
|
|
8585
|
+
if (cmd && cmd.kind === "BinaryCmd" && SEQUENCE_OPS().has(cmd.Op)) {
|
|
8563
8586
|
visit(cmd.X, depth + 1);
|
|
8564
8587
|
visit(cmd.Y, depth + 1);
|
|
8565
8588
|
return;
|
|
@@ -12905,13 +12928,13 @@ function writtenTexts(args) {
|
|
|
12905
12928
|
}
|
|
12906
12929
|
|
|
12907
12930
|
// src/shell/write-source.ts
|
|
12908
|
-
var RDR_IN = (() => {
|
|
12931
|
+
var RDR_IN = lazy(() => {
|
|
12909
12932
|
try {
|
|
12910
12933
|
return parseShared("x <y").Stmts[0].Redirs[0].Op;
|
|
12911
12934
|
} catch {
|
|
12912
12935
|
return null;
|
|
12913
12936
|
}
|
|
12914
|
-
})
|
|
12937
|
+
});
|
|
12915
12938
|
var COPY_VERBS2 = /* @__PURE__ */ new Set([
|
|
12916
12939
|
"cp",
|
|
12917
12940
|
"mv",
|
|
@@ -12948,7 +12971,7 @@ function shellWriteUnseen(command, target) {
|
|
|
12948
12971
|
);
|
|
12949
12972
|
const redirs = n.Redirs || [];
|
|
12950
12973
|
const redirectsTo = redirs.some((r) => r.Word && resolveWordLiteral(r.Word) === target);
|
|
12951
|
-
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);
|
|
12952
12975
|
const named = words.includes(target);
|
|
12953
12976
|
if (!redirectsTo && !named) return true;
|
|
12954
12977
|
const head = unwrapCommandHead(words);
|
|
@@ -15135,14 +15158,14 @@ var COMPOSER_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
15135
15158
|
"--add-repository"
|
|
15136
15159
|
]);
|
|
15137
15160
|
function composerPackages(words, from, manager, out) {
|
|
15138
|
-
const
|
|
15139
|
-
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;
|
|
15140
15163
|
for (const raw of specs) {
|
|
15141
15164
|
const sep = raw.search(/[:=]/);
|
|
15142
15165
|
const name = sep < 0 ? raw : raw.slice(0, sep);
|
|
15143
15166
|
if (!COMPOSER_NAME_RE.test(name)) continue;
|
|
15144
15167
|
let ver = sep < 0 ? void 0 : raw.slice(sep + 1);
|
|
15145
|
-
if (manager === "composer create-project" && ver === void 0) ver =
|
|
15168
|
+
if (manager === "composer create-project" && ver === void 0) ver = ops2[2] ?? void 0;
|
|
15146
15169
|
push(out, "Packagist", manager, name.toLowerCase(), exactVersion(ver), raw);
|
|
15147
15170
|
}
|
|
15148
15171
|
}
|
|
@@ -19012,7 +19035,7 @@ function matchCanaryArgs(args, values) {
|
|
|
19012
19035
|
// src/scan/canonical.ts
|
|
19013
19036
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
19014
19037
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
|
|
19015
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
19038
|
+
var CANONICAL_EXTRACTOR_HASH = "8726a60ddd4bad7b";
|
|
19016
19039
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
19017
19040
|
function extractCanonicalFindings(call, ctx) {
|
|
19018
19041
|
const out = [];
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
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();
|
|
6
|
+
|
|
1
7
|
// src/files/protected-access.ts
|
|
2
8
|
import picomatch from "picomatch";
|
|
3
9
|
|
|
@@ -3292,12 +3298,29 @@ function resolveCheckMap(settings) {
|
|
|
3292
3298
|
// src/rules/index.ts
|
|
3293
3299
|
import pm from "picomatch";
|
|
3294
3300
|
|
|
3295
|
-
// src/shell/
|
|
3296
|
-
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
|
+
}
|
|
3297
3322
|
|
|
3298
3323
|
// src/shell/plain-tree.ts
|
|
3299
|
-
import mvdanSh from "mvdan-sh";
|
|
3300
|
-
var { syntax } = mvdanSh;
|
|
3301
3324
|
var KINDS = {
|
|
3302
3325
|
File: { nodes: ["Stmts"] },
|
|
3303
3326
|
Stmt: { nodes: ["Cmd", "Redirs"], scalars: ["Negated", "Background", "Coprocess"] },
|
|
@@ -3356,7 +3379,7 @@ function isGoNode(v) {
|
|
|
3356
3379
|
return v !== null && typeof v === "object" && typeof v.Pos === "function";
|
|
3357
3380
|
}
|
|
3358
3381
|
function toPlainTree(goNode) {
|
|
3359
|
-
const kind =
|
|
3382
|
+
const kind = getSyntax().NodeType(goNode);
|
|
3360
3383
|
const out = { kind, pos: goNode.Pos().Offset(), end: goNode.End().Offset() };
|
|
3361
3384
|
const spec = KINDS[kind];
|
|
3362
3385
|
if (!spec) {
|
|
@@ -3837,12 +3860,12 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
3837
3860
|
category
|
|
3838
3861
|
};
|
|
3839
3862
|
}
|
|
3840
|
-
const
|
|
3841
|
-
if (
|
|
3863
|
+
const path2 = protectedLiteral(text, isProtected);
|
|
3864
|
+
if (path2) {
|
|
3842
3865
|
return {
|
|
3843
3866
|
outcome: "dangerous",
|
|
3844
3867
|
what: WHAT["reads-protected"],
|
|
3845
|
-
evidence:
|
|
3868
|
+
evidence: path2.slice(0, 60),
|
|
3846
3869
|
category: "reads-protected"
|
|
3847
3870
|
};
|
|
3848
3871
|
}
|
|
@@ -3854,8 +3877,7 @@ function judgeInlineCode(language, code, isProtected) {
|
|
|
3854
3877
|
}
|
|
3855
3878
|
|
|
3856
3879
|
// src/shell/index.ts
|
|
3857
|
-
var
|
|
3858
|
-
var sharedParser = syntax2.NewParser();
|
|
3880
|
+
var sharedParser = lazy(() => getSyntax().NewParser());
|
|
3859
3881
|
var MESSAGE_FLAGS = /* @__PURE__ */ new Set([
|
|
3860
3882
|
"-m",
|
|
3861
3883
|
"--message",
|
|
@@ -3918,7 +3940,7 @@ function parseShared(command) {
|
|
|
3918
3940
|
}
|
|
3919
3941
|
let parsed;
|
|
3920
3942
|
try {
|
|
3921
|
-
parsed = toPlainTree(sharedParser.Parse(command, "cmd"));
|
|
3943
|
+
parsed = toPlainTree(sharedParser().Parse(command, "cmd"));
|
|
3922
3944
|
} catch {
|
|
3923
3945
|
parsed = PARSE_FAIL;
|
|
3924
3946
|
}
|
|
@@ -5195,7 +5217,7 @@ function redirStdinOps() {
|
|
|
5195
5217
|
}
|
|
5196
5218
|
function deriveBinaryOp(sample) {
|
|
5197
5219
|
try {
|
|
5198
|
-
const f = toPlainTree(sharedParser.Parse(sample, "cmd"));
|
|
5220
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
5199
5221
|
let op = -1;
|
|
5200
5222
|
walk(f, (node) => {
|
|
5201
5223
|
const n = node;
|
|
@@ -5841,22 +5863,27 @@ function recordTopLevelAssignments(f) {
|
|
|
5841
5863
|
}
|
|
5842
5864
|
function probeBinOp(src) {
|
|
5843
5865
|
try {
|
|
5844
|
-
const cmd = toPlainTree(
|
|
5866
|
+
const cmd = toPlainTree(getSyntax().NewParser().Parse(src, "probe"))?.Stmts?.[0]?.Cmd;
|
|
5845
5867
|
if (cmd && cmd.kind === "BinaryCmd") return cmd.Op;
|
|
5846
5868
|
} catch {
|
|
5847
5869
|
}
|
|
5848
5870
|
return null;
|
|
5849
5871
|
}
|
|
5850
|
-
var
|
|
5851
|
-
|
|
5852
|
-
|
|
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
|
+
});
|
|
5853
5880
|
function recordTopLevelStmt(stmt) {
|
|
5854
5881
|
if (!stmt || !stmt.Cmd) return false;
|
|
5855
5882
|
const t = stmt.Cmd.kind;
|
|
5856
5883
|
if (t === "BinaryCmd") {
|
|
5857
|
-
if (!AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
5884
|
+
if (!andOrOps().AND_OR_OPS.has(stmt.Cmd.Op)) return false;
|
|
5858
5885
|
if (!recordTopLevelStmt(stmt.Cmd.X)) return false;
|
|
5859
|
-
if (stmt.Cmd.Op === AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
5886
|
+
if (stmt.Cmd.Op === andOrOps().AND_OP) return recordTopLevelStmt(stmt.Cmd.Y);
|
|
5860
5887
|
return true;
|
|
5861
5888
|
}
|
|
5862
5889
|
if (t !== "CallExpr" && t !== "DeclClause") return false;
|
|
@@ -6314,7 +6341,7 @@ function isWaivableCleanupTarget(p) {
|
|
|
6314
6341
|
}
|
|
6315
6342
|
function deriveRedirOp(sample) {
|
|
6316
6343
|
try {
|
|
6317
|
-
const f = toPlainTree(sharedParser.Parse(sample, "cmd"));
|
|
6344
|
+
const f = toPlainTree(sharedParser().Parse(sample, "cmd"));
|
|
6318
6345
|
let op = -1;
|
|
6319
6346
|
walk(f, (node) => {
|
|
6320
6347
|
const n = node;
|
|
@@ -6326,14 +6353,13 @@ function deriveRedirOp(sample) {
|
|
|
6326
6353
|
return -1;
|
|
6327
6354
|
}
|
|
6328
6355
|
}
|
|
6329
|
-
var REDIR_TRUNCATE_OPS = /* @__PURE__ */ new Set([deriveRedirOp(">_f")]);
|
|
6330
|
-
var REDIR_FILE_IN_OPS =
|
|
6331
|
-
[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")])
|
|
6332
6362
|
);
|
|
6333
|
-
var REDIR_HEREDOC_OPS = /* @__PURE__ */ new Set([
|
|
6334
|
-
deriveRedirOp("cat <<X\nX"),
|
|
6335
|
-
deriveRedirOp("cat <<-X\nX")
|
|
6336
|
-
]);
|
|
6337
6363
|
function collectSameCommandCreations(f) {
|
|
6338
6364
|
const created = /* @__PURE__ */ new Set();
|
|
6339
6365
|
try {
|
|
@@ -6341,9 +6367,9 @@ function collectSameCommandCreations(f) {
|
|
|
6341
6367
|
for (const stmt of stmts) {
|
|
6342
6368
|
if (!stmt || !stmt.Cmd || stmt.Cmd.kind !== "CallExpr") continue;
|
|
6343
6369
|
const redirs = stmt.Redirs || [];
|
|
6344
|
-
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;
|
|
6345
6371
|
for (const r of redirs) {
|
|
6346
|
-
if (r && REDIR_TRUNCATE_OPS.has(r.Op) && r.N == null) {
|
|
6372
|
+
if (r && REDIR_TRUNCATE_OPS().has(r.Op) && r.N == null) {
|
|
6347
6373
|
const w = resolveWordLiteral(r.Word);
|
|
6348
6374
|
if (w) created.add(stripDotSlash(w));
|
|
6349
6375
|
}
|
|
@@ -6943,7 +6969,7 @@ function literalShellPayload(words, name) {
|
|
|
6943
6969
|
function jailedRedirectRead(stmt) {
|
|
6944
6970
|
const redirs = stmt.Redirs || [];
|
|
6945
6971
|
for (const r of redirs) {
|
|
6946
|
-
if (!r || !REDIR_FILE_IN_OPS.has(r.Op)) continue;
|
|
6972
|
+
if (!r || !REDIR_FILE_IN_OPS().has(r.Op)) continue;
|
|
6947
6973
|
const p = resolveWordLiteral(r.Word);
|
|
6948
6974
|
if (p === null || p === "") continue;
|
|
6949
6975
|
const hit = matchSensitivePath(p);
|
|
@@ -7028,9 +7054,9 @@ function ruleServerMatches(rule, serverLabel) {
|
|
|
7028
7054
|
return true;
|
|
7029
7055
|
}
|
|
7030
7056
|
var FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
7031
|
-
function getNestedValue(obj,
|
|
7057
|
+
function getNestedValue(obj, path2) {
|
|
7032
7058
|
if (!obj || typeof obj !== "object") return null;
|
|
7033
|
-
const segments2 =
|
|
7059
|
+
const segments2 = path2.split(".");
|
|
7034
7060
|
for (const seg of segments2) {
|
|
7035
7061
|
if (FORBIDDEN_PATH_SEGMENTS.has(seg)) return null;
|
|
7036
7062
|
}
|
|
@@ -7266,8 +7292,6 @@ function shellRuleArgs(tool, args, ruleTool, inspection = {}) {
|
|
|
7266
7292
|
}
|
|
7267
7293
|
|
|
7268
7294
|
// src/shell/file-access.ts
|
|
7269
|
-
import mvdanSh3 from "mvdan-sh";
|
|
7270
|
-
var { syntax: syntax3 } = mvdanSh3;
|
|
7271
7295
|
var MAX_ALTERNATIVES = 64;
|
|
7272
7296
|
var MAX_CALL_DEPTH2 = 4;
|
|
7273
7297
|
var MAX_CALL_WALKS2 = 256;
|
|
@@ -7284,7 +7308,7 @@ function runnablePrefix(command) {
|
|
|
7284
7308
|
let text = command;
|
|
7285
7309
|
for (let attempt = 0; attempt < 32; attempt++) {
|
|
7286
7310
|
try {
|
|
7287
|
-
return toPlainTree(
|
|
7311
|
+
return toPlainTree(getSyntax().NewParser().Parse(text, ""));
|
|
7288
7312
|
} catch (error) {
|
|
7289
7313
|
const message = String(typeof error?.Error === "function" ? error.Error() : error?.message);
|
|
7290
7314
|
const line = Number(/^(\d+):/.exec(message)?.[1]);
|
|
@@ -7383,18 +7407,22 @@ function merge(a, b) {
|
|
|
7383
7407
|
function opOf(sample) {
|
|
7384
7408
|
return parseShared(sample).Stmts[0].Redirs[0].Op;
|
|
7385
7409
|
}
|
|
7386
|
-
var
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
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
|
+
)
|
|
7396
7424
|
)
|
|
7397
|
-
);
|
|
7425
|
+
}));
|
|
7398
7426
|
function wordValues(word, state) {
|
|
7399
7427
|
const toWords = (values, quoted) => values.map((value) => ({
|
|
7400
7428
|
value,
|
|
@@ -7406,7 +7434,7 @@ function wordValues(word, state) {
|
|
|
7406
7434
|
const name = node.Param?.Value;
|
|
7407
7435
|
const known = name === "PWD" ? state.cwd : state.vars.get(name);
|
|
7408
7436
|
if (node.Exp) {
|
|
7409
|
-
if (!DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7437
|
+
if (!ops().DEFAULT_OPS.has(node.Exp.Op)) return null;
|
|
7410
7438
|
if (known && known.length) return toWords(known, quoted);
|
|
7411
7439
|
const fallback = expand(node.Exp.Word?.Parts ?? [], quoted);
|
|
7412
7440
|
return fallback.dynamic ? null : fallback.out.map(asWord);
|
|
@@ -7931,7 +7959,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7931
7959
|
function stdinText(stmt) {
|
|
7932
7960
|
for (const redir of stmt?.Redirs ?? []) {
|
|
7933
7961
|
if (redir.Hdoc) return resolveWordLiteral(redir.Hdoc);
|
|
7934
|
-
if (redir.Op === HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
7962
|
+
if (redir.Op === ops().HERE_STRING) return resolveWordLiteral(redir.Word);
|
|
7935
7963
|
}
|
|
7936
7964
|
return null;
|
|
7937
7965
|
}
|
|
@@ -7961,10 +7989,10 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7961
7989
|
for (const redir of stmt.Redirs ?? []) {
|
|
7962
7990
|
substitutions(redir.Word, state, depth);
|
|
7963
7991
|
for (const word of wordValues(redir.Word, state)) {
|
|
7964
|
-
if (WRITES.has(redir.Op))
|
|
7965
|
-
add("write", word, state, APPENDS.has(redir.Op) ? { append: true } : {});
|
|
7966
|
-
if (READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
7967
|
-
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))
|
|
7968
7996
|
add("write", word, state);
|
|
7969
7997
|
}
|
|
7970
7998
|
substitutions(redir.Hdoc, state, depth);
|
|
@@ -7996,16 +8024,17 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
7996
8024
|
const seen = clone(state);
|
|
7997
8025
|
let pureAnd = true;
|
|
7998
8026
|
segments2.forEach(({ op, part }, i) => {
|
|
7999
|
-
if (op === AND || op === OR) {
|
|
8000
|
-
if (i > 0 && op === AND && pureAnd && state.onSuccess)
|
|
8001
|
-
|
|
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);
|
|
8002
8031
|
statement(part, state, depth + 1);
|
|
8003
8032
|
} else {
|
|
8004
8033
|
statement(part, clone(state), depth + 1);
|
|
8005
8034
|
if (i > 0 && readsScriptFromStdin(part))
|
|
8006
8035
|
nestedPayload(producedText(segments2[i - 1].part), clone(state), depth);
|
|
8007
8036
|
}
|
|
8008
|
-
if (i > 0 && op !== AND) pureAnd = false;
|
|
8037
|
+
if (i > 0 && op !== ops().AND) pureAnd = false;
|
|
8009
8038
|
merge(seen, state);
|
|
8010
8039
|
});
|
|
8011
8040
|
merge(state, seen);
|
|
@@ -8131,8 +8160,8 @@ function collectFileAccesses(tool, args, context = {}, inspection = {}) {
|
|
|
8131
8160
|
}
|
|
8132
8161
|
return out;
|
|
8133
8162
|
}
|
|
8134
|
-
function within(
|
|
8135
|
-
return
|
|
8163
|
+
function within(path2, root) {
|
|
8164
|
+
return path2 === root || path2.startsWith(root === "/" ? "/" : root + "/");
|
|
8136
8165
|
}
|
|
8137
8166
|
function hits(access, paths, directories, context) {
|
|
8138
8167
|
const home = context.homeDirs?.[0] ?? "~";
|
|
@@ -8261,17 +8290,17 @@ function evaluateProtectedFileAccess(accesses, context, settings) {
|
|
|
8261
8290
|
}
|
|
8262
8291
|
|
|
8263
8292
|
// src/shell/derived-writes.ts
|
|
8264
|
-
var SEQUENCE_OPS = (() => {
|
|
8265
|
-
const
|
|
8293
|
+
var SEQUENCE_OPS = lazy(() => {
|
|
8294
|
+
const ops2 = /* @__PURE__ */ new Set();
|
|
8266
8295
|
for (const text of ["x && y", "x || y"]) {
|
|
8267
8296
|
try {
|
|
8268
8297
|
const f = parseShared(text);
|
|
8269
|
-
if (typeof f !== "symbol")
|
|
8298
|
+
if (typeof f !== "symbol") ops2.add(f.Stmts[0].Cmd.Op);
|
|
8270
8299
|
} catch {
|
|
8271
8300
|
}
|
|
8272
8301
|
}
|
|
8273
|
-
return
|
|
8274
|
-
})
|
|
8302
|
+
return ops2;
|
|
8303
|
+
});
|
|
8275
8304
|
function offsetMapper(text) {
|
|
8276
8305
|
if (!/[^\u0000-\u007f]/.test(text)) return (b) => b;
|
|
8277
8306
|
const starts = [];
|
|
@@ -8299,7 +8328,7 @@ function pipelineTexts(command) {
|
|
|
8299
8328
|
const visit = (stmt, depth) => {
|
|
8300
8329
|
if (!stmt || depth > 64) return;
|
|
8301
8330
|
const cmd = stmt.Cmd;
|
|
8302
|
-
if (cmd && cmd.kind === "BinaryCmd" && SEQUENCE_OPS.has(cmd.Op)) {
|
|
8331
|
+
if (cmd && cmd.kind === "BinaryCmd" && SEQUENCE_OPS().has(cmd.Op)) {
|
|
8303
8332
|
visit(cmd.X, depth + 1);
|
|
8304
8333
|
visit(cmd.Y, depth + 1);
|
|
8305
8334
|
return;
|
|
@@ -12645,13 +12674,13 @@ function writtenTexts(args) {
|
|
|
12645
12674
|
}
|
|
12646
12675
|
|
|
12647
12676
|
// src/shell/write-source.ts
|
|
12648
|
-
var RDR_IN = (() => {
|
|
12677
|
+
var RDR_IN = lazy(() => {
|
|
12649
12678
|
try {
|
|
12650
12679
|
return parseShared("x <y").Stmts[0].Redirs[0].Op;
|
|
12651
12680
|
} catch {
|
|
12652
12681
|
return null;
|
|
12653
12682
|
}
|
|
12654
|
-
})
|
|
12683
|
+
});
|
|
12655
12684
|
var COPY_VERBS2 = /* @__PURE__ */ new Set([
|
|
12656
12685
|
"cp",
|
|
12657
12686
|
"mv",
|
|
@@ -12688,7 +12717,7 @@ function shellWriteUnseen(command, target) {
|
|
|
12688
12717
|
);
|
|
12689
12718
|
const redirs = n.Redirs || [];
|
|
12690
12719
|
const redirectsTo = redirs.some((r) => r.Word && resolveWordLiteral(r.Word) === target);
|
|
12691
|
-
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);
|
|
12692
12721
|
const named = words.includes(target);
|
|
12693
12722
|
if (!redirectsTo && !named) return true;
|
|
12694
12723
|
const head = unwrapCommandHead(words);
|
|
@@ -14875,14 +14904,14 @@ var COMPOSER_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
|
14875
14904
|
"--add-repository"
|
|
14876
14905
|
]);
|
|
14877
14906
|
function composerPackages(words, from, manager, out) {
|
|
14878
|
-
const
|
|
14879
|
-
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;
|
|
14880
14909
|
for (const raw of specs) {
|
|
14881
14910
|
const sep = raw.search(/[:=]/);
|
|
14882
14911
|
const name = sep < 0 ? raw : raw.slice(0, sep);
|
|
14883
14912
|
if (!COMPOSER_NAME_RE.test(name)) continue;
|
|
14884
14913
|
let ver = sep < 0 ? void 0 : raw.slice(sep + 1);
|
|
14885
|
-
if (manager === "composer create-project" && ver === void 0) ver =
|
|
14914
|
+
if (manager === "composer create-project" && ver === void 0) ver = ops2[2] ?? void 0;
|
|
14886
14915
|
push(out, "Packagist", manager, name.toLowerCase(), exactVersion(ver), raw);
|
|
14887
14916
|
}
|
|
14888
14917
|
}
|
|
@@ -16237,9 +16266,9 @@ function bareToolName(toolName) {
|
|
|
16237
16266
|
const parts = toolName.split("__");
|
|
16238
16267
|
return (parts.length >= 3 ? parts.slice(2).join("__") : toolName).toLowerCase();
|
|
16239
16268
|
}
|
|
16240
|
-
function valuesAt(args,
|
|
16269
|
+
function valuesAt(args, path2) {
|
|
16241
16270
|
let cursors = [args];
|
|
16242
|
-
for (const rawSegment of
|
|
16271
|
+
for (const rawSegment of path2.split(".")) {
|
|
16243
16272
|
const isArray = rawSegment.endsWith("[]");
|
|
16244
16273
|
const key = isArray ? rawSegment.slice(0, -2) : rawSegment;
|
|
16245
16274
|
const next = [];
|
|
@@ -16270,8 +16299,8 @@ function extractToolDestinations(toolName, args) {
|
|
|
16270
16299
|
try {
|
|
16271
16300
|
const out = [];
|
|
16272
16301
|
const paths = DESTINATION_ARGS.get(bareToolName(toolName)) ?? [];
|
|
16273
|
-
for (const
|
|
16274
|
-
for (const value of valuesAt(args,
|
|
16302
|
+
for (const path2 of paths) {
|
|
16303
|
+
for (const value of valuesAt(args, path2)) {
|
|
16275
16304
|
const host2 = hostOf(value);
|
|
16276
16305
|
if (host2) out.push({ host: host2, binary: toolName, raw: value });
|
|
16277
16306
|
}
|
|
@@ -16304,8 +16333,8 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
16304
16333
|
try {
|
|
16305
16334
|
const paths = DESTINATION_ARGS.get(bareToolName(toolName));
|
|
16306
16335
|
if (!paths) return null;
|
|
16307
|
-
for (const
|
|
16308
|
-
for (const value of valuesAt(args,
|
|
16336
|
+
for (const path2 of paths) {
|
|
16337
|
+
for (const value of valuesAt(args, path2)) {
|
|
16309
16338
|
const host2 = hostOf(value);
|
|
16310
16339
|
if (!host2) continue;
|
|
16311
16340
|
const m = classifySsrf(host2);
|
|
@@ -16314,7 +16343,7 @@ function ssrfDestinationFloor(toolName, args, opts = {}) {
|
|
|
16314
16343
|
const decision = ssrfFloorDecision(m, written, opts);
|
|
16315
16344
|
if (decision === null) continue;
|
|
16316
16345
|
const reason = decision === "review" ? ssrfDisguisedReason(m, written) : ssrfReason(m, host2);
|
|
16317
|
-
return { ...m, argPath:
|
|
16346
|
+
return { ...m, argPath: path2, host: host2, reason, decision };
|
|
16318
16347
|
}
|
|
16319
16348
|
}
|
|
16320
16349
|
return null;
|
|
@@ -18752,7 +18781,7 @@ function matchCanaryArgs(args, values) {
|
|
|
18752
18781
|
// src/scan/canonical.ts
|
|
18753
18782
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
18754
18783
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v35";
|
|
18755
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
18784
|
+
var CANONICAL_EXTRACTOR_HASH = "8726a60ddd4bad7b";
|
|
18756
18785
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
18757
18786
|
function extractCanonicalFindings(call, ctx) {
|
|
18758
18787
|
const out = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node9/policy-engine",
|
|
3
|
-
"version": "2.47.
|
|
3
|
+
"version": "2.47.2",
|
|
4
4
|
"description": "Shared policy evaluation engine for node9 — DLP, smart rules, AST shell parsing, shields, loop detection. Pure functions, no I/O. Used by both node9-proxy and the node9 SaaS firewall.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://node9.ai",
|