@node9/policy-engine 2.53.0 → 2.54.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 +15 -6
- package/dist/index.d.ts +15 -6
- package/dist/index.js +100 -15
- package/dist/index.mjs +100 -15
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -169,6 +169,12 @@ interface FileAccess {
|
|
|
169
169
|
recursive?: boolean;
|
|
170
170
|
/** A write that adds to the file (`>>`, `tee -a`): its content stays. */
|
|
171
171
|
append?: true;
|
|
172
|
+
/** A shell write whose whole content is literal (a heredoc, `echo`, `printf`
|
|
173
|
+
* redirected to the file): what the file will hold (node9Firewall#385). */
|
|
174
|
+
text?: string;
|
|
175
|
+
/** An in-place edit made only of substitutions (`sed -i 's/a/b/'`): the
|
|
176
|
+
* replacement texts, judged as an edit tool's new text would be. */
|
|
177
|
+
edits?: string[];
|
|
172
178
|
/** This basename-joined candidate applies only if this operand is a directory. */
|
|
173
179
|
directoryTarget?: string;
|
|
174
180
|
candidates?: string[];
|
|
@@ -1356,6 +1362,8 @@ interface LegacyPolicyKnobs {
|
|
|
1356
1362
|
registrySignals?: boolean;
|
|
1357
1363
|
newPackage?: string;
|
|
1358
1364
|
installScript?: string;
|
|
1365
|
+
lookalike?: string;
|
|
1366
|
+
establishedAge?: string;
|
|
1359
1367
|
maxAgeHours?: number;
|
|
1360
1368
|
onlineFallback?: boolean;
|
|
1361
1369
|
allow?: string[];
|
|
@@ -1447,11 +1455,12 @@ declare function levelCheckValue(mode: string | undefined, id: string): Verdict
|
|
|
1447
1455
|
/** Every check a level changes, with its value. */
|
|
1448
1456
|
declare function levelChecks(mode: string | undefined): Readonly<Record<string, Verdict>>;
|
|
1449
1457
|
/** The package registry signals (`loading.malicious-package` tuning), which
|
|
1450
|
-
* allow only review or off
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1458
|
+
* allow only review or off, as a level sets them: Soft turns every signal off;
|
|
1459
|
+
* Strict and Block all ask about a young release of an established package
|
|
1460
|
+
* too (`establishedAge`, node9Firewall#385 wave 3); Standard and Audit keep
|
|
1461
|
+
* the defaults. Only the keys returned are written. */
|
|
1462
|
+
declare function levelPackageSignals(mode: string | undefined): Partial<Record<PackageSignal, 'review' | 'off'>> | undefined;
|
|
1463
|
+
type PackageSignal = 'newPackage' | 'installScript' | 'lookalike' | 'establishedAge';
|
|
1455
1464
|
|
|
1456
1465
|
interface PipeChainAnalysis {
|
|
1457
1466
|
isPipeline: boolean;
|
|
@@ -2446,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
|
2446
2455
|
* files changed, this hash must change too, and you must consciously
|
|
2447
2456
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2448
2457
|
*/
|
|
2449
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2458
|
+
declare const CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
|
|
2450
2459
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2451
2460
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2452
2461
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -169,6 +169,12 @@ interface FileAccess {
|
|
|
169
169
|
recursive?: boolean;
|
|
170
170
|
/** A write that adds to the file (`>>`, `tee -a`): its content stays. */
|
|
171
171
|
append?: true;
|
|
172
|
+
/** A shell write whose whole content is literal (a heredoc, `echo`, `printf`
|
|
173
|
+
* redirected to the file): what the file will hold (node9Firewall#385). */
|
|
174
|
+
text?: string;
|
|
175
|
+
/** An in-place edit made only of substitutions (`sed -i 's/a/b/'`): the
|
|
176
|
+
* replacement texts, judged as an edit tool's new text would be. */
|
|
177
|
+
edits?: string[];
|
|
172
178
|
/** This basename-joined candidate applies only if this operand is a directory. */
|
|
173
179
|
directoryTarget?: string;
|
|
174
180
|
candidates?: string[];
|
|
@@ -1356,6 +1362,8 @@ interface LegacyPolicyKnobs {
|
|
|
1356
1362
|
registrySignals?: boolean;
|
|
1357
1363
|
newPackage?: string;
|
|
1358
1364
|
installScript?: string;
|
|
1365
|
+
lookalike?: string;
|
|
1366
|
+
establishedAge?: string;
|
|
1359
1367
|
maxAgeHours?: number;
|
|
1360
1368
|
onlineFallback?: boolean;
|
|
1361
1369
|
allow?: string[];
|
|
@@ -1447,11 +1455,12 @@ declare function levelCheckValue(mode: string | undefined, id: string): Verdict
|
|
|
1447
1455
|
/** Every check a level changes, with its value. */
|
|
1448
1456
|
declare function levelChecks(mode: string | undefined): Readonly<Record<string, Verdict>>;
|
|
1449
1457
|
/** The package registry signals (`loading.malicious-package` tuning), which
|
|
1450
|
-
* allow only review or off
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1458
|
+
* allow only review or off, as a level sets them: Soft turns every signal off;
|
|
1459
|
+
* Strict and Block all ask about a young release of an established package
|
|
1460
|
+
* too (`establishedAge`, node9Firewall#385 wave 3); Standard and Audit keep
|
|
1461
|
+
* the defaults. Only the keys returned are written. */
|
|
1462
|
+
declare function levelPackageSignals(mode: string | undefined): Partial<Record<PackageSignal, 'review' | 'off'>> | undefined;
|
|
1463
|
+
type PackageSignal = 'newPackage' | 'installScript' | 'lookalike' | 'establishedAge';
|
|
1455
1464
|
|
|
1456
1465
|
interface PipeChainAnalysis {
|
|
1457
1466
|
isPipeline: boolean;
|
|
@@ -2446,7 +2455,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
|
2446
2455
|
* files changed, this hash must change too, and you must consciously
|
|
2447
2456
|
* decide whether to bump CANONICAL_EXTRACTOR_VERSION."
|
|
2448
2457
|
*/
|
|
2449
|
-
declare const CANONICAL_EXTRACTOR_HASH = "
|
|
2458
|
+
declare const CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
|
|
2450
2459
|
declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
|
|
2451
2460
|
declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
|
|
2452
2461
|
/**
|
package/dist/index.js
CHANGED
|
@@ -2711,7 +2711,7 @@ var CHECK_TEXT = {
|
|
|
2711
2711
|
advice: "Fixed at Block. A person accepts the change on the machine (node9 mcp pin update)."
|
|
2712
2712
|
},
|
|
2713
2713
|
"loading.malicious-package": {
|
|
2714
|
-
plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only. A new release built from the same repository as the one before it (registry provenance) and an install script the package has always run do not stop; a release that lost the provenance its previous release had does.",
|
|
2714
|
+
plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only. A new release built from the same repository as the one before it (registry provenance) and an install script the package has always run do not stop; a release that lost the provenance its previous release had does. A name that looks like a popular package and has no standing of its own, a name no package on npm or PyPI has, or a package npm removed as malicious also stops for review (the lookalike tuning). A fresh release of a package over a year old that released within the last six months is its normal cadence: Standard lets it through, Strict asks (the establishedAge tuning).",
|
|
2715
2715
|
example: "npm install of a package flagged as malware",
|
|
2716
2716
|
advice: "Keep Block for known-malicious packages; brand-new packages already stop for Review."
|
|
2717
2717
|
},
|
|
@@ -2815,7 +2815,12 @@ function levelChecks(mode) {
|
|
|
2815
2815
|
return LEVEL_CHECKS[levelOf(mode)];
|
|
2816
2816
|
}
|
|
2817
2817
|
function levelPackageSignals(mode) {
|
|
2818
|
-
|
|
2818
|
+
const level = levelOf(mode);
|
|
2819
|
+
if (level === "soft") {
|
|
2820
|
+
return { newPackage: "off", installScript: "off", lookalike: "off", establishedAge: "off" };
|
|
2821
|
+
}
|
|
2822
|
+
if (level === "strict" || level === "block-all") return { establishedAge: "review" };
|
|
2823
|
+
return void 0;
|
|
2819
2824
|
}
|
|
2820
2825
|
|
|
2821
2826
|
// src/owasp.ts
|
|
@@ -4277,12 +4282,46 @@ function wordValues(word, state) {
|
|
|
4277
4282
|
if (!dynamic) return out.map(asWord);
|
|
4278
4283
|
return out.filter((piece) => piece.value !== "").map((piece) => ({ value: piece.value, pattern: piece.pattern + "*", dynamic: true }));
|
|
4279
4284
|
}
|
|
4285
|
+
function sedSubstitutions(script) {
|
|
4286
|
+
const out = [];
|
|
4287
|
+
for (const raw of script.split(/\r?\n|;/)) {
|
|
4288
|
+
const cmd = raw.trim();
|
|
4289
|
+
if (cmd === "") continue;
|
|
4290
|
+
const m = /^(?:(?:\d+|\$|\/(?:\\.|[^\\/])*\/)(?:,(?:\d+|\$|\/(?:\\.|[^\\/])*\/))?)?s(.)/.exec(
|
|
4291
|
+
cmd
|
|
4292
|
+
);
|
|
4293
|
+
if (!m) return null;
|
|
4294
|
+
const delimiter = m[1];
|
|
4295
|
+
if (delimiter === "\\") return null;
|
|
4296
|
+
const parts = [];
|
|
4297
|
+
let cur = "";
|
|
4298
|
+
let i = m[0].length;
|
|
4299
|
+
for (; i < cmd.length && parts.length < 2; i++) {
|
|
4300
|
+
const ch = cmd[i];
|
|
4301
|
+
if (ch === "\\" && i + 1 < cmd.length) {
|
|
4302
|
+
cur += ch + cmd[++i];
|
|
4303
|
+
continue;
|
|
4304
|
+
}
|
|
4305
|
+
if (ch === delimiter) {
|
|
4306
|
+
parts.push(cur);
|
|
4307
|
+
cur = "";
|
|
4308
|
+
continue;
|
|
4309
|
+
}
|
|
4310
|
+
cur += ch;
|
|
4311
|
+
}
|
|
4312
|
+
if (parts.length < 2) return null;
|
|
4313
|
+
if (!/^[gpiImM0-9]*$/.test(cmd.slice(i))) return null;
|
|
4314
|
+
out.push(parts[1].replace(/\\(.)/g, "$1"));
|
|
4315
|
+
}
|
|
4316
|
+
return out.length > 0 ? out : null;
|
|
4317
|
+
}
|
|
4280
4318
|
function collectShellFileAccesses(command, context = {}) {
|
|
4281
4319
|
const out = [];
|
|
4282
4320
|
let payloads = 256;
|
|
4283
4321
|
const functions = /* @__PURE__ */ new Map();
|
|
4284
4322
|
const seenCalls = /* @__PURE__ */ new Set();
|
|
4285
4323
|
const pipedStdin = /* @__PURE__ */ new WeakMap();
|
|
4324
|
+
let currentStdin = null;
|
|
4286
4325
|
let callWalks2 = MAX_CALL_WALKS;
|
|
4287
4326
|
const initial = {
|
|
4288
4327
|
cwd: [context.cwd ?? ""],
|
|
@@ -4377,8 +4416,9 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4377
4416
|
}
|
|
4378
4417
|
const locate = (p) => tokens.find((w) => w?.value === p) ?? { value: p };
|
|
4379
4418
|
if (name === "sed") {
|
|
4380
|
-
let inplace = false, hasScript = false, ended = false;
|
|
4419
|
+
let inplace = false, hasScript = false, ended = false, scriptUnknown = false;
|
|
4381
4420
|
const files = [];
|
|
4421
|
+
const scriptParts = [];
|
|
4382
4422
|
for (let i = 0; i < args.length; i++) {
|
|
4383
4423
|
const token = args[i];
|
|
4384
4424
|
if (!token) {
|
|
@@ -4396,7 +4436,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4396
4436
|
hasScript = true;
|
|
4397
4437
|
const eq = value.indexOf("=");
|
|
4398
4438
|
const script = eq < 0 ? args[++i] : { value: value.slice(eq + 1) };
|
|
4399
|
-
if (value.startsWith("--file")
|
|
4439
|
+
if (value.startsWith("--file")) {
|
|
4440
|
+
scriptUnknown = true;
|
|
4441
|
+
if (script) add("read", script, state);
|
|
4442
|
+
} else if (script?.value) scriptParts.push(script.value);
|
|
4443
|
+
else scriptUnknown = true;
|
|
4400
4444
|
}
|
|
4401
4445
|
continue;
|
|
4402
4446
|
}
|
|
@@ -4411,7 +4455,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4411
4455
|
if (flag === "e" || flag === "f") {
|
|
4412
4456
|
hasScript = true;
|
|
4413
4457
|
const script = value.slice(j + 1) ? { value: value.slice(j + 1) } : args[++i];
|
|
4414
|
-
if (flag === "f"
|
|
4458
|
+
if (flag === "f") {
|
|
4459
|
+
scriptUnknown = true;
|
|
4460
|
+
if (script) add("read", script, state);
|
|
4461
|
+
} else if (script?.value) scriptParts.push(script.value);
|
|
4462
|
+
else scriptUnknown = true;
|
|
4415
4463
|
break;
|
|
4416
4464
|
}
|
|
4417
4465
|
if (flag === "l") {
|
|
@@ -4421,10 +4469,14 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4421
4469
|
}
|
|
4422
4470
|
continue;
|
|
4423
4471
|
}
|
|
4424
|
-
if (!hasScript)
|
|
4425
|
-
|
|
4472
|
+
if (!hasScript) {
|
|
4473
|
+
hasScript = true;
|
|
4474
|
+
scriptParts.push(value);
|
|
4475
|
+
} else files.push(token);
|
|
4426
4476
|
}
|
|
4427
|
-
|
|
4477
|
+
const edits = inplace && !scriptUnknown ? sedSubstitutions(scriptParts.join("\n")) : null;
|
|
4478
|
+
for (const file of files)
|
|
4479
|
+
add(inplace ? "write" : "read", file, state, edits ? { edits } : {});
|
|
4428
4480
|
return;
|
|
4429
4481
|
}
|
|
4430
4482
|
if (FS_READ_TOOLS.has(name) && name !== "dd") {
|
|
@@ -4551,9 +4603,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4551
4603
|
continue;
|
|
4552
4604
|
const remove = name === "rm" || name === "unlink";
|
|
4553
4605
|
const append = name === "tee" && strings.some((s) => s === "--append" || /^-[^-]*a/.test(s));
|
|
4606
|
+
const teed = name === "tee" && !append ? currentStdin : null;
|
|
4554
4607
|
add(remove ? "remove" : name === "touch" ? "create" : "write", token, state, {
|
|
4555
4608
|
recursive: remove && strings.some((s) => /^-[^-]*[rR]/.test(s) || s === "--recursive"),
|
|
4556
|
-
...append ? { append: true } : {}
|
|
4609
|
+
...append ? { append: true } : {},
|
|
4610
|
+
...teed !== null ? { text: teed } : {}
|
|
4557
4611
|
});
|
|
4558
4612
|
}
|
|
4559
4613
|
return;
|
|
@@ -4875,11 +4929,18 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4875
4929
|
if (stmt.Background) state = clone(state);
|
|
4876
4930
|
const headWord = stmt.Cmd && stmt.Cmd.kind === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
|
|
4877
4931
|
const sends = SENDING_STDIN.has(headWord);
|
|
4932
|
+
let produced;
|
|
4878
4933
|
for (const redir of stmt.Redirs ?? []) {
|
|
4879
4934
|
substitutions(redir.Word, state, depth);
|
|
4880
4935
|
for (const word of wordValues(redir.Word, state)) {
|
|
4881
|
-
if (ops().WRITES.has(redir.Op))
|
|
4882
|
-
|
|
4936
|
+
if (ops().WRITES.has(redir.Op)) {
|
|
4937
|
+
if (ops().APPENDS.has(redir.Op)) add("write", word, state, { append: true });
|
|
4938
|
+
else {
|
|
4939
|
+
const stdout = redir.N == null || redir.N.Value === "1";
|
|
4940
|
+
if (stdout && produced === void 0) produced = producedText(stmt);
|
|
4941
|
+
add("write", word, state, stdout && produced ? { text: produced } : {});
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4883
4944
|
if (ops().READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
4884
4945
|
if (redir.Op === ops().DUP_OUT && word.value && !/^\d+$/.test(word.value))
|
|
4885
4946
|
add("write", word, state);
|
|
@@ -4891,6 +4952,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4891
4952
|
stdinScript(stmt, state, depth);
|
|
4892
4953
|
const fedText = stdinText(stmt);
|
|
4893
4954
|
if (fedText !== null) nestedPayload(xargsPayload(stmt, fedText), clone(state), depth);
|
|
4955
|
+
currentStdin = fedText;
|
|
4894
4956
|
switch (cmd.kind) {
|
|
4895
4957
|
case "CallExpr":
|
|
4896
4958
|
call(cmd, state, depth);
|
|
@@ -15154,8 +15216,16 @@ function evaluateGitHooksFileAccess(args, accesses, context, settings, shell) {
|
|
|
15154
15216
|
disarms = true;
|
|
15155
15217
|
how = "removed";
|
|
15156
15218
|
} else if (texts === null) {
|
|
15157
|
-
|
|
15158
|
-
|
|
15219
|
+
if (access.edits) {
|
|
15220
|
+
disarms = access.edits.some(editDisarms);
|
|
15221
|
+
how = "edited to exit";
|
|
15222
|
+
} else if (access.text !== void 0) {
|
|
15223
|
+
disarms = hookTextRunsNothing(access.text);
|
|
15224
|
+
how = "emptied";
|
|
15225
|
+
} else {
|
|
15226
|
+
disarms = true;
|
|
15227
|
+
how = "overwritten";
|
|
15228
|
+
}
|
|
15159
15229
|
} else if (texts.whole.length > 0) {
|
|
15160
15230
|
disarms = texts.whole.some(hookTextRunsNothing);
|
|
15161
15231
|
how = "emptied";
|
|
@@ -17162,6 +17232,16 @@ var TUNING_FIELDS = [
|
|
|
17162
17232
|
name: "installScript",
|
|
17163
17233
|
legacy: ["packageCheck", "installScript"]
|
|
17164
17234
|
},
|
|
17235
|
+
{
|
|
17236
|
+
checkId: "loading.malicious-package",
|
|
17237
|
+
name: "lookalike",
|
|
17238
|
+
legacy: ["packageCheck", "lookalike"]
|
|
17239
|
+
},
|
|
17240
|
+
{
|
|
17241
|
+
checkId: "loading.malicious-package",
|
|
17242
|
+
name: "establishedAge",
|
|
17243
|
+
legacy: ["packageCheck", "establishedAge"]
|
|
17244
|
+
},
|
|
17165
17245
|
{
|
|
17166
17246
|
checkId: "loading.malicious-package",
|
|
17167
17247
|
name: "onlineFallback",
|
|
@@ -17191,7 +17271,11 @@ function tuningFromLegacyPolicy(policy) {
|
|
|
17191
17271
|
const out = {};
|
|
17192
17272
|
const p = policy;
|
|
17193
17273
|
if (policy.packageCheck?.registrySignals === false) {
|
|
17194
|
-
out["loading.malicious-package"] = {
|
|
17274
|
+
out["loading.malicious-package"] = {
|
|
17275
|
+
newPackage: "off",
|
|
17276
|
+
installScript: "off",
|
|
17277
|
+
lookalike: "off"
|
|
17278
|
+
};
|
|
17195
17279
|
}
|
|
17196
17280
|
for (const f of TUNING_FIELDS) {
|
|
17197
17281
|
const [block, key] = f.legacy;
|
|
@@ -17210,6 +17294,7 @@ function tuningToLegacyPolicy(policy, tuning) {
|
|
|
17210
17294
|
if (normalized.registrySignals === false) {
|
|
17211
17295
|
normalized.newPackage ??= "off";
|
|
17212
17296
|
normalized.installScript ??= "off";
|
|
17297
|
+
normalized.lookalike ??= "off";
|
|
17213
17298
|
}
|
|
17214
17299
|
delete normalized.registrySignals;
|
|
17215
17300
|
}
|
|
@@ -20608,7 +20693,7 @@ function matchCanaryArgs(args, values) {
|
|
|
20608
20693
|
// src/scan/canonical.ts
|
|
20609
20694
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20610
20695
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
20611
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20696
|
+
var CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
|
|
20612
20697
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20613
20698
|
function extractCanonicalFindings(call, ctx) {
|
|
20614
20699
|
const out = [];
|
package/dist/index.mjs
CHANGED
|
@@ -2448,7 +2448,7 @@ var CHECK_TEXT = {
|
|
|
2448
2448
|
advice: "Fixed at Block. A person accepts the change on the machine (node9 mcp pin update)."
|
|
2449
2449
|
},
|
|
2450
2450
|
"loading.malicious-package": {
|
|
2451
|
-
plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only. A new release built from the same repository as the one before it (registry provenance) and an install script the package has always run do not stop; a release that lost the provenance its previous release had does.",
|
|
2451
|
+
plain: "The agent installs a package that the public malicious-package database (OSV) lists, or one published minutes ago. Covers npm, PyPI, RubyGems, crates.io, Go, NuGet, Maven, Packagist and VS Code extensions; the publish-age and install-script signals are npm and PyPI only. A new release built from the same repository as the one before it (registry provenance) and an install script the package has always run do not stop; a release that lost the provenance its previous release had does. A name that looks like a popular package and has no standing of its own, a name no package on npm or PyPI has, or a package npm removed as malicious also stops for review (the lookalike tuning). A fresh release of a package over a year old that released within the last six months is its normal cadence: Standard lets it through, Strict asks (the establishedAge tuning).",
|
|
2452
2452
|
example: "npm install of a package flagged as malware",
|
|
2453
2453
|
advice: "Keep Block for known-malicious packages; brand-new packages already stop for Review."
|
|
2454
2454
|
},
|
|
@@ -2552,7 +2552,12 @@ function levelChecks(mode) {
|
|
|
2552
2552
|
return LEVEL_CHECKS[levelOf(mode)];
|
|
2553
2553
|
}
|
|
2554
2554
|
function levelPackageSignals(mode) {
|
|
2555
|
-
|
|
2555
|
+
const level = levelOf(mode);
|
|
2556
|
+
if (level === "soft") {
|
|
2557
|
+
return { newPackage: "off", installScript: "off", lookalike: "off", establishedAge: "off" };
|
|
2558
|
+
}
|
|
2559
|
+
if (level === "strict" || level === "block-all") return { establishedAge: "review" };
|
|
2560
|
+
return void 0;
|
|
2556
2561
|
}
|
|
2557
2562
|
|
|
2558
2563
|
// src/owasp.ts
|
|
@@ -4014,12 +4019,46 @@ function wordValues(word, state) {
|
|
|
4014
4019
|
if (!dynamic) return out.map(asWord);
|
|
4015
4020
|
return out.filter((piece) => piece.value !== "").map((piece) => ({ value: piece.value, pattern: piece.pattern + "*", dynamic: true }));
|
|
4016
4021
|
}
|
|
4022
|
+
function sedSubstitutions(script) {
|
|
4023
|
+
const out = [];
|
|
4024
|
+
for (const raw of script.split(/\r?\n|;/)) {
|
|
4025
|
+
const cmd = raw.trim();
|
|
4026
|
+
if (cmd === "") continue;
|
|
4027
|
+
const m = /^(?:(?:\d+|\$|\/(?:\\.|[^\\/])*\/)(?:,(?:\d+|\$|\/(?:\\.|[^\\/])*\/))?)?s(.)/.exec(
|
|
4028
|
+
cmd
|
|
4029
|
+
);
|
|
4030
|
+
if (!m) return null;
|
|
4031
|
+
const delimiter = m[1];
|
|
4032
|
+
if (delimiter === "\\") return null;
|
|
4033
|
+
const parts = [];
|
|
4034
|
+
let cur = "";
|
|
4035
|
+
let i = m[0].length;
|
|
4036
|
+
for (; i < cmd.length && parts.length < 2; i++) {
|
|
4037
|
+
const ch = cmd[i];
|
|
4038
|
+
if (ch === "\\" && i + 1 < cmd.length) {
|
|
4039
|
+
cur += ch + cmd[++i];
|
|
4040
|
+
continue;
|
|
4041
|
+
}
|
|
4042
|
+
if (ch === delimiter) {
|
|
4043
|
+
parts.push(cur);
|
|
4044
|
+
cur = "";
|
|
4045
|
+
continue;
|
|
4046
|
+
}
|
|
4047
|
+
cur += ch;
|
|
4048
|
+
}
|
|
4049
|
+
if (parts.length < 2) return null;
|
|
4050
|
+
if (!/^[gpiImM0-9]*$/.test(cmd.slice(i))) return null;
|
|
4051
|
+
out.push(parts[1].replace(/\\(.)/g, "$1"));
|
|
4052
|
+
}
|
|
4053
|
+
return out.length > 0 ? out : null;
|
|
4054
|
+
}
|
|
4017
4055
|
function collectShellFileAccesses(command, context = {}) {
|
|
4018
4056
|
const out = [];
|
|
4019
4057
|
let payloads = 256;
|
|
4020
4058
|
const functions = /* @__PURE__ */ new Map();
|
|
4021
4059
|
const seenCalls = /* @__PURE__ */ new Set();
|
|
4022
4060
|
const pipedStdin = /* @__PURE__ */ new WeakMap();
|
|
4061
|
+
let currentStdin = null;
|
|
4023
4062
|
let callWalks2 = MAX_CALL_WALKS;
|
|
4024
4063
|
const initial = {
|
|
4025
4064
|
cwd: [context.cwd ?? ""],
|
|
@@ -4114,8 +4153,9 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4114
4153
|
}
|
|
4115
4154
|
const locate = (p) => tokens.find((w) => w?.value === p) ?? { value: p };
|
|
4116
4155
|
if (name === "sed") {
|
|
4117
|
-
let inplace = false, hasScript = false, ended = false;
|
|
4156
|
+
let inplace = false, hasScript = false, ended = false, scriptUnknown = false;
|
|
4118
4157
|
const files = [];
|
|
4158
|
+
const scriptParts = [];
|
|
4119
4159
|
for (let i = 0; i < args.length; i++) {
|
|
4120
4160
|
const token = args[i];
|
|
4121
4161
|
if (!token) {
|
|
@@ -4133,7 +4173,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4133
4173
|
hasScript = true;
|
|
4134
4174
|
const eq = value.indexOf("=");
|
|
4135
4175
|
const script = eq < 0 ? args[++i] : { value: value.slice(eq + 1) };
|
|
4136
|
-
if (value.startsWith("--file")
|
|
4176
|
+
if (value.startsWith("--file")) {
|
|
4177
|
+
scriptUnknown = true;
|
|
4178
|
+
if (script) add("read", script, state);
|
|
4179
|
+
} else if (script?.value) scriptParts.push(script.value);
|
|
4180
|
+
else scriptUnknown = true;
|
|
4137
4181
|
}
|
|
4138
4182
|
continue;
|
|
4139
4183
|
}
|
|
@@ -4148,7 +4192,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4148
4192
|
if (flag === "e" || flag === "f") {
|
|
4149
4193
|
hasScript = true;
|
|
4150
4194
|
const script = value.slice(j + 1) ? { value: value.slice(j + 1) } : args[++i];
|
|
4151
|
-
if (flag === "f"
|
|
4195
|
+
if (flag === "f") {
|
|
4196
|
+
scriptUnknown = true;
|
|
4197
|
+
if (script) add("read", script, state);
|
|
4198
|
+
} else if (script?.value) scriptParts.push(script.value);
|
|
4199
|
+
else scriptUnknown = true;
|
|
4152
4200
|
break;
|
|
4153
4201
|
}
|
|
4154
4202
|
if (flag === "l") {
|
|
@@ -4158,10 +4206,14 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4158
4206
|
}
|
|
4159
4207
|
continue;
|
|
4160
4208
|
}
|
|
4161
|
-
if (!hasScript)
|
|
4162
|
-
|
|
4209
|
+
if (!hasScript) {
|
|
4210
|
+
hasScript = true;
|
|
4211
|
+
scriptParts.push(value);
|
|
4212
|
+
} else files.push(token);
|
|
4163
4213
|
}
|
|
4164
|
-
|
|
4214
|
+
const edits = inplace && !scriptUnknown ? sedSubstitutions(scriptParts.join("\n")) : null;
|
|
4215
|
+
for (const file of files)
|
|
4216
|
+
add(inplace ? "write" : "read", file, state, edits ? { edits } : {});
|
|
4165
4217
|
return;
|
|
4166
4218
|
}
|
|
4167
4219
|
if (FS_READ_TOOLS.has(name) && name !== "dd") {
|
|
@@ -4288,9 +4340,11 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4288
4340
|
continue;
|
|
4289
4341
|
const remove = name === "rm" || name === "unlink";
|
|
4290
4342
|
const append = name === "tee" && strings.some((s) => s === "--append" || /^-[^-]*a/.test(s));
|
|
4343
|
+
const teed = name === "tee" && !append ? currentStdin : null;
|
|
4291
4344
|
add(remove ? "remove" : name === "touch" ? "create" : "write", token, state, {
|
|
4292
4345
|
recursive: remove && strings.some((s) => /^-[^-]*[rR]/.test(s) || s === "--recursive"),
|
|
4293
|
-
...append ? { append: true } : {}
|
|
4346
|
+
...append ? { append: true } : {},
|
|
4347
|
+
...teed !== null ? { text: teed } : {}
|
|
4294
4348
|
});
|
|
4295
4349
|
}
|
|
4296
4350
|
return;
|
|
@@ -4612,11 +4666,18 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4612
4666
|
if (stmt.Background) state = clone(state);
|
|
4613
4667
|
const headWord = stmt.Cmd && stmt.Cmd.kind === "CallExpr" ? base(resolveWordLiteral(stmt.Cmd.Args?.[0])) : "";
|
|
4614
4668
|
const sends = SENDING_STDIN.has(headWord);
|
|
4669
|
+
let produced;
|
|
4615
4670
|
for (const redir of stmt.Redirs ?? []) {
|
|
4616
4671
|
substitutions(redir.Word, state, depth);
|
|
4617
4672
|
for (const word of wordValues(redir.Word, state)) {
|
|
4618
|
-
if (ops().WRITES.has(redir.Op))
|
|
4619
|
-
|
|
4673
|
+
if (ops().WRITES.has(redir.Op)) {
|
|
4674
|
+
if (ops().APPENDS.has(redir.Op)) add("write", word, state, { append: true });
|
|
4675
|
+
else {
|
|
4676
|
+
const stdout = redir.N == null || redir.N.Value === "1";
|
|
4677
|
+
if (stdout && produced === void 0) produced = producedText(stmt);
|
|
4678
|
+
add("write", word, state, stdout && produced ? { text: produced } : {});
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4620
4681
|
if (ops().READS.has(redir.Op)) add("read", word, state, sends ? { upload: true } : {});
|
|
4621
4682
|
if (redir.Op === ops().DUP_OUT && word.value && !/^\d+$/.test(word.value))
|
|
4622
4683
|
add("write", word, state);
|
|
@@ -4628,6 +4689,7 @@ function collectShellFileAccesses(command, context = {}) {
|
|
|
4628
4689
|
stdinScript(stmt, state, depth);
|
|
4629
4690
|
const fedText = stdinText(stmt);
|
|
4630
4691
|
if (fedText !== null) nestedPayload(xargsPayload(stmt, fedText), clone(state), depth);
|
|
4692
|
+
currentStdin = fedText;
|
|
4631
4693
|
switch (cmd.kind) {
|
|
4632
4694
|
case "CallExpr":
|
|
4633
4695
|
call(cmd, state, depth);
|
|
@@ -14891,8 +14953,16 @@ function evaluateGitHooksFileAccess(args, accesses, context, settings, shell) {
|
|
|
14891
14953
|
disarms = true;
|
|
14892
14954
|
how = "removed";
|
|
14893
14955
|
} else if (texts === null) {
|
|
14894
|
-
|
|
14895
|
-
|
|
14956
|
+
if (access.edits) {
|
|
14957
|
+
disarms = access.edits.some(editDisarms);
|
|
14958
|
+
how = "edited to exit";
|
|
14959
|
+
} else if (access.text !== void 0) {
|
|
14960
|
+
disarms = hookTextRunsNothing(access.text);
|
|
14961
|
+
how = "emptied";
|
|
14962
|
+
} else {
|
|
14963
|
+
disarms = true;
|
|
14964
|
+
how = "overwritten";
|
|
14965
|
+
}
|
|
14896
14966
|
} else if (texts.whole.length > 0) {
|
|
14897
14967
|
disarms = texts.whole.some(hookTextRunsNothing);
|
|
14898
14968
|
how = "emptied";
|
|
@@ -16899,6 +16969,16 @@ var TUNING_FIELDS = [
|
|
|
16899
16969
|
name: "installScript",
|
|
16900
16970
|
legacy: ["packageCheck", "installScript"]
|
|
16901
16971
|
},
|
|
16972
|
+
{
|
|
16973
|
+
checkId: "loading.malicious-package",
|
|
16974
|
+
name: "lookalike",
|
|
16975
|
+
legacy: ["packageCheck", "lookalike"]
|
|
16976
|
+
},
|
|
16977
|
+
{
|
|
16978
|
+
checkId: "loading.malicious-package",
|
|
16979
|
+
name: "establishedAge",
|
|
16980
|
+
legacy: ["packageCheck", "establishedAge"]
|
|
16981
|
+
},
|
|
16902
16982
|
{
|
|
16903
16983
|
checkId: "loading.malicious-package",
|
|
16904
16984
|
name: "onlineFallback",
|
|
@@ -16928,7 +17008,11 @@ function tuningFromLegacyPolicy(policy) {
|
|
|
16928
17008
|
const out = {};
|
|
16929
17009
|
const p = policy;
|
|
16930
17010
|
if (policy.packageCheck?.registrySignals === false) {
|
|
16931
|
-
out["loading.malicious-package"] = {
|
|
17011
|
+
out["loading.malicious-package"] = {
|
|
17012
|
+
newPackage: "off",
|
|
17013
|
+
installScript: "off",
|
|
17014
|
+
lookalike: "off"
|
|
17015
|
+
};
|
|
16932
17016
|
}
|
|
16933
17017
|
for (const f of TUNING_FIELDS) {
|
|
16934
17018
|
const [block, key] = f.legacy;
|
|
@@ -16947,6 +17031,7 @@ function tuningToLegacyPolicy(policy, tuning) {
|
|
|
16947
17031
|
if (normalized.registrySignals === false) {
|
|
16948
17032
|
normalized.newPackage ??= "off";
|
|
16949
17033
|
normalized.installScript ??= "off";
|
|
17034
|
+
normalized.lookalike ??= "off";
|
|
16950
17035
|
}
|
|
16951
17036
|
delete normalized.registrySignals;
|
|
16952
17037
|
}
|
|
@@ -20345,7 +20430,7 @@ function matchCanaryArgs(args, values) {
|
|
|
20345
20430
|
// src/scan/canonical.ts
|
|
20346
20431
|
var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
|
|
20347
20432
|
var CANONICAL_EXTRACTOR_VERSION = "canonical-v39";
|
|
20348
|
-
var CANONICAL_EXTRACTOR_HASH = "
|
|
20433
|
+
var CANONICAL_EXTRACTOR_HASH = "9b120b2f71641789";
|
|
20349
20434
|
var DEDUPE_PREVIEW_LEN = 120;
|
|
20350
20435
|
function extractCanonicalFindings(call, ctx) {
|
|
20351
20436
|
const out = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node9/policy-engine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.54.1",
|
|
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",
|