@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.
@@ -15115,6 +15115,21 @@ function registerPack(pack) {
15115
15115
  function getLoadedRules() {
15116
15116
  return [...packs.values()].flatMap((p) => p.rules);
15117
15117
  }
15118
+ function outsideWrittenRegions(candidates, context) {
15119
+ const regions = context?.writtenRegions;
15120
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
15121
+ return candidates.filter((c) => {
15122
+ if (c.rule.category !== "code_flaw") return true;
15123
+ const { start, end } = c.match.span;
15124
+ return !regions.some(
15125
+ (r) => r.start <= start && end <= r.end && ruleApplies(
15126
+ c.rule,
15127
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
15128
+ "code_change"
15129
+ )
15130
+ );
15131
+ });
15132
+ }
15118
15133
  function spansOverlap(a, b) {
15119
15134
  return a.start < b.end && a.end > b.start;
15120
15135
  }
@@ -15302,17 +15317,20 @@ function scanEncoded(text2, ruleset, context) {
15302
15317
  function scanText(text2, ruleset, context) {
15303
15318
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
15304
15319
  const normalization = normalizeFormatChars(text2);
15305
- const originalCandidates = buildCandidates(text2, ruleset, extension, context?.eventKind);
15320
+ const originalCandidates = outsideWrittenRegions(
15321
+ buildCandidates(text2, ruleset, extension, context?.eventKind),
15322
+ context
15323
+ );
15306
15324
  if (!normalization) return gate(originalCandidates, text2, void 0);
15307
15325
  const pooledOriginal = originalCandidates.map(
15308
15326
  (candidate) => withNormalizedSpan(candidate, normalization)
15309
15327
  );
15310
- const normalizedCandidates = buildCandidates(
15311
- normalization.normalized,
15312
- ruleset,
15313
- extension,
15314
- context?.eventKind
15315
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text2));
15328
+ const normalizedCandidates = outsideWrittenRegions(
15329
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
15330
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text2)
15331
+ ),
15332
+ context
15333
+ );
15316
15334
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text2, normalization);
15317
15335
  return mergeOverlappingSameRule(findings, text2);
15318
15336
  }
@@ -15373,6 +15391,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
15373
15391
  "code-flaws/sql-inject-concat-dot",
15374
15392
  "code-flaws/sql-inject-format",
15375
15393
  "code-flaws/sql-inject-interp",
15394
+ "code-flaws/sql-inject-interp-multiline",
15376
15395
  "code-flaws/ssrf-user-url",
15377
15396
  "code-flaws/xss-dangerously-set",
15378
15397
  "code-flaws/xss-inner-html",
@@ -16462,7 +16481,7 @@ var sql_inject_concat_dot_default = {
16462
16481
  severity: "high",
16463
16482
  matcher: {
16464
16483
  type: "regex",
16465
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
16484
+ 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*\\.",
16466
16485
  flags: "gi"
16467
16486
  },
16468
16487
  appliesTo: {
@@ -16480,7 +16499,7 @@ var sql_inject_concat_default = {
16480
16499
  severity: "high",
16481
16500
  matcher: {
16482
16501
  type: "regex",
16483
- 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*\\+`,
16502
+ 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*\\+",
16484
16503
  flags: "gi"
16485
16504
  },
16486
16505
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -16495,7 +16514,7 @@ var sql_inject_format_default = {
16495
16514
  severity: "high",
16496
16515
  matcher: {
16497
16516
  type: "regex",
16498
- 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]+\\})`,
16517
+ 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]+\\})",
16499
16518
  flags: "gi"
16500
16519
  },
16501
16520
  examples: [
@@ -16504,6 +16523,24 @@ var sql_inject_format_default = {
16504
16523
  ]
16505
16524
  };
16506
16525
 
16526
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
16527
+ var sql_inject_interp_multiline_default = {
16528
+ specVersion: 1,
16529
+ id: "code-flaws/sql-inject-interp-multiline",
16530
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
16531
+ category: "code_flaw",
16532
+ severity: "high",
16533
+ matcher: {
16534
+ type: "regex",
16535
+ 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_])',
16536
+ flags: "gi"
16537
+ },
16538
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
16539
+ appliesTo: {
16540
+ extensions: [".rb", ".php"]
16541
+ }
16542
+ };
16543
+
16507
16544
  // ../../rules/code-flaws/sql-inject-interp.json
