@node9/policy-engine 2.65.8 → 2.65.10

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 CHANGED
@@ -2487,7 +2487,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
2487
2487
  * and fails CI when the hash drifts without a version bump — forgetting
2488
2488
  * is loud, not silent.
2489
2489
  */
2490
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
2490
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v41";
2491
2491
  /**
2492
2492
  * SHA-256 prefix of the detector-source files
2493
2493
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -2498,7 +2498,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
2498
2498
  * files changed, this hash must change too, and you must consciously
2499
2499
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2500
2500
  */
2501
- declare const CANONICAL_EXTRACTOR_HASH = "0981d8f2268c7d69";
2501
+ declare const CANONICAL_EXTRACTOR_HASH = "dbde5e7f06f3738a";
2502
2502
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2503
2503
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2504
2504
  /**
package/dist/index.d.ts CHANGED
@@ -2487,7 +2487,7 @@ declare const LONG_OUTPUT_THRESHOLD_BYTES: number;
2487
2487
  * and fails CI when the hash drifts without a version bump — forgetting
2488
2488
  * is loud, not silent.
2489
2489
  */
2490
- declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
2490
+ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v41";
2491
2491
  /**
2492
2492
  * SHA-256 prefix of the detector-source files
2493
2493
  * (canonical.ts + pii.ts + destructive-regex.ts).
@@ -2498,7 +2498,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
2498
2498
  * files changed, this hash must change too, and you must consciously
2499
2499
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2500
2500
  */
