@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.
@@ -15129,6 +15129,21 @@ function registerPack(pack) {
15129
15129
  function getLoadedRules() {
15130
15130
  return [...packs.values()].flatMap((p) => p.rules);
15131
15131
  }
15132
+ function outsideWrittenRegions(candidates, context) {
15133
+ const regions = context?.writtenRegions;
15134
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
15135
+ return candidates.filter((c) => {
15136
+ if (c.rule.category !== "code_flaw") return true;
15137
+ const { start, end } = c.match.span;
15138
+ return !regions.some(
15139
+ (r) => r.start <= start && end <= r.end && ruleApplies(
15140
+ c.rule,
15141
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
15142
+ "code_change"
15143
+ )
15144
+ );
15145
+ });
15146
+ }
15132
15147
  function spansOverlap(a, b) {
15133
15148
  return a.start < b.end && a.end > b.start;
15134
15149
  }
@@ -15316,17 +15331,20 @@ function scanEncoded(text2, ruleset, context) {
15316
15331
  function scanText(text2, ruleset, context) {
15317
15332
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
15318
15333
  const normalization = normalizeFormatChars(text2);
15319
- const originalCandidates = buildCandidates(text2, ruleset, extension, context?.eventKind);
15334
+ const originalCandidates = outsideWrittenRegions(
15335
+ buildCandidates(text2, ruleset, extension, context?.eventKind),
15336
+ context
15337
+ );
15320
15338
  if (!normalization) return gate(originalCandidates, text2, void 0);
15321
15339
  const pooledOriginal = originalCandidates.map(
15322
15340
  (candidate) => withNormalizedSpan(candidate, normalization)
15323
15341
  );
15324
- const normalizedCandidates = buildCandidates(
15325
- normalization.normalized,
15326
- ruleset,
15327
- extension,
15328
- context?.eventKind
15329
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text2));
15342
+ const normalizedCandidates = outsideWrittenRegions(
15343
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
15344
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text2)
15345
+ ),
15346
+ context
15347
+ );
15330
15348
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text2, normalization);
15331
15349
  return mergeOverlappingSameRule(findings, text2);
15332
15350
  }
@@ -15387,6 +15405,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
15387
15405
  "code-flaws/sql-inject-concat-dot",
15388
15406
  "code-flaws/sql-inject-format",
15389
15407
  "code-flaws/sql-inject-interp",
15408
+ "code-flaws/sql-inject-interp-multiline",
15390
15409
  "code-flaws/ssrf-user-url",
15391
15410
  "code-flaws/xss-dangerously-set",
15392
15411
  "code-flaws/xss-inner-html",
@@ -16525,7 +16544,7 @@ var sql_inject_concat_dot_default = {
16525
16544
  severity: "high",
16526
16545
  matcher: {
16527
16546
  type: "regex",
16528
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
16547
+ 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*\\.",
16529
16548
  flags: "gi"
16530
16549
  },
16531
16550
  appliesTo: {
@@ -16543,7 +16562,7 @@ var sql_inject_concat_default = {
16543
16562
  severity: "high",
16544
16563
  matcher: {
16545
16564
  type: "regex",
16546
- 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*\\+`,
16565
+ 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*\\+",
16547
16566
  flags: "gi"
16548
16567
  },
16549
16568
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -16558,7 +16577,7 @@ var sql_inject_format_default = {
16558
16577
  severity: "high",
16559
16578
  matcher: {
16560
16579
  type: "regex",
16561
- 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]+\\})`,
16580
+ 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]+\\})",
16562
16581
  flags: "gi"
16563
16582
  },
16564
16583
  examples: [
@@ -16567,6 +16586,24 @@ var sql_inject_format_default = {
16567
16586
  ]
16568
16587
  };
16569
16588
 
16589
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
16590
+ var sql_inject_interp_multiline_default = {
16591
+ specVersion: 1,
16592
+ id: "code-flaws/sql-inject-interp-multiline",
16593
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
16594
+ category: "code_flaw",
16595
+ severity: "high",
16596
+ matcher: {
16597
+ type: "regex",
16598
+ 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_])',
16599
+ flags: "gi"
16600
+ },
16601
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
16602
+ appliesTo: {
16603
+ extensions: [".rb", ".php"]
16604
+ }
16605
+ };
16606
+
16570
16607
  // ../../rules/code-flaws/sql-inject-interp.json
16571
16608
  var sql_inject_interp_default = {
16572
16609
  specVersion: 1,
@@ -16576,7 +16613,7 @@ var sql_inject_interp_default = {
16576
16613
  severity: "high",
16577
16614
  matcher: {
16578
16615
  type: "regex",
16579
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
16616
+ 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_])',
16580
16617
  flags: "gi"
16581
16618
  },
