@akasecurity/ai-tc-codex 0.9.22 → 0.9.24

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.
@@ -8763,7 +8763,11 @@ var ListFindingTypesQuery = object({
8763
8763
  // and so is not bounded by what any page happens to hold.
8764
8764
  includeId: string2().optional(),
8765
8765
  limit: coerce_exports.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
8766
- cursor: string2().optional()
8766
+ cursor: string2().optional(),
8767
+ // A row position to read from, for jumping to a page instead of stepping to
8768
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
8769
+ // from wherever it lands.
8770
+ offset: coerce_exports.number().int().min(0).optional()
8767
8771
  });
8768
8772
  var ListFindingTypesResponse = object({
8769
8773
  totals: object({
@@ -8844,7 +8848,11 @@ var ListFindingInstancesQuery = object({
8844
8848
  sessionId: string2().optional(),
8845
8849
  from: iso_exports.datetime().optional(),
8846
8850
  limit: coerce_exports.number().int().min(1).max(MAX_FLAT_FINDINGS_LIMIT).optional(),
8847
- cursor: string2().optional()
8851
+ cursor: string2().optional(),
8852
+ // A row position to read from, for jumping to a page instead of stepping to
8853
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
8854
+ // from wherever it lands.
8855
+ offset: coerce_exports.number().int().min(0).optional()
8848
8856
  });
8849
8857
  var ListFindingInstancesResponse = object({
8850
8858
  // Instances matching the filters across the whole scope, not just this
@@ -8916,7 +8924,11 @@ var ListFindingLocationsQuery = object({
8916
8924
  // rather than a deep-link corner. Never affects totals, facets or the cursor.
8917
8925
  includeId: string2().optional(),
8918
8926
  limit: coerce_exports.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
8919
- cursor: string2().optional()
8927
+ cursor: string2().optional(),
8928
+ // A row position to read from, for jumping to a page instead of stepping to
8929
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
8930
+ // from wherever it lands.
8931
+ offset: coerce_exports.number().int().min(0).optional()
8920
8932
  });
8921
8933
  var ListFindingLocationsResponse = object({
8922
8934
  totals: object({
@@ -11469,7 +11481,11 @@ var MAX_VAULT_PAGE_LIMIT = 200;
11469
11481
  var ListVaultInventoryQuery = object({
11470
11482
  limit: coerce_exports.number().int().min(1).max(MAX_VAULT_PAGE_LIMIT).optional(),
11471
11483
  // Opaque; names the last row of the page just served.
11472
- cursor: string2().optional()
11484
+ cursor: string2().optional(),
11485
+ // A row position to read from, for jumping to a page instead of stepping to
11486
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
11487
+ // from wherever it lands.
11488
+ offset: coerce_exports.number().int().min(0).optional()
11473
11489
  });
11474
11490
  var ListVaultInventoryResponse = object({
11475
11491
  // Vaulted values across the whole store, not just this page — cursor-
@@ -11481,7 +11497,11 @@ var ListVaultInventoryResponse = object({
11481
11497
  });
11482
11498
  var ListVaultReuseQuery = object({
11483
11499
  limit: coerce_exports.number().int().min(1).max(MAX_VAULT_PAGE_LIMIT).optional(),
11484
- cursor: string2().optional()
11500
+ cursor: string2().optional(),
11501
+ // A row position to read from, for jumping to a page instead of stepping to
11502
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
11503
+ // from wherever it lands.
11504
+ offset: coerce_exports.number().int().min(0).optional()
11485
11505
  });
11486
11506
  var ListVaultReuseResponse = object({
11487
11507
  // Reused values across the whole store — the number the section's claim
@@ -11497,9 +11517,15 @@ var ListVaultDerefsQuery = object({
11497
11517
  // over a Server Action, which preserves the type, never as a URL param.
11498
11518
  includeBatched: boolean2().optional(),
11499
11519
  limit: coerce_exports.number().int().min(1).max(MAX_VAULT_PAGE_LIMIT).optional(),
11500
- cursor: string2().optional()
11520
+ cursor: string2().optional(),
11521
+ // A row position to read from, for jumping to a page instead of stepping to
11522
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
11523
+ // from wherever it lands.
11524
+ offset: coerce_exports.number().int().min(0).optional()
11501
11525
  });
11502
11526
  var ListVaultDerefsResponse = object({
11527
+ // Rows this filter selects across the whole trail, not just this page.
11528
+ totals: object({ derefs: number2().int().nonnegative() }),
11503
11529
  items: array(VaultDeref),
11504
11530
  nextCursor: string2().nullable(),
11505
11531
  // Display/view-render rows the query hid, over the WHOLE trail rather than
@@ -19871,7 +19897,7 @@ var SqliteFindingsRepository = class {
19871
19897
  };
19872
19898
  const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
19873
19899
  const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
19874
- const start = cursor === null ? 0 : firstAfter(sorted, cursor);
19900
+ const start = query.offset ?? (cursor === null ? 0 : firstAfter(sorted, cursor));
19875
19901
  const page = sorted.slice(start, start + limit);
19876
19902
  const lastOnPage = page.at(-1);
19877
19903
  const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
@@ -19965,7 +19991,7 @@ var SqliteFindingsRepository = class {
19965
19991
  accumulator.add(row);
19966
19992
  if (!matchesInstanceFilters(row, opts)) continue;
19967
19993
  total += 1;
19968
- if (!isPastCursor(row)) continue;
19994
+ if (query.offset === void 0 ? !isPastCursor(row) : total <= query.offset) continue;
19969
19995
  if (items.length < limit) {
19970
19996
  items.push(toInstanceDetail(row));
19971
19997
  last = row;
@@ -20054,7 +20080,7 @@ var SqliteFindingsRepository = class {
20054
20080
  }
20055
20081
  }
20056
20082
  sorted.sort(compareLocationOrder);
20057
- const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
20083
+ const start = query.offset ?? (cursor === null ? 0 : firstLocationAfter(sorted, cursor));
20058
20084
  const page = sorted.slice(start, start + limit);
20059
20085
  const lastOnPage = page.at(-1);
20060
20086
  const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
@@ -22682,6 +22708,9 @@ function pageLimit(requested, fallback) {
22682
22708
  if (requested === void 0) return fallback;
22683
22709
  return Math.min(Math.max(1, Math.trunc(requested)), MAX_VAULT_PAGE_LIMIT);
22684
22710
  }
22711
+ function pageOffset(requested) {
22712
+ return requested === void 0 ? 0 : Math.max(0, Math.trunc(requested));
22713
+ }
22685
22714
  function encodeReuseCursor(payload) {
22686
22715
  return Buffer.from(JSON.stringify(payload)).toString("base64url");
22687
22716
  }
@@ -23029,7 +23058,8 @@ var SqliteSecretVaultRepository = class {
23029
23058
  */
23030
23059
  listInventory(query = {}, now = Date.now()) {
23031
23060
  const limit = pageLimit(query.limit, DEFAULT_VAULT_INVENTORY_LIMIT);
23032
- const cursor = query.cursor === void 0 ? null : decodeKeysetCursor(query.cursor);
23061
+ const offset = pageOffset(query.offset);
23062
+ const cursor = query.cursor === void 0 || query.offset !== void 0 ? null : decodeKeysetCursor(query.cursor);
23033
23063
  const where = cursor === null ? "" : "WHERE (v.last_seen < :cursorLastSeen OR (v.last_seen = :cursorLastSeen AND v.pointer_id < :cursorPointerId))";
23034
23064
  const rows = allRows(
23035
23065
  this.db.prepare(
@@ -23043,11 +23073,12 @@ var SqliteSecretVaultRepository = class {
23043
23073
  FROM secret_vault v
23044
23074
  ${where}
23045
23075
  ORDER BY v.last_seen DESC, v.pointer_id DESC
23046
- LIMIT :limit`
23076
+ LIMIT :limit OFFSET :offset`
23047
23077
  ),
23048
23078
  bindParams({
23049
23079
  now,
23050
23080
  limit: limit + 1,
23081
+ offset,
23051
23082
  ...cursor === null ? {} : { cursorLastSeen: cursor.startedAtMs, cursorPointerId: cursor.id }
23052
23083
  })
23053
23084
  );
@@ -23071,7 +23102,8 @@ var SqliteSecretVaultRepository = class {
23071
23102
  */
23072
23103
  listReuse(query = {}, now = Date.now()) {
23073
23104
  const limit = pageLimit(query.limit, DEFAULT_VAULT_INVENTORY_LIMIT);
23074
- const cursor = query.cursor === void 0 ? null : decodeReuseCursor(query.cursor);
23105
+ const offset = pageOffset(query.offset);
23106
+ const cursor = query.cursor === void 0 || query.offset !== void 0 ? null : decodeReuseCursor(query.cursor);
23075
23107
  const after = cursor === null ? "" : `AND (v.occurrence_count < :cursorOccurrences
23076
23108
  OR (v.occurrence_count = :cursorOccurrences AND v.pointer_id < :cursorPointerId))`;
23077
23109
  const rows = allRows(
@@ -23086,11 +23118,12 @@ var SqliteSecretVaultRepository = class {
23086
23118
  FROM secret_vault v
23087
23119
  WHERE ${REUSED_PREDICATE} ${after}
23088
23120
  ORDER BY v.occurrence_count DESC, v.pointer_id DESC
23089
- LIMIT :limit`
23121
+ LIMIT :limit OFFSET :offset`
23090
23122
  ),
23091
23123
  bindParams({
23092
23124
  now,
23093
23125
  limit: limit + 1,
23126
+ offset,
23094
23127
  ...cursor === null ? {} : { cursorOccurrences: cursor.occurrences, cursorPointerId: cursor.pointerId }
23095
23128
  })
23096
23129
  );
@@ -23115,7 +23148,8 @@ var SqliteSecretVaultRepository = class {
23115
23148
  */
23116
23149
  listDerefs(query = {}) {
23117
23150
  const limit = pageLimit(query.limit, DEFAULT_VAULT_DEREFS_LIMIT);
23118
- const cursor = query.cursor === void 0 ? null : decodeKeysetCursor(query.cursor);
23151
+ const offset = pageOffset(query.offset);
23152
+ const cursor = query.cursor === void 0 || query.offset !== void 0 ? null : decodeKeysetCursor(query.cursor);
23119
23153
  const conditions = [];
23120
23154
  if (query.includeBatched !== true) {
23121
23155
  conditions.push(`reason NOT IN ('display', 'view-render')`);
@@ -23128,21 +23162,28 @@ var SqliteSecretVaultRepository = class {
23128
23162
  this.db.prepare(
23129
23163
  `SELECT id, pointer_id, at, target, reason, outcome, grant_id, pointer_count
23130
23164
  FROM secret_vault_deref ${where}
23131
- ORDER BY at DESC, id DESC LIMIT :limit`
23165
+ ORDER BY at DESC, id DESC LIMIT :limit OFFSET :offset`
23132
23166
  ),
23133
23167
  bindParams({
23134
23168
  limit: limit + 1,
23169
+ offset,
23135
23170
  ...cursor === null ? {} : { cursorAt: cursor.startedAtMs, cursorId: cursor.id }
23136
23171
  })
23137
23172
  );
23138
23173
  const hasMore = rows.length > limit;
23139
23174
  const page = hasMore ? rows.slice(0, limit) : rows;
23140
23175
  const last = page[page.length - 1];
23141
- const hiddenBatched = query.includeBatched === true ? 0 : countScalar(
23142
- this.db,
23143
- `SELECT count(*) AS n FROM secret_vault_deref WHERE reason IN ('display', 'view-render')`
23144
- );
23176
+ const counts = getRow(
23177
+ this.db.prepare(
23178
+ `SELECT count(*) AS total,
23179
+ count(*) FILTER (WHERE reason IN ('display', 'view-render')) AS hidden
23180
+ FROM secret_vault_deref`
23181
+ )
23182
+ ) ?? { total: 0, hidden: 0 };
23183
+ const includeBatched = query.includeBatched === true;
23184
+ const hiddenBatched = includeBatched ? 0 : counts.hidden;
23145
23185
  return {
23186
+ totals: { derefs: includeBatched ? counts.total : counts.total - counts.hidden },
23146
23187
  items: page.map((r) => ({
23147
23188
  id: r.id,
23148
23189
  pointerId: r.pointer_id,
@@ -23167,6 +23208,43 @@ var SqliteSecretVaultRepository = class {
23167
23208
  `SELECT COUNT(*) AS n FROM secret_vault v WHERE ${REUSED_PREDICATE}`
23168
23209
  );
23169
23210
  }
23211
+ /**
23212
+ * Every entry held, and how many of them are NOT under `currentVersion` — the
23213
+ * standing record of a fingerprint-key rotation whose re-key did not reach
23214
+ * every row.
23215
+ *
23216
+ * This is the durable form of what `SecretVault.refreshFingerprints` reports
23217
+ * once. That count is an event, gone the moment it is printed; this is the
23218
+ * condition, and it stays true until some later rotation re-keys the rows. It
23219
+ * is therefore the one that can answer "is a shortfall still outstanding?" —
23220
+ * including for a rotation run from the CLI, which no dashboard render saw.
23221
+ *
23222
+ * `<>` rather than `<`: a row ahead of the current version is equally
23223
+ * unmatchable, and that is reachable — a key file restored from a backup, or
23224
+ * replaced after being lost, leaves rows stamped higher than the key is.
23225
+ *
23226
+ * Both numbers come from ONE statement, which is why this returns a pair
23227
+ * instead of offering two counts to call. Read separately, a purge landing
23228
+ * between them hands back a `stale` counted over rows the later `total` no
23229
+ * longer includes, and a disclosure built from that pair states a fraction
23230
+ * true of no state of the table — "1 of 0 stored values", or a negative
23231
+ * remainder. Same reasoning as `purgeVault`'s count, which comes from the
23232
+ * delete rather than from a `countEntries` standing beside it.
23233
+ */
23234
+ countFingerprintEpochs(currentVersion) {
23235
+ const row = getRow(
23236
+ this.db.prepare(
23237
+ `SELECT COUNT(*) AS total,
23238
+ COALESCE(
23239
+ SUM(CASE WHEN fingerprint_key_version <> :currentVersion THEN 1 ELSE 0 END),
23240
+ 0
23241
+ ) AS stale
23242
+ FROM secret_vault`
23243
+ ),
23244
+ { currentVersion }
23245
+ ) ?? { stale: 0, total: 0 };
23246
+ return { stale: row.stale, total: row.total };
23247
+ }
23170
23248
  };
23171
23249
 
23172
23250
  // ../../packages/persistence/src/repositories/security.ts
@@ -24956,13 +25034,22 @@ var SecretVault = class {
24956
25034
  * fingerprint collides with a row already refreshed, is skipped rather than
24957
25035
  * aborting the pass — one damaged entry must not strand the re-key of every
24958
25036
  * other. A skipped row keeps resolving under its old fingerprint epoch.
25037
+ *
25038
+ * Every skip is COUNTED, because best-effort and silent are different things:
25039
+ * the loss above is invisible at the moment it happens and only shows up later
25040
+ * as a duplicate pointer, so the pass owes its caller a denominator rather
25041
+ * than a bare success count.
24959
25042
  */
24960
25043
  async refreshFingerprints(next) {
24961
25044
  let refreshed = 0;
25045
+ let skipped = 0;
24962
25046
  for (const row of this.#repo.listAll()) {
24963
25047
  try {
24964
25048
  const raw = await this.#openRow(row);
24965
- if (raw === null) continue;
25049
+ if (raw === null) {
25050
+ skipped += 1;
25051
+ continue;
25052
+ }
24966
25053
  this.#repo.refreshFingerprint(row.pointerId, {
24967
25054
  valueFingerprint: exactFingerprintValue(next, raw),
24968
25055
  valueIdentityFingerprint: fingerprintValue(next, raw),
@@ -24970,10 +25057,10 @@ var SecretVault = class {
24970
25057
  });
24971
25058
  refreshed += 1;
24972
25059
  } catch {
24973
- continue;
25060
+ skipped += 1;
24974
25061
  }
24975
25062
  }
24976
- return refreshed;
25063
+ return { refreshed, skipped };
24977
25064
  }
24978
25065
  /**
24979
25066
  * Destroy every entry, making all outstanding pointers permanently
@@ -26292,6 +26379,21 @@ function passesPostValidators(rule, value) {
26292
26379
  function getLoadedRules() {
26293
26380
  return [...packs.values()].flatMap((p) => p.rules);
26294
26381
  }
26382
+ function outsideWrittenRegions(candidates, context) {
26383
+ const regions = context?.writtenRegions;
26384
+ if (!regions || regions.length === 0 || context.eventKind !== "tool_use") return candidates;
26385
+ return candidates.filter((c) => {
26386
+ if (c.rule.category !== "code_flaw") return true;
26387
+ const { start, end } = c.match.span;
26388
+ return !regions.some(
26389
+ (r) => r.start <= start && end <= r.end && ruleApplies(
26390
+ c.rule,
26391
+ r.filePath === void 0 ? void 0 : extensionOf(r.filePath),
26392
+ "code_change"
26393
+ )
26394
+ );
26395
+ });
26396
+ }
26295
26397
  function spansOverlap(a, b) {
26296
26398
  return a.start < b.end && a.end > b.start;
26297
26399
  }
@@ -26479,17 +26581,20 @@ function scanEncoded(text, ruleset, context) {
26479
26581
  function scanText(text, ruleset, context) {
26480
26582
  const extension = context?.filePath ? extensionOf(context.filePath) : void 0;
26481
26583
  const normalization = normalizeFormatChars(text);
26482
- const originalCandidates = buildCandidates(text, ruleset, extension, context?.eventKind);
26584
+ const originalCandidates = outsideWrittenRegions(
26585
+ buildCandidates(text, ruleset, extension, context?.eventKind),
26586
+ context
26587
+ );
26483
26588
  if (!normalization) return gate(originalCandidates, text, void 0);
26484
26589
  const pooledOriginal = originalCandidates.map(
26485
26590
  (candidate) => withNormalizedSpan(candidate, normalization)
26486
26591
  );
26487
- const normalizedCandidates = buildCandidates(
26488
- normalization.normalized,
26489
- ruleset,
26490
- extension,
26491
- context?.eventKind
26492
- ).map((candidate) => mapCandidateToOriginal(candidate, normalization, text));
26592
+ const normalizedCandidates = outsideWrittenRegions(
26593
+ buildCandidates(normalization.normalized, ruleset, extension, context?.eventKind).map(
26594
+ (candidate) => mapCandidateToOriginal(candidate, normalization, text)
26595
+ ),
26596
+ context
26597
+ );
26493
26598
  const findings = gate([...pooledOriginal, ...normalizedCandidates], text, normalization);
26494
26599
  return mergeOverlappingSameRule(findings, text);
26495
26600
  }
@@ -27380,7 +27485,7 @@ var sql_inject_concat_dot_default = {
27380
27485
  severity: "high",
27381
27486
  matcher: {
27382
27487
  type: "regex",
27383
- pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
27488
+ pattern: "([\"'])(?=((?:(?!\\1)[^\\n])*?\\b(?:select\\b(?:(?!\\1|\\bselect\\b)[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b)))))\\2(?:(?!\\1(?:(?!\\1)[^\\n])*?\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\.",
27384
27489
  flags: "gi"
27385
27490
  },
27386
27491
  appliesTo: {
@@ -27398,7 +27503,7 @@ var sql_inject_concat_default = {
27398
27503
  severity: "high",
27399
27504
  matcher: {
27400
27505
  type: "regex",
27401
- pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
27506
+ pattern: "([\"'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?!\\1)['\"%]|between\\b))))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+(?:only\\s+)?\\S+(?:(?:\\s+as\\s+[\\w`\\[\\]]+)?\\s+set\\b|(?:\\s*,\\s*[\\w.`\\[\\]$]+)+\\s+set\\s+[\\w.`\\[\\]$]+\\s*=)|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b|where\\b))[^\\n])*?[\"']\\s*\\+",
27402
27507
  flags: "gi"
27403
27508
  },
27404
27509
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -27413,7 +27518,7 @@ var sql_inject_format_default = {
27413
27518
  severity: "high",
27414
27519
  matcher: {
27415
27520
  type: "regex",
27416
- pattern: `(["'\`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(["'\`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\b(?:(?!\\bwhere\\b|\\3)[^\\n])*?=))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:=\\s*['"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})`,
27521
+ pattern: "([\"'`])\\s*(?=((?:select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?\\bfrom\\b)|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\2(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b)|\\1)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|([\"'`])\\s*(?=((?:(?!\\3)[^\\n])*?\\bwhere\\s+[\\w.`\\[\\]${}]+(?:\\s*(?:!=|[=<>])|\\s+(?:in\\s*\\(|like\\s*(?=(?!\\3)['\"%])|between\\b))))\\4(?:(?!\\bwhere\\b|\\3)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|(?<=^|\\n)[ \\t]*(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))\\5(?:(?!\\b(?:select\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+(?:replace|ignore|rollback|abort|fail))\\s+){0,2}into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database|index|view)\\b))[^\\n])*?(?:=\\s*['\"]?\\s*(?:%[sd]|\\{[^{}\\n]+\\})|[#$]\\{[^{}\\n]+\\})",
27417
27522
  flags: "gi"
27418
27523
  },
27419
27524
  examples: [
@@ -27422,6 +27527,24 @@ var sql_inject_format_default = {
27422
27527
  ]
27423
27528
  };
27424
27529
 
27530
+ // ../../rules/code-flaws/sql-inject-interp-multiline.json
27531
+ var sql_inject_interp_multiline_default = {
27532
+ specVersion: 1,
27533
+ id: "code-flaws/sql-inject-interp-multiline",
27534
+ name: "SQL injection via Ruby string interpolation or PHP variable (statement on its own line, e.g. a heredoc)",
27535
+ category: "code_flaw",
27536
+ severity: "high",
27537
+ matcher: {
27538
+ type: "regex",
27539
+ 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_])',
27540
+ flags: "gi"
27541
+ },
27542
+ examples: ["sql = <<~SQL\n SELECT * FROM users WHERE id = #{params[:id]}\nSQL"],
27543
+ appliesTo: {
27544
+ extensions: [".rb", ".php"]
27545
+ }
27546
+ };
27547
+
27425
27548
  // ../../rules/code-flaws/sql-inject-interp.json
27426
27549
  var sql_inject_interp_default = {
27427
27550
  specVersion: 1,
@@ -27431,7 +27554,7 @@ var sql_inject_interp_default = {
27431
27554
  severity: "high",
27432
27555
  matcher: {
27433
27556
  type: "regex",
27434
- pattern: "([\"'`])\\s*\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])|(?<=^|\\n)[ \\t]*(?:select|insert|update|delete|where)\\s[^\\n]*?(?:#\\{|\\$[a-z_])",
27557
+ pattern: '(?<![\\w\'"`})\\]])(["\'`])[ \\t]*(?=(?:select\\b(?:#\\{(?:[^{}\\n]|\\{(?:[^{}\\n]|\\{[^{}\\n]{0,100}\\}){0,100}\\}){0,200}\\}|\\{\\$[^}\\n]{0,200}\\}|\\\\(?!\\1[ \\t]*(?:select|insert|update|delete|where)\\b).|(?!\\1)(?!#\\{|\\{\\$|\\\\)[\\s\\S]){0,1000}?\\bfrom\\b|insert\\s+(?:(?:ignore|low_priority|delayed|high_priority|or\\s+\\w+)\\s+){0,2}(?:into\\b|[\\w.`]+\\s*\\()|update\\s+(?:(?:low_priority|ignore|or\\s+\\w+)\\s+){0,2}(?:only\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?(?:\\s*,\\s*(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+(?:\\s+(?:as\\s+)?(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+)?){0,7}(?:(?:\\s+\\w+){0,2}\\s+join\\b(?:(?!\\bset\\b)(?!\\1)[^\\n]){1,300})?\\s+set(?:\\s+|(?=`))(?:(?:[\\w.`\\"$]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\$\\{[^}\\n]{1,200}\\}|->|\\[[^\\]\\n]{1,200}\\])+\\s*=|#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;),]|\\n|$|(?:where|order|limit)\\b)))|delete\\s+(?:(?:low_priority|quick|ignore)\\s+){0,3}(?:from\\b|[\\w.`]+(?:\\s*,\\s*[\\w.`]+)*\\s+from\\s+[\\w.`]+(?:\\s+(?:as\\s+)?\\w+)?\\s+(?:(?:inner|cross|(?:left|right)(?:\\s+outer)?)\\s+)?(?:join|using|where)\\b)|where\\s+(?:(?:not\\s+)?(?:\\(\\s*)*(?:#\\{|\\{\\$|\\$[a-z_]\\w*(?:\\[[^\\]\\n]{1,200}\\])*(?=\\s*(?:["\'`;)]|\\n|$|(?:and|or|order|group|limit)\\b)))|(?:not\\s+)?exists\\s*\\(|(?:not\\s+)?(?:\\(\\s*)*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?(?:\\s*,\\s*(?:[\\w.`$"]|#\\{[^}\\n]{1,200}\\}|\\{\\$[^}\\n]{1,200}\\}|\\[[^\\]\\n]{1,200}\\]|\'[^\'\\n]{0,200}\')+(?:\\s*\\((?:[^()\\n]|\\((?:[^()\\n]|\\([^()\\n]{0,200}\\))*\\))*\\))?){0,4}\\s*(?:\\)\\s*)?(?:[=<>!~@|&:%^*/+-]+|\\b(?:is|in|not|i?like|regexp|rlike|similar\\s+to|glob|between|against|match|exists|and|or)\\b))))\\b(?:select|insert|update|delete|where)\\b(?:(?!\\1)[^\\n])*?(?:#\\{|\\$[a-z_])',
27435
27558
  flags: "gi"
27436
27559
  },
27437
27560
  examples: [
@@ -29159,12 +29282,13 @@ var BUNDLED_PACKS = [
29159
29282
  {
29160
29283
  packId: "code-flaws",
29161
29284
  name: "Code Security Flaws",
29162
- version: "0.1.3",
29285
+ version: "0.1.6",
29163
29286
  rawRules: [
29164
29287
  sql_inject_concat_default,
29165
29288
  sql_inject_concat_dot_default,
29166
29289
  sql_inject_format_default,
29167
29290
  sql_inject_interp_default,
29291
+ sql_inject_interp_multiline_default,
29168
29292
  cmd_inject_shell_default,
29169
29293
  cmd_inject_exec_default,
29170
29294
  cmd_inject_node_exec_default,
@@ -29196,6 +29320,7 @@ var BUNDLED_PACKS = [
29196
29320
  "code-flaws/sql-inject-concat-dot": "SQL injection (PHP)",
29197
29321
  "code-flaws/sql-inject-format": "SQL injection (format string)",
29198
29322
  "code-flaws/sql-inject-interp": "SQL injection (interpolation)",
29323
+ "code-flaws/sql-inject-interp-multiline": "SQL injection (interpolation)",
29199
29324
  "code-flaws/cmd-inject-shell": "Command injection (shell)",
29200
29325
  "code-flaws/cmd-inject-exec": "Command injection (Java exec)",
29201
29326
  "code-flaws/cmd-inject-node-exec": "Command injection (Node exec)",
@@ -29737,6 +29862,7 @@ function createIsolatedScanner(data, opts = {}) {
29737
29862
  text,
29738
29863
  filePath: context?.filePath,
29739
29864
  eventKind: context?.eventKind,
29865
+ writtenRegions: context?.writtenRegions,
29740
29866
  attribute: scanOpts?.attribute === true
29741
29867
  }),
29742
29868
  reply: (message) => {
package/scripts/intro.js CHANGED
@@ -8382,7 +8382,11 @@ var ListFindingTypesQuery = object({
8382
8382
  // and so is not bounded by what any page happens to hold.
8383
8383
  includeId: string2().optional(),
8384
8384
  limit: coerce_exports.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
8385
- cursor: string2().optional()
8385
+ cursor: string2().optional(),
8386
+ // A row position to read from, for jumping to a page instead of stepping to
8387
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
8388
+ // from wherever it lands.
8389
+ offset: coerce_exports.number().int().min(0).optional()
8386
8390
  });
8387
8391
  var ListFindingTypesResponse = object({
8388
8392
  totals: object({
@@ -8462,7 +8466,11 @@ var ListFindingInstancesQuery = object({
8462
8466
  sessionId: string2().optional(),
8463
8467
  from: iso_exports.datetime().optional(),
8464
8468
  limit: coerce_exports.number().int().min(1).max(MAX_FLAT_FINDINGS_LIMIT).optional(),
8465
- cursor: string2().optional()
8469
+ cursor: string2().optional(),
8470
+ // A row position to read from, for jumping to a page instead of stepping to
8471
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
8472
+ // from wherever it lands.
8473
+ offset: coerce_exports.number().int().min(0).optional()
8466
8474
  });
8467
8475
  var ListFindingInstancesResponse = object({
8468
8476
  // Instances matching the filters across the whole scope, not just this
@@ -8533,7 +8541,11 @@ var ListFindingLocationsQuery = object({
8533
8541
  // rather than a deep-link corner. Never affects totals, facets or the cursor.
8534
8542
  includeId: string2().optional(),
8535
8543
  limit: coerce_exports.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
8536
- cursor: string2().optional()
8544
+ cursor: string2().optional(),
8545
+ // A row position to read from, for jumping to a page instead of stepping to
8546
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
8547
+ // from wherever it lands.
8548
+ offset: coerce_exports.number().int().min(0).optional()
8537
8549
  });
8538
8550
  var ListFindingLocationsResponse = object({
8539
8551
  totals: object({
@@ -10930,7 +10942,11 @@ var MAX_VAULT_PAGE_LIMIT = 200;
10930
10942
  var ListVaultInventoryQuery = object({
10931
10943
  limit: coerce_exports.number().int().min(1).max(MAX_VAULT_PAGE_LIMIT).optional(),
10932
10944
  // Opaque; names the last row of the page just served.
10933
- cursor: string2().optional()
10945
+ cursor: string2().optional(),
10946
+ // A row position to read from, for jumping to a page instead of stepping to
10947
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
10948
+ // from wherever it lands.
10949
+ offset: coerce_exports.number().int().min(0).optional()
10934
10950
  });
10935
10951
  var ListVaultInventoryResponse = object({
10936
10952
  // Vaulted values across the whole store, not just this page — cursor-
@@ -10942,7 +10958,11 @@ var ListVaultInventoryResponse = object({
10942
10958
  });
10943
10959
  var ListVaultReuseQuery = object({
10944
10960
  limit: coerce_exports.number().int().min(1).max(MAX_VAULT_PAGE_LIMIT).optional(),
10945
- cursor: string2().optional()
10961
+ cursor: string2().optional(),
10962
+ // A row position to read from, for jumping to a page instead of stepping to
10963
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
10964
+ // from wherever it lands.
10965
+ offset: coerce_exports.number().int().min(0).optional()
10946
10966
  });
10947
10967
  var ListVaultReuseResponse = object({
10948
10968
  // Reused values across the whole store — the number the section's claim
@@ -10958,9 +10978,15 @@ var ListVaultDerefsQuery = object({
10958
10978
  // over a Server Action, which preserves the type, never as a URL param.
10959
10979
  includeBatched: boolean2().optional(),
10960
10980
  limit: coerce_exports.number().int().min(1).max(MAX_VAULT_PAGE_LIMIT).optional(),
10961
- cursor: string2().optional()
10981
+ cursor: string2().optional(),
10982
+ // A row position to read from, for jumping to a page instead of stepping to
10983
+ // it. Takes precedence over `cursor`, and the page's `nextCursor` carries on
10984
+ // from wherever it lands.
10985
+ offset: coerce_exports.number().int().min(0).optional()
10962
10986
  });
10963
10987
  var ListVaultDerefsResponse = object({
10988
+ // Rows this filter selects across the whole trail, not just this page.
10989
+ totals: object({ derefs: number2().int().nonnegative() }),
10964
10990
  items: array(VaultDeref),
10965
10991
  nextCursor: string2().nullable(),
10966
10992
  // Display/view-render rows the query hid, over the WHOLE trail rather than