@akasecurity/ai-tc-antigravity 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.
@@ -32,9 +32,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
  mod
33
33
  ));
34
34
 
35
- // ../../node_modules/.pnpm/ignore@7.0.13/node_modules/ignore/index.js
35
+ // ../../node_modules/.pnpm/ignore@7.0.14/node_modules/ignore/index.js
36
36
  var require_ignore = __commonJS({
37
- "../../node_modules/.pnpm/ignore@7.0.13/node_modules/ignore/index.js"(exports, module) {
37
+ "../../node_modules/.pnpm/ignore@7.0.14/node_modules/ignore/index.js"(exports, module) {
38
38
  "use strict";
39
39
  function makeArray(subject) {
40
40
  return Array.isArray(subject) ? subject : [subject];
@@ -46,6 +46,7 @@ var require_ignore = __commonJS({
46
46
  var REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
47
47
  var BOM = "\uFEFF";
48
48
  var REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
49
+ var REGEX_ANCHORED_GLOBSTAR = /^\/\*{2,}$/;
49
50
  var REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
50
51
  var REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
51
52
  var REGEX_SPLITALL_CRLF = /\r?\n/g;
@@ -227,6 +228,20 @@ var require_ignore = __commonJS({
227
228
  (_, run, space) => space ? run.slice(0, run.length - run.length % 2) + SPACE2 : run,
228
229
  ESCAPE + SPACE2
229
230
  ],
231
+ // git's wildmatch() reads a run of two or more asterisks as one globstar
232
+ // whenever the run fills a path segment: it starts the pattern or follows
233
+ // a `/`, and it ends the pattern or comes before a `/`. A run of two is
234
+ // already `**`; a longer one is folded into `**` here, so the steps
235
+ // below only ever have to know `**`.
236
+ // `***/foo` -> `**/foo`, `a/***/b` -> `a/**/b`, `a/***` -> `a/**`
237
+ // git also takes a run beside a literal prefix (`a***/b`) or beside an
238
+ // escaped slash (`***\/b`) as a globstar, and this does not; the README
239
+ // lists both, under "A run of asterisks".
240
+ [
241
+ /(^|\/)\*{3,}(?=\/|$)/g,
242
+ (_, start) => `${start}**`,
243
+ "*"
244
+ ],
230
245
  // Escape metacharacters
231
246
  // which is written down by users but means special for regular expressions.
232
247
  // > There are 12 characters with special meanings:
@@ -488,6 +503,9 @@ var require_ignore = __commonJS({
488
503
  return out;
489
504
  };
490
505
  var makeRegexPrefix = (pattern) => {
506
+ if (REGEX_ANCHORED_GLOBSTAR.test(pattern)) {
507
+ pattern = "**";
508
+ }
491
509
  const { source, sources } = extractBrackets(pattern);
492
510
  const replaced = REPLACERS.reduce(
493
511
  // A pass whose matcher finds nothing hands back the very string it was
@@ -703,39 +721,33 @@ var require_ignore = __commonJS({
703
721
  }
704
722
  // Test one single path without recursively checking parent directories
705
723
  //
706
- // - checkUnignored `boolean` whether should check if the path is unignored,
707
- // setting `checkUnignored` to `false` could reduce additional
708
- // path matching.
709
- // - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
710
- // @returns {TestResult} true if a file is ignored
711
- test(path, checkUnignored, mode) {
712
- let ignored = false;
713
- let unignored = false;
714
- let matchedRule;
724
+ // - mode `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
725
+ // @returns {TestResult}
726
+ test(path, mode) {
715
727
  const rules = this._rules;
716
728
  const { length } = rules;
717
729
  const shortcut = this._basenameCount * 2 >= length;
718
730
  const basename7 = shortcut ? basenameOf(path) : path;
719
- for (let index = 0; index < length; index++) {
731
+ for (let index = length - 1; index >= 0; index--) {
720
732
  const rule = rules[index];
721
- const { negative } = rule;
722
- const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
723
- if (!skip && rule[mode].test(
733
+ if (rule[mode].test(
724
734
  shortcut && rule._basenameOnly ? basename7 : path
725
735
  )) {
726
- ignored = !negative;
727
- unignored = negative;
728
- matchedRule = negative ? UNDEFINED : rule;
736
+ const { negative } = rule;
737
+ const ret = {
738
+ ignored: !negative,
739
+ unignored: negative
740
+ };
741
+ if (!negative) {
742
+ ret.rule = rule;
743
+ }
744
+ return ret;
729
745
  }
730
746
  }
731
- const ret = {
732
- ignored,
733
- unignored
747
+ return {
748
+ ignored: false,
749
+ unignored: false
734
750
  };
735
- if (matchedRule) {
736
- ret.rule = matchedRule;
737
- }
738
- return ret;
739
751
  }
740
752
  };
741
753
  var throwError = (message, Ctor) => {
@@ -808,36 +820,36 @@ var require_ignore = __commonJS({
808
820
  return this.add(pattern);
809
821
  }
810
822
  // @returns {TestResult}
811
- _test(originalPath, cache, checkUnignored) {
823
+ _test(originalPath, cache) {
812
824
  const path = originalPath && checkPath.convert(originalPath);
813
825
  checkPath(
814
826
  path,
815
827
  originalPath,
816
828
  this._strictPathCheck ? throwError : RETURN_FALSE
817
829
  );
818
- return this._t(path, cache, checkUnignored);
830
+ return this._t(path, cache);
819
831
  }
820
832
  checkIgnore(path) {
821
833
  if (path.charCodeAt(path.length - 1) !== SLASH_CODE) {
822
834
  return this.test(path);
823
835
  }
824
- const dir = this._t(path, this._testCache, true);
836
+ const dir = this._t(path, this._testCache);
825
837
  if (dir.ignored) {
826
838
  return dir;
827
839
  }
828
840
  const literal2 = this._rules.testLiteral(path);
829
841
  return literal2.ignored || literal2.unignored ? literal2 : dir;
830
842
  }
831
- _t(path, cache, checkUnignored) {
843
+ _t(path, cache) {
832
844
  if (path in cache) {
833
845
  return cache[path];
834
846
  }
835
847
  const parentPath = parentOf(path);
836
- const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
837
- return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
848
+ const parent = parentPath ? this._t(parentPath, cache) : UNDEFINED;
849
+ return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, MODE_IGNORE);
838
850
  }
839
851
  ignores(path) {
840
- return this._test(path, this._ignoreCache, false).ignored;
852
+ return this._test(path, this._ignoreCache).ignored;
841
853
  }
842
854
  createFilter() {
843
855
  return (path) => !this.ignores(path);
@@ -847,7 +859,7 @@ var require_ignore = __commonJS({
847
859
  }
848
860
  // @returns {TestResult}
849
861
  test(path) {
850
- return this._test(path, this._testCache, true);
862
+ return this._test(path, this._testCache);
851
863
  }
852
864
  };
853
865
  var factory = (options) => new Ignore(options);
@@ -24866,6 +24878,43 @@ var SqliteSecretVaultRepository = class {
24866
24878
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
24867
24879
  );
24868
24880
  }
24881
+ /**
24882
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
24883
+ * standing record of a fingerprint-key rotation whose re-key did not reach
24884
+ * every row.
24885
+ *
24886
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
24887
+ * once. That count is an event, gone the moment it is printed; this is the
24888
+ * condition, and it stays true until some later rotation re-keys the rows. It
24889
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
24890
+ * including for a rotation run from the CLI, which no dashboard render saw.
24891
+ *
24892
+ * `<>` rather than `<`: a row ahead of the current version is equally
24893
+ * unmatchable, and that is reachable — a key file restored from a backup, or
24894
+ * replaced after being lost, leaves rows stamped higher than the key is.
24895
+ *
24896
+ * Both numbers come from ONE statement, which is why this returns a pair
24897
+ * instead of offering two counts to call. Read separately, a purge landing
24898
+ * between them hands back a `stale` counted over rows the later `total` no
24899
+ * longer includes, and a disclosure built from that pair states a fraction
24900
+ * true of no state of the table — "1 of 0 stored values", or a negative
24901
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
24902
+ * delete rather than from a `countEntries` standing beside it.
24903
+ */
24904
+ countFingerprintEpochs(currentVersion) {
24905
+ const row = getRow(
24906
+ this.db.prepare(
24907
+ `SELECT COUNT(*) AS total,
24908
+ COALESCE(
24909
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
24910
+ 0
24911
+ ) AS stale
24912
+ FROM secret_vault`
24913
+ ),
24914
+ { currentVersion }
24915
+ ) ?? { stale: 0, total: 0 };
24916
+ return { stale: row.stale, total: row.total };
24917
+ }
24869
24918
  };
24870
24919
 
24871
24920
  // ../../packages/persistence/src/repositories/security.ts
@@ -26695,13 +26744,22 @@ var SecretVault = class {
26695
26744
  * fingerprint collides with a row already refreshed, is skipped rather than
26696
26745
  * aborting the pass — one damaged entry must not strand the re-key of every
26697
26746
  * other. A skipped row keeps resolving under its old fingerprint epoch.
26747
+ *
26748
+ * Every skip is COUNTED, because best-effort and silent are different things:
26749
+ * the loss above is invisible at the moment it happens and only shows up later
26750
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
26751
+ * than a bare success count.
26698
26752
  */
26699
26753
  async refreshFingerprints(next) {
26700
26754
  let refreshed = 0;
26755
+ let skipped = 0;
26701
26756
  for (const row of this.#repo.listAll()) {
26702
26757
  try {
26703
26758
  const raw = await this.#openRow(row);
26704
- if (raw === null) continue;
26759
+ if (raw === null) {
26760
+ skipped += 1;
26761
+ continue;
26762
+ }
26705
26763
  this.#repo.refreshFingerprint(row.pointerId, {
26706
26764
  valueFingerprint: exactFingerprintValue(next, raw),
26707
26765
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -26709,10 +26767,10 @@ var SecretVault = class {
26709
26767
  });
26710
26768
  refreshed += 1;
26711
26769
  } catch {
26712
- continue;
26770
+ skipped += 1;
26713
26771
  }
26714
26772
  }
26715
- return refreshed;
26773
+ return { refreshed, skipped };
26716
26774
  }
26717
26775
  /**
26718
26776
  * Destroy every entry, making all outstanding pointers permanently
@@ -29261,6 +29319,21 @@ function registerPack(pack) {
29261
29319
  function getLoadedRules() {
29262
29320
  return [...packs.values()].flatMap((p) => p.rules);
29263
29321
  }
29322
+ function outsideWrittenRegions(candidates, context) {
29323
+ const regions = context?.writtenRegions;
29324
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
29325
+ return candidates.filter((c) => {
29326
+ if (c.rule.category !== "code_flaw") return true;
29327
+ const { start, end } = c.match.span;
29328
+ return !regions.some(
29329
+ (r) => r.start <= start && end <= r.end && ruleApplies(
29330
+ c.rule,
29331
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
29332
+ "code_change"
29333
+ )
29334
+ );
29335
+ });
29336
+ }
29264
29337
  function spansOverlap(a, b) {
29265
29338
  return a.start < b.end && a.end > b.start;
29266
29339
  }
@@ -29448,17 +29521,20 @@ function scanEncoded(text, ruleset, context) {
29448
29521
  function scanText(text, ruleset, context) {
29449
29522
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
29450
29523
  const normalization = normalizeFormatChars(text);
29451
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
29524
+ const originalCandidates = outsideWrittenRegions(
29525
+ buildCandidates(text, ruleset, extension, context?.eventKind),
29526
+ context
29527
+ );
29452
29528
  if (!normalization) return gate(originalCandidates, text, void 0);
29453
29529
  const pooledOriginal = originalCandidates.map(
29454
29530
  (candidate) => withNormalizedSpan(candidate, normalization)
29455
29531
  );
29456
- const normalizedCandidates = buildCandidates(
29457
- normalization.normalized,
29458
- ruleset,
29459
- extension,
29460
- context?.eventKind
29461
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
29532
+ const normalizedCandidates = outsideWrittenRegions(
29533
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
29534
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
29535
+ ),
29536
+ context
29537
+ );
29462
29538
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
29463
29539
  return mergeOverlappingSameRule(findings, text);
29464
29540
  }
@@ -29519,6 +29595,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
29519
29595
  "code-flaws/sql-inject-concat-dot",
29520
29596
  "code-flaws/sql-inject-format",
29521
29597
  "code-flaws/sql-inject-interp",
29598
+ "code-flaws/sql-inject-interp-multiline",
29522
29599
  "code-flaws/ssrf-user-url",
29523
29600
  "code-flaws/xss-dangerously-set",
29524
29601
  "code-flaws/xss-inner-html",
@@ -30657,7 +30734,7 @@ var sql_inject_concat_dot_default = {
30657
30734
  severity: "high",
30658
30735
  matcher: {
30659
30736
  type: "regex",
30660
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
30737
+ 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*\\.",
30661
30738
  flags: "gi"
30662
30739
  },
30663
30740
  appliesTo: {
@@ -30675,7 +30752,7 @@ var sql_inject_concat_default = {
30675
30752
  severity: "high",
30676
30753
  matcher: {
30677
30754
  type: "regex",
30678
- 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*\\+`,
30755
+ 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*\\+",
30679
30756
  flags: "gi"
30680
30757
  },
30681
30758
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -30690,7 +30767,7 @@ var sql_inject_format_default = {
30690
30767
  severity: "high",
30691
30768
  matcher: {
30692
30769
  type: "regex",
30693
- 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]+\\})`,
30770
+ 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]+\\})",
30694
30771
  flags: "gi"
30695
30772
  },
30696
30773
  examples: [
@@ -30699,6 +30776,24 @@ var sql_inject_format_default = {
30699
30776
  ]
30700
30777
  };
30701
30778
 
30779
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
30780
+ var sql_inject_interp_multiline_default = {
30781
+ specVersion: 1,
30782
+ id: "code-flaws/sql-inject-interp-multiline",
30783
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
30784
+ category: "code_flaw",
30785
+ severity: "high",
30786
+ matcher: {
30787
+ type: "regex",
30788
+ 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_])',
30789
+ flags: "gi"
30790
+ },
30791
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
30792
+ appliesTo: {
30793
+ extensions: [".rb", ".php"]
30794
+ }
30795
+ };
30796
+
30702
30797
  // ../../rules/code-flaws/sql-inject-interp.json
30703
30798
  var sql_inject_interp_default = {
30704
30799
  specVersion: 1,
@@ -30708,7 +30803,7 @@ var sql_inject_interp_default = {
30708
30803
  severity: "high",
30709
30804
  matcher: {
30710
30805
  type: "regex",
30711
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
30806
+ 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_])',
30712
30807
  flags: "gi"
30713
30808
  },
30714
30809
  examples: [
@@ -32436,12 +32531,13 @@ var BUNDLED_PACKS = [
32436
32531
  {
32437
32532
  packId: "code-flaws",
32438
32533
  name: "Code Security Flaws",
32439
- version: "0.1.3",
32534
+ version: "0.1.6",
32440
32535
  rawRules: [
32441
32536
  sql_inject_concat_default,
32442
32537
  sql_inject_concat_dot_default,
32443
32538
  sql_inject_format_default,
32444
32539
  sql_inject_interp_default,
32540
+ sql_inject_interp_multiline_default,
32445
32541
  cmd_inject_shell_default,
32446
32542
  cmd_inject_exec_default,
32447
32543
  cmd_inject_node_exec_default,
@@ -32473,6 +32569,7 @@ var BUNDLED_PACKS = [
32473
32569
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
32474
32570
  "code-flaws/sql-inject-format": "SQL injection (format string)",
32475
32571
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
32572
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
32476
32573
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
32477
32574
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
32478
32575
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -33584,6 +33681,7 @@ function createIsolatedScanner(data, opts = {}) {
33584
33681
  text,
33585
33682
  filePath: context?.filePath,
33586
33683
  eventKind: context?.eventKind,
33684
+ writtenRegions: context?.writtenRegions,
33587
33685
  attribute: scanOpts?.attribute === true
33588
33686
  }),
33589
33687
  reply: (message) => {
@@ -34385,7 +34483,8 @@ function createPluginRuntime(gateway, settings, opts) {
34385
34483
  input.text,
34386
34484
  {
34387
34485
  filePath: input.metadata?.filePath,
34388
- eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
34486
+ eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
34487
+ writtenRegions: opts2.writtenRegions
34389
34488
  },
34390
34489
  {
34391
34490
  sourceTool: input.sourceTool,
@@ -23783,6 +23783,43 @@ var SqliteSecretVaultRepository = class {
23783
23783
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
23784
23784
  );
23785
23785
  }
23786
+ /**
23787
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
23788
+ * standing record of a fingerprint-key rotation whose re-key did not reach
23789
+ * every row.
23790
+ *
23791
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
23792
+ * once. That count is an event, gone the moment it is printed; this is the
23793
+ * condition, and it stays true until some later rotation re-keys the rows. It
23794
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
23795
+ * including for a rotation run from the CLI, which no dashboard render saw.
23796
+ *
23797
+ * `<>` rather than `<`: a row ahead of the current version is equally
23798
+ * unmatchable, and that is reachable — a key file restored from a backup, or
23799
+ * replaced after being lost, leaves rows stamped higher than the key is.
23800
+ *
23801
+ * Both numbers come from ONE statement, which is why this returns a pair
23802
+ * instead of offering two counts to call. Read separately, a purge landing
23803
+ * between them hands back a `stale` counted over rows the later `total` no
23804
+ * longer includes, and a disclosure built from that pair states a fraction
23805
+ * true of no state of the table — "1 of 0 stored values", or a negative
23806
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
23807
+ * delete rather than from a `countEntries` standing beside it.
23808
+ */
23809
+ countFingerprintEpochs(currentVersion) {
23810
+ const row = getRow(
23811
+ this.db.prepare(
23812
+ `SELECT COUNT(*) AS total,
23813
+ COALESCE(
23814
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
23815
+ 0
23816
+ ) AS stale
23817
+ FROM secret_vault`
23818
+ ),
23819
+ { currentVersion }
23820
+ ) ?? { stale: 0, total: 0 };
23821
+ return { stale: row.stale, total: row.total };
23822
+ }
23786
23823
  };
23787
23824
 
23788
23825
  // ../../packages/persistence/src/repositories/security.ts
@@ -25505,13 +25542,22 @@ var SecretVault = class {
25505
25542
  * fingerprint collides with a row already refreshed, is skipped rather than
25506
25543
  * aborting the pass — one damaged entry must not strand the re-key of every
25507
25544
  * other. A skipped row keeps resolving under its old fingerprint epoch.
25545
+ *
25546
+ * Every skip is COUNTED, because best-effort and silent are different things:
25547
+ * the loss above is invisible at the moment it happens and only shows up later
25548
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
25549
+ * than a bare success count.
25508
25550
  */
25509
25551
  async refreshFingerprints(next) {
25510
25552
  let refreshed = 0;
25553
+ let skipped = 0;
25511
25554
  for (const row of this.#repo.listAll()) {
25512
25555
  try {
25513
25556
  const raw = await this.#openRow(row);
25514
- if (raw === null) continue;
25557
+ if (raw === null) {
25558
+ skipped += 1;
25559
+ continue;
25560
+ }
25515
25561
  this.#repo.refreshFingerprint(row.pointerId, {
25516
25562
  valueFingerprint: exactFingerprintValue(next, raw),
25517
25563
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -25519,10 +25565,10 @@ var SecretVault = class {
25519
25565
  });
25520
25566
  refreshed += 1;
25521
25567
  } catch {
25522
- continue;
25568
+ skipped += 1;
25523
25569
  }
25524
25570
  }
25525
- return refreshed;
25571
+ return { refreshed, skipped };
25526
25572
  }
25527
25573
  /**
25528
25574
  * Destroy every entry, making all outstanding pointers permanently
@@ -26892,6 +26938,21 @@ function passesPostValidators(rule, value) {
26892
26938
  function getLoadedRules() {
26893
26939
  return [...packs.values()].flatMap((p) => p.rules);
26894
26940
  }
26941
+ function outsideWrittenRegions(candidates, context) {
26942
+ const regions = context?.writtenRegions;
26943
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
26944
+ return candidates.filter((c) => {
26945
+ if (c.rule.category !== "code_flaw") return true;
26946
+ const { start, end } = c.match.span;
26947
+ return !regions.some(
26948
+ (r) => r.start <= start && end <= r.end && ruleApplies(
26949
+ c.rule,
26950
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
26951
+ "code_change"
26952
+ )
26953
+ );
26954
+ });
26955
+ }
26895
26956
  function spansOverlap(a, b) {
26896
26957
  return a.start < b.end && a.end > b.start;
26897
26958
  }
@@ -27079,17 +27140,20 @@ function scanEncoded(text, ruleset, context) {
27079
27140
  function scanText(text, ruleset, context) {
27080
27141
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
27081
27142
  const normalization = normalizeFormatChars(text);
27082
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
27143
+ const originalCandidates = outsideWrittenRegions(
27144
+ buildCandidates(text, ruleset, extension, context?.eventKind),
27145
+ context
27146
+ );
27083
27147
  if (!normalization) return gate(originalCandidates, text, void 0);
27084
27148
  const pooledOriginal = originalCandidates.map(
27085
27149
  (candidate) => withNormalizedSpan(candidate, normalization)
27086
27150
  );
27087
- const normalizedCandidates = buildCandidates(
27088
- normalization.normalized,
27089
- ruleset,
27090
- extension,
27091
- context?.eventKind
27092
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
27151
+ const normalizedCandidates = outsideWrittenRegions(
27152
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
27153
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
27154
+ ),
27155
+ context
27156
+ );
27093
27157
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
27094
27158
  return mergeOverlappingSameRule(findings, text);
27095
27159
  }
@@ -27980,7 +28044,7 @@ var sql_inject_concat_dot_default = {
27980
28044
  severity: "high",
27981
28045
  matcher: {
27982
28046
  type: "regex",
27983
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
28047
+ 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*\\.",
27984
28048
  flags: "gi"
27985
28049
  },
27986
28050
  appliesTo: {
@@ -27998,7 +28062,7 @@ var sql_inject_concat_default = {
27998
28062
  severity: "high",
27999
28063
  matcher: {
28000
28064
  type: "regex",
28001
- 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*\\+`,
28065
+ 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*\\+",
28002
28066
  flags: "gi"
28003
28067
  },
28004
28068
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -28013,7 +28077,7 @@ var sql_inject_format_default = {
28013
28077
  severity: "high",
28014
28078
  matcher: {
28015
28079
  type: "regex",
28016
- 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]+\\})`,
28080
+ 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]+\\})",
28017
28081
  flags: "gi"
28018
28082
  },
28019
28083
  examples: [
@@ -28022,6 +28086,24 @@ var sql_inject_format_default = {
28022
28086
  ]
28023
28087
  };
28024
28088
 
28089
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
28090
+ var sql_inject_interp_multiline_default = {
28091
+ specVersion: 1,
28092
+ id: "code-flaws/sql-inject-interp-multiline",
28093
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
28094
+ category: "code_flaw",
28095
+ severity: "high",
28096
+ matcher: {
28097
+ type: "regex",
28098
+ 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_])',
28099
+ flags: "gi"
28100
+ },
28101
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
28102
+ appliesTo: {
28103
+ extensions: [".rb", ".php"]
28104
+ }
28105
+ };
28106
+
28025
28107
  // ../../rules/code-flaws/sql-inject-interp.json
28026
28108
  var sql_inject_interp_default = {
28027
28109
  specVersion: 1,
@@ -28031,7 +28113,7 @@ var sql_inject_interp_default = {
28031
28113
  severity: "high",
28032
28114
  matcher: {
28033
28115
  type: "regex",
28034
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
28116
+ 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_])',
28035
28117
  flags: "gi"
28036
28118
  },
28037
28119
  examples: [
@@ -29759,12 +29841,13 @@ var BUNDLED_PACKS = [
29759
29841
  {
29760
29842
  packId: "code-flaws",
29761
29843
  name: "Code Security Flaws",
29762
- version: "0.1.3",
29844
+ version: "0.1.6",
29763
29845
  rawRules: [
29764
29846
  sql_inject_concat_default,
29765
29847
  sql_inject_concat_dot_default,
29766
29848
  sql_inject_format_default,
29767
29849
  sql_inject_interp_default,
29850
+ sql_inject_interp_multiline_default,
29768
29851
  cmd_inject_shell_default,
29769
29852
  cmd_inject_exec_default,
29770
29853
  cmd_inject_node_exec_default,
@@ -29796,6 +29879,7 @@ var BUNDLED_PACKS = [
29796
29879
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
29797
29880
  "code-flaws/sql-inject-format": "SQL injection (format string)",
29798
29881
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
29882
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
29799
29883
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
29800
29884
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
29801
29885
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -30452,6 +30536,7 @@ function createIsolatedScanner(data, opts = {}) {
30452
30536
  text,
30453
30537
  filePath: context?.filePath,
30454
30538
  eventKind: context?.eventKind,
30539
+ writtenRegions: context?.writtenRegions,
30455
30540
  attribute: scanOpts?.attribute === true
30456
30541
  }),
30457
30542
  reply: (message) => {