@node9/policy-engine 2.33.1 → 2.33.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 CHANGED
@@ -1249,22 +1249,28 @@ declare function normalizeTrustedEntry(raw: unknown): string | null;
1249
1249
  /** What a person reads for an entry: the masked part, without the hash. */
1250
1250
  declare function entryDisplay(entry: string): string;
1251
1251
  /**
1252
- * IBANs (mod-97), card numbers (exactly what detectPii reports, so not the
1253
- * fractional part of a number), account numbers (a whole IBAN-shaped value,
1254
- * or a number under an account key) and email addresses inside a text,
1255
- * masked the way destinations are. No quote or backslash is introduced or
1256
- * removed, so a JSON string stays a JSON string; a card written as a bare
1257
- * JSON number does not stay a number, so arguments go through
1258
- * maskPersonalValue instead.
1252
+ * IBANs (mod-97), card numbers (the detector's patterns and Luhn check),
1253
+ * account numbers (a whole IBAN-shaped value, or a number under an account
1254
+ * key) and email addresses inside a text, masked the way destinations are.
1255
+ * Masking is stricter than detection: a card is masked even where detectPii
1256
+ * exempts it as the fractional part of a number ("1.<card>", "0,<card>"),
1257
+ * since a hidden fraction in a log costs nothing and a shown card leaks; so
1258
+ * a Luhn-valid fractional part inside text is masked too. No quote or
1259
+ * backslash is introduced or removed, so a JSON string stays a JSON string;
1260
+ * a card written as a bare JSON number does not stay a number, so arguments
1261
+ * go through maskPersonalValue instead.
1259
1262
  */
1260
1263
  declare function maskPersonalData(text: string): string;
1261
1264
  /**
1262
1265
  * maskPersonalData over a JSON-shaped value (tool arguments), leaf by leaf, so
1263
- * the result is always a value: a string leaf is masked in its JSON form under
1264
- * its own key (the account-key and whole-value rules still see both), an
1265
- * object key is masked as text, and a number whose text holds personal data (a
1266
- * card passed as a number) becomes the masked string. Anything deeper than 64
1267
- * levels is replaced by '[REDACTED]'. Pure, never throws.
1266
+ * the result is always a value. A string leaf is masked twice: as raw text
1267
+ * first (a real newline or tab stays a word boundary, so a card or IBAN that
1268
+ * begins a line is found, as detectArgsPii finds it), then in its JSON form
1269
+ * under its own key (the account-key and whole-value rules see both). An
1270
+ * object key is masked as text; two keys that mask alike are told apart by a
1271
+ * `#2`, `#3` suffix so no entry is lost. A number whose text holds a card
1272
+ * becomes the masked string; a fraction stays the same number. Anything
1273
+ * deeper than 64 levels is replaced by '[REDACTED]'. Pure, never throws.
1268
1274
  */
1269
1275
  declare function maskPersonalValue(value: unknown): unknown;
1270
1276
 
@@ -2018,7 +2024,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
2018
2024
  * files changed, this hash must change too, and you must consciously
2019
2025
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2020
2026
  */
2021
- declare const CANONICAL_EXTRACTOR_HASH = "a358f47eacca6e14";
2027
+ declare const CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
2022
2028
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2023
2029
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2024
2030
  /**
package/dist/index.d.ts CHANGED
@@ -1249,22 +1249,28 @@ declare function normalizeTrustedEntry(raw: unknown): string | null;
1249
1249
  /** What a person reads for an entry: the masked part, without the hash. */
1250
1250
  declare function entryDisplay(entry: string): string;
1251
1251
  /**
1252
- * IBANs (mod-97), card numbers (exactly what detectPii reports, so not the
1253
- * fractional part of a number), account numbers (a whole IBAN-shaped value,
1254
- * or a number under an account key) and email addresses inside a text,
1255
- * masked the way destinations are. No quote or backslash is introduced or
1256
- * removed, so a JSON string stays a JSON string; a card written as a bare
1257
- * JSON number does not stay a number, so arguments go through
1258
- * maskPersonalValue instead.
1252
+ * IBANs (mod-97), card numbers (the detector's patterns and Luhn check),
1253
+ * account numbers (a whole IBAN-shaped value, or a number under an account
1254
+ * key) and email addresses inside a text, masked the way destinations are.
1255
+ * Masking is stricter than detection: a card is masked even where detectPii
1256
+ * exempts it as the fractional part of a number ("1.<card>", "0,<card>"),
1257
+ * since a hidden fraction in a log costs nothing and a shown card leaks; so
1258
+ * a Luhn-valid fractional part inside text is masked too. No quote or
1259
+ * backslash is introduced or removed, so a JSON string stays a JSON string;
1260
+ * a card written as a bare JSON number does not stay a number, so arguments
1261
+ * go through maskPersonalValue instead.
1259
1262
  */
