@akasecurity/ai-tc-codex 0.9.22 → 0.9.23

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.
@@ -23167,6 +23167,43 @@ var SqliteSecretVaultRepository = class {
23167
23167
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
23168
23168
  );
23169
23169
  }
23170
+ /**
23171
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
23172
+ * standing record of a fingerprint-key rotation whose re-key did not reach
23173
+ * every row.
23174
+ *
23175
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
23176
+ * once. That count is an event, gone the moment it is printed; this is the
23177
+ * condition, and it stays true until some later rotation re-keys the rows. It
23178
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
23179
+ * including for a rotation run from the CLI, which no dashboard render saw.
23180
+ *
23181
+ * `<>` rather than `<`: a row ahead of the current version is equally
23182
+ * unmatchable, and that is reachable — a key file restored from a backup, or
23183
+ * replaced after being lost, leaves rows stamped higher than the key is.
23184
+ *
23185
+ * Both numbers come from ONE statement, which is why this returns a pair
23186
+ * instead of offering two counts to call. Read separately, a purge landing
23187
+ * between them hands back a `stale` counted over rows the later `total` no
23188
+ * longer includes, and a disclosure built from that pair states a fraction
23189
+ * true of no state of the table — "1 of 0 stored values", or a negative
23190
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
23191
+ * delete rather than from a `countEntries` standing beside it.
23192
+ */
23193
+ countFingerprintEpochs(currentVersion) {
23194
+ const row = getRow(
23195
+ this.db.prepare(
23196
+ `SELECT COUNT(*) AS total,
23197
+ COALESCE(
23198
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
23199
+ 0
23200
+ ) AS stale
23201
+ FROM secret_vault`
23202
+ ),
23203
+ { currentVersion }
23204
+ ) ?? { stale: 0, total: 0 };
23205
+ return { stale: row.stale, total: row.total };
23206
+ }
23170
23207
  };
23171
23208
 
23172
23209
  // ../../packages/persistence/src/repositories/security.ts
@@ -24956,13 +24993,22 @@ var SecretVault = class {
24956
24993
  * fingerprint collides with a row already refreshed, is skipped rather than
24957
24994
  * aborting the pass — one damaged entry must not strand the re-key of every
24958
24995
  * other. A skipped row keeps resolving under its old fingerprint epoch.
24996
+ *
24997
+ * Every skip is COUNTED, because best-effort and silent are different things:
24998
+ * the loss above is invisible at the moment it happens and only shows up later
24999
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
25000
+ * than a bare success count.
24959
25001
  */
24960
25002
  async refreshFingerprints(next) {
24961
25003
  let refreshed = 0;
25004
+ let skipped = 0;
24962
25005
  for (const row of this.#repo.listAll()) {
24963
25006
  try {
24964
25007
  const raw = await this.#openRow(row);
24965
- if (raw === null) continue;
25008
+ if (raw === null) {
25009
+ skipped += 1;
25010
+ continue;
25011
+ }
24966
25012
  this.#repo.refreshFingerprint(row.pointerId, {
24967
25013
  valueFingerprint: exactFingerprintValue(next, raw),
24968
25014
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -24970,10 +25016,10 @@ var SecretVault = class {
24970
25016
  });
24971
25017
  refreshed += 1;
24972
25018
  } catch {
24973
- continue;
25019
+ skipped += 1;
24974
25020
  }
24975
25021
  }
24976
- return refreshed;
25022
+ return { refreshed, skipped };
24977
25023
  }
