@akasecurity/ai-tc-codex 0.9.17-beta.1 → 0.9.17

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.
@@ -22552,6 +22552,11 @@ var CaptureAttributes = external_exports.object({
22552
22552
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
22553
22553
  // repeated rather than referenced because a store reader opens this file.
22554
22554
  redact_degraded_to: ActionTaken.optional(),
22555
+ // Why a capture has no content and no findings: its field was refused
22556
+ // because its bounded scan did not finish (see EventMetadata.scanIncomplete,
22557
+ // whose value this is). Absent on every capture that was scanned, so a
22558
+ // reader can tell a refused row from an empty clean one.
22559
+ scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
22555
22560
  // The scope key this capture was stamped with: the canonical repository
22556
22561
  // (`host/owner/repo`) of the path the capture names (a relative path is read
22557
22562
  // against its working directory), else of its own working directory, or a
@@ -23893,7 +23898,19 @@ var EventMetadata = external_exports.object({
23893
23898
  // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23894
23899
  // Closing either means moving the reason onto the finding row, which
23895
23900
  // already carries its own action.
23896
- redactDegradedTo: ActionTaken.optional()
23901
+ redactDegradedTo: ActionTaken.optional(),
23902
+ // Set when this capture's field was REFUSED rather than scanned: a hook
23903
+ // bounds the scan of a large field (see `LargeInputScanOptions` in
23904
+ // @akasecurity/plugin-sdk), and a scan that did not finish blocks the
23905
+ // field instead of letting it through unscanned.
23906
+ //
23907
+ // - 'timeout': the bounded scan ran out of time.
23908
+ // - 'unavailable': no worker could run it.
23909
+ //
23910
+ // A refused row stores '' as its content and has no findings, which is
23911
+ // exactly what a clean, empty capture looks like — this marker is the only
23912
+ // thing that tells the two apart. Absent on every capture that was scanned.
23913
+ scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
23897
23914
  }).meta({ id: "EventMetadata" });
23898
23915
  var Event = external_exports.object({
23899
23916
  id: external_exports.guid(),
@@ -25710,6 +25727,7 @@ function toCaptureAttributes(event) {
25710
25727
  ...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
25711
25728
  ...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
25712
25729
  ...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
25730
+ ...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
25713
25731
  // `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
25714
25732
  // has ever populated either), but every legacy metadata key still rides
25715
25733
  // the bag rather than being silently dropped — CaptureAttributes'
@@ -38656,6 +38674,38 @@ function worstProbeMs(rule, now = wallClock, corroborate) {
38656
38674
  }
38657
38675
  var CPU_CORROBORATION_SHARE = 0.2;
38658
38676
  var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
38677
+ function repeatTo(unit, length) {
38678
+ return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
38679
+ }
38680
+ function joinTo(length, open3, close, item) {
38681
+ const parts = [];
38682
+ let size = open3.length;
38683
+ for (let i = 0; size < length; i++) {
38684
+ const next = (i === 0 ? "" : ",") + item(i);
38685
+ parts.push(next);
38686
+ size += next.length;
38687
+ }
38688
+ return (open3 + parts.join("") + close).slice(0, length);
38689
+ }
38690
+ var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
38691
+ var GROWTH_CORPORA = [
38692
+ {
38693
+ name: "one-line JSON dictionary",
38694
+ build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
38695
+ },
38696
+ {
38697
+ name: "JSON array of quoted SQL keywords",
38698
+ build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
38699
+ },
38700
+ { name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
38701
+ { name: "double-quote run", build: (length) => repeatTo('"', length) },
38702
+ { name: "space run", build: (length) => repeatTo(" ", length) },
38703
+ { name: "newline run", build: (length) => repeatTo("\n", length) },
38704
+ ...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
38705
+ name: `unit run ${JSON.stringify(unit)}`,
38706
+ build: (length) => repeatTo(unit, length)
38707
+ }))
38708
+ ];
38659
38709
  function checkRuleTiming(rule, corroborate) {
38660
38710
  const { ms, probe, corroboratedMs } = worstProbeMs(rule, wallClock, corroborate);
38661
38711
  const work = corroboratedMs ?? 0;
@@ -38957,7 +39007,7 @@ var auth_jwt_no_verify_default = {
38957
39007
  severity: "critical",
38958
39008
  matcher: {
38959
39009
  type: "regex",
38960
- pattern: "(verify\\s*=\\s*false|verify_signature.*false|algorithms\\s*=\\s*\\[\\])",
39010
+ pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
38961
39011
  flags: "gi"
38962
39012
  },
38963
39013
  requiresNearby: {
@@ -39045,7 +39095,7 @@ var cmd_inject_shell_default = {
39045
39095
  severity: "critical",
39046
39096
  matcher: {
39047
39097
  type: "regex",
39048
- pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
39098
+ pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
39049
39099
  flags: "gi"
39050
39100
  },
39051
39101
  requiresNearby: {
@@ -39174,7 +39224,7 @@ var deser_yaml_unsafe_default = {
39174
39224
  severity: "high",
39175
39225
  matcher: {
39176
39226
  type: "regex",
39177
- pattern: "\\byaml\\.load\\s*\\((?![^)]*SafeLoader|[^)]*safe_load)",
39227
+ pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
39178
39228
  flags: "gi"
39179
39229
  },
39180
39230
  examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
@@ -39391,7 +39441,7 @@ var sql_inject_concat_dot_default = {
39391
39441
  severity: "high",
39392
39442
  matcher: {
39393
39443
  type: "regex",
39394
- pattern: `["'][^\\n]*?(select|insert|update|delete|drop|where)[^\\n]*?["']\\s*\\.`,
39444
+ pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
39395
39445
  flags: "gi"
39396
39446
  },
39397
39447
  appliesTo: {
@@ -39409,7 +39459,7 @@ var sql_inject_concat_default = {
39409
39459
  severity: "high",
39410
39460
  matcher: {
39411
39461
  type: "regex",
39412
- pattern: `["']\\s*(?:select\\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[^\\n]*?=)[^\\n]*?["']\\s*\\+`,
39462
+ 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*\\+`,
39413
39463
  flags: "gi"
39414
39464
  },
39415
39465
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -39424,7 +39474,7 @@ var sql_inject_format_default = {
39424
39474
  severity: "high",
39425
39475
  matcher: {
39426
39476
  type: "regex",
39427
- pattern: "\\b(?:select\\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[^\\n]*?=)[^\\n]*?(?:[%][sd]|\\{[^}]+\\})",
39477
+ pattern: "\\b(?=(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))\\1(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|\\b(?=(where\\b(?:(?!\\bwhere\\b)[^\\n])*?=))\\2(?:(?!\\bwhere\\b)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})",
39428
39478
  flags: "gi"
39429
39479
  },
39430
39480
  examples: [
@@ -39442,7 +39492,7 @@ var sql_inject_interp_default = {
39442
39492
  severity: "high",
39443
39493
  matcher: {
39444
39494
  type: "regex",
39445
- pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
39495
+ pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
39446
39496
  flags: "gi"
39447
39497
  },
39448
39498
  examples: [
@@ -39817,7 +39867,7 @@ var stack_trace_default = {
39817
39867
  severity: "low",
39818
39868
  matcher: {
39819
39869
  type: "regex",
39820
- pattern: "(?:^|\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
39870
+ pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
39821
39871
  flags: "g"
39822
39872
  },
39823
39873
  examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
@@ -40975,7 +41025,7 @@ var BUNDLED_PACKS = [
40975
41025
  {
40976
41026
  packId: "code-flaws",
40977
41027
  name: "Code Security Flaws",
40978
- version: "0.1.0",
41028
+ version: "0.1.1",
40979
41029
  rawRules: [
40980
41030
  sql_inject_concat_default,
40981
41031
  sql_inject_concat_dot_default,
@@ -41025,7 +41075,7 @@ var BUNDLED_PACKS = [
41025
41075
  {
41026
41076
  packId: "core-code-context",
41027
41077
  name: "Code Context",
41028
- version: "0.2.1",
41078
+ version: "0.2.2",
41029
41079
  rawRules: [
41030
41080
  internal_ip_default,
41031
41081
  localhost_ref_default,
@@ -41494,9 +41544,10 @@ function createIsolatedScanner(data, opts = {}) {
41494
41544
  if (job.timer !== void 0) return;
41495
41545
  job.startedAt = performance.now();
41496
41546
  job.progressAt = job.startedAt;
41547
+ const budget = job.deadlineAt === void 0 ? job.budgetMs : Math.max(0, Math.min(job.budgetMs, job.deadlineAt - job.startedAt));
41497
41548
  job.timer = setTimeout(() => {
41498
41549
  onDeadline(job);
41499
- }, job.budgetMs);
41550
+ }, budget);
41500
41551
  }
41501
41552
  function runOne(spec, fail) {
41502
41553
  if (closed) {
@@ -41507,6 +41558,12 @@ function createIsolatedScanner(data, opts = {}) {
41507
41558
  fail({ status: "unavailable", reason: `the scan worker crashed: ${broken}` });
41508
41559
  return;
41509
41560
  }
41561
+ const now = performance.now();
41562
+ const deadlineAt = spec.deadlineAt;
41563
+ if (deadlineAt !== void 0 && deadlineAt <= now) {
41564
+ fail({ status: "timeout", culpritIndex: void 0, elapsedMs: 0 });
41565
+ return;
41566
+ }
41510
41567
  const started = ensureWorker();
41511
41568
  if (!(started instanceof Worker)) {
41512
41569
  broken = started.error;
@@ -41514,11 +41571,11 @@ function createIsolatedScanner(data, opts = {}) {
41514
41571
  return;
41515
41572
  }
41516
41573
  const id = nextJobId++;
41517
- const now = performance.now();
41518
41574
  const job = {
41519
41575
  id,
41520
41576
  worker: started,
41521
41577
  budgetMs: spec.budgetMs,
41578
+ deadlineAt,
41522
41579
  startedAt: now,
41523
41580
  progressIndex: -1,
41524
41581
  progressAt: now,
@@ -41532,14 +41589,19 @@ function createIsolatedScanner(data, opts = {}) {
41532
41589
  if (readyWorker === started) {
41533
41590
  beginDeadline(job);
41534
41591
  } else {
41592
+ const startBudget = spec.startBudgetMs ?? startBudgetMs;
41593
+ const callerLimited = deadlineAt !== void 0 && deadlineAt - now < startBudget;
41594
+ const startWaitMs = callerLimited ? deadlineAt - now : startBudget;
41535
41595
  job.startupTimer = setTimeout(() => {
41536
41596
  if (pending !== job) return;
41537
41597
  kill(job.worker);
41538
- failPending({
41539
- status: "unavailable",
41540
- reason: `the scan worker did not start within ${String(startBudgetMs)}ms`
41541
- });
41542
- }, startBudgetMs);
41598
+ failPending(
41599
+ callerLimited ? { status: "timeout", culpritIndex: void 0, elapsedMs: performance.now() - now } : {
41600
+ status: "unavailable",
41601
+ reason: `the scan worker did not start within ${String(startBudget)}ms`
41602
+ }
41603
+ );
41604
+ }, startWaitMs);
41543
41605
  }
41544
41606
  try {
41545
41607
  started.postMessage(spec.build(id));
@@ -41568,7 +41630,9 @@ function createIsolatedScanner(data, opts = {}) {
41568
41630
  return enqueue((resolve4) => {
41569
41631
  runOne(
41570
41632
  {
41571
- budgetMs,
41633
+ budgetMs: scanOpts?.budgetMs ?? budgetMs,
41634
+ startBudgetMs: scanOpts?.startBudgetMs,
41635
+ deadlineAt: scanOpts?.deadlineAt,
41572
41636
  build: (id) => ({
41573
41637
  kind: "scan",
41574
41638
  id,
@@ -41762,6 +41826,9 @@ function createGuardedScanner(partition, gateway, opts) {
41762
41826
  let unverified = partition.unverified;
41763
41827
  let isolated = unverified.length > 0 ? createIsolatedScanner({ verified, unverified }, opts) : void 0;
41764
41828
  let retired = false;
41829
+ let bounded;
41830
+ let boundedWarned = false;
41831
+ let closed = false;
41765
41832
  function inProcess(text, context) {
41766
41833
  return scan(text, verified, context);
41767
41834
  }
@@ -41823,11 +41890,48 @@ function createGuardedScanner(partition, gateway, opts) {
41823
41890
  await degrade();
41824
41891
  return inProcess(text, context);
41825
41892
  }
41893
+ async function scanBounded(text, context, bound) {
41894
+ const remainingMs = bound.remainingMs;
41895
+ let outcome;
41896
+ if (closed) {
41897
+ outcome = { status: "unavailable", reason: "the scan worker is closed" };
41898
+ } else if (remainingMs !== void 0 && !(remainingMs > 0)) {
41899
+ outcome = { status: "timeout", culpritIndex: void 0, elapsedMs: 0 };
41900
+ } else {
41901
+ bounded ??= createIsolatedScanner({ verified, unverified }, opts);
41902
+ const deadlineAt = remainingMs === void 0 ? void 0 : performance.now() + remainingMs;
41903
+ try {
41904
+ outcome = await bounded.scan(text, context, {
41905
+ budgetMs: bound.budgetMs,
41906
+ startBudgetMs: bound.startBudgetMs,
41907
+ deadlineAt
41908
+ });
41909
+ } catch (error62) {
41910
+ outcome = {
41911
+ status: "unavailable",
41912
+ reason: error62 instanceof Error ? error62.message : "the scan worker failed unexpectedly"
41913
+ };
41914
+ }
41915
+ }
41916
+ if (outcome.status !== "ok" && !boundedWarned) {
41917
+ boundedWarned = true;
41918
+ process.stderr.write(
41919
+ outcome.status === "timeout" ? `[aka] a large input could not be scanned within its time limit and was refused.
41920
+ ` : `[aka] a large input could not be scanned and was refused: ${outcome.reason}.
41921
+ `
41922
+ );
41923
+ }
41924
+ return outcome;
41925
+ }
41826
41926
  return {
41827
41927
  scan: guardedScan,
41928
+ scanBounded,
41828
41929
  degraded: () => retired,
41829
41930
  async close() {
41830
- await retire();
41931
+ closed = true;
41932
+ const live = bounded;
41933
+ bounded = void 0;
41934
+ await Promise.all([retire(), live?.close()]);
41831
41935
  }
41832
41936
  };
41833
41937
  }
@@ -41983,6 +42087,16 @@ function conditionsMatch(conditions, ctx) {
41983
42087
  if (conditions.provider !== void 0) return false;
41984
42088
  return true;
41985
42089
  }
42090
+ function readRemainingMs(largeInput) {
42091
+ const read = largeInput.remainingMs;
42092
+ if (read === void 0) return void 0;
42093
+ try {
42094
+ const remaining = read();
42095
+ return typeof remaining !== "number" || Number.isNaN(remaining) ? 0 : remaining;
42096
+ } catch {
42097
+ return 0;
42098
+ }
42099
+ }
41986
42100
  var bundlesPacked = false;
41987
42101
  function createPluginRuntime(gateway, settings, opts) {
41988
42102
  if (!bundlesPacked) {
@@ -41992,6 +42106,7 @@ function createPluginRuntime(gateway, settings, opts) {
41992
42106
  const policyMode = settings.policy;
41993
42107
  let redactFallback = settings.redactFallback;
41994
42108
  const dataDir2 = opts?.dataDir;
42109
+ const largeInput = opts?.largeInput;
41995
42110
  let rules = [];
41996
42111
  let evidenceOf = evidenceLookup(rules);
41997
42112
  let scanner;
@@ -42204,7 +42319,24 @@ function createPluginRuntime(gateway, settings, opts) {
42204
42319
  await ensureInitialized();
42205
42320
  if (!scanner) throw new Error("the runtime initialized without a scanner");
42206
42321
  const shielded = shieldPointers(text);
42207
- const matched = await scanner.scan(shielded.text, context);
42322
+ let matched;
42323
+ if (largeInput !== void 0 && shielded.text.length >= largeInput.thresholdChars) {
42324
+ const outcome = await scanner.scanBounded(shielded.text, context, {
42325
+ budgetMs: largeInput.budgetMs,
42326
+ startBudgetMs: largeInput.startBudgetMs,
42327
+ remainingMs: readRemainingMs(largeInput)
42328
+ });
42329
+ if (outcome.status !== "ok") {
42330
+ return {
42331
+ decision: { action: "block", text: null, findings: [], scanIncomplete: outcome.status },
42332
+ excepted: /* @__PURE__ */ new Set(),
42333
+ exceptionIds: []
42334
+ };
42335
+ }
42336
+ matched = outcome.findings;
42337
+ } else {
42338
+ matched = await scanner.scan(shielded.text, context);
42339
+ }
42208
42340
  const findings = dropShieldedFindings(matched, shielded.spans);
42209
42341
  const fpCache = /* @__PURE__ */ new Map();
42210
42342
  const { excepted, exceptionIds } = await applyExceptions(findings, ctx, fpCache);
@@ -42245,20 +42377,24 @@ function createPluginRuntime(gateway, settings, opts) {
42245
42377
  }
42246
42378
  async function persistCapture(input2, opts2, { decision, excepted, exceptionIds, timingStartedAt }) {
42247
42379
  const filePath = input2.metadata?.filePath;
42248
- if (opts2.persist === "with-findings" && decision.findings.length === 0) return;
42380
+ if (opts2.persist === "with-findings" && decision.findings.length === 0 && decision.scanIncomplete === void 0) {
42381
+ return;
42382
+ }
42249
42383
  try {
42250
42384
  const contentHash = contentHashOf(input2.text);
42251
42385
  const maskedFindings = decision.findings.filter(
42252
42386
  (match) => isActionAtLeast(actionForFinding(match, excepted, opts2.rewritable), "redact")
42253
42387
  );
42254
- const storedContent = maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
42388
+ const storedContent = decision.scanIncomplete !== void 0 ? "" : maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
42255
42389
  const inspectionMs = elapsedMs(timingStartedAt);
42256
42390
  const redactDegradedTo = decision.redactDegradedTo;
42257
- const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 ? {
42391
+ const scanIncomplete = decision.scanIncomplete;
42392
+ const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 || scanIncomplete !== void 0 ? {
42258
42393
  ...input2.metadata,
42259
42394
  ...exceptionIds.length > 0 ? { exceptionIds } : {},
42260
42395
  ...inspectionMs !== void 0 ? { inspectionMs } : {},
42261
- ...redactDegradedTo !== void 0 ? { redactDegradedTo } : {}
42396
+ ...redactDegradedTo !== void 0 ? { redactDegradedTo } : {},
42397
+ ...scanIncomplete !== void 0 ? { scanIncomplete } : {}
42262
42398
  } : input2.metadata;
42263
42399
  const event = buildIngestEvent({
42264
42400
  kind: input2.kind,
@@ -43997,6 +44133,7 @@ var CORRELATION_ID = EventMetadata.shape.correlationId;
43997
44133
  var TRACE_ID = EventMetadata.shape.traceId;
43998
44134
  var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
43999
44135
  var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
44136
+ var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
44000
44137
 
44001
44138
  // ../../packages/plugin-runtime/src/attached/history-sync.ts
44002
44139
  var CAPTURE_BATCH_BYTES = 1024 * 1024;
@@ -21761,6 +21761,11 @@ var CaptureAttributes = external_exports.object({
21761
21761
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
21762
21762
  // repeated rather than referenced because a store reader opens this file.
21763
21763
  redact_degraded_to: ActionTaken.optional(),
21764
+ // Why a capture has no content and no findings: its field was refused
21765
+ // because its bounded scan did not finish (see EventMetadata.scanIncomplete,
21766
+ // whose value this is). Absent on every capture that was scanned, so a
21767
+ // reader can tell a refused row from an empty clean one.
21768
+ scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
21764
21769
  // The scope key this capture was stamped with: the canonical repository
21765
21770
  // (`host/owner/repo`) of the path the capture names (a relative path is read
21766
21771
  // against its working directory), else of its own working directory, or a
@@ -23102,7 +23107,19 @@ var EventMetadata = external_exports.object({
23102
23107
  // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23103
23108
  // Closing either means moving the reason onto the finding row, which
23104
23109
  // already carries its own action.
23105
- redactDegradedTo: ActionTaken.optional()
23110
+ redactDegradedTo: ActionTaken.optional(),
23111
+ // Set when this capture's field was REFUSED rather than scanned: a hook
23112
+ // bounds the scan of a large field (see `LargeInputScanOptions` in
23113
+ // @akasecurity/plugin-sdk), and a scan that did not finish blocks the
23114
+ // field instead of letting it through unscanned.
23115
+ //
23116
+ // - 'timeout': the bounded scan ran out of time.
23117
+ // - 'unavailable': no worker could run it.
23118
+ //
23119
+ // A refused row stores '' as its content and has no findings, which is
23120
+ // exactly what a clean, empty capture looks like — this marker is the only
23121
+ // thing that tells the two apart. Absent on every capture that was scanned.
23122
+ scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
23106
23123
  }).meta({ id: "EventMetadata" });
23107
23124
  var Event = external_exports.object({
23108
23125
  id: external_exports.guid(),
@@ -24911,6 +24928,7 @@ function toCaptureAttributes(event) {
24911
24928
  ...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
24912
24929
  ...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
24913
24930
  ...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
24931
+ ...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
24914
24932
  // `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
24915
24933
  // has ever populated either), but every legacy metadata key still rides
24916
24934
  // the bag rather than being silently dropped — CaptureAttributes'
@@ -36233,6 +36251,38 @@ var POLYNOMIAL_PROBES = ["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].m
36233
36251
  );
36234
36252
  var CPU_CORROBORATION_SHARE = 0.2;
36235
36253
  var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
36254
+ function repeatTo(unit, length) {
36255
+ return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
36256
+ }
36257
+ function joinTo(length, open3, close, item) {
36258
+ const parts = [];
36259
+ let size = open3.length;
36260
+ for (let i = 0; size < length; i++) {
36261
+ const next = (i === 0 ? "" : ",") + item(i);
36262
+ parts.push(next);
36263
+ size += next.length;
36264
+ }
36265
+ return (open3 + parts.join("") + close).slice(0, length);
36266
+ }
36267
+ var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
36268
+ var GROWTH_CORPORA = [
36269
+ {
36270
+ name: "one-line JSON dictionary",
36271
+ build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
36272
+ },
36273
+ {
36274
+ name: "JSON array of quoted SQL keywords",
36275
+ build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
36276
+ },
36277
+ { name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
36278
+ { name: "double-quote run", build: (length) => repeatTo('"', length) },
36279
+ { name: "space run", build: (length) => repeatTo(" ", length) },
36280
+ { name: "newline run", build: (length) => repeatTo("\n", length) },
36281
+ ...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
36282
+ name: `unit run ${JSON.stringify(unit)}`,
36283
+ build: (length) => repeatTo(unit, length)
36284
+ }))
36285
+ ];
36236
36286
 
36237
36287
  // ../../rules/code-flaws/auth-jwt-no-verify.json
36238
36288
  var auth_jwt_no_verify_default = {
@@ -36243,7 +36293,7 @@ var auth_jwt_no_verify_default = {
36243
36293
  severity: "critical",
36244
36294
  matcher: {
36245
36295
  type: "regex",
36246
- pattern: "(verify\\s*=\\s*false|verify_signature.*false|algorithms\\s*=\\s*\\[\\])",
36296
+ pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
36247
36297
  flags: "gi"
36248
36298
  },
36249
36299
  requiresNearby: {
@@ -36331,7 +36381,7 @@ var cmd_inject_shell_default = {
36331
36381
  severity: "critical",
36332
36382
  matcher: {
36333
36383
  type: "regex",
36334
- pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
36384
+ pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
36335
36385
  flags: "gi"
36336
36386
  },
36337
36387
  requiresNearby: {
@@ -36460,7 +36510,7 @@ var deser_yaml_unsafe_default = {
36460
36510
  severity: "high",
36461
36511
  matcher: {
36462
36512
  type: "regex",
36463
- pattern: "\\byaml\\.load\\s*\\((?![^)]*SafeLoader|[^)]*safe_load)",
36513
+ pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
36464
36514
  flags: "gi"
36465
36515
  },
36466
36516
  examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
@@ -36677,7 +36727,7 @@ var sql_inject_concat_dot_default = {
36677
36727
  severity: "high",
36678
36728
  matcher: {
36679
36729
  type: "regex",
36680
- pattern: `["'][^\\n]*?(select|insert|update|delete|drop|where)[^\\n]*?["']\\s*\\.`,
36730
+ pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
36681
36731
  flags: "gi"
36682
36732
  },
36683
36733
  appliesTo: {
@@ -36695,7 +36745,7 @@ var sql_inject_concat_default = {
36695
36745
  severity: "high",
36696
36746
  matcher: {
36697
36747
  type: "regex",
36698
- pattern: `["']\\s*(?:select\\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[^\\n]*?=)[^\\n]*?["']\\s*\\+`,
36748
+ 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*\\+`,
36699
36749
  flags: "gi"
36700
36750
  },
36701
36751
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -36710,7 +36760,7 @@ var sql_inject_format_default = {
36710
36760
  severity: "high",
36711
36761
  matcher: {
36712
36762
  type: "regex",
36713
- pattern: "\\b(?:select\\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[^\\n]*?=)[^\\n]*?(?:[%][sd]|\\{[^}]+\\})",
36763
+ pattern: "\\b(?=(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))\\1(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|\\b(?=(where\\b(?:(?!\\bwhere\\b)[^\\n])*?=))\\2(?:(?!\\bwhere\\b)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})",
36714
36764
  flags: "gi"
36715
36765
  },
36716
36766
  examples: [
@@ -36728,7 +36778,7 @@ var sql_inject_interp_default = {
36728
36778
  severity: "high",
36729
36779
  matcher: {
36730
36780
  type: "regex",
36731
- pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
36781
+ pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
36732
36782
  flags: "gi"
36733
36783
  },
36734
36784
  examples: [
@@ -37103,7 +37153,7 @@ var stack_trace_default = {
37103
37153
  severity: "low",
37104
37154
  matcher: {
37105
37155
  type: "regex",
37106
- pattern: "(?:^|\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
37156
+ pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
37107
37157
  flags: "g"
37108
37158
  },
37109
37159
  examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
@@ -38261,7 +38311,7 @@ var BUNDLED_PACKS = [
38261
38311
  {
38262
38312
  packId: "code-flaws",
38263
38313
  name: "Code Security Flaws",
38264
- version: "0.1.0",
38314
+ version: "0.1.1",
38265
38315
  rawRules: [
38266
38316
  sql_inject_concat_default,
38267
38317
  sql_inject_concat_dot_default,
@@ -38311,7 +38361,7 @@ var BUNDLED_PACKS = [
38311
38361
  {
38312
38362
  packId: "core-code-context",
38313
38363
  name: "Code Context",
38314
- version: "0.2.1",
38364
+ version: "0.2.2",
38315
38365
  rawRules: [
38316
38366
  internal_ip_default,
38317
38367
  localhost_ref_default,
@@ -39923,6 +39973,7 @@ var CORRELATION_ID = EventMetadata.shape.correlationId;
39923
39973
  var TRACE_ID = EventMetadata.shape.traceId;
39924
39974
  var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
39925
39975
  var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
39976
+ var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
39926
39977
 
39927
39978
  // ../../packages/plugin-runtime/src/attached/history-sync.ts
39928
39979
  var CAPTURE_BATCH_BYTES = 1024 * 1024;
@@ -21674,6 +21674,11 @@ var CaptureAttributes = external_exports.object({
21674
21674
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
21675
21675
  // repeated rather than referenced because a store reader opens this file.
21676
21676
  redact_degraded_to: ActionTaken.optional(),
21677
+ // Why a capture has no content and no findings: its field was refused
21678
+ // because its bounded scan did not finish (see EventMetadata.scanIncomplete,
21679
+ // whose value this is). Absent on every capture that was scanned, so a
21680
+ // reader can tell a refused row from an empty clean one.
21681
+ scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
21677
21682
  // The scope key this capture was stamped with: the canonical repository
21678
21683
  // (`host/owner/repo`) of the path the capture names (a relative path is read
21679
21684
  // against its working directory), else of its own working directory, or a
@@ -23015,7 +23020,19 @@ var EventMetadata = external_exports.object({
23015
23020
  // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23016
23021
  // Closing either means moving the reason onto the finding row, which
23017
23022
  // already carries its own action.
23018
- redactDegradedTo: ActionTaken.optional()
23023
+ redactDegradedTo: ActionTaken.optional(),
23024
+ // Set when this capture's field was REFUSED rather than scanned: a hook
23025
+ // bounds the scan of a large field (see `LargeInputScanOptions` in
23026
+ // @akasecurity/plugin-sdk), and a scan that did not finish blocks the
23027
+ // field instead of letting it through unscanned.
23028
+ //
23029
+ // - 'timeout': the bounded scan ran out of time.
23030
+ // - 'unavailable': no worker could run it.
23031
+ //
23032
+ // A refused row stores '' as its content and has no findings, which is
23033
+ // exactly what a clean, empty capture looks like — this marker is the only
23034
+ // thing that tells the two apart. Absent on every capture that was scanned.
23035
+ scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
23019
23036
  }).meta({ id: "EventMetadata" });
23020
23037
  var Event = external_exports.object({
23021
23038
  id: external_exports.guid(),
@@ -24758,6 +24775,7 @@ function toCaptureAttributes(event) {
24758
24775
  ...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
24759
24776
  ...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
24760
24777
  ...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
24778
+ ...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
24761
24779
  // `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
24762
24780
  // has ever populated either), but every legacy metadata key still rides
24763
24781
  // the bag rather than being silently dropped — CaptureAttributes'
@@ -35444,6 +35462,13 @@ function rebuildCapture(row) {
35444
35462
  ...withField(
35445
35463
  "redactDegradedTo",
35446
35464
  keep(stringOrUndefined(attributes.redact_degraded_to), REDACT_DEGRADED_TO)
35465
+ ),
35466
+ // Carried, for the same reason again: a refused row's content is '' and it
35467
+ // has no findings, so without the marker the deployment reads a refusal as
35468
+ // a clean empty capture. Parsed against the wire for the same reason too.
35469
+ ...withField(
35470
+ "scanIncomplete",
35471
+ keep(stringOrUndefined(attributes.scan_incomplete), SCAN_INCOMPLETE)
35447
35472
  )
35448
35473
  // inspectionMs is DELIBERATELY not carried. It measures latency a live host
35449
35474
  // session actually waited on, and a row being drained hours later is not
@@ -35474,6 +35499,7 @@ var CORRELATION_ID = EventMetadata.shape.correlationId;
35474
35499
  var TRACE_ID = EventMetadata.shape.traceId;
35475
35500
  var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
35476
35501
  var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
35502
+ var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
35477
35503
  function isoOrUndefined(epochMs) {
35478
35504
  if (!Number.isFinite(epochMs)) return void 0;
35479
35505
  const iso = new Date(epochMs);
package/scripts/intro.js CHANGED
@@ -21318,6 +21318,11 @@ var CaptureAttributes = external_exports.object({
21318
21318
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
21319
21319
  // repeated rather than referenced because a store reader opens this file.
21320
21320
  redact_degraded_to: ActionTaken.optional(),
21321
+ // Why a capture has no content and no findings: its field was refused
21322
+ // because its bounded scan did not finish (see EventMetadata.scanIncomplete,
21323
+ // whose value this is). Absent on every capture that was scanned, so a
21324
+ // reader can tell a refused row from an empty clean one.
21325
+ scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
21321
21326
  // The scope key this capture was stamped with: the canonical repository
21322
21327
  // (`host/owner/repo`) of the path the capture names (a relative path is read
21323
21328
  // against its working directory), else of its own working directory, or a
@@ -22628,7 +22633,19 @@ var EventMetadata = external_exports.object({
22628
22633
  // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
22629
22634
  // Closing either means moving the reason onto the finding row, which
22630
22635
  // already carries its own action.
22631
- redactDegradedTo: ActionTaken.optional()
22636
+ redactDegradedTo: ActionTaken.optional(),
22637
+ // Set when this capture's field was REFUSED rather than scanned: a hook
22638
+ // bounds the scan of a large field (see `LargeInputScanOptions` in
22639
+ // @akasecurity/plugin-sdk), and a scan that did not finish blocks the
22640
+ // field instead of letting it through unscanned.
22641
+ //
22642
+ // - 'timeout': the bounded scan ran out of time.
22643
+ // - 'unavailable': no worker could run it.
22644
+ //
22645
+ // A refused row stores '' as its content and has no findings, which is
22646
+ // exactly what a clean, empty capture looks like — this marker is the only
22647
+ // thing that tells the two apart. Absent on every capture that was scanned.
22648
+ scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
22632
22649
  }).meta({ id: "EventMetadata" });
22633
22650
  var Event = external_exports.object({
22634
22651
  id: external_exports.guid(),