1260
1263
  declare function maskPersonalData(text: string): string;
1261
1264
  /**
1262
1265
  * maskPersonalData over a JSON-shaped value (tool arguments), leaf by leaf, so
1263
- * the result is always a value: a string leaf is masked in its JSON form under
1264
- * its own key (the account-key and whole-value rules still see both), an
1265
- * object key is masked as text, and a number whose text holds personal data (a
1266
- * card passed as a number) becomes the masked string. Anything deeper than 64
1267
- * levels is replaced by '[REDACTED]'. Pure, never throws.
1266
+ * the result is always a value. A string leaf is masked twice: as raw text
1267
+ * first (a real newline or tab stays a word boundary, so a card or IBAN that
1268
+ * begins a line is found, as detectArgsPii finds it), then in its JSON form
1269
+ * under its own key (the account-key and whole-value rules see both). An
1270
+ * object key is masked as text; two keys that mask alike are told apart by a
1271
+ * `#2`, `#3` suffix so no entry is lost. A number whose text holds a card
1272
+ * becomes the masked string; a fraction stays the same number. Anything
1273
+ * deeper than 64 levels is replaced by '[REDACTED]'. Pure, never throws.
1268
1274
  */
1269
1275
  declare function maskPersonalValue(value: unknown): unknown;
1270
1276
 
@@ -2018,7 +2024,7 @@ declare const CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
2018
2024
  * files changed, this hash must change too, and you must consciously
2019
2025
  * decide whether to bump CANONICAL_EXTRACTOR_VERSION."
2020
2026
  */
2021
- declare const CANONICAL_EXTRACTOR_HASH = "a358f47eacca6e14";
2027
+ declare const CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
2022
2028
  declare function extractCanonicalFindings(call: ToolCallEntry, ctx: ExtractContext): CanonicalFinding[];
2023
2029
  declare function extractSessionLevelFindings(calls: ReadonlyArray<SessionToolCall>, ctx: SessionExtractContext): CanonicalFinding[];
2024
2030
  /**
package/dist/index.js CHANGED
@@ -11554,12 +11554,13 @@ var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
11554
11554
  var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
11555
11555
  var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
11556
11556
  var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
11557
- function* validCardRuns(text, base2) {
11557
+ function* validCardRuns(text, base2, exemptFractions = true) {
11558
11558
  const re = new RegExp(base2.source, "g");
11559
11559
  let m;
11560
11560
  while ((m = re.exec(text)) !== null) {
11561
11561
  const digits = m[0].replace(/\D/g, "");
11562
- if (!isDecimalFraction(text, m.index, digits.length === m[0].length) && validateLuhn(digits)) {
11562
+ const fraction = exemptFractions && isDecimalFraction(text, m.index, digits.length === m[0].length);
11563
+ if (!fraction && validateLuhn(digits)) {
11563
11564
  yield { index: m.index, length: m[0].length, digits };
11564
11565
  } else {
11565
11566
  re.lastIndex = m.index + 1;
@@ -11572,12 +11573,12 @@ function hasValidCard(text) {
11572
11573
  }
11573
11574
  return false;
11574
11575
  }
11575
- function replaceValidCards(text, replace) {
11576
+ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
11576
11577
  let out = text;
11577
11578
  for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
11578
11579
  let res = "";
11579
11580
  let last = 0;
11580
- for (const run of validCardRuns(out, base2)) {
11581
+ for (const run of validCardRuns(out, base2, exemptFractions)) {
11581
11582
  res += out.slice(last, run.index) + replace(run.digits);
11582
11583
  last = run.index + run.length;
11583
11584
  }
@@ -11751,6 +11752,9 @@ var EMAIL_TEXT_RE = /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}
11751
11752
  var ACCOUNT_KEY_RE = /("(?:iban|account|account_number|accountNumber)"\s*:\s*")([A-Za-z0-9 .-]{6,40})(")/g;
11752
11753
  var ACCOUNT_VALUE_RE = /"([A-Z]{2}\d{2}[A-Z0-9]{11,30})"/g;
11753
11754
  function maskPersonalData(text) {
11755
+ return maskText(text, false);
11756
+ }
11757
+ function maskText(text, exemptFractions) {
11754
11758
  if (!text) return text;
11755
11759
  try {
11756
11760
  let out = text;
@@ -11758,7 +11762,9 @@ function maskPersonalData(text) {
11758
11762
  const v = m.replace(/[ -]/g, "").toUpperCase();
11759
11763
  return validateIban(v) ? `${v.slice(0, 4)} **** **** ${v.slice(-4)}` : m;
11760
11764
  });
11761
- out = replaceValidCards(out, (digits) => `**** **** **** ${digits.slice(-4)}`);
11765
+ out = replaceValidCards(out, (digits) => `**** **** **** ${digits.slice(-4)}`, {
11766
+ exemptFractions
11767
+ });
11762
11768
  out = out.replace(
11763
11769
  ACCOUNT_VALUE_RE,
11764
11770
  (m, v) => IBAN_LENGTH[v.slice(0, 2).toUpperCase()] === v.length ? `"****${v.slice(-4)}"` : m
@@ -11782,7 +11788,7 @@ function maskLeaf(value, key, depth) {
11782
11788
  if (depth > MAX_MASK_DEPTH) return "[REDACTED]";
11783
11789
  if (typeof value === "string") {
11784
11790
  try {
11785
- const json = `{${JSON.stringify(key)}:${JSON.stringify(value)}}`;
11791
+ const json = `{${JSON.stringify(key)}:${JSON.stringify(maskPersonalData(value))}}`;
11786
11792
  return Object.values(JSON.parse(maskPersonalData(json)))[0];
11787
11793
  } catch {
11788
11794
  return "[REDACTED]";
@@ -11790,13 +11796,20 @@ function maskLeaf(value, key, depth) {
11790
11796
  }
11791
11797
  if (typeof value === "number") {
11792
11798
  const text = String(value);
11793
- const masked = maskPersonalData(text);
11799
+ const masked = maskText(text, true);
11794
11800
  return masked === text ? value : masked;
11795
11801
  }
11796
11802
  if (Array.isArray(value)) return value.map((v) => maskLeaf(v, key, depth + 1));
11797
11803
  if (value && typeof value === "object") {
11804
+ const used = /* @__PURE__ */ new Set();
11798
11805
  return Object.fromEntries(
11799
- Object.entries(value).map(([k, v]) => [maskPersonalData(k), maskLeaf(v, k, depth + 1)])
11806
+ Object.entries(value).map(([k, v]) => {
11807
+ const base2 = maskPersonalData(k);
11808
+ let name = base2;
11809
+ for (let n = 2; used.has(name); n++) name = `${base2}#${n}`;
11810
+ used.add(name);
11811
+ return [name, maskLeaf(v, k, depth + 1)];
11812
+ })
11800
11813
  );