24978
25024
  /**
24979
25025
  * Destroy every entry, making all outstanding pointers permanently
@@ -26292,6 +26338,21 @@ function passesPostValidators(rule, value) {
26292
26338
  function getLoadedRules() {
26293
26339
  return [...packs.values()].flatMap((p) => p.rules);
26294
26340
  }
26341
+ function outsideWrittenRegions(candidates, context) {
26342
+ const regions = context?.writtenRegions;
26343
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
26344
+ return candidates.filter((c) => {
26345
+ if (c.rule.category !== "code_flaw") return true;
26346
+ const { start, end } = c.match.span;
26347
+ return !regions.some(
26348
+ (r) => r.start <= start && end <= r.end && ruleApplies(
26349
+ c.rule,
26350
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
26351
+ "code_change"
26352
+ )
26353
+ );
26354
+ });
26355
+ }
26295
26356
  function spansOverlap(a, b) {
26296
26357
  return a.start < b.end && a.end > b.start;
26297
26358
  }
@@ -26479,17 +26540,20 @@ function scanEncoded(text, ruleset, context) {
26479
26540
  function scanText(text, ruleset, context) {
26480
26541
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
26481
26542
  const normalization = normalizeFormatChars(text);
26482
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
26543
+ const originalCandidates = outsideWrittenRegions(
26544
+ buildCandidates(text, ruleset, extension, context?.eventKind),
26545
+ context
26546
+ );
26483
26547
  if (!normalization) return gate(originalCandidates, text, void 0);
26484
26548
  const pooledOriginal = originalCandidates.map(
26485
26549
  (candidate) => withNormalizedSpan(candidate, normalization)
26486
26550
  );
26487
- const normalizedCandidates = buildCandidates(
26488
- normalization.normalized,
26489
- ruleset,
26490
- extension,
26491
- context?.eventKind
26492
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
26551
+ const normalizedCandidates = outsideWrittenRegions(
26552
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
26553
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
26554
+ ),
26555
+ context
26556
+ );
26493
26557
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
26494
26558
  return mergeOverlappingSameRule(findings, text);
26495
26559
  }
@@ -27380,7 +27444,7 @@ var sql_inject_concat_dot_default = {
27380
27444
  severity: "high",
27381
27445
  matcher: {
27382
27446
  type: "regex",
27383
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
27447
+ pattern: "([\"'])(?=((?:(?!\\1)[^\\n])*?\\b(?:select\\b(?:(?!\\1|\\bselect\\b)[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b)))))\\2(?:(?!\\1(?:(?!\\1)[^\\n])*?\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\.",
27384
27448
  flags: "gi"
27385
27449
  },
27386
27450
  appliesTo: {
@@ -27398,7 +27462,7 @@ var sql_inject_concat_default = {
27398
27462
  severity: "high",
27399
27463
  matcher: {
27400
27464
  type: "regex",
27401
- pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
27465
+ pattern: "([\"'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b))))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\+",
27402
27466
  flags: "gi"
27403
27467
  },
27404
27468
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -27413,7 +27477,7 @@ var sql_inject_format_default = {
27413
27477
  severity: "high",
27414
27478
  matcher: {
27415
27479
  type: "regex",
27416
- pattern: `(["'\`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(["'\`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\b(?:(?!\\bwhere\\b|\\3)[^\\n])*?=))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:=\\s*['"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})`,
27480
+ pattern: "([\"'`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|([\"'`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?=(?!\\3)['\"%])|between\\b))))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?(?:=\\s*['\"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})",
27417
27481
  flags: "gi"
27418
27482
  },
27419
27483
  examples: [
@@ -27422,6 +27486,24 @@ var sql_inject_format_default = {
27422
27486
  ]
27423
27487
  };
27424
27488
 
27489
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
27490
+ var sql_inject_interp_multiline_default = {
27491
+ specVersion: 1,
27492
+ id: "code-flaws/sql-inject-interp-multiline",
27493
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
27494
+ category: "code_flaw",
27495
+ severity: "high",
27496
+ matcher: {
27497
+ type: "regex",
27498
+ pattern: '(?<=^|\\n)[ \\t]*(?=(?:select\\b(?:[^\\n]*\\n){0,3}?[^\\n]*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}into\\b|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])',
27499
+ flags: "gi"
27500
+ },
27501
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
27502
+ appliesTo: {
27503
+ extensions: [".rb", ".php"]
27504
+ }
27505
+ };
27506
+
27425
27507
  // ../../rules/code-flaws/sql-inject-interp.json
27426
27508
  var sql_inject_interp_default = {
27427
27509
  specVersion: 1,
@@ -27431,7 +27513,7 @@ var sql_inject_interp_default = {
27431
27513
  severity: "high",
27432
27514
  matcher: {
27433
27515
  type: "regex",
27434
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
27516
+ pattern: '(?<![\\w\'"`})\\]])(["\'`])[ \\t]*(?=(?:select\\b(?:#\\{(?:[^{}\\n]|\\{(?:[^{}\\n]|\\{[^{}\\n]{0,100}\\}){0,100}\\}){0,200}\\}|\\{\\$[^}\\n]{0,200}\\}|\\\\(?!\\1[ \\t]*(?:select|insert|update|delete|where)\\b).|(?!\\1)(?!#\\{|\\{\\$|\\\\)[\\s\\S]){0,1000}?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}(?:into\\b|[\\w.`]+\\s*\\()|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}(?:(?:\\s+\\w+){0,2}\\s+join\\b(?:(?!\\bset\\b)(?!\\1)[^\\n]){1,300})?\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])',
27435
27517
  flags: "gi"
27436
27518
  },
27437
27519
  examples: [
@@ -29159,12 +29241,13 @@ var BUNDLED_PACKS = [
29159
29241
  {
29160
29242
  packId: "code-flaws",
29161
29243
  name: "Code Security Flaws",
29162
- version: "0.1.3",
29244
+ version: "0.1.6",
29163
29245
  rawRules: [
29164
29246
  sql_inject_concat_default,
29165
29247
  sql_inject_concat_dot_default,
29166
29248
  sql_inject_format_default,
29167
29249
  sql_inject_interp_default,
29250
+ sql_inject_interp_multiline_default,
29168
29251
  cmd_inject_shell_default,
29169
29252
  cmd_inject_exec_default,
29170
29253
  cmd_inject_node_exec_default,
@@ -29196,6 +29279,7 @@ var BUNDLED_PACKS = [
29196
29279
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
29197
29280
  "code-flaws/sql-inject-format": "SQL injection (format string)",
29198
29281
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
29282
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
29199
29283
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
29200
29284
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
29201
29285
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -29737,6 +29821,7 @@ function createIsolatedScanner(data, opts = {}) {
29737
29821
  text,
29738
29822
  filePath: context?.filePath,
29739
29823
  eventKind: context?.eventKind,
29824
+ writtenRegions: context?.writtenRegions,
29740
29825
  attribute: scanOpts?.attribute === true
29741
29826
  }),
29742
29827
  reply: (message) => {
@@ -22695,6 +22695,43 @@ var SqliteSecretVaultRepository = class {
22695
22695
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
22696
22696
  );
22697
22697
  }
22698
+ /**
22699
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
22700
+ * standing record of a fingerprint-key rotation whose re-key did not reach
22701
+ * every row.
22702
+ *
22703
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
22704
+ * once. That count is an event, gone the moment it is printed; this is the
22705
+ * condition, and it stays true until some later rotation re-keys the rows. It
22706
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
22707
+ * including for a rotation run from the CLI, which no dashboard render saw.
22708
+ *
22709
+ * `<>` rather than `<`: a row ahead of the current version is equally
22710
+ * unmatchable, and that is reachable — a key file restored from a backup, or
22711
+ * replaced after being lost, leaves rows stamped higher than the key is.
22712
+ *
22713
+ * Both numbers come from ONE statement, which is why this returns a pair
22714
+ * instead of offering two counts to call. Read separately, a purge landing
22715
+ * between them hands back a `stale` counted over rows the later `total` no
22716
+ * longer includes, and a disclosure built from that pair states a fraction
22717
+ * true of no state of the table — "1 of 0 stored values", or a negative
22718
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
22719
+ * delete rather than from a `countEntries` standing beside it.
22720
+ */
22721
+ countFingerprintEpochs(currentVersion) {
22722
+ const row = getRow(
22723
+ this.db.prepare(
22724
+ `SELECT COUNT(*) AS total,
22725
+ COALESCE(
22726
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
22727
+ 0
22728
+ ) AS stale
22729
+ FROM secret_vault`
22730
+ ),
22731
+ { currentVersion }
22732
+ ) ?? { stale: 0, total: 0 };
22733
+ return { stale: row.stale, total: row.total };
22734
+ }
22698
22735
  };
