@node9/policy-engine 2.27.0 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +60 -4
- package/dist/index.mjs +60 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -447,6 +447,8 @@ interface PackageInstallRequest {
|
|
|
447
447
|
version?: string;
|
|
448
448
|
/** The argument as written. */
|
|
449
449
|
raw: string;
|
|
450
|
+
/** Literal cd steps before this call; null means the execution context is unknown. */
|
|
451
|
+
localCwd?: string[] | null;
|
|
450
452
|
}
|
|
451
453
|
/** PEP 503 normalisation: lowercase, runs of `-_.` collapse to `-`. */
|
|
452
454
|
declare function normalizePyPiName(name: string): string;
|
|
@@ -731,7 +733,10 @@ interface LegacyPolicyKnobs {
|
|
|
731
733
|
packageCheck?: {
|
|
732
734
|
enabled?: boolean;
|
|
733
735
|
onMalicious?: string;
|
|
736
|
+
/** 2.27.0: one boolean for both signals. Read, never written. */
|
|
734
737
|
registrySignals?: boolean;
|
|
738
|
+
newPackage?: string;
|
|
739
|
+
installScript?: string;
|
|
735
740
|
maxAgeHours?: number;
|
|
736
741
|
onlineFallback?: boolean;
|
|
737
742
|
allow?: string[];
|
package/dist/index.d.ts
CHANGED
|
@@ -447,6 +447,8 @@ interface PackageInstallRequest {
|
|
|
447
447
|
version?: string;
|
|
448
448
|
/** The argument as written. */
|
|
449
449
|
raw: string;
|
|
450
|
+
/** Literal cd steps before this call; null means the execution context is unknown. */
|
|
451
|
+
localCwd?: string[] | null;
|
|
450
452
|
}
|
|
451
453
|
/** PEP 503 normalisation: lowercase, runs of `-_.` collapse to `-`. */
|
|
452
454
|
declare function normalizePyPiName(name: string): string;
|
|
@@ -731,7 +733,10 @@ interface LegacyPolicyKnobs {
|
|
|
731
733
|
packageCheck?: {
|
|
732
734
|
enabled?: boolean;
|
|
733
735
|
onMalicious?: string;
|
|
736
|
+
/** 2.27.0: one boolean for both signals. Read, never written. */
|
|
734
737
|
registrySignals?: boolean;
|
|
738
|
+
newPackage?: string;
|
|
739
|
+
installScript?: string;
|
|
735
740
|
maxAgeHours?: number;
|
|
736
741
|
onlineFallback?: boolean;
|
|
737
742
|
allow?: string[];
|
package/dist/index.js
CHANGED
|
@@ -4323,14 +4323,54 @@ function pipInstall(words, from, manager, out) {
|
|
|
4323
4323
|
if (v >= 0 && lower(words[v]) === "install")
|
|
4324
4324
|
pushPy(out, manager, operands(words, v + 1, PIP_VALUE_FLAGS));
|
|
4325
4325
|
}
|
|
4326
|
+
function localContexts(file) {
|
|
4327
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
4328
|
+
const sample = parseShared("cd . && true");
|
|
4329
|
+
if (typeof sample === "symbol") return contexts;
|
|
4330
|
+
const andOp = sample.Stmts[0].Cmd.Op;
|
|
4331
|
+
function visit(stmt, steps, depth = 0) {
|
|
4332
|
+
if (depth > 64) return null;
|
|
4333
|
+
if (!stmt || stmt.Background || stmt.Negated || stmt.Redirs?.length) return null;
|
|
4334
|
+
const cmd = stmt.Cmd;
|
|
4335
|
+
const kind = syntax2.NodeType(cmd);
|
|
4336
|
+
if (kind === "BinaryCmd" && cmd.Op === andOp) {
|
|
4337
|
+
const next = visit(cmd.X, steps, depth + 1);
|
|
4338
|
+
return next === null ? null : visit(cmd.Y, next, depth + 1);
|
|
4339
|
+
}
|
|
4340
|
+
if (kind !== "CallExpr" || cmd.Assigns?.length) return null;
|
|
4341
|
+
const words = (cmd.Args ?? []).map((w) => resolveWordLiteral(w));
|
|
4342
|
+
if (words[0] === "cd" && words.length === 2 && typeof words[1] === "string" && words[1] && !/^[-~]/.test(words[1]))
|
|
4343
|
+
return [...steps, words[1]];
|
|
4344
|
+
if (!["npx", "npm", "bunx", "bun"].includes(words[0])) return null;
|
|
4345
|
+
if (words.some(
|
|
4346
|
+
(w) => w === null || /^(?:--(?:prefix|cwd|directory|workspace|workspaces|global|ignore-existing)(?:=|$)|-[Cwg])/.test(
|
|
4347
|
+
w
|
|
4348
|
+
)
|
|
4349
|
+
))
|
|
4350
|
+
return null;
|
|
4351
|
+
contexts.set(cmd.Pos().Offset(), steps);
|
|
4352
|
+
return null;
|
|
4353
|
+
}
|
|
4354
|
+
if (file.Stmts?.length === 1) visit(file.Stmts[0], []);
|
|
4355
|
+
return contexts;
|
|
4356
|
+
}
|
|
4326
4357
|
function collect(command, out, depth) {
|
|
4327
4358
|
if (!command || command.length > 5e4) return;
|
|
4328
4359
|
const f = parseShared(command);
|
|
4329
4360
|
if (typeof f === "symbol") return;
|
|
4361
|
+
const contexts = depth === 0 ? localContexts(f) : /* @__PURE__ */ new Map();
|
|
4330
4362
|
syntax2.Walk(f, (node) => {
|
|
4331
4363
|
if (node && syntax2.NodeType(node) === "CallExpr") {
|
|
4332
4364
|
const words = (node.Args || []).map((a) => resolveWordLiteral(a));
|
|
4365
|
+
const start = out.length;
|
|
4333
4366
|
if (words.length > 0) fromCall(words, out, depth);
|
|
4367
|
+
const steps = contexts.get(node.Pos().Offset());
|
|
4368
|
+
for (let i = start; i < out.length; i++) {
|
|
4369
|
+
if (["npx", "bunx", "npm exec"].includes(out[i].manager)) {
|
|
4370
|
+
if (!steps) out[i].localCwd = null;
|
|
4371
|
+
else if (steps.length) out[i].localCwd = steps;
|
|
4372
|
+
}
|
|
4373
|
+
}
|
|
4334
4374
|
}
|
|
4335
4375
|
return true;
|
|
4336
4376
|
});
|
|
@@ -4340,7 +4380,7 @@ function extractPackageInstalls(command) {
|
|
|
4340
4380
|
collect(command, out, 0);
|
|
4341
4381
|
const seen = /* @__PURE__ */ new Set();
|
|
4342
4382
|
return out.filter((r) => {
|
|
4343
|
-
const k =
|
|
4383
|
+
const k = JSON.stringify([r.ecosystem, r.manager, r.name, r.raw, r.localCwd]);
|
|
4344
4384
|
if (seen.has(k)) return false;
|
|
4345
4385
|
seen.add(k);
|
|
4346
4386
|
return true;
|
|
@@ -6201,14 +6241,19 @@ var TUNING_FIELDS = [
|
|
|
6201
6241
|
{ checkId: "loading.skill-tamper", name: "roots", legacy: ["skillPinning", "roots"] },
|
|
6202
6242
|
{
|
|
6203
6243
|
checkId: "loading.malicious-package",
|
|
6204
|
-
name: "
|
|
6205
|
-
legacy: ["packageCheck", "
|
|
6244
|
+
name: "newPackage",
|
|
6245
|
+
legacy: ["packageCheck", "newPackage"]
|
|
6206
6246
|
},
|
|
6207
6247
|
{
|
|
6208
6248
|
checkId: "loading.malicious-package",
|
|
6209
6249
|
name: "maxAgeHours",
|
|
6210
6250
|
legacy: ["packageCheck", "maxAgeHours"]
|
|
6211
6251
|
},
|
|
6252
|
+
{
|
|
6253
|
+
checkId: "loading.malicious-package",
|
|
6254
|
+
name: "installScript",
|
|
6255
|
+
legacy: ["packageCheck", "installScript"]
|
|
6256
|
+
},
|
|
6212
6257
|
{
|
|
6213
6258
|
checkId: "loading.malicious-package",
|
|
6214
6259
|
name: "onlineFallback",
|
|
@@ -6219,6 +6264,9 @@ var TUNING_FIELDS = [
|
|
|
6219
6264
|
function tuningFromLegacyPolicy(policy) {
|
|
6220
6265
|
const out = {};
|
|
6221
6266
|
const p = policy;
|
|
6267
|
+
if (policy.packageCheck?.registrySignals === false) {
|
|
6268
|
+
out["loading.malicious-package"] = { newPackage: "off", installScript: "off" };
|
|
6269
|
+
}
|
|
6222
6270
|
for (const f of TUNING_FIELDS) {
|
|
6223
6271
|
const [block, key] = f.legacy;
|
|
6224
6272
|
const value = p[block]?.[key];
|
|
@@ -6231,7 +6279,15 @@ function tuningToLegacyPolicy(policy, tuning) {
|
|
|
6231
6279
|
const unknown = [];
|
|
6232
6280
|
for (const [id, fields] of Object.entries(tuning)) {
|
|
6233
6281
|
if (!fields || typeof fields !== "object") continue;
|
|
6234
|
-
|
|
6282
|
+
const normalized = { ...fields };
|
|
6283
|
+
if (id === "loading.malicious-package") {
|
|
6284
|
+
if (normalized.registrySignals === false) {
|
|
6285
|
+
normalized.newPackage ??= "off";
|
|
6286
|
+
normalized.installScript ??= "off";
|
|
6287
|
+
}
|
|
6288
|
+
delete normalized.registrySignals;
|
|
6289
|
+
}
|
|
6290
|
+
for (const [name, value] of Object.entries(normalized)) {
|
|
6235
6291
|
const field = TUNING_FIELDS.find((f) => f.checkId === id && f.name === name);
|
|
6236
6292
|
if (!field) {
|
|
6237
6293
|
unknown.push(`${id}.${name}`);
|
package/dist/index.mjs
CHANGED
|
@@ -4145,14 +4145,54 @@ function pipInstall(words, from, manager, out) {
|
|
|
4145
4145
|
if (v >= 0 && lower(words[v]) === "install")
|
|
4146
4146
|
pushPy(out, manager, operands(words, v + 1, PIP_VALUE_FLAGS));
|
|
4147
4147
|
}
|
|
4148
|
+
function localContexts(file) {
|
|
4149
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
4150
|
+
const sample = parseShared("cd . && true");
|
|
4151
|
+
if (typeof sample === "symbol") return contexts;
|
|
4152
|
+
const andOp = sample.Stmts[0].Cmd.Op;
|
|
4153
|
+
function visit(stmt, steps, depth = 0) {
|
|
4154
|
+
if (depth > 64) return null;
|
|
4155
|
+
if (!stmt || stmt.Background || stmt.Negated || stmt.Redirs?.length) return null;
|
|
4156
|
+
const cmd = stmt.Cmd;
|
|
4157
|
+
const kind = syntax2.NodeType(cmd);
|
|
4158
|
+
if (kind === "BinaryCmd" && cmd.Op === andOp) {
|
|
4159
|
+
const next = visit(cmd.X, steps, depth + 1);
|
|
4160
|
+
return next === null ? null : visit(cmd.Y, next, depth + 1);
|
|
4161
|
+
}
|
|
4162
|
+
if (kind !== "CallExpr" || cmd.Assigns?.length) return null;
|
|
4163
|
+
const words = (cmd.Args ?? []).map((w) => resolveWordLiteral(w));
|
|
4164
|
+
if (words[0] === "cd" && words.length === 2 && typeof words[1] === "string" && words[1] && !/^[-~]/.test(words[1]))
|
|
4165
|
+
return [...steps, words[1]];
|
|
4166
|
+
if (!["npx", "npm", "bunx", "bun"].includes(words[0])) return null;
|
|
4167
|
+
if (words.some(
|
|
4168
|
+
(w) => w === null || /^(?:--(?:prefix|cwd|directory|workspace|workspaces|global|ignore-existing)(?:=|$)|-[Cwg])/.test(
|
|
4169
|
+
w
|
|
4170
|
+
)
|
|
4171
|
+
))
|
|
4172
|
+
return null;
|
|
4173
|
+
contexts.set(cmd.Pos().Offset(), steps);
|
|
4174
|
+
return null;
|
|
4175
|
+
}
|
|
4176
|
+
if (file.Stmts?.length === 1) visit(file.Stmts[0], []);
|
|
4177
|
+
return contexts;
|
|
4178
|
+
}
|
|
4148
4179
|
function collect(command, out, depth) {
|
|
4149
4180
|
if (!command || command.length > 5e4) return;
|
|
4150
4181
|
const f = parseShared(command);
|
|
4151
4182
|
if (typeof f === "symbol") return;
|
|
4183
|
+
const contexts = depth === 0 ? localContexts(f) : /* @__PURE__ */ new Map();
|
|
4152
4184
|
syntax2.Walk(f, (node) => {
|
|
4153
4185
|
if (node && syntax2.NodeType(node) === "CallExpr") {
|
|
4154
4186
|
const words = (node.Args || []).map((a) => resolveWordLiteral(a));
|
|
4187
|
+
const start = out.length;
|
|
4155
4188
|
if (words.length > 0) fromCall(words, out, depth);
|
|
4189
|
+
const steps = contexts.get(node.Pos().Offset());
|
|
4190
|
+
for (let i = start; i < out.length; i++) {
|
|
4191
|
+
if (["npx", "bunx", "npm exec"].includes(out[i].manager)) {
|
|
4192
|
+
if (!steps) out[i].localCwd = null;
|
|
4193
|
+
else if (steps.length) out[i].localCwd = steps;
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4156
4196
|
}
|
|
4157
4197
|
return true;
|
|
4158
4198
|
});
|
|
@@ -4162,7 +4202,7 @@ function extractPackageInstalls(command) {
|
|
|
4162
4202
|
collect(command, out, 0);
|
|
4163
4203
|
const seen = /* @__PURE__ */ new Set();
|
|
4164
4204
|
return out.filter((r) => {
|
|
4165
|
-
const k =
|
|
4205
|
+
const k = JSON.stringify([r.ecosystem, r.manager, r.name, r.raw, r.localCwd]);
|
|
4166
4206
|
if (seen.has(k)) return false;
|
|
4167
4207
|
seen.add(k);
|
|
4168
4208
|
return true;
|
|
@@ -6023,14 +6063,19 @@ var TUNING_FIELDS = [
|
|
|
6023
6063
|
{ checkId: "loading.skill-tamper", name: "roots", legacy: ["skillPinning", "roots"] },
|
|
6024
6064
|
{
|
|
6025
6065
|
checkId: "loading.malicious-package",
|
|
6026
|
-
name: "
|
|
6027
|
-
legacy: ["packageCheck", "
|
|
6066
|
+
name: "newPackage",
|
|
6067
|
+
legacy: ["packageCheck", "newPackage"]
|
|
6028
6068
|
},
|
|
6029
6069
|
{
|
|
6030
6070
|
checkId: "loading.malicious-package",
|
|
6031
6071
|
name: "maxAgeHours",
|
|
6032
6072
|
legacy: ["packageCheck", "maxAgeHours"]
|
|
6033
6073
|
},
|
|
6074
|
+
{
|
|
6075
|
+
checkId: "loading.malicious-package",
|
|
6076
|
+
name: "installScript",
|
|
6077
|
+
legacy: ["packageCheck", "installScript"]
|
|
6078
|
+
},
|
|
6034
6079
|
{
|
|
6035
6080
|
checkId: "loading.malicious-package",
|
|
6036
6081
|
name: "onlineFallback",
|
|
@@ -6041,6 +6086,9 @@ var TUNING_FIELDS = [
|
|
|
6041
6086
|
function tuningFromLegacyPolicy(policy) {
|
|
6042
6087
|
const out = {};
|
|
6043
6088
|
const p = policy;
|
|
6089
|
+
if (policy.packageCheck?.registrySignals === false) {
|
|
6090
|
+
out["loading.malicious-package"] = { newPackage: "off", installScript: "off" };
|
|
6091
|
+
}
|
|
6044
6092
|
for (const f of TUNING_FIELDS) {
|
|
6045
6093
|
const [block, key] = f.legacy;
|
|
6046
6094
|
const value = p[block]?.[key];
|
|
@@ -6053,7 +6101,15 @@ function tuningToLegacyPolicy(policy, tuning) {
|
|
|
6053
6101
|
const unknown = [];
|
|
6054
6102
|
for (const [id, fields] of Object.entries(tuning)) {
|
|
6055
6103
|
if (!fields || typeof fields !== "object") continue;
|
|
6056
|
-
|
|
6104
|
+
const normalized = { ...fields };
|
|
6105
|
+
if (id === "loading.malicious-package") {
|
|
6106
|
+
if (normalized.registrySignals === false) {
|
|
6107
|
+
normalized.newPackage ??= "off";
|
|
6108
|
+
normalized.installScript ??= "off";
|
|
6109
|
+
}
|
|
6110
|
+
delete normalized.registrySignals;
|
|
6111
|
+
}
|
|
6112
|
+
for (const [name, value] of Object.entries(normalized)) {
|
|
6057
6113
|
const field = TUNING_FIELDS.find((f) => f.checkId === id && f.name === name);
|
|
6058
6114
|
if (!field) {
|
|
6059
6115
|
unknown.push(`${id}.${name}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node9/policy-engine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.0",
|
|
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",
|