11801
11814
  }
11802
11815
  return value;
@@ -12753,7 +12766,7 @@ function matchCanaryArgs(args, values) {
12753
12766
  // src/scan/canonical.ts
12754
12767
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
12755
12768
  var CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
12756
- var CANONICAL_EXTRACTOR_HASH = "a358f47eacca6e14";
12769
+ var CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
12757
12770
  var DEDUPE_PREVIEW_LEN = 120;
12758
12771
  function extractCanonicalFindings(call, ctx) {
12759
12772
  const out = [];
package/dist/index.mjs CHANGED
@@ -11332,12 +11332,13 @@ var PII_PHONE_RE = /\b(?:\+?1[-.\s]?)?\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/;
11332
11332
  var PII_CC16_RE = /\b(?:4\d{3}|5[1-5]\d{2}|6\d{3})[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}\b/;
11333
11333
  var PII_CC15_RE = /\b3[47]\d{2}[-\s]?\d{6}[-\s]?\d{5}\b/;
11334
11334
  var PII_IBAN_RE = /\b[A-Z]{2}\d{2}(?:[A-Z0-9]|[ -][A-Z0-9]){11,30}\b/;
11335
- function* validCardRuns(text, base2) {
11335
+ function* validCardRuns(text, base2, exemptFractions = true) {
11336
11336
  const re = new RegExp(base2.source, "g");
11337
11337
  let m;
11338
11338
  while ((m = re.exec(text)) !== null) {
11339
11339
  const digits = m[0].replace(/\D/g, "");
11340
- if (!isDecimalFraction(text, m.index, digits.length === m[0].length) && validateLuhn(digits)) {
11340
+ const fraction = exemptFractions && isDecimalFraction(text, m.index, digits.length === m[0].length);
11341
+ if (!fraction && validateLuhn(digits)) {
11341
11342
  yield { index: m.index, length: m[0].length, digits };
11342
11343
  } else {
11343
11344
  re.lastIndex = m.index + 1;
@@ -11350,12 +11351,12 @@ function hasValidCard(text) {
11350
11351
  }
11351
11352
  return false;
11352
11353
  }
11353
- function replaceValidCards(text, replace) {
11354
+ function replaceValidCards(text, replace, { exemptFractions = true } = {}) {
11354
11355
  let out = text;
11355
11356
  for (const base2 of [PII_CC16_RE, PII_CC15_RE]) {
11356
11357
  let res = "";
11357
11358
  let last = 0;
11358
- for (const run of validCardRuns(out, base2)) {
11359
+ for (const run of validCardRuns(out, base2, exemptFractions)) {
11359
11360
  res += out.slice(last, run.index) + replace(run.digits);
11360
11361
  last = run.index + run.length;
11361
11362
  }
@@ -11529,6 +11530,9 @@ var EMAIL_TEXT_RE = /[\p{L}\p{N}._%+-]+@[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}
11529
11530
  var ACCOUNT_KEY_RE = /("(?:iban|account|account_number|accountNumber)"\s*:\s*")([A-Za-z0-9 .-]{6,40})(")/g;
11530
11531
  var ACCOUNT_VALUE_RE = /"([A-Z]{2}\d{2}[A-Z0-9]{11,30})"/g;
11531
11532
  function maskPersonalData(text) {
11533
+ return maskText(text, false);
11534
+ }
11535
+ function maskText(text, exemptFractions) {
11532
11536
  if (!text) return text;
11533
11537
  try {
11534
11538
  let out = text;
@@ -11536,7 +11540,9 @@ function maskPersonalData(text) {
11536
11540
  const v = m.replace(/[ -]/g, "").toUpperCase();
11537
11541
  return validateIban(v) ? `${v.slice(0, 4)} **** **** ${v.slice(-4)}` : m;
11538
11542
  });
11539
- out = replaceValidCards(out, (digits) => `**** **** **** ${digits.slice(-4)}`);
11543
+ out = replaceValidCards(out, (digits) => `**** **** **** ${digits.slice(-4)}`, {
11544
+ exemptFractions
11545
+ });
11540
11546
  out = out.replace(
11541
11547
  ACCOUNT_VALUE_RE,
11542
11548
  (m, v) => IBAN_LENGTH[v.slice(0, 2).toUpperCase()] === v.length ? `"****${v.slice(-4)}"` : m
@@ -11560,7 +11566,7 @@ function maskLeaf(value, key, depth) {
11560
11566
  if (depth > MAX_MASK_DEPTH) return "[REDACTED]";
11561
11567
  if (typeof value === "string") {
11562
11568
  try {
11563
- const json = `{${JSON.stringify(key)}:${JSON.stringify(value)}}`;
11569
+ const json = `{${JSON.stringify(key)}:${JSON.stringify(maskPersonalData(value))}}`;
11564
11570
  return Object.values(JSON.parse(maskPersonalData(json)))[0];
11565
11571
  } catch {
11566
11572
  return "[REDACTED]";
@@ -11568,13 +11574,20 @@ function maskLeaf(value, key, depth) {
11568
11574
  }
11569
11575
  if (typeof value === "number") {
11570
11576
  const text = String(value);
11571
- const masked = maskPersonalData(text);
11577
+ const masked = maskText(text, true);
11572
11578
  return masked === text ? value : masked;
11573
11579
  }
11574
11580
  if (Array.isArray(value)) return value.map((v) => maskLeaf(v, key, depth + 1));
11575
11581
  if (value && typeof value === "object") {
11582
+ const used = /* @__PURE__ */ new Set();
11576
11583
  return Object.fromEntries(
11577
- Object.entries(value).map(([k, v]) => [maskPersonalData(k), maskLeaf(v, k, depth + 1)])
11584
+ Object.entries(value).map(([k, v]) => {
11585
+ const base2 = maskPersonalData(k);
11586
+ let name = base2;
11587
+ for (let n = 2; used.has(name); n++) name = `${base2}#${n}`;
11588
+ used.add(name);
11589
+ return [name, maskLeaf(v, k, depth + 1)];
11590
+ })
11578
11591
  );
11579
11592
  }
11580
11593
  return value;
@@ -12531,7 +12544,7 @@ function matchCanaryArgs(args, values) {
12531
12544
  // src/scan/canonical.ts
12532
12545
  var LONG_OUTPUT_THRESHOLD_BYTES = 100 * 1024;
12533
12546
  var CANONICAL_EXTRACTOR_VERSION = "canonical-v27";
12534
- var CANONICAL_EXTRACTOR_HASH = "a358f47eacca6e14";
12547
+ var CANONICAL_EXTRACTOR_HASH = "60cee75c7e2a5c7c";
12535
12548
  var DEDUPE_PREVIEW_LEN = 120;
12536
12549
  function extractCanonicalFindings(call, ctx) {
12537
12550
  const out = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node9/policy-engine",
3
- "version": "2.33.1",
3
+ "version": "2.33.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",