22699
22736
 
22700
22737
  // ../../packages/persistence/src/repositories/security.ts
@@ -25514,7 +25551,7 @@ var sql_inject_concat_dot_default = {
25514
25551
  severity: "high",
25515
25552
  matcher: {
25516
25553
  type: "regex",
25517
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
25554
+ pattern: "([\"'])(?=((?:(?!\\1)[^\\n])*?\\b(?:select\\b(?:(?!\\1|\\bselect\\b)[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b)))))\\2(?:(?!\\1(?:(?!\\1)[^\\n])*?\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\.",
25518
25555
  flags: "gi"
25519
25556
  },
25520
25557
  appliesTo: {
@@ -25532,7 +25569,7 @@ var sql_inject_concat_default = {
25532
25569
  severity: "high",
25533
25570
  matcher: {
25534
25571
  type: "regex",
25535
- pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
25572
+ pattern: "([\"'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b))))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\+",
25536
25573
  flags: "gi"
25537
25574
  },
25538
25575
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -25547,7 +25584,7 @@ var sql_inject_format_default = {
25547
25584
  severity: "high",
25548
25585
  matcher: {
25549
25586
  type: "regex",
25550
- pattern: `(["'\`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(["'\`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\b(?:(?!\\bwhere\\b|\\3)[^\\n])*?=))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:=\\s*['"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})`,
25587
+ pattern: "([\"'`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|([\"'`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?=(?!\\3)['\"%])|between\\b))))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?(?:=\\s*['\"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})",
25551
25588
  flags: "gi"
25552
25589
  },
25553
25590
  examples: [
@@ -25556,6 +25593,24 @@ var sql_inject_format_default = {
25556
25593
  ]
25557
25594
  };
25558
25595
 
25596
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
25597
+ var sql_inject_interp_multiline_default = {
25598
+ specVersion: 1,
25599
+ id: "code-flaws/sql-inject-interp-multiline",
25600
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
25601
+ category: "code_flaw",
25602
+ severity: "high",
25603
+ matcher: {
25604
+ type: "regex",
25605
+ pattern: '(?<=^|\\n)[ \\t]*(?=(?:select\\b(?:[^\\n]*\\n){0,3}?[^\\n]*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}into\\b|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])',
25606
+ flags: "gi"
25607
+ },
25608
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
25609
+ appliesTo: {
25610
+ extensions: [".rb", ".php"]
25611
+ }
25612
+ };
25613
+
25559
25614
  // ../../rules/code-flaws/sql-inject-interp.json
25560
25615
  var sql_inject_interp_default = {
25561
25616
  specVersion: 1,
@@ -25565,7 +25620,7 @@ var sql_inject_interp_default = {
25565
25620
  severity: "high",
25566
25621
  matcher: {
25567
25622
  type: "regex",
25568
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
25623
+ pattern: '(?<![\\w\'"`})\\]])(["\'`])[ \\t]*(?=(?:select\\b(?:#\\{(?:[^{}\\n]|\\{(?:[^{}\\n]|\\{[^{}\\n]{0,100}\\}){0,100}\\}){0,200}\\}|\\{\\$[^}\\n]{0,200}\\}|\\\\(?!\\1[ \\t]*(?:select|insert|update|delete|where)\\b).|(?!\\1)(?!#\\{|\\{\\$|\\\\)[\\s\\S]){0,1000}?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}(?:into\\b|[\\w.`]+\\s*\\()|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}(?:(?:\\s+\\w+){0,2}\\s+join\\b(?:(?!\\bset\\b)(?!\\1)[^\\n]){1,300})?\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])',
25569
25624
  flags: "gi"
25570
25625
  },
25571
25626
  examples: [
@@ -27293,12 +27348,13 @@ var BUNDLED_PACKS = [
27293
27348
  {
27294
27349
  packId: "code-flaws",
27295
27350
  name: "Code Security Flaws",
27296
- version: "0.1.3",
27351
+ version: "0.1.6",
27297
27352
  rawRules: [
27298
27353
  sql_inject_concat_default,
27299
27354
  sql_inject_concat_dot_default,
27300
27355
  sql_inject_format_default,
27301
27356
  sql_inject_interp_default,
27357
+ sql_inject_interp_multiline_default,
27302
27358
  cmd_inject_shell_default,
27303
27359
  cmd_inject_exec_default,
27304
27360
  cmd_inject_node_exec_default,
@@ -27330,6 +27386,7 @@ var BUNDLED_PACKS = [
27330
27386
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
27331
27387
  "code-flaws/sql-inject-format": "SQL injection (format string)",
27332
27388
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
27389
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
27333
27390
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
27334
27391
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
27335
27392
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -23804,6 +23804,43 @@ var SqliteSecretVaultRepository = class {
23804
23804
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
23805
23805
  );
23806
23806
  }
23807
+ /**
23808
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
23809
+ * standing record of a fingerprint-key rotation whose re-key did not reach
23810
+ * every row.
23811
+ *
23812
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
23813
+ * once. That count is an event, gone the moment it is printed; this is the
23814
+ * condition, and it stays true until some later rotation re-keys the rows. It
23815
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
23816
+ * including for a rotation run from the CLI, which no dashboard render saw.
23817
+ *
23818
+ * `<>` rather than `<`: a row ahead of the current version is equally
23819
+ * unmatchable, and that is reachable — a key file restored from a backup, or
23820
+ * replaced after being lost, leaves rows stamped higher than the key is.
23821
+ *
23822
+ * Both numbers come from ONE statement, which is why this returns a pair
23823
+ * instead of offering two counts to call. Read separately, a purge landing
23824
+ * between them hands back a `stale` counted over rows the later `total` no
23825
+ * longer includes, and a disclosure built from that pair states a fraction
23826
+ * true of no state of the table — "1 of 0 stored values", or a negative
23827
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
23828
+ * delete rather than from a `countEntries` standing beside it.
23829
+ */
23830
+ countFingerprintEpochs(currentVersion) {
23831
+ const row = getRow(
23832
+ this.db.prepare(
23833
+ `SELECT COUNT(*) AS total,
23834
+ COALESCE(
23835
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
23836
+ 0
23837
+ ) AS stale
23838
+ FROM secret_vault`
23839
+ ),
23840
+ { currentVersion }
23841
+ ) ?? { stale: 0, total: 0 };
23842
+ return { stale: row.stale, total: row.total };
23843
+ }
23807
23844
  };
23808
23845
 
23809
23846
  // ../../packages/persistence/src/repositories/security.ts
@@ -25660,13 +25697,22 @@ var SecretVault = class {
25660
25697
  * fingerprint collides with a row already refreshed, is skipped rather than
25661
25698
  * aborting the pass — one damaged entry must not strand the re-key of every
25662
25699
  * other. A skipped row keeps resolving under its old fingerprint epoch.
25700
+ *
25701
+ * Every skip is COUNTED, because best-effort and silent are different things:
25702
+ * the loss above is invisible at the moment it happens and only shows up later
25703
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
25704
+ * than a bare success count.
25663
25705
  */
25664
25706
  async refreshFingerprints(next) {
25665
25707
  let refreshed = 0;
25708
+ let skipped = 0;
25666
25709
  for (const row of this.#repo.listAll()) {
25667
25710
  try {
25668
25711
  const raw = await this.#openRow(row);
25669
- if (raw === null) continue;
25712
+ if (raw === null) {
25713
+ skipped += 1;
25714
+ continue;
25715
+ }
25670
25716
  this.#repo.refreshFingerprint(row.pointerId, {
25671
25717
  valueFingerprint: exactFingerprintValue(next, raw),
25672
25718
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -25674,10 +25720,10 @@ var SecretVault = class {
25674
25720
  });
25675
25721
  refreshed += 1;
25676
25722
  } catch {
25677
- continue;
25723
+ skipped += 1;
25678
25724
  }
25679
25725
  }
25680
- return refreshed;
25726
+ return { refreshed, skipped };
25681
25727
  }
25682
25728
  /**
25683
25729
  * Destroy every entry, making all outstanding pointers permanently
@@ -27016,6 +27062,21 @@ function registerPack(pack) {
27016
27062
  function getLoadedRules() {
27017
27063
  return [...packs.values()].flatMap((p) => p.rules);
27018
27064
  }
27065
+ function outsideWrittenRegions(candidates, context) {
27066
+ const regions = context?.writtenRegions;
27067
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
27068
+ return candidates.filter((c) => {
27069
+ if (c.rule.category !== "code_flaw") return true;
27070
+ const { start, end } = c.match.span;
27071
+ return !regions.some(
27072
+ (r) => r.start <= start && end <= r.end && ruleApplies(
27073
+ c.rule,
27074
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
27075
+ "code_change"
27076
+ )
27077
+ );
27078
+ });
27079
+ }
27019
27080
  function spansOverlap(a, b) {
27020
27081
  return a.start < b.end && a.end > b.start;
27021
27082
  }
@@ -27203,17 +27264,20 @@ function scanEncoded(text2, ruleset, context) {
27203
27264
  function scanText(text2, ruleset, context) {
27204
27265
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
27205
27266
  const normalization = normalizeFormatChars(text2);
27206
- const originalCandidates = buildCandidates(text2, ruleset, extension, context?.eventKind);
27267
+ const originalCandidates = outsideWrittenRegions(
27268
+ buildCandidates(text2, ruleset, extension, context?.eventKind),
27269
+ context
27270
+ );
27207
27271
  if (!normalization) return gate(originalCandidates, text2, void 0);
27208
27272
  const pooledOriginal = originalCandidates.map(
27209
27273
  (candidate) => withNormalizedSpan(candidate, normalization)
27210
27274
  );
27211
- const normalizedCandidates = buildCandidates(
27212
- normalization.normalized,
27213
- ruleset,
27214
- extension,
27215
- context?.eventKind
27216
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text2));
27275
+ const normalizedCandidates = outsideWrittenRegions(
27276
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
27277
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text2)
27278
+ ),
27279
+ context
27280
+ );
27217
27281
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text2, normalization);
27218
27282
  return mergeOverlappingSameRule(findings, text2);
27219
27283
  }
@@ -27274,6 +27338,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
27274
27338
  "code-flaws/sql-inject-concat-dot",
27275
27339
  "code-flaws/sql-inject-format",
27276
27340
  "code-flaws/sql-inject-interp",
27341
+ "code-flaws/sql-inject-interp-multiline",
27277
27342
  "code-flaws/ssrf-user-url",
27278
27343
  "code-flaws/xss-dangerously-set",
27279
27344
  "code-flaws/xss-inner-html",
@@ -28412,7 +28477,7 @@ var sql_inject_concat_dot_default = {
28412
28477
  severity: "high",
28413
28478
  matcher: {
28414
28479
  type: "regex",
28415
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
28480
+ pattern: "([\"'])(?=((?:(?!\\1)[^\\n])*?\\b(?:select\\b(?:(?!\\1|\\bselect\\b)[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b)))))\\2(?:(?!\\1(?:(?!\\1)[^\\n])*?\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\.",
28416
28481
  flags: "gi"
28417
28482
  },
28418
28483
  appliesTo: {
@@ -28430,7 +28495,7 @@ var sql_inject_concat_default = {
28430
28495
  severity: "high",
28431
28496
  matcher: {
28432
28497
  type: "regex",
28433
- pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
28498
+ pattern: "([\"'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b))))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\+",
28434
28499
  flags: "gi"
28435
28500
  },
28436
28501
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -28445,7 +28510,7 @@ var sql_inject_format_default = {
28445
28510
  severity: "high",
28446
28511
  matcher: {
28447
28512
  type: "regex",
28448
- pattern: `(["'\`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(["'\`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\b(?:(?!\\bwhere\\b|\\3)[^\\n])*?=))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:=\\s*['"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})`,
28513
+ pattern: "([\"'`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|([\"'`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?=(?!\\3)['\"%])|between\\b))))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?(?:=\\s*['\"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})",
28449
28514
  flags: "gi"
28450
28515
  },
28451
28516
  examples: [
@@ -28454,6 +28519,24 @@ var sql_inject_format_default = {
28454
28519
  ]
28455
28520
  };
28456
28521
 
28522
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
28523
+ var sql_inject_interp_multiline_default = {
28524
+ specVersion: 1,
28525
+ id: "code-flaws/sql-inject-interp-multiline",
28526
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
28527
+ category: "code_flaw",
28528
+ severity: "high",
28529
+ matcher: {
28530
+ type: "regex",
28531
+ pattern: '(?<=^|\\n)[ \\t]*(?=(?:select\\b(?:[^\\n]*\\n){0,3}?[^\\n]*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}into\\b|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])',
28532
+ flags: "gi"
28533
+ },
28534
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
28535
+ appliesTo: {
28536
+ extensions: [".rb", ".php"]
28537
+ }
28538
+ };
28539
+
28457
28540
  // ../../rules/code-flaws/sql-inject-interp.json
28458
28541
  var sql_inject_interp_default = {
28459
28542
  specVersion: 1,
@@ -28463,7 +28546,7 @@ var sql_inject_interp_default = {
28463
28546
  severity: "high",
28464
28547
  matcher: {
28465
28548
  type: "regex",
28466
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
28549
+ pattern: '(?<![\\w\'"`})\\]])(["\'`])[ \\t]*(?=(?:select\\b(?:#\\{(?:[^{}\\n]|\\{(?:[^{}\\n]|\\{[^{}\\n]{0,100}\\}){0,100}\\}){0,200}\\}|\\{\\$[^}\\n]{0,200}\\}|\\\\(?!\\1[ \\t]*(?:select|insert|update|delete|where)\\b).|(?!\\1)(?!#\\{|\\{\\$|\\\\)[\\s\\S]){0,1000}?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}(?:into\\b|[\\w.`]+\\s*\\()|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}(?:(?:\\s+\\w+){0,2}\\s+join\\b(?:(?!\\bset\\b)(?!\\1)[^\\n]){1,300})?\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])',
28467
28550
  flags: "gi"
28468
28551
  },
28469
28552
  examples: [
@@ -30191,12 +30274,13 @@ var BUNDLED_PACKS = [
30191
30274
  {
30192
30275
  packId: "code-flaws",
30193
30276
  name: "Code Security Flaws",
30194
- version: "0.1.3",
30277
+ version: "0.1.6",
30195
30278
  rawRules: [
30196
30279
  sql_inject_concat_default,
30197
30280
  sql_inject_concat_dot_default,
30198
30281
  sql_inject_format_default,
30199
30282
  sql_inject_interp_default,
30283
+ sql_inject_interp_multiline_default,
30200
30284
  cmd_inject_shell_default,
30201
30285
  cmd_inject_exec_default,
30202
30286
  cmd_inject_node_exec_default,
@@ -30228,6 +30312,7 @@ var BUNDLED_PACKS = [
30228
30312
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
30229
30313
  "code-flaws/sql-inject-format": "SQL injection (format string)",
30230
30314
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
30315
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
30231
30316
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
30232
30317
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
30233
30318
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -31320,6 +31405,7 @@ function createIsolatedScanner(data, opts = {}) {
31320
31405
  text: text2,
31321
31406
  filePath: context?.filePath,
31322
31407
  eventKind: context?.eventKind,
31408
+ writtenRegions: context?.writtenRegions,
31323
31409
  attribute: scanOpts?.attribute === true
31324
31410
  }),
31325
31411
  reply: (message) => {
@@ -32133,7 +32219,8 @@ function createPluginRuntime(gateway, settings, opts) {
32133
32219
  input.text,
32134
32220
  {
32135
32221
  filePath: input.metadata?.filePath,
32136
- eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
32222
+ eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
32223
+ writtenRegions: opts2.writtenRegions
32137
32224
  },
32138
32225
  {
32139
32226
  sourceTool: input.sourceTool,