@akasecurity/ai-tc-copilot 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.
@@ -15114,6 +15114,21 @@ function registerPack(pack) {
15114
15114
  function getLoadedRules() {
15115
15115
  return [...packs.values()].flatMap((p) => p.rules);
15116
15116
  }
15117
+ function outsideWrittenRegions(candidates, context) {
15118
+ const regions = context?.writtenRegions;
15119
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
15120
+ return candidates.filter((c) => {
15121
+ if (c.rule.category !== "code_flaw") return true;
15122
+ const { start, end } = c.match.span;
15123
+ return !regions.some(
15124
+ (r) => r.start <= start && end <= r.end && ruleApplies(
15125
+ c.rule,
15126
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
15127
+ "code_change"
15128
+ )
15129
+ );
15130
+ });
15131
+ }
15117
15132
  function spansOverlap(a, b) {
15118
15133
  return a.start < b.end && a.end > b.start;
15119
15134
  }
@@ -15301,17 +15316,20 @@ function scanEncoded(text, ruleset, context) {
15301
15316
  function scanText(text, ruleset, context) {
15302
15317
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
15303
15318
  const normalization = normalizeFormatChars(text);
15304
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
15319
+ const originalCandidates = outsideWrittenRegions(
15320
+ buildCandidates(text, ruleset, extension, context?.eventKind),
15321
+ context
15322
+ );
15305
15323
  if (!normalization) return gate(originalCandidates, text, void 0);
15306
15324
  const pooledOriginal = originalCandidates.map(
15307
15325
  (candidate) => withNormalizedSpan(candidate, normalization)
15308
15326
  );
15309
- const normalizedCandidates = buildCandidates(
15310
- normalization.normalized,
15311
- ruleset,
15312
- extension,
15313
- context?.eventKind
15314
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
15327
+ const normalizedCandidates = outsideWrittenRegions(
15328
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
15329
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
15330
+ ),
15331
+ context
15332
+ );
15315
15333
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
15316
15334
  return mergeOverlappingSameRule(findings, text);
15317
15335
  }
@@ -15372,6 +15390,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
15372
15390
  "code-flaws/sql-inject-concat-dot",
15373
15391
  "code-flaws/sql-inject-format",
15374
15392
  "code-flaws/sql-inject-interp",
15393
+ "code-flaws/sql-inject-interp-multiline",
15375
15394
  "code-flaws/ssrf-user-url",
15376
15395
  "code-flaws/xss-dangerously-set",
15377
15396
  "code-flaws/xss-inner-html",
@@ -16510,7 +16529,7 @@ var sql_inject_concat_dot_default = {
16510
16529
  severity: "high",
16511
16530
  matcher: {
16512
16531
  type: "regex",
16513
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
16532
+ 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*\\.",
16514
16533
  flags: "gi"
16515
16534
  },
16516
16535
  appliesTo: {
@@ -16528,7 +16547,7 @@ var sql_inject_concat_default = {
16528
16547
  severity: "high",
16529
16548
  matcher: {
16530
16549
  type: "regex",
16531
- 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*\\+`,
16550
+ 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*\\+",
16532
16551
  flags: "gi"
16533
16552
  },
16534
16553
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -16543,7 +16562,7 @@ var sql_inject_format_default = {
16543
16562
  severity: "high",
16544
16563
  matcher: {
16545
16564
  type: "regex",
16546
- 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]+\\})`,
16565
+ 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]+\\})",
16547
16566
  flags: "gi"
16548
16567
  },
16549
16568
  examples: [
@@ -16552,6 +16571,24 @@ var sql_inject_format_default = {
16552
16571
  ]
16553
16572
  };
16554
16573
 
16574
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
16575
+ var sql_inject_interp_multiline_default = {
16576
+ specVersion: 1,
16577
+ id: "code-flaws/sql-inject-interp-multiline",
16578
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
16579
+ category: "code_flaw",
16580
+ severity: "high",
16581
+ matcher: {
16582
+ type: "regex",
16583
+ 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_])',
16584
+ flags: "gi"
16585
+ },
16586
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
16587
+ appliesTo: {
16588
+ extensions: [".rb", ".php"]
16589
+ }
16590
+ };
16591
+
16555
16592
  // ../../rules/code-flaws/sql-inject-interp.json
16556
16593
  var sql_inject_interp_default = {
16557
16594
  specVersion: 1,
@@ -16561,7 +16598,7 @@ var sql_inject_interp_default = {
16561
16598
  severity: "high",
16562
16599
  matcher: {
16563
16600
  type: "regex",
16564
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
16601
+ 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_])',
16565
16602
  flags: "gi"
16566
16603
  },