16508
16545
  var sql_inject_interp_default = {
16509
16546
  specVersion: 1,
@@ -16513,7 +16550,7 @@ var sql_inject_interp_default = {
16513
16550
  severity: "high",
16514
16551
  matcher: {
16515
16552
  type: "regex",
16516
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
16553
+ 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_])',
16517
16554
  flags: "gi"
16518
16555
  },
16519
16556
  examples: [
@@ -18241,12 +18278,13 @@ var BUNDLED_PACKS = [
18241
18278
  {
18242
18279
  packId: "code-flaws",
18243
18280
  name: "Code Security Flaws",
18244
- version: "0.1.3",
18281
+ version: "0.1.6",
18245
18282
  rawRules: [
18246
18283
  sql_inject_concat_default,
18247
18284
  sql_inject_concat_dot_default,
18248
18285
  sql_inject_format_default,
18249
18286
  sql_inject_interp_default,
18287
+ sql_inject_interp_multiline_default,
18250
18288
  cmd_inject_shell_default,
18251
18289
  cmd_inject_exec_default,
18252
18290
  cmd_inject_node_exec_default,
@@ -18278,6 +18316,7 @@ var BUNDLED_PACKS = [
18278
18316
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
18279
18317
  "code-flaws/sql-inject-format": "SQL injection (format string)",
18280
18318
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
18319
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
18281
18320
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
18282
18321
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
18283
18322
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -28364,6 +28403,43 @@ var SqliteSecretVaultRepository = class {
28364
28403
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
28365
28404
  );
28366
28405
  }
28406
+ /**
28407
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
28408
+ * standing record of a fingerprint-key rotation whose re-key did not reach
28409
+ * every row.
28410
+ *
28411
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
28412
+ * once. That count is an event, gone the moment it is printed; this is the
28413
+ * condition, and it stays true until some later rotation re-keys the rows. It
28414
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
28415
+ * including for a rotation run from the CLI, which no dashboard render saw.
28416
+ *
28417
+ * `<>` rather than `<`: a row ahead of the current version is equally
28418
+ * unmatchable, and that is reachable — a key file restored from a backup, or
28419
+ * replaced after being lost, leaves rows stamped higher than the key is.
28420
+ *
28421
+ * Both numbers come from ONE statement, which is why this returns a pair
28422
+ * instead of offering two counts to call. Read separately, a purge landing
28423
+ * between them hands back a `stale` counted over rows the later `total` no
28424
+ * longer includes, and a disclosure built from that pair states a fraction
28425
+ * true of no state of the table — "1 of 0 stored values", or a negative
28426
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
28427
+ * delete rather than from a `countEntries` standing beside it.
28428
+ */
28429
+ countFingerprintEpochs(currentVersion) {
28430
+ const row = getRow(
28431
+ this.db.prepare(
28432
+ `SELECT COUNT(*) AS total,
28433
+ COALESCE(
28434
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
28435
+ 0
28436
+ ) AS stale
28437
+ FROM secret_vault`
28438
+ ),
28439
+ { currentVersion }
28440
+ ) ?? { stale: 0, total: 0 };
28441
+ return { stale: row.stale, total: row.total };
28442
+ }
28367
28443
  };
28368
28444
 
28369
28445
  // ../../packages/persistence/src/repositories/security.ts
@@ -30086,13 +30162,22 @@ var SecretVault = class {
30086
30162
  * fingerprint collides with a row already refreshed, is skipped rather than
30087
30163
  * aborting the pass — one damaged entry must not strand the re-key of every
30088
30164
  * other. A skipped row keeps resolving under its old fingerprint epoch.
30165
+ *
30166
+ * Every skip is COUNTED, because best-effort and silent are different things:
30167
+ * the loss above is invisible at the moment it happens and only shows up later
30168
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
30169
+ * than a bare success count.
30089
30170
  */
30090
30171
  async refreshFingerprints(next) {
30091
30172
  let refreshed = 0;
30173
+ let skipped = 0;
30092
30174
  for (const row of this.#repo.listAll()) {
30093
30175
  try {
30094
30176
  const raw = await this.#openRow(row);
30095
- if (raw === null) continue;
30177
+ if (raw === null) {
30178
+ skipped += 1;
30179
+ continue;
30180
+ }
30096
30181
  this.#repo.refreshFingerprint(row.pointerId, {
30097
30182
  valueFingerprint: exactFingerprintValue(next, raw),
30098
30183
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -30100,10 +30185,10 @@ var SecretVault = class {
30100
30185
  });
30101
30186
  refreshed += 1;
30102
30187
  } catch {
30103
- continue;
30188
+ skipped += 1;
30104
30189
  }
30105
30190
  }
30106
- return refreshed;
30191
+ return { refreshed, skipped };
30107
30192
  }
30108
30193
  /**
30109
30194
  * Destroy every entry, making all outstanding pointers permanently
@@ -31062,6 +31147,7 @@ function createIsolatedScanner(data, opts = {}) {
31062
31147
  text: text2,
31063
31148
  filePath: context?.filePath,
31064
31149
  eventKind: context?.eventKind,
31150
+ writtenRegions: context?.writtenRegions,
31065
31151
  attribute: scanOpts?.attribute === true
31066
31152
  }),
31067
31153
  reply: (message) => {
@@ -23709,6 +23709,43 @@ var SqliteSecretVaultRepository = class {
23709
23709
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
23710
23710
  );
23711
23711
  }
23712
+ /**
23713
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
23714
+ * standing record of a fingerprint-key rotation whose re-key did not reach
23715
+ * every row.
23716
+ *
23717
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
23718
+ * once. That count is an event, gone the moment it is printed; this is the
23719
+ * condition, and it stays true until some later rotation re-keys the rows. It
23720
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
23721
+ * including for a rotation run from the CLI, which no dashboard render saw.
23722
+ *
23723
+ * `<>` rather than `<`: a row ahead of the current version is equally
23724
+ * unmatchable, and that is reachable — a key file restored from a backup, or
23725
+ * replaced after being lost, leaves rows stamped higher than the key is.
23726
+ *
23727
+ * Both numbers come from ONE statement, which is why this returns a pair
23728
+ * instead of offering two counts to call. Read separately, a purge landing
23729
+ * between them hands back a `stale` counted over rows the later `total` no
23730
+ * longer includes, and a disclosure built from that pair states a fraction
23731
+ * true of no state of the table — "1 of 0 stored values", or a negative
23732
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
23733
+ * delete rather than from a `countEntries` standing beside it.
23734
+ */
23735
+ countFingerprintEpochs(currentVersion) {
23736
+ const row = getRow(
23737
+ this.db.prepare(
23738
+ `SELECT COUNT(*) AS total,
23739
+ COALESCE(
23740
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
23741
+ 0
23742
+ ) AS stale
23743
+ FROM secret_vault`
23744
+ ),
23745
+ { currentVersion }
23746
+ ) ?? { stale: 0, total: 0 };
23747
+ return { stale: row.stale, total: row.total };
23748
+ }
23712
23749
  };
23713
23750
 
23714
23751
  // ../../packages/persistence/src/repositories/security.ts
@@ -25518,13 +25555,22 @@ var SecretVault = class {
25518
25555
  * fingerprint collides with a row already refreshed, is skipped rather than
25519
25556
  * aborting the pass — one damaged entry must not strand the re-key of every
25520
25557
  * other. A skipped row keeps resolving under its old fingerprint epoch.
25558
+ *
25559
+ * Every skip is COUNTED, because best-effort and silent are different things:
25560
+ * the loss above is invisible at the moment it happens and only shows up later
25561
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
25562
+ * than a bare success count.
25521
25563
  */
25522
25564
  async refreshFingerprints(next) {
25523
25565
  let refreshed = 0;
25566
+ let skipped = 0;
25524
25567
  for (const row of this.#repo.listAll()) {
25525
25568
  try {
25526
25569
  const raw = await this.#openRow(row);
25527
- if (raw === null) continue;
25570
+ if (raw === null) {
25571
+ skipped += 1;
25572
+ continue;
25573
+ }
25528
25574
  this.#repo.refreshFingerprint(row.pointerId, {
25529
25575
  valueFingerprint: exactFingerprintValue(next, raw),
25530
25576
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -25532,10 +25578,10 @@ var SecretVault = class {
25532
25578
  });
25533
25579
  refreshed += 1;
25534
25580
  } catch {
25535
- continue;
25581
+ skipped += 1;
25536
25582
  }
25537
25583
  }
25538
- return refreshed;
25584
+ return { refreshed, skipped };
25539
25585
  }
25540
25586
  /**
25541
25587
  * Destroy every entry, making all outstanding pointers permanently
@@ -26874,6 +26920,21 @@ function registerPack(pack) {
26874
26920
  function getLoadedRules() {
26875
26921
  return [...packs.values()].flatMap((p) => p.rules);
26876
26922
  }
26923
+ function outsideWrittenRegions(candidates, context) {
26924
+ const regions = context?.writtenRegions;
26925
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
26926
+ return candidates.filter((c) => {
26927
+ if (c.rule.category !== "code_flaw") return true;
26928
+ const { start, end } = c.match.span;
26929
+ return !regions.some(
26930
+ (r) => r.start <= start && end <= r.end && ruleApplies(
26931
+ c.rule,
26932
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
26933
+ "code_change"
26934
+ )
26935
+ );
26936
+ });
26937
+ }
26877
26938
  function spansOverlap(a, b) {
26878
26939
  return a.start < b.end && a.end > b.start;
26879
26940
  }
@@ -27061,17 +27122,20 @@ function scanEncoded(text, ruleset, context) {
27061
27122
  function scanText(text, ruleset, context) {
27062
27123
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
27063
27124
  const normalization = normalizeFormatChars(text);
27064
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
27125
+ const originalCandidates = outsideWrittenRegions(
27126
+ buildCandidates(text, ruleset, extension, context?.eventKind),
27127
+ context
27128
+ );
27065
27129
  if (!normalization) return gate(originalCandidates, text, void 0);
27066
27130
  const pooledOriginal = originalCandidates.map(
27067
27131
  (candidate) => withNormalizedSpan(candidate, normalization)
27068
27132
  );
27069
- const normalizedCandidates = buildCandidates(
27070
- normalization.normalized,
27071
- ruleset,
27072
- extension,
27073
- context?.eventKind
27074
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
27133
+ const normalizedCandidates = outsideWrittenRegions(
27134
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
27135
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
27136
+ ),
27137
+ context
27138
+ );
27075
27139
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
27076
27140
  return mergeOverlappingSameRule(findings, text);
27077
27141
  }
@@ -27132,6 +27196,7 @@ var BUNDLED_CODE_EVIDENCE = /* @__PURE__ */ new Set([
27132
27196
  "code-flaws/sql-inject-concat-dot",
27133
27197
  "code-flaws/sql-inject-format",
27134
27198
  "code-flaws/sql-inject-interp",
27199
+ "code-flaws/sql-inject-interp-multiline",
27135
27200
  "code-flaws/ssrf-user-url",
27136
27201
  "code-flaws/xss-dangerously-set",
27137
27202
  "code-flaws/xss-inner-html",
@@ -28270,7 +28335,7 @@ var sql_inject_concat_dot_default = {
28270
28335
  severity: "high",
28271
28336
  matcher: {
28272
28337
  type: "regex",
28273
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
28338
+ 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*\\.",
28274
28339
  flags: "gi"
28275
28340
  },
28276
28341
  appliesTo: {
@@ -28288,7 +28353,7 @@ var sql_inject_concat_default = {
28288
28353
  severity: "high",
28289
28354
  matcher: {
28290
28355
  type: "regex",
28291
- 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*\\+`,
28356
+ 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*\\+",
28292
28357
  flags: "gi"
28293
28358
  },
28294
28359
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -28303,7 +28368,7 @@ var sql_inject_format_default = {
28303
28368
  severity: "high",
28304
28369
  matcher: {
28305
28370
  type: "regex",
28306
- 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]+\\})`,
28371
+ 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]+\\})",
28307
28372
  flags: "gi"
28308
28373
  },
28309
28374
  examples: [
@@ -28312,6 +28377,24 @@ var sql_inject_format_default = {
28312
28377
  ]
28313
28378
  };
28314
28379
 
28380
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
28381
+ var sql_inject_interp_multiline_default = {
28382
+ specVersion: 1,
28383
+ id: "code-flaws/sql-inject-interp-multiline",
28384
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
28385
+ category: "code_flaw",
28386
+ severity: "high",
28387
+ matcher: {
28388
+ type: "regex",
28389
+ 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_])',
28390
+ flags: "gi"
28391
+ },
28392
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
28393
+ appliesTo: {
28394
+ extensions: [".rb", ".php"]
28395
+ }
28396
+ };
28397
+
28315
28398
  // ../../rules/code-flaws/sql-inject-interp.json
28316
28399
  var sql_inject_interp_default = {
28317
28400
  specVersion: 1,
@@ -28321,7 +28404,7 @@ var sql_inject_interp_default = {
28321
28404
  severity: "high",
28322
28405
  matcher: {
28323
28406
  type: "regex",
28324
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
28407
+ 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_])',
28325
28408
  flags: "gi"
28326
28409
  },
28327
28410
  examples: [
@@ -30049,12 +30132,13 @@ var BUNDLED_PACKS = [
30049
30132
  {
30050
30133
  packId: "code-flaws",
30051
30134
  name: "Code Security Flaws",
30052
- version: "0.1.3",
30135
+ version: "0.1.6",
30053
30136
  rawRules: [
30054
30137
  sql_inject_concat_default,
30055
30138
  sql_inject_concat_dot_default,
30056
30139
  sql_inject_format_default,
30057
30140
  sql_inject_interp_default,
30141
+ sql_inject_interp_multiline_default,
30058
30142
  cmd_inject_shell_default,
30059
30143
  cmd_inject_exec_default,
30060
30144
  cmd_inject_node_exec_default,
@@ -30086,6 +30170,7 @@ var BUNDLED_PACKS = [
30086
30170
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
30087
30171
  "code-flaws/sql-inject-format": "SQL injection (format string)",
30088
30172
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
30173
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
30089
30174
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
30090
30175
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
30091
30176
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -31165,6 +31250,7 @@ function createIsolatedScanner(data, opts = {}) {
31165
31250
  text,
31166
31251
  filePath: context?.filePath,
31167
31252
  eventKind: context?.eventKind,
31253
+ writtenRegions: context?.writtenRegions,
31168
31254
  attribute: scanOpts?.attribute === true
31169
31255
  }),
31170
31256
  reply: (message) => {
@@ -31912,7 +31998,8 @@ function createPluginRuntime(gateway, settings, opts) {
31912
31998
  input.text,
31913
31999
  {
31914
32000
  filePath: input.metadata?.filePath,
31915
- eventKind: opts2.kindScopedRules === false ? void 0 : input.kind
32001
+ eventKind: opts2.kindScopedRules === false ? void 0 : input.kind,
32002
+ writtenRegions: opts2.writtenRegions
31916
32003
  },
31917
32004
  {
31918
32005
  sourceTool: input.sourceTool,
@@ -35944,6 +36031,7 @@ var DAY_MS5 = 24 * 60 * 60 * 1e3;
35944
36031
 
35945
36032
  // src/remediation/redact.ts
35946
36033
  import {
36034
+ chmodSync as chmodSync4,
35947
36035
  lstatSync as lstatSync6,
35948
36036
  readdirSync as readdirSync5,
35949
36037
  readFileSync as readFileSync27,
@@ -36000,9 +36088,11 @@ function sweepStrandedTemps(realPath) {
36000
36088
  for (const name of names) {
36001
36089
  if (!name.startsWith(prefix) || !name.endsWith(TMP_SUFFIX)) continue;
36002
36090
  const pidPart = name.slice(prefix.length, name.length - TMP_SUFFIX.length);
36003
- if (!/^\d+$/.test(pidPart)) continue;
36004
- const pid = Number(pidPart);
36005
- if (pid !== process.pid && isProcessAlive(pid)) continue;
36091
+ if (pidPart !== "") {
36092
+ if (!/^\d+$/.test(pidPart)) continue;
36093
+ const pid = Number(pidPart);
36094
+ if (pid !== process.pid && isProcessAlive(pid)) continue;
36095
+ }
36006
36096
  try {
36007
36097
  const stranded = join40(dir, name);
36008
36098
  if (!lstatSync6(stranded).isFile()) continue;
@@ -36049,6 +36139,7 @@ function redactLeakedKeysDetailed(targets, scope = platformRedactionScope()) {
36049
36139
  const tmpPath = tempPathFor(filePath);
36050
36140
  try {
36051
36141
  writeFileSync7(tmpPath, content, { mode, flag: "wx" });
36142
+ chmodSync4(tmpPath, mode);
36052
36143
  renameSync5(tmpPath, filePath);
36053
36144
  } catch {
36054
36145
  try {
@@ -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 });