16582
16619
  examples: [
@@ -18304,12 +18341,13 @@ var BUNDLED_PACKS = [
18304
18341
  {
18305
18342
  packId: "code-flaws",
18306
18343
  name: "Code Security Flaws",
18307
- version: "0.1.3",
18344
+ version: "0.1.6",
18308
18345
  rawRules: [
18309
18346
  sql_inject_concat_default,
18310
18347
  sql_inject_concat_dot_default,
18311
18348
  sql_inject_format_default,
18312
18349
  sql_inject_interp_default,
18350
+ sql_inject_interp_multiline_default,
18313
18351
  cmd_inject_shell_default,
18314
18352
  cmd_inject_exec_default,
18315
18353
  cmd_inject_node_exec_default,
@@ -18341,6 +18379,7 @@ var BUNDLED_PACKS = [
18341
18379
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
18342
18380
  "code-flaws/sql-inject-format": "SQL injection (format string)",
18343
18381
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
18382
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
18344
18383
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
18345
18384
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
18346
18385
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -28442,6 +28481,43 @@ var SqliteSecretVaultRepository = class {
28442
28481
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
28443
28482
  );
28444
28483
  }
28484
+ /**
28485
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
28486
+ * standing record of a fingerprint-key rotation whose re-key did not reach
28487
+ * every row.
28488
+ *
28489
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
28490
+ * once. That count is an event, gone the moment it is printed; this is the
28491
+ * condition, and it stays true until some later rotation re-keys the rows. It
28492
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
28493
+ * including for a rotation run from the CLI, which no dashboard render saw.
28494
+ *
28495
+ * `<>` rather than `<`: a row ahead of the current version is equally
28496
+ * unmatchable, and that is reachable — a key file restored from a backup, or
28497
+ * replaced after being lost, leaves rows stamped higher than the key is.
28498
+ *
28499
+ * Both numbers come from ONE statement, which is why this returns a pair
28500
+ * instead of offering two counts to call. Read separately, a purge landing
28501
+ * between them hands back a `stale` counted over rows the later `total` no
28502
+ * longer includes, and a disclosure built from that pair states a fraction
28503
+ * true of no state of the table — "1 of 0 stored values", or a negative
28504
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
28505
+ * delete rather than from a `countEntries` standing beside it.
28506
+ */
28507
+ countFingerprintEpochs(currentVersion) {
28508
+ const row = getRow(
28509
+ this.db.prepare(
28510
+ `SELECT COUNT(*) AS total,
28511
+ COALESCE(
28512
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
28513
+ 0
28514
+ ) AS stale
28515
+ FROM secret_vault`
28516
+ ),
28517
+ { currentVersion }
28518
+ ) ?? { stale: 0, total: 0 };
28519
+ return { stale: row.stale, total: row.total };
28520
+ }
28445
28521
  };
28446
28522
 
28447
28523
  // ../../packages/persistence/src/repositories/security.ts
@@ -30308,13 +30384,22 @@ var SecretVault = class {
30308
30384
  * fingerprint collides with a row already refreshed, is skipped rather than
30309
30385
  * aborting the pass — one damaged entry must not strand the re-key of every
30310
30386
  * other. A skipped row keeps resolving under its old fingerprint epoch.
30387
+ *
30388
+ * Every skip is COUNTED, because best-effort and silent are different things:
30389
+ * the loss above is invisible at the moment it happens and only shows up later
30390
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
30391
+ * than a bare success count.
30311
30392
  */
30312
30393
  async refreshFingerprints(next) {
30313
30394
  let refreshed = 0;
30395
+ let skipped = 0;
30314
30396
  for (const row of this.#repo.listAll()) {
30315
30397
  try {
30316
30398
  const raw = await this.#openRow(row);
30317
- if (raw === null) continue;
30399
+ if (raw === null) {
30400
+ skipped += 1;
30401
+ continue;
30402
+ }
30318
30403
  this.#repo.refreshFingerprint(row.pointerId, {
30319
30404
  valueFingerprint: exactFingerprintValue(next, raw),
30320
30405
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -30322,10 +30407,10 @@ var SecretVault = class {
30322
30407
  });
30323
30408
  refreshed += 1;
30324
30409
  } catch {
30325
- continue;
30410
+ skipped += 1;
30326
30411
  }
30327
30412
  }
30328
- return refreshed;
30413
+ return { refreshed, skipped };
30329
30414
  }
30330
30415
  /**
30331
30416
  * Destroy every entry, making all outstanding pointers permanently
@@ -31252,6 +31337,7 @@ function createIsolatedScanner(data, opts = {}) {
31252
31337
  text: text2,
31253
31338
  filePath: context?.filePath,
31254
31339
  eventKind: context?.eventKind,
31340
+ writtenRegions: context?.writtenRegions,
31255
31341
  attribute: scanOpts?.attribute === true
31256
31342
  }),
31257
31343
  reply: (message) => {
@@ -32065,7 +32151,8 @@ function createPluginRuntime(gateway, settings, opts) {
32065
32151
  input.text,
32066
32152
  {
32067
32153
  filePath: input.metadata?.filePath,
32068
- eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
32154
+ eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
32155
+ writtenRegions: opts2.writtenRegions
32069
32156
  },
32070
32157
  {
32071
32158
  sourceTool: input.sourceTool,
package/scripts/query.js CHANGED
@@ -23862,6 +23862,43 @@ var SqliteSecretVaultRepository = class {
23862
23862
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
23863
23863
  );
23864
23864
  }
23865
+ /**
23866
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
23867
+ * standing record of a fingerprint-key rotation whose re-key did not reach
23868
+ * every row.
23869
+ *
23870
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
23871
+ * once. That count is an event, gone the moment it is printed; this is the
23872
+ * condition, and it stays true until some later rotation re-keys the rows. It
23873
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
23874
+ * including for a rotation run from the CLI, which no dashboard render saw.
23875
+ *
23876
+ * `<>` rather than `<`: a row ahead of the current version is equally
23877
+ * unmatchable, and that is reachable — a key file restored from a backup, or
23878
+ * replaced after being lost, leaves rows stamped higher than the key is.
23879
+ *
23880
+ * Both numbers come from ONE statement, which is why this returns a pair
23881
+ * instead of offering two counts to call. Read separately, a purge landing
23882
+ * between them hands back a `stale` counted over rows the later `total` no
23883
+ * longer includes, and a disclosure built from that pair states a fraction
23884
+ * true of no state of the table — "1 of 0 stored values", or a negative
23885
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
23886
+ * delete rather than from a `countEntries` standing beside it.
23887
+ */
23888
+ countFingerprintEpochs(currentVersion) {
23889
+ const row = getRow(
23890
+ this.db.prepare(
23891
+ `SELECT COUNT(*) AS total,
23892
+ COALESCE(
23893
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
23894
+ 0
23895
+ ) AS stale
23896
+ FROM secret_vault`
23897
+ ),
23898
+ { currentVersion }
23899
+ ) ?? { stale: 0, total: 0 };
23900
+ return { stale: row.stale, total: row.total };
23901
+ }
23865
23902
  };
23866
23903
 
23867
23904
  // ../../packages/persistence/src/repositories/security.ts
@@ -25584,13 +25621,22 @@ var SecretVault = class {
25584
25621
  * fingerprint collides with a row already refreshed, is skipped rather than
25585
25622
  * aborting the pass — one damaged entry must not strand the re-key of every
25586
25623
  * other. A skipped row keeps resolving under its old fingerprint epoch.
25624
+ *
25625
+ * Every skip is COUNTED, because best-effort and silent are different things:
25626
+ * the loss above is invisible at the moment it happens and only shows up later
25627
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
25628
+ * than a bare success count.
25587
25629
  */
25588
25630
  async refreshFingerprints(next) {
25589
25631
  let refreshed = 0;
25632
+ let skipped = 0;
25590
25633
  for (const row of this.#repo.listAll()) {
25591
25634
  try {
25592
25635
  const raw = await this.#openRow(row);
25593
- if (raw === null) continue;
25636
+ if (raw === null) {
25637
+ skipped += 1;
25638
+ continue;
25639
+ }
25594
25640
  this.#repo.refreshFingerprint(row.pointerId, {
25595
25641
  valueFingerprint: exactFingerprintValue(next, raw),
25596
25642
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -25598,10 +25644,10 @@ var SecretVault = class {
25598
25644
  });
25599
25645
  refreshed += 1;
25600
25646
  } catch {
25601
- continue;
25647
+ skipped += 1;
25602
25648
  }
25603
25649
  }
25604
- return refreshed;
25650
+ return { refreshed, skipped };
25605
25651
  }
25606
25652
  /**
25607
25653
  * Destroy every entry, making all outstanding pointers permanently
@@ -26971,6 +27017,21 @@ function passesPostValidators(rule, value) {
26971
27017
  function getLoadedRules() {
26972
27018
  return [...packs.values()].flatMap((p) => p.rules);
26973
27019
  }
27020
+ function outsideWrittenRegions(candidates, context) {
27021
+ const regions = context?.writtenRegions;
27022
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
27023
+ return candidates.filter((c) => {
27024
+ if (c.rule.category !== "code_flaw") return true;
27025
+ const { start, end } = c.match.span;
27026
+ return !regions.some(
27027
+ (r) => r.start <= start && end <= r.end && ruleApplies(
27028
+ c.rule,
27029
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
27030
+ "code_change"
27031
+ )
27032
+ );
27033
+ });
27034
+ }
26974
27035
  function spansOverlap(a, b) {
26975
27036
  return a.start < b.end && a.end > b.start;
26976
27037
  }
@@ -27158,17 +27219,20 @@ function scanEncoded(text, ruleset, context) {
27158
27219
  function scanText(text, ruleset, context) {
27159
27220
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
27160
27221
  const normalization = normalizeFormatChars(text);
27161
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
27222
+ const originalCandidates = outsideWrittenRegions(
27223
+ buildCandidates(text, ruleset, extension, context?.eventKind),
27224
+ context
27225
+ );
27162
27226
  if (!normalization) return gate(originalCandidates, text, void 0);
27163
27227
  const pooledOriginal = originalCandidates.map(
27164
27228
  (candidate) => withNormalizedSpan(candidate, normalization)
27165
27229
  );
27166
- const normalizedCandidates = buildCandidates(
27167
- normalization.normalized,
27168
- ruleset,
27169
- extension,
27170
- context?.eventKind
27171
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
27230
+ const normalizedCandidates = outsideWrittenRegions(
27231
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
27232
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
27233
+ ),
27234
+ context
27235
+ );
27172
27236
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
27173
27237
  return mergeOverlappingSameRule(findings, text);
27174
27238
  }
@@ -28117,7 +28181,7 @@ var sql_inject_concat_dot_default = {
28117
28181
  severity: "high",
28118
28182
  matcher: {
28119
28183
  type: "regex",
28120
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
28184
+ 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*\\.",
28121
28185
  flags: "gi"
28122
28186
  },
28123
28187
  appliesTo: {
@@ -28135,7 +28199,7 @@ var sql_inject_concat_default = {
28135
28199
  severity: "high",
28136
28200
  matcher: {
28137
28201
  type: "regex",
28138
- 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*\\+`,
28202
+ 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*\\+",
28139
28203
  flags: "gi"
28140
28204
  },
28141
28205
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -28150,7 +28214,7 @@ var sql_inject_format_default = {
28150
28214
  severity: "high",
28151
28215
  matcher: {
28152
28216
  type: "regex",
28153
- 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]+\\})`,
28217
+ 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]+\\})",
28154
28218
  flags: "gi"
28155
28219
  },
28156
28220
  examples: [
@@ -28159,6 +28223,24 @@ var sql_inject_format_default = {
28159
28223
  ]
28160
28224
  };
28161
28225
 
28226
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
28227
+ var sql_inject_interp_multiline_default = {
28228
+ specVersion: 1,
28229
+ id: "code-flaws/sql-inject-interp-multiline",
28230
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
28231
+ category: "code_flaw",
28232
+ severity: "high",
28233
+ matcher: {
28234
+ type: "regex",
28235
+ 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_])',
28236
+ flags: "gi"
28237
+ },
28238
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
28239
+ appliesTo: {
28240
+ extensions: [".rb", ".php"]
28241
+ }
28242
+ };
28243
+
28162
28244
  // ../../rules/code-flaws/sql-inject-interp.json
28163
28245
  var sql_inject_interp_default = {
28164
28246
  specVersion: 1,
@@ -28168,7 +28250,7 @@ var sql_inject_interp_default = {
28168
28250
  severity: "high",
28169
28251
  matcher: {
28170
28252
  type: "regex",
28171
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
28253
+ 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_])',
28172
28254
  flags: "gi"
28173
28255
  },
28174
28256
  examples: [
@@ -29896,12 +29978,13 @@ var BUNDLED_PACKS = [
29896
29978
  {
29897
29979
  packId: "code-flaws",
29898
29980
  name: "Code Security Flaws",
29899
- version: "0.1.3",
29981
+ version: "0.1.6",
29900
29982
  rawRules: [
29901
29983
  sql_inject_concat_default,
29902
29984
  sql_inject_concat_dot_default,
29903
29985
  sql_inject_format_default,
29904
29986
  sql_inject_interp_default,
29987
+ sql_inject_interp_multiline_default,
29905
29988
  cmd_inject_shell_default,
29906
29989
  cmd_inject_exec_default,
29907
29990
  cmd_inject_node_exec_default,
@@ -29933,6 +30016,7 @@ var BUNDLED_PACKS = [
29933
30016
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
29934
30017
  "code-flaws/sql-inject-format": "SQL injection (format string)",
29935
30018
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
30019
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
29936
30020
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
29937
30021
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
29938
30022
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -30594,6 +30678,7 @@ function createIsolatedScanner(data, opts = {}) {
30594
30678
  text,
30595
30679
  filePath: context?.filePath,
30596
30680
  eventKind: context?.eventKind,
30681
+ writtenRegions: context?.writtenRegions,
30597
30682
  attribute: scanOpts?.attribute === true
30598
30683
  }),
30599
30684
  reply: (message) => {