16567
16604
  examples: [
@@ -18289,12 +18326,13 @@ var BUNDLED_PACKS = [
18289
18326
  {
18290
18327
  packId: "code-flaws",
18291
18328
  name: "Code Security Flaws",
18292
- version: "0.1.3",
18329
+ version: "0.1.6",
18293
18330
  rawRules: [
18294
18331
  sql_inject_concat_default,
18295
18332
  sql_inject_concat_dot_default,
18296
18333
  sql_inject_format_default,
18297
18334
  sql_inject_interp_default,
18335
+ sql_inject_interp_multiline_default,
18298
18336
  cmd_inject_shell_default,
18299
18337
  cmd_inject_exec_default,
18300
18338
  cmd_inject_node_exec_default,
@@ -18326,6 +18364,7 @@ var BUNDLED_PACKS = [
18326
18364
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
18327
18365
  "code-flaws/sql-inject-format": "SQL injection (format string)",
18328
18366
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
18367
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
18329
18368
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
18330
18369
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
18331
18370
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -28418,6 +28457,43 @@ var SqliteSecretVaultRepository = class {
28418
28457
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
28419
28458
  );
28420
28459
  }
28460
+ /**
28461
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
28462
+ * standing record of a fingerprint-key rotation whose re-key did not reach
28463
+ * every row.
28464
+ *
28465
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
28466
+ * once. That count is an event, gone the moment it is printed; this is the
28467
+ * condition, and it stays true until some later rotation re-keys the rows. It
28468
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
28469
+ * including for a rotation run from the CLI, which no dashboard render saw.
28470
+ *
28471
+ * `<>` rather than `<`: a row ahead of the current version is equally
28472
+ * unmatchable, and that is reachable — a key file restored from a backup, or
28473
+ * replaced after being lost, leaves rows stamped higher than the key is.
28474
+ *
28475
+ * Both numbers come from ONE statement, which is why this returns a pair
28476
+ * instead of offering two counts to call. Read separately, a purge landing
28477
+ * between them hands back a `stale` counted over rows the later `total` no
28478
+ * longer includes, and a disclosure built from that pair states a fraction
28479
+ * true of no state of the table — "1 of 0 stored values", or a negative
28480
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
28481
+ * delete rather than from a `countEntries` standing beside it.
28482
+ */
28483
+ countFingerprintEpochs(currentVersion) {
28484
+ const row = getRow(
28485
+ this.db.prepare(
28486
+ `SELECT COUNT(*) AS total,
28487
+ COALESCE(
28488
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
28489
+ 0
28490
+ ) AS stale
28491
+ FROM secret_vault`
28492
+ ),
28493
+ { currentVersion }
28494
+ ) ?? { stale: 0, total: 0 };
28495
+ return { stale: row.stale, total: row.total };
28496
+ }
28421
28497
  };
28422
28498
 
28423
28499
  // ../../packages/persistence/src/repositories/security.ts
@@ -30274,13 +30350,22 @@ var SecretVault = class {
30274
30350
  * fingerprint collides with a row already refreshed, is skipped rather than
30275
30351
  * aborting the pass — one damaged entry must not strand the re-key of every
30276
30352
  * other. A skipped row keeps resolving under its old fingerprint epoch.
30353
+ *
30354
+ * Every skip is COUNTED, because best-effort and silent are different things:
30355
+ * the loss above is invisible at the moment it happens and only shows up later
30356
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
30357
+ * than a bare success count.
30277
30358
  */
30278
30359
  async refreshFingerprints(next) {
30279
30360
  let refreshed = 0;
30361
+ let skipped = 0;
30280
30362
  for (const row of this.#repo.listAll()) {
30281
30363
  try {
30282
30364
  const raw = await this.#openRow(row);
30283
- if (raw === null) continue;
30365
+ if (raw === null) {
30366
+ skipped += 1;
30367
+ continue;
30368
+ }
30284
30369
  this.#repo.refreshFingerprint(row.pointerId, {
30285
30370
  valueFingerprint: exactFingerprintValue(next, raw),
30286
30371
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -30288,10 +30373,10 @@ var SecretVault = class {
30288
30373
  });
30289
30374
  refreshed += 1;
30290
30375
  } catch {
30291
- continue;
30376
+ skipped += 1;
30292
30377
  }
30293
30378
  }
30294
- return refreshed;
30379
+ return { refreshed, skipped };
30295
30380
  }
30296
30381
  /**
30297
30382
  * Destroy every entry, making all outstanding pointers permanently
@@ -31218,6 +31303,7 @@ function createIsolatedScanner(data, opts = {}) {
31218
31303
  text,
31219
31304
  filePath: context?.filePath,
31220
31305
  eventKind: context?.eventKind,
31306
+ writtenRegions: context?.writtenRegions,
31221
31307
  attribute: scanOpts?.attribute === true
31222
31308
  }),
31223
31309
  reply: (message) => {
@@ -31955,7 +32041,8 @@ function createPluginRuntime(gateway, settings, opts) {
31955
32041
  input.text,
31956
32042
  {
31957
32043
  filePath: input.metadata?.filePath,
31958
- eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
32044
+ eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
32045
+ writtenRegions: opts2.writtenRegions
31959
32046
  },
31960
32047
  {
31961
32048
  sourceTool: input.sourceTool,
@@ -13495,6 +13495,21 @@ function passesPostValidators(rule, value) {
13495
13495
  function getLoadedRules() {
13496
13496
  return [...packs.values()].flatMap((p) => p.rules);
13497
13497
  }
13498
+ function outsideWrittenRegions(candidates, context) {
13499
+ const regions = context?.writtenRegions;
13500
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
13501
+ return candidates.filter((c) => {
13502
+ if (c.rule.category !== "code_flaw") return true;
13503
+ const { start, end } = c.match.span;
13504
+ return !regions.some(
13505
+ (r) => r.start <= start && end <= r.end && ruleApplies(
13506
+ c.rule,
13507
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
13508
+ "code_change"
13509
+ )
13510
+ );
13511
+ });
13512
+ }
13498
13513
  function spansOverlap(a, b) {
13499
13514
  return a.start < b.end && a.end > b.start;
13500
13515
  }
@@ -13682,17 +13697,20 @@ function scanEncoded(text, ruleset2, context) {
13682
13697
  function scanText(text, ruleset2, context) {
13683
13698
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
13684
13699
  const normalization = normalizeFormatChars(text);
13685
- const originalCandidates = buildCandidates(text, ruleset2, extension, context?.eventKind);
13700
+ const originalCandidates = outsideWrittenRegions(
13701
+ buildCandidates(text, ruleset2, extension, context?.eventKind),
13702
+ context
13703
+ );
13686
13704
  if (!normalization) return gate(originalCandidates, text, void 0);
13687
13705
  const pooledOriginal = originalCandidates.map(
13688
13706
  (candidate) => withNormalizedSpan(candidate, normalization)
13689
13707
  );
13690
- const normalizedCandidates = buildCandidates(
13691
- normalization.normalized,
13692
- ruleset2,
13693
- extension,
13694
- context?.eventKind
13695
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
13708
+ const normalizedCandidates = outsideWrittenRegions(
13709
+ buildCandidates(normalization.normalized, ruleset2, extension, context?.eventKind).map(
13710
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
13711
+ ),
13712
+ context
13713
+ );
13696
13714
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
13697
13715
  return mergeOverlappingSameRule(findings, text);
13698
13716
  }
@@ -14015,6 +14033,21 @@ var ruleset = [...verified, ...unverified];
14015
14033
  function post(message) {
14016
14034
  port.postMessage(message);
14017
14035
  }
14036
+ var MAX_REGIONS = 64;
14037
+ function validRegions(value, length) {
14038
+ if (!Array.isArray(value) || value.length === 0 || value.length > MAX_REGIONS) return void 0;
14039
+ let previousEnd = 0;
14040
+ for (const region of value) {
14041
+ if (typeof region !== "object" || region === null) return void 0;
14042
+ const { start, end, filePath } = region;
14043
+ if (filePath !== void 0 && typeof filePath !== "string") return void 0;
14044
+ if (typeof start !== "number" || typeof end !== "number") return void 0;
14045
+ if (!Number.isInteger(start) || !Number.isInteger(end)) return void 0;
14046
+ if (start < previousEnd || start >= end || end > length) return void 0;
14047
+ previousEnd = end;
14048
+ }
14049
+ return value;
14050
+ }
14018
14051
  port.on("message", (job) => {
14019
14052
  try {
14020
14053
  if (job.kind === "probe") {
@@ -14030,7 +14063,8 @@ port.on("message", (job) => {
14030
14063
  });
14031
14064
  return;
14032
14065
  }
14033
- const context = job.filePath === void 0 && job.eventKind === void 0 ? void 0 : { filePath: job.filePath, eventKind: job.eventKind };
14066
+ const writtenRegions = validRegions(job.writtenRegions, job.text.length);
14067
+ const context = job.filePath === void 0 && job.eventKind === void 0 && writtenRegions === void 0 ? void 0 : { filePath: job.filePath, eventKind: job.eventKind, writtenRegions };
14034
14068
  if (job.attribute) {
14035
14069
  for (const [index, rule] of unverified.entries()) {
14036
14070
  post({ kind: "progress", index });