2501
- declare const CANONICAL_EXTRACTOR_HASH = "0981d8f2268c7d69";
2501
+ declare const CANONICAL_EXTRACTOR_HASH = "dbde5e7f06f3738a";
2502
2502
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2503
2503
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2504
2504
  /**
package/dist/index.js CHANGED
@@ -4523,7 +4523,8 @@ function collectShellFileAccesses(command, context = {}, report) {
4523
4523
  }
4524
4524
  function fromWords(tokens, state, nested, depth) {
4525
4525
  const words = tokens.map((w) => w && !w.dynamic ? w.value : null);
4526
- const head = unwrapCommandHead(words, true);
4526
+ let head = unwrapCommandHead(words, true);
4527
+ if (base(words[head]) === "builtin" && ["cd", "pushd"].includes(base(words[head + 1]))) head++;
4527
4528
  const name = base(words[head]);
4528
4529
  if (name === "find") {
4529
4530
  findActions2(tokens, words, head, state, nested, depth);
@@ -4700,7 +4701,8 @@ function collectShellFileAccesses(command, context = {}, report) {
4700
4701
  if (!target) return;
4701
4702
  const targetSpelling = target.value || target.pattern;
4702
4703
  for (const source of operands2) {
4703
- if (name === "mv") add("remove", source, state, { recursive: true, followFinal: false });
4704
+ if (name === "mv")
4705
+ add("remove", source, state, { recursive: true, followFinal: false, copy: true });
4704
4706
  else if (name !== "ln" && !linkOnly)
4705
4707
  add("read", source, state, { recursive, followFinal: !preserveSourceLink, copy: true });
4706
4708
  if (!noDirectory)
@@ -8628,9 +8630,10 @@ function analyzeFsOperation(command) {
8628
8630
  fsOpCache.set(command, hit);
8629
8631
  return hit;
8630
8632
  }
8633
+ const changesDir = CHANGES_DIR_RE.test(command) || CHANGES_DIR_RE.test(normalized);
8631
8634
  const own = analyzeFsOperationImpl(command);
8632
- const direct = stdinShell && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8633
- const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
8635
+ const direct = (stdinShell || changesDir) && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8636
+ const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command, changesDir));
8634
8637
  const computed = withInline?.verdict === "block" || !dotenvCli ? withInline : stricter(withInline, dotenvCliJailRead(command));
8635
8638
  if (fsOpCache.size >= FS_OP_CACHE_MAX) {
8636
8639
  const oldest = fsOpCache.keys().next().value;
@@ -9102,6 +9105,7 @@ var STDIN_SHELL_WORD_RE = new RegExp(
9102
9105
  "i"
9103
9106
  );
9104
9107
  var feedsShellStdin = (command) => /\||<</.test(command) && STDIN_SHELL_WORD_RE.test(command);
9108
+ var CHANGES_DIR_RE = /(?:^|[\s;&|({'"`])(?:cd|pushd)\s/;
9105
9109
  var SOURCES_FILE_RE = /(?:^|[;&|(\s])(?:source|\.)\s/;
9106
9110
  function printsEnvironment(words) {
9107
9111
  const [name, ...rest] = words;
@@ -9435,6 +9439,12 @@ function matchSensitiveGlob(glob, dotGlob) {
9435
9439
  }
9436
9440
  return null;
9437
9441
  }
9442
+ function underEnteredDir(a, name) {
9443
+ const dir = a.cwd ?? "";
9444
+ if (!dir || /^(?:[/\\~$]|[A-Za-z]:)/.test(name)) return name;
9445
+ const rest = name.replace(/^(?:\.\/)+/, "");
9446
+ return `${dir.replace(/[/\\]+$/, "")}/${rest}`;
9447
+ }
9438
9448
  function structuralJailRead(command) {
9439
9449
  let accesses;
9440
9450
  const report = { exhausted: false };
@@ -9448,35 +9458,77 @@ function structuralJailRead(command) {
9448
9458
  const sourcedHit = sourcedAndPrinted(command);
9449
9459
  if (sourcedHit?.verdict === "block") return sourcedHit;
9450
9460
  let review = sourcedHit;
9461
+ let relativeCopy = null;
9451
9462
  for (const a of accesses) {
9452
- if (a.operation !== "read" || a.listing || a.recursive || a.copy) continue;
9463
+ if (a.copy && !a.listing && (a.operation === "read" || a.operation === "remove")) {
9464
+ const entered = underEnteredDir(a, a.path);
9465
+ if (entered !== a.path) relativeCopy ??= copyVerdictOf(matchSensitivePath(entered));
9466
+ continue;
9467
+ }
9468
+ if (a.operation !== "read" || a.listing || a.recursive) continue;
9453
9469
  const glob = a.glob ?? (GLOB_META.test(a.path) ? a.path : void 0);
9454
- const hit = glob ? matchSensitiveGlob(glob, !!a.dotGlob) : matchSensitivePath(a.path);
9470
+ const hit = glob ? matchSensitiveGlob(underEnteredDir(a, glob), !!a.dotGlob) : matchSensitivePath(underEnteredDir(a, a.path));
9455
9471
  if (hit?.verdict === "block") return hit;
9456
9472
  review ??= hit;
9457
9473
  }
9474
+ review = stricter(review, relativeCopy);
9458
9475
  return report.exhausted ? stricter(review, UNANALYSABLE_NESTING) : review;
9459
9476
  }
9460
9477
  var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
9461
9478
  var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
9462
- function inlineCodeJailRead(command) {
9479
+ function inlineCodeJailRead(command, changesDir = false) {
9463
9480
  const calls = inlineExecCalls(command);
9464
9481
  if (calls === PARSE_FAIL) return null;
9465
9482
  let review = null;
9483
+ let entered = null;
9484
+ const dirs = () => entered ??= changesDir ? enteredDirs(command) : [];
9466
9485
  for (const call of calls) {
9467
9486
  const language = inlineLanguageOf(call.interp);
9468
9487
  if (language === null) continue;
9469
9488
  for (const code of call.code) {
9470
9489
  if (code === null) continue;
9471
9490
  for (const p of inlineReadPaths(language, code, call.preload)) {
9472
- const hit = matchSensitivePath(p);
9473
- if (hit?.verdict === "block") return hit;
9474
- review ??= hit;
9491
+ const relative = !/^(?:[/\\~$]|[A-Za-z]:)/.test(p);
9492
+ const spellings = relative ? [p, ...dirs().map((d) => `${d}/${p}`)] : [p];
9493
+ for (const spelling of spellings) {
9494
+ const hit = matchSensitivePath(spelling);
9495
+ if (hit?.verdict === "block") return hit;
9496
+ review ??= hit;
9497
+ }
9475
9498
  }
9476
9499
  }
9477
9500
  }
9478
9501
  return review;
9479
9502
  }
9503
+ var MAX_ENTERED_DIRS = 16;
9504
+ function enteredDirs(command, depth = 0, out = []) {
9505
+ if (depth > 3) return out;
9506
+ try {
9507
+ walkCommandScope(command, (node) => {
9508
+ const n = node;
9509
+ if (!n || n.kind !== "CallExpr" || out.length >= MAX_ENTERED_DIRS) return true;
9510
+ const words = callWords(n);
9511
+ if (words.length === 0) return true;
9512
+ let head = unwrapCommandHead(words);
9513
+ if (baseWord(words[head]) === "builtin") head++;
9514
+ const name = baseWord(words[head]);
9515
+ if (name !== "cd" && name !== "pushd") {
9516
+ const payload = literalShellPayload(words, baseWord(words[0]));
9517
+ if (payload !== null) enteredDirs(payload, depth + 1, out);
9518
+ return true;
9519
+ }
9520
+ const target = words.slice(head + 1).find((w) => w === null || !w.startsWith("-"));
9521
+ if (!target) return true;
9522
+ const dir = target.replace(/[/\\]+$/, "");
9523
+ const rooted = /^(?:[/\\~]|[A-Za-z]:)/.test(dir);
9524
+ for (const d of rooted ? [dir] : [dir, ...out.map((prev) => `${prev}/${dir}`)])
9525
+ if (out.length < MAX_ENTERED_DIRS && !out.includes(d)) out.push(d);
9526
+ return true;
9527
+ });
9528
+ } catch {
9529
+ }
9530
+ return out;
9531
+ }
9480
9532
  var DOTENV_CLI_PRESCREEN_RE = /\bdotenvx?\b/i;
9481
9533
  var MAX_DOTENV_PAYLOAD_DEPTH = 3;
9482
9534
  function dotenvCliReads(command, depth = 0) {
@@ -21732,8 +21784,8 @@ function matchCanaryArgs(args, values) {
21732
21784
 
21733
21785
  // src/scan/canonical.ts
21734
21786
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
21735
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
21736
- var CANONICAL_EXTRACTOR_HASH = "0981d8f2268c7d69";
21787
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v41";
21788
+ var CANONICAL_EXTRACTOR_HASH = "dbde5e7f06f3738a";
21737
21789
  var DEDUPE_PREVIEW_LEN = 120;
21738
21790
  function extractCanonicalFindings(call, ctx) {
21739
21791
  const out = [];
package/dist/index.mjs CHANGED
@@ -4253,7 +4253,8 @@ function collectShellFileAccesses(command, context = {}, report) {
4253
4253
  }
4254
4254
  function fromWords(tokens, state, nested, depth) {
4255
4255
  const words = tokens.map((w) => w && !w.dynamic ? w.value : null);
4256
- const head = unwrapCommandHead(words, true);
4256
+ let head = unwrapCommandHead(words, true);
4257
+ if (base(words[head]) === "builtin" && ["cd", "pushd"].includes(base(words[head + 1]))) head++;
4257
4258
  const name = base(words[head]);
4258
4259
  if (name === "find") {
4259
4260
  findActions2(tokens, words, head, state, nested, depth);
@@ -4430,7 +4431,8 @@ function collectShellFileAccesses(command, context = {}, report) {
4430
4431
  if (!target) return;
4431
4432
  const targetSpelling = target.value || target.pattern;
4432
4433
  for (const source of operands2) {
4433
- if (name === "mv") add("remove", source, state, { recursive: true, followFinal: false });
4434
+ if (name === "mv")
4435
+ add("remove", source, state, { recursive: true, followFinal: false, copy: true });
4434
4436
  else if (name !== "ln" && !linkOnly)
4435
4437
  add("read", source, state, { recursive, followFinal: !preserveSourceLink, copy: true });
4436
4438
  if (!noDirectory)
@@ -8358,9 +8360,10 @@ function analyzeFsOperation(command) {
8358
8360
  fsOpCache.set(command, hit);
8359
8361
  return hit;
8360
8362
  }
8363
+ const changesDir = CHANGES_DIR_RE.test(command) || CHANGES_DIR_RE.test(normalized);
8361
8364
  const own = analyzeFsOperationImpl(command);
8362
- const direct = stdinShell && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8363
- const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command));
8365
+ const direct = (stdinShell || changesDir) && own?.verdict !== "block" ? stricter(own, structuralJailRead(command)) : own ?? (INDIRECT_SHAPE_RE.test(command) ? structuralJailRead(command) : null);
8366
+ const withInline = direct?.verdict === "block" || !runsInlineInterpreter(command, normalized) ? direct : stricter(direct, inlineCodeJailRead(command, changesDir));
8364
8367
  const computed = withInline?.verdict === "block" || !dotenvCli ? withInline : stricter(withInline, dotenvCliJailRead(command));
8365
8368
  if (fsOpCache.size >= FS_OP_CACHE_MAX) {
8366
8369
  const oldest = fsOpCache.keys().next().value;
@@ -8832,6 +8835,7 @@ var STDIN_SHELL_WORD_RE = new RegExp(
8832
8835
  "i"
8833
8836
  );
8834
8837
  var feedsShellStdin = (command) => /\||<</.test(command) && STDIN_SHELL_WORD_RE.test(command);
8838
+ var CHANGES_DIR_RE = /(?:^|[\s;&|({'"`])(?:cd|pushd)\s/;
8835
8839
  var SOURCES_FILE_RE = /(?:^|[;&|(\s])(?:source|\.)\s/;
8836
8840
  function printsEnvironment(words) {
8837
8841
  const [name, ...rest] = words;
@@ -9165,6 +9169,12 @@ function matchSensitiveGlob(glob, dotGlob) {
9165
9169
  }
9166
9170
  return null;
9167
9171
  }
9172
+ function underEnteredDir(a, name) {
9173
+ const dir = a.cwd ?? "";
9174
+ if (!dir || /^(?:[/\\~$]|[A-Za-z]:)/.test(name)) return name;
9175
+ const rest = name.replace(/^(?:\.\/)+/, "");
9176
+ return `${dir.replace(/[/\\]+$/, "")}/${rest}`;
9177
+ }
9168
9178
  function structuralJailRead(command) {
9169
9179
  let accesses;
9170
9180
  const report = { exhausted: false };
@@ -9178,35 +9188,77 @@ function structuralJailRead(command) {
9178
9188
  const sourcedHit = sourcedAndPrinted(command);
9179
9189
  if (sourcedHit?.verdict === "block") return sourcedHit;
9180
9190
  let review = sourcedHit;
9191
+ let relativeCopy = null;
9181
9192
  for (const a of accesses) {
9182
- if (a.operation !== "read" || a.listing || a.recursive || a.copy) continue;
9193
+ if (a.copy && !a.listing && (a.operation === "read" || a.operation === "remove")) {
9194
+ const entered = underEnteredDir(a, a.path);
9195
+ if (entered !== a.path) relativeCopy ??= copyVerdictOf(matchSensitivePath(entered));
9196
+ continue;
9197
+ }
9198
+ if (a.operation !== "read" || a.listing || a.recursive) continue;
9183
9199
  const glob = a.glob ?? (GLOB_META.test(a.path) ? a.path : void 0);
9184
- const hit = glob ? matchSensitiveGlob(glob, !!a.dotGlob) : matchSensitivePath(a.path);
9200
+ const hit = glob ? matchSensitiveGlob(underEnteredDir(a, glob), !!a.dotGlob) : matchSensitivePath(underEnteredDir(a, a.path));
9185
9201
  if (hit?.verdict === "block") return hit;
9186
9202
  review ??= hit;
9187
9203
  }
9204
+ review = stricter(review, relativeCopy);
9188
9205
  return report.exhausted ? stricter(review, UNANALYSABLE_NESTING) : review;
9189
9206
  }
9190
9207
  var INLINE_INTERP_PRESCREEN_RE = /(?:^|[^\w-])(?:python|node|tsx|ts-node|deno|bun|perl|ruby|irb|php)(?![A-Za-z_])/i;
9191
9208
  var runsInlineInterpreter = (command, normalized) => INLINE_INTERP_PRESCREEN_RE.test(command) || INLINE_INTERP_PRESCREEN_RE.test(normalized);
9192
- function inlineCodeJailRead(command) {
9209
+ function inlineCodeJailRead(command, changesDir = false) {
9193
9210
  const calls = inlineExecCalls(command);
9194
9211
  if (calls === PARSE_FAIL) return null;
9195
9212
  let review = null;
9213
+ let entered = null;
9214
+ const dirs = () => entered ??= changesDir ? enteredDirs(command) : [];
9196
9215
  for (const call of calls) {
9197
9216
  const language = inlineLanguageOf(call.interp);
9198
9217
  if (language === null) continue;
9199
9218
  for (const code of call.code) {
9200
9219
  if (code === null) continue;
9201
9220
  for (const p of inlineReadPaths(language, code, call.preload)) {
9202
- const hit = matchSensitivePath(p);
9203
- if (hit?.verdict === "block") return hit;
9204
- review ??= hit;
9221
+ const relative = !/^(?:[/\\~$]|[A-Za-z]:)/.test(p);
9222
+ const spellings = relative ? [p, ...dirs().map((d) => `${d}/${p}`)] : [p];
9223
+ for (const spelling of spellings) {
9224
+ const hit = matchSensitivePath(spelling);
9225
+ if (hit?.verdict === "block") return hit;
9226
+ review ??= hit;
9227
+ }
9205
9228
  }
9206
9229
  }
9207
9230
  }
9208
9231
  return review;
9209
9232
  }
9233
+ var MAX_ENTERED_DIRS = 16;
9234
+ function enteredDirs(command, depth = 0, out = []) {
9235
+ if (depth > 3) return out;
9236
+ try {
9237
+ walkCommandScope(command, (node) => {
9238
+ const n = node;
9239
+ if (!n || n.kind !== "CallExpr" || out.length >= MAX_ENTERED_DIRS) return true;
9240
+ const words = callWords(n);
9241
+ if (words.length === 0) return true;
9242
+ let head = unwrapCommandHead(words);
9243
+ if (baseWord(words[head]) === "builtin") head++;
9244
+ const name = baseWord(words[head]);
9245
+ if (name !== "cd" && name !== "pushd") {
9246
+ const payload = literalShellPayload(words, baseWord(words[0]));
9247
+ if (payload !== null) enteredDirs(payload, depth + 1, out);
9248
+ return true;
9249
+ }
9250
+ const target = words.slice(head + 1).find((w) => w === null || !w.startsWith("-"));
9251
+ if (!target) return true;
9252
+ const dir = target.replace(/[/\\]+$/, "");
9253
+ const rooted = /^(?:[/\\~]|[A-Za-z]:)/.test(dir);
9254
+ for (const d of rooted ? [dir] : [dir, ...out.map((prev) => `${prev}/${dir}`)])
9255
+ if (out.length < MAX_ENTERED_DIRS && !out.includes(d)) out.push(d);
9256
+ return true;
9257
+ });
9258
+ } catch {
9259
+ }
9260
+ return out;
9261
+ }
9210
9262
  var DOTENV_CLI_PRESCREEN_RE = /\bdotenvx?\b/i;
9211
9263
  var MAX_DOTENV_PAYLOAD_DEPTH = 3;
9212
9264
  function dotenvCliReads(command, depth = 0) {
@@ -21462,8 +21514,8 @@ function matchCanaryArgs(args, values) {
21462
21514
 
21463
21515
  // src/scan/canonical.ts
21464
21516
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
21465
- var CANONICAL_EXTRACTOR_VERSION = "canonical-v40";
21466
- var CANONICAL_EXTRACTOR_HASH = "0981d8f2268c7d69";
21517
+ var CANONICAL_EXTRACTOR_VERSION = "canonical-v41";
21518
+ var CANONICAL_EXTRACTOR_HASH = "dbde5e7f06f3738a";
21467
21519
  var DEDUPE_PREVIEW_LEN = 120;
21468
21520
  function extractCanonicalFindings(call, ctx) {
21469
21521
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.65.8",
3
+ "version": "2.65.10",
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",