@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.
@@ -21684,6 +21684,11 @@ var CaptureAttributes = external_exports.object({
21684
21684
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
21685
21685
  // repeated rather than referenced because a store reader opens this file.
21686
21686
  redact_degraded_to: ActionTaken.optional(),
21687
+ // Why a capture has no content and no findings: its field was refused
21688
+ // because its bounded scan did not finish (see EventMetadata.scanIncomplete,
21689
+ // whose value this is). Absent on every capture that was scanned, so a
21690
+ // reader can tell a refused row from an empty clean one.
21691
+ scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
21687
21692
  // The scope key this capture was stamped with: the canonical repository
21688
21693
  // (`host/owner/repo`) of the path the capture names (a relative path is read
21689
21694
  // against its working directory), else of its own working directory, or a
@@ -23025,7 +23030,19 @@ var EventMetadata = external_exports.object({
23025
23030
  // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23026
23031
  // Closing either means moving the reason onto the finding row, which
23027
23032
  // already carries its own action.
23028
- redactDegradedTo: ActionTaken.optional()
23033
+ redactDegradedTo: ActionTaken.optional(),
23034
+ // Set when this capture's field was REFUSED rather than scanned: a hook
23035
+ // bounds the scan of a large field (see `LargeInputScanOptions` in
23036
+ // @akasecurity/plugin-sdk), and a scan that did not finish blocks the
23037
+ // field instead of letting it through unscanned.
23038
+ //
23039
+ // - 'timeout': the bounded scan ran out of time.
23040
+ // - 'unavailable': no worker could run it.
23041
+ //
23042
+ // A refused row stores '' as its content and has no findings, which is
23043
+ // exactly what a clean, empty capture looks like — this marker is the only
23044
+ // thing that tells the two apart. Absent on every capture that was scanned.
23045
+ scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
23029
23046
  }).meta({ id: "EventMetadata" });
23030
23047
  var Event = external_exports.object({
23031
23048
  id: external_exports.guid(),
@@ -24842,6 +24859,7 @@ function toCaptureAttributes(event) {
24842
24859
  ...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
24843
24860
  ...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
24844
24861
  ...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
24862
+ ...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
24845
24863
  // `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
24846
24864
  // has ever populated either), but every legacy metadata key still rides
24847
24865
  // the bag rather than being silently dropped — CaptureAttributes'
@@ -36865,6 +36883,38 @@ function worstProbeMs(rule, now = wallClock, corroborate) {
36865
36883
  }
36866
36884
  var CPU_CORROBORATION_SHARE = 0.2;
36867
36885
  var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
36886
+ function repeatTo(unit, length) {
36887
+ return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
36888
+ }
36889
+ function joinTo(length, open3, close, item) {
36890
+ const parts = [];
36891
+ let size = open3.length;
36892
+ for (let i = 0; size < length; i++) {
36893
+ const next = (i === 0 ? "" : ",") + item(i);
36894
+ parts.push(next);
36895
+ size += next.length;
36896
+ }
36897
+ return (open3 + parts.join("") + close).slice(0, length);
36898
+ }
36899
+ var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
36900
+ var GROWTH_CORPORA = [
36901
+ {
36902
+ name: "one-line JSON dictionary",
36903
+ build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
36904
+ },
36905
+ {
36906
+ name: "JSON array of quoted SQL keywords",
36907
+ build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
36908
+ },
36909
+ { name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
36910
+ { name: "double-quote run", build: (length) => repeatTo('"', length) },
36911
+ { name: "space run", build: (length) => repeatTo(" ", length) },
36912
+ { name: "newline run", build: (length) => repeatTo("\n", length) },
36913
+ ...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
36914
+ name: `unit run ${JSON.stringify(unit)}`,
36915
+ build: (length) => repeatTo(unit, length)
36916
+ }))
36917
+ ];
36868
36918
  function checkRuleTiming(rule, corroborate) {
36869
36919
  const { ms, probe, corroboratedMs } = worstProbeMs(rule, wallClock, corroborate);
36870
36920
  const work = corroboratedMs ?? 0;
@@ -37166,7 +37216,7 @@ var auth_jwt_no_verify_default = {
37166
37216
  severity: "critical",
37167
37217
  matcher: {
37168
37218
  type: "regex",
37169
- pattern: "(verify\\s*=\\s*false|verify_signature.*false|algorithms\\s*=\\s*\\[\\])",
37219
+ pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
37170
37220
  flags: "gi"
37171
37221
  },
37172
37222
  requiresNearby: {
@@ -37254,7 +37304,7 @@ var cmd_inject_shell_default = {
37254
37304
  severity: "critical",
37255
37305
  matcher: {
37256
37306
  type: "regex",
37257
- pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
37307
+ pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
37258
37308
  flags: "gi"
37259
37309
  },
37260
37310
  requiresNearby: {
@@ -37383,7 +37433,7 @@ var deser_yaml_unsafe_default = {
37383
37433
  severity: "high",
37384
37434
  matcher: {
37385
37435
  type: "regex",
37386
- pattern: "\\byaml\\.load\\s*\\((?![^)]*SafeLoader|[^)]*safe_load)",
37436
+ pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
37387
37437
  flags: "gi"
37388
37438
  },
37389
37439
  examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
@@ -37600,7 +37650,7 @@ var sql_inject_concat_dot_default = {
37600
37650
  severity: "high",
37601
37651
  matcher: {
37602
37652
  type: "regex",
37603
- pattern: `["'][^\\n]*?(select|insert|update|delete|drop|where)[^\\n]*?["']\\s*\\.`,
37653
+ pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
37604
37654
  flags: "gi"
37605
37655
  },
37606
37656
  appliesTo: {
@@ -37618,7 +37668,7 @@ var sql_inject_concat_default = {
37618
37668
  severity: "high",
37619
37669
  matcher: {
37620
37670
  type: "regex",
37621
- 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*\\+`,
37671
+ 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*\\+`,
37622
37672
  flags: "gi"
37623
37673
  },
37624
37674
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -37633,7 +37683,7 @@ var sql_inject_format_default = {
37633
37683
  severity: "high",
37634
37684
  matcher: {
37635
37685
  type: "regex",
37636
- 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]|\\{[^}]+\\})",
37686
+ 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]+\\})",
37637
37687
  flags: "gi"
37638
37688
  },
37639
37689
  examples: [
@@ -37651,7 +37701,7 @@ var sql_inject_interp_default = {
37651
37701
  severity: "high",
37652
37702
  matcher: {
37653
37703
  type: "regex",
37654
- pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
37704
+ pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
37655
37705
  flags: "gi"
37656
37706
  },
37657
37707
  examples: [
@@ -38026,7 +38076,7 @@ var stack_trace_default = {
38026
38076
  severity: "low",
38027
38077
  matcher: {
38028
38078
  type: "regex",
38029
- pattern: "(?:^|\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
38079
+ pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
38030
38080
  flags: "g"
38031
38081
  },
38032
38082
  examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
@@ -39184,7 +39234,7 @@ var BUNDLED_PACKS = [
39184
39234
  {
39185
39235
  packId: "code-flaws",
39186
39236
  name: "Code Security Flaws",
39187
- version: "0.1.0",
39237
+ version: "0.1.1",
39188
39238
  rawRules: [
39189
39239
  sql_inject_concat_default,
39190
39240
  sql_inject_concat_dot_default,
@@ -39234,7 +39284,7 @@ var BUNDLED_PACKS = [
39234
39284
  {
39235
39285
  packId: "core-code-context",
39236
39286
  name: "Code Context",
39237
- version: "0.2.1",
39287
+ version: "0.2.2",
39238
39288
  rawRules: [
39239
39289
  internal_ip_default,
39240
39290
  localhost_ref_default,
@@ -39681,9 +39731,10 @@ function createIsolatedScanner(data, opts = {}) {
39681
39731
  if (job.timer !== void 0) return;
39682
39732
  job.startedAt = performance.now();
39683
39733
  job.progressAt = job.startedAt;
39734
+ const budget = job.deadlineAt === void 0 ? job.budgetMs : Math.max(0, Math.min(job.budgetMs, job.deadlineAt - job.startedAt));
39684
39735
  job.timer = setTimeout(() => {
39685
39736
  onDeadline(job);
39686
- }, job.budgetMs);
39737
+ }, budget);
39687
39738
  }
39688
39739
  function runOne(spec, fail) {
39689
39740
  if (closed) {
@@ -39694,6 +39745,12 @@ function createIsolatedScanner(data, opts = {}) {
39694
39745
  fail({ status: "unavailable", reason: `the scan worker crashed: ${broken}` });
39695
39746
  return;
39696
39747
  }
39748
+ const now = performance.now();
39749
+ const deadlineAt = spec.deadlineAt;
39750
+ if (deadlineAt !== void 0 && deadlineAt <= now) {
39751
+ fail({ status: "timeout", culpritIndex: void 0, elapsedMs: 0 });
39752
+ return;
39753
+ }
39697
39754
  const started = ensureWorker();
39698
39755
  if (!(started instanceof Worker)) {
39699
39756
  broken = started.error;
@@ -39701,11 +39758,11 @@ function createIsolatedScanner(data, opts = {}) {
39701
39758
  return;
39702
39759
  }
39703
39760
  const id = nextJobId++;
39704
- const now = performance.now();
39705
39761
  const job = {
39706
39762
  id,
39707
39763
  worker: started,
39708
39764
  budgetMs: spec.budgetMs,
39765
+ deadlineAt,
39709
39766
  startedAt: now,
39710
39767
  progressIndex: -1,
39711
39768
  progressAt: now,
@@ -39719,14 +39776,19 @@ function createIsolatedScanner(data, opts = {}) {
39719
39776
  if (readyWorker === started) {
39720
39777
  beginDeadline(job);
39721
39778
  } else {
39779
+ const startBudget = spec.startBudgetMs ?? startBudgetMs;
39780
+ const callerLimited = deadlineAt !== void 0 && deadlineAt - now < startBudget;
39781
+ const startWaitMs = callerLimited ? deadlineAt - now : startBudget;
39722
39782
  job.startupTimer = setTimeout(() => {
39723
39783
  if (pending !== job) return;
39724
39784
  kill(job.worker);
39725
- failPending({
39726
- status: "unavailable",
39727
- reason: `the scan worker did not start within ${String(startBudgetMs)}ms`
39728
- });
39729
- }, startBudgetMs);
39785
+ failPending(
39786
+ callerLimited ? { status: "timeout", culpritIndex: void 0, elapsedMs: performance.now() - now } : {
39787
+ status: "unavailable",
39788
+ reason: `the scan worker did not start within ${String(startBudget)}ms`
39789
+ }
39790
+ );
39791
+ }, startWaitMs);
39730
39792
  }
39731
39793
  try {
39732
39794
  started.postMessage(spec.build(id));
@@ -39755,7 +39817,9 @@ function createIsolatedScanner(data, opts = {}) {
39755
39817
  return enqueue((resolve3) => {
39756
39818
  runOne(
39757
39819
  {
39758
- budgetMs,
39820
+ budgetMs: scanOpts?.budgetMs ?? budgetMs,
39821
+ startBudgetMs: scanOpts?.startBudgetMs,
39822
+ deadlineAt: scanOpts?.deadlineAt,
39759
39823
  build: (id) => ({
39760
39824
  kind: "scan",
39761
39825
  id,
@@ -39949,6 +40013,9 @@ function createGuardedScanner(partition, gateway, opts) {
39949
40013
  let unverified = partition.unverified;
39950
40014
  let isolated = unverified.length > 0 ? createIsolatedScanner({ verified, unverified }, opts) : void 0;
39951
40015
  let retired = false;
40016
+ let bounded;
40017
+ let boundedWarned = false;
40018
+ let closed = false;
39952
40019
  function inProcess(text, context) {
39953
40020
  return scan(text, verified, context);
39954
40021
  }
@@ -40010,11 +40077,48 @@ function createGuardedScanner(partition, gateway, opts) {
40010
40077
  await degrade();
40011
40078
  return inProcess(text, context);
40012
40079
  }
40080
+ async function scanBounded(text, context, bound) {
40081
+ const remainingMs = bound.remainingMs;
40082
+ let outcome;
40083
+ if (closed) {
40084
+ outcome = { status: "unavailable", reason: "the scan worker is closed" };
40085
+ } else if (remainingMs !== void 0 && !(remainingMs > 0)) {
40086
+ outcome = { status: "timeout", culpritIndex: void 0, elapsedMs: 0 };
40087
+ } else {
40088
+ bounded ??= createIsolatedScanner({ verified, unverified }, opts);
40089
+ const deadlineAt = remainingMs === void 0 ? void 0 : performance.now() + remainingMs;
40090
+ try {
40091
+ outcome = await bounded.scan(text, context, {
40092
+ budgetMs: bound.budgetMs,
40093
+ startBudgetMs: bound.startBudgetMs,
40094
+ deadlineAt
40095
+ });
40096
+ } catch (error62) {
40097
+ outcome = {
40098
+ status: "unavailable",
40099
+ reason: error62 instanceof Error ? error62.message : "the scan worker failed unexpectedly"
40100
+ };
40101
+ }
40102
+ }
40103
+ if (outcome.status !== "ok" && !boundedWarned) {
40104
+ boundedWarned = true;
40105
+ process.stderr.write(
40106
+ outcome.status === "timeout" ? `[aka] a large input could not be scanned within its time limit and was refused.
40107
+ ` : `[aka] a large input could not be scanned and was refused: ${outcome.reason}.
40108
+ `
40109
+ );
40110
+ }
40111
+ return outcome;
40112
+ }
40013
40113
  return {
40014
40114
  scan: guardedScan,
40115
+ scanBounded,
40015
40116
  degraded: () => retired,
40016
40117
  async close() {
40017
- await retire();
40118
+ closed = true;
40119
+ const live = bounded;
40120
+ bounded = void 0;
40121
+ await Promise.all([retire(), live?.close()]);
40018
40122
  }
40019
40123
  };
40020
40124
  }
@@ -40141,6 +40245,19 @@ function conditionsMatch(conditions, ctx) {
40141
40245
  if (conditions.provider !== void 0) return false;
40142
40246
  return true;
40143
40247
  }
40248
+ var LARGE_INPUT_THRESHOLD_CHARS = 32768;
40249
+ var LARGE_INPUT_SCAN_BUDGET_MS = 2e3;
40250
+ var LARGE_INPUT_START_BUDGET_MS = 1500;
40251
+ function readRemainingMs(largeInput) {
40252
+ const read = largeInput.remainingMs;
40253
+ if (read === void 0) return void 0;
40254
+ try {
40255
+ const remaining = read();
40256
+ return typeof remaining !== "number" || Number.isNaN(remaining) ? 0 : remaining;
40257
+ } catch {
40258
+ return 0;
40259
+ }
40260
+ }
40144
40261
  var bundlesPacked = false;
40145
40262
  function createPluginRuntime(gateway, settings, opts) {
40146
40263
  if (!bundlesPacked) {
@@ -40150,6 +40267,7 @@ function createPluginRuntime(gateway, settings, opts) {
40150
40267
  const policyMode = settings.policy;
40151
40268
  let redactFallback = settings.redactFallback;
40152
40269
  const dataDir2 = opts?.dataDir;
40270
+ const largeInput = opts?.largeInput;
40153
40271
  let rules = [];
40154
40272
  let evidenceOf = evidenceLookup(rules);
40155
40273
  let scanner;
@@ -40362,7 +40480,24 @@ function createPluginRuntime(gateway, settings, opts) {
40362
40480
  await ensureInitialized();
40363
40481
  if (!scanner) throw new Error("the runtime initialized without a scanner");
40364
40482
  const shielded = shieldPointers(text);
40365
- const matched = await scanner.scan(shielded.text, context);
40483
+ let matched;
40484
+ if (largeInput !== void 0 && shielded.text.length >= largeInput.thresholdChars) {
40485
+ const outcome = await scanner.scanBounded(shielded.text, context, {
40486
+ budgetMs: largeInput.budgetMs,
40487
+ startBudgetMs: largeInput.startBudgetMs,
40488
+ remainingMs: readRemainingMs(largeInput)
40489
+ });
40490
+ if (outcome.status !== "ok") {
40491
+ return {
40492
+ decision: { action: "block", text: null, findings: [], scanIncomplete: outcome.status },
40493
+ excepted: /* @__PURE__ */ new Set(),
40494
+ exceptionIds: []
40495
+ };
40496
+ }
40497
+ matched = outcome.findings;
40498
+ } else {
40499
+ matched = await scanner.scan(shielded.text, context);
40500
+ }
40366
40501
  const findings = dropShieldedFindings(matched, shielded.spans);
40367
40502
  const fpCache = /* @__PURE__ */ new Map();
40368
40503
  const { excepted, exceptionIds } = await applyExceptions(findings, ctx, fpCache);
@@ -40403,20 +40538,24 @@ function createPluginRuntime(gateway, settings, opts) {
40403
40538
  }
40404
40539
  async function persistCapture(input2, opts2, { decision, excepted, exceptionIds, timingStartedAt }) {
40405
40540
  const filePath = input2.metadata?.filePath;
40406
- if (opts2.persist === "with-findings" && decision.findings.length === 0) return;
40541
+ if (opts2.persist === "with-findings" && decision.findings.length === 0 && decision.scanIncomplete === void 0) {
40542
+ return;
40543
+ }
40407
40544
  try {
40408
40545
  const contentHash = contentHashOf(input2.text);
40409
40546
  const maskedFindings = decision.findings.filter(
40410
40547
  (match) => isActionAtLeast(actionForFinding(match, excepted, opts2.rewritable), "redact")
40411
40548
  );
40412
- const storedContent = maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
40549
+ const storedContent = decision.scanIncomplete !== void 0 ? "" : maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
40413
40550
  const inspectionMs = elapsedMs(timingStartedAt);
40414
40551
  const redactDegradedTo = decision.redactDegradedTo;
40415
- const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 ? {
40552
+ const scanIncomplete = decision.scanIncomplete;
40553
+ const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 || scanIncomplete !== void 0 ? {
40416
40554
  ...input2.metadata,
40417
40555
  ...exceptionIds.length > 0 ? { exceptionIds } : {},
40418
40556
  ...inspectionMs !== void 0 ? { inspectionMs } : {},
40419
- ...redactDegradedTo !== void 0 ? { redactDegradedTo } : {}
40557
+ ...redactDegradedTo !== void 0 ? { redactDegradedTo } : {},
40558
+ ...scanIncomplete !== void 0 ? { scanIncomplete } : {}
40420
40559
  } : input2.metadata;
40421
40560
  const event = buildIngestEvent({
40422
40561
  kind: input2.kind,
@@ -40537,6 +40676,17 @@ function createPluginRuntime(gateway, settings, opts) {
40537
40676
  };
40538
40677
  }
40539
40678
 
40679
+ // src/hooks/large-input.ts
40680
+ var HOOK_SCAN_DEADLINE_MS = 6e3;
40681
+ function largeInputBound(deadlineAt, now = () => performance.now()) {
40682
+ return {
40683
+ thresholdChars: LARGE_INPUT_THRESHOLD_CHARS,
40684
+ budgetMs: LARGE_INPUT_SCAN_BUDGET_MS,
40685
+ startBudgetMs: LARGE_INPUT_START_BUDGET_MS,
40686
+ remainingMs: () => deadlineAt - now()
40687
+ };
40688
+ }
40689
+
40540
40690
  // src/present.ts
40541
40691
  var fg = (hex3) => (text) => {
40542
40692
  const r = Number.parseInt(hex3.slice(1, 3), 16);
@@ -40578,6 +40728,9 @@ function blockMessage(input2) {
40578
40728
  "More: aka exception --help"
40579
40729
  ].join("\n");
40580
40730
  }
40731
+ function tooLargeToScanMessage(subject) {
40732
+ return `This ${subject} is too large for AKA to scan within the time limit, so it was blocked. Shorten it or send it in smaller parts.`;
40733
+ }
40581
40734
  function exceptionPointer(references) {
40582
40735
  const ref = references?.[0];
40583
40736
  if (ref === void 0) return "";
@@ -40617,6 +40770,15 @@ function decidePreToolUse(toolName, toolInput, scanned) {
40617
40770
  let escalatedExecutable = false;
40618
40771
  let escalatedUnredactable = false;
40619
40772
  let updatedInput = null;
40773
+ if (scanned.some(({ result }) => result.scanIncomplete !== void 0)) {
40774
+ return {
40775
+ hookSpecificOutput: {
40776
+ hookEventName: "PreToolUse",
40777
+ permissionDecision: "deny",
40778
+ permissionDecisionReason: tooLargeToScanMessage(`${toolName} call`)
40779
+ }
40780
+ };
40781
+ }
40620
40782
  for (const { spec, result } of scanned) {
40621
40783
  if (result.redactDegradedTo === "block") escalatedExecutable = true;
40622
40784
  const unredactable = result.action === "redact" && result.text === null;
@@ -42211,6 +42373,7 @@ var CORRELATION_ID = EventMetadata.shape.correlationId;
42211
42373
  var TRACE_ID = EventMetadata.shape.traceId;
42212
42374
  var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
42213
42375
  var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
42376
+ var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
42214
42377
 
42215
42378
  // ../../packages/plugin-runtime/src/attached/history-sync.ts
42216
42379
  var CAPTURE_BATCH_BYTES = 1024 * 1024;
@@ -43288,7 +43451,10 @@ async function main() {
43288
43451
  return;
43289
43452
  }
43290
43453
  const gateway = opened.gateway;
43291
- const runtime = createPluginRuntime(gateway, config2.settings, { dataDir: config2.dataDir });
43454
+ const runtime = createPluginRuntime(gateway, config2.settings, {
43455
+ dataDir: config2.dataDir,
43456
+ largeInput: largeInputBound(HOOK_SCAN_DEADLINE_MS)
43457
+ });
43292
43458
  const toolInput = { ...rawToolInput };
43293
43459
  const kind = toolName === "apply_patch" ? "code_change" : "tool_use";
43294
43460
  const metadata = baseMetadata(input2) ?? {};
@@ -43314,6 +43480,7 @@ async function main() {
43314
43480
  }
43315
43481
  );
43316
43482
  scanned.push({ spec, result });
43483
+ if (result.scanIncomplete !== void 0) break;
43317
43484
  }
43318
43485
  } finally {
43319
43486
  await runtime.close();
package/scripts/query.js CHANGED
@@ -21828,6 +21828,11 @@ var CaptureAttributes = external_exports.object({
21828
21828
  // here too. The full statement is on EventMetadata.redactDegradedTo; it is
21829
21829
  // repeated rather than referenced because a store reader opens this file.
21830
21830
  redact_degraded_to: ActionTaken.optional(),
21831
+ // Why a capture has no content and no findings: its field was refused
21832
+ // because its bounded scan did not finish (see EventMetadata.scanIncomplete,
21833
+ // whose value this is). Absent on every capture that was scanned, so a
21834
+ // reader can tell a refused row from an empty clean one.
21835
+ scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
21831
21836
  // The scope key this capture was stamped with: the canonical repository
21832
21837
  // (`host/owner/repo`) of the path the capture names (a relative path is read
21833
21838
  // against its working directory), else of its own working directory, or a
@@ -23169,7 +23174,19 @@ var EventMetadata = external_exports.object({
23169
23174
  // Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
23170
23175
  // Closing either means moving the reason onto the finding row, which
23171
23176
  // already carries its own action.
23172
- redactDegradedTo: ActionTaken.optional()
23177
+ redactDegradedTo: ActionTaken.optional(),
23178
+ // Set when this capture's field was REFUSED rather than scanned: a hook
23179
+ // bounds the scan of a large field (see `LargeInputScanOptions` in
23180
+ // @akasecurity/plugin-sdk), and a scan that did not finish blocks the
23181
+ // field instead of letting it through unscanned.
23182
+ //
23183
+ // - 'timeout': the bounded scan ran out of time.
23184
+ // - 'unavailable': no worker could run it.
23185
+ //
23186
+ // A refused row stores '' as its content and has no findings, which is
23187
+ // exactly what a clean, empty capture looks like — this marker is the only
23188
+ // thing that tells the two apart. Absent on every capture that was scanned.
23189
+ scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
23173
23190
  }).meta({ id: "EventMetadata" });
23174
23191
  var Event = external_exports.object({
23175
23192
  id: external_exports.guid(),
@@ -24990,6 +25007,7 @@ function toCaptureAttributes(event) {
24990
25007
  ...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
24991
25008
  ...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
24992
25009
  ...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
25010
+ ...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
24993
25011
  // `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
24994
25012
  // has ever populated either), but every legacy metadata key still rides
24995
25013
  // the bag rather than being silently dropped — CaptureAttributes'
@@ -36370,6 +36388,38 @@ var POLYNOMIAL_PROBES = ["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].m
36370
36388
  );
36371
36389
  var CPU_CORROBORATION_SHARE = 0.2;
36372
36390
  var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
36391
+ function repeatTo(unit, length) {
36392
+ return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
36393
+ }
36394
+ function joinTo(length, open3, close, item) {
36395
+ const parts = [];
36396
+ let size = open3.length;
36397
+ for (let i = 0; size < length; i++) {
36398
+ const next = (i === 0 ? "" : ",") + item(i);
36399
+ parts.push(next);
36400
+ size += next.length;
36401
+ }
36402
+ return (open3 + parts.join("") + close).slice(0, length);
36403
+ }
36404
+ var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
36405
+ var GROWTH_CORPORA = [
36406
+ {
36407
+ name: "one-line JSON dictionary",
36408
+ build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
36409
+ },
36410
+ {
36411
+ name: "JSON array of quoted SQL keywords",
36412
+ build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
36413
+ },
36414
+ { name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
36415
+ { name: "double-quote run", build: (length) => repeatTo('"', length) },
36416
+ { name: "space run", build: (length) => repeatTo(" ", length) },
36417
+ { name: "newline run", build: (length) => repeatTo("\n", length) },
36418
+ ...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
36419
+ name: `unit run ${JSON.stringify(unit)}`,
36420
+ build: (length) => repeatTo(unit, length)
36421
+ }))
36422
+ ];
36373
36423
 
36374
36424
  // ../../rules/code-flaws/auth-jwt-no-verify.json
36375
36425
  var auth_jwt_no_verify_default = {
@@ -36380,7 +36430,7 @@ var auth_jwt_no_verify_default = {
36380
36430
  severity: "critical",
36381
36431
  matcher: {
36382
36432
  type: "regex",
36383
- pattern: "(verify\\s*=\\s*false|verify_signature.*false|algorithms\\s*=\\s*\\[\\])",
36433
+ pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
36384
36434
  flags: "gi"
36385
36435
  },
36386
36436
  requiresNearby: {
@@ -36468,7 +36518,7 @@ var cmd_inject_shell_default = {
36468
36518
  severity: "critical",
36469
36519
  matcher: {
36470
36520
  type: "regex",
36471
- pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
36521
+ pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
36472
36522
  flags: "gi"
36473
36523
  },
36474
36524
  requiresNearby: {
@@ -36597,7 +36647,7 @@ var deser_yaml_unsafe_default = {
36597
36647
  severity: "high",
36598
36648
  matcher: {
36599
36649
  type: "regex",
36600
- pattern: "\\byaml\\.load\\s*\\((?![^)]*SafeLoader|[^)]*safe_load)",
36650
+ pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
36601
36651
  flags: "gi"
36602
36652
  },
36603
36653
  examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
@@ -36814,7 +36864,7 @@ var sql_inject_concat_dot_default = {
36814
36864
  severity: "high",
36815
36865
  matcher: {
36816
36866
  type: "regex",
36817
- pattern: `["'][^\\n]*?(select|insert|update|delete|drop|where)[^\\n]*?["']\\s*\\.`,
36867
+ pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
36818
36868
  flags: "gi"
36819
36869
  },
36820
36870
  appliesTo: {
@@ -36832,7 +36882,7 @@ var sql_inject_concat_default = {
36832
36882
  severity: "high",
36833
36883
  matcher: {
36834
36884
  type: "regex",
36835
- 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*\\+`,
36885
+ 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*\\+`,
36836
36886
  flags: "gi"
36837
36887
  },
36838
36888
  examples: ['"SELECT * FROM users WHERE id = " + userId']
@@ -36847,7 +36897,7 @@ var sql_inject_format_default = {
36847
36897
  severity: "high",
36848
36898
  matcher: {
36849
36899
  type: "regex",
36850
- 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]|\\{[^}]+\\})",
36900
+ 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]+\\})",
36851
36901
  flags: "gi"
36852
36902
  },
36853
36903
  examples: [
@@ -36865,7 +36915,7 @@ var sql_inject_interp_default = {
36865
36915
  severity: "high",
36866
36916
  matcher: {
36867
36917
  type: "regex",
36868
- pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
36918
+ pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
36869
36919
  flags: "gi"
36870
36920
  },
36871
36921
  examples: [
@@ -37240,7 +37290,7 @@ var stack_trace_default = {
37240
37290
  severity: "low",
37241
37291
  matcher: {
37242
37292
  type: "regex",
37243
- pattern: "(?:^|\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
37293
+ pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
37244
37294
  flags: "g"
37245
37295
  },
37246
37296
  examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
@@ -38398,7 +38448,7 @@ var BUNDLED_PACKS = [
38398
38448
  {
38399
38449
  packId: "code-flaws",
38400
38450
  name: "Code Security Flaws",
38401
- version: "0.1.0",
38451
+ version: "0.1.1",
38402
38452
  rawRules: [
38403
38453
  sql_inject_concat_default,
38404
38454
  sql_inject_concat_dot_default,
@@ -38448,7 +38498,7 @@ var BUNDLED_PACKS = [
38448
38498
  {
38449
38499
  packId: "core-code-context",
38450
38500
  name: "Code Context",
38451
- version: "0.2.1",
38501
+ version: "0.2.2",
38452
38502
  rawRules: [
38453
38503
  internal_ip_default,
38454
38504
  localhost_ref_default,
@@ -40065,6 +40115,7 @@ var CORRELATION_ID = EventMetadata.shape.correlationId;
40065
40115
  var TRACE_ID = EventMetadata.shape.traceId;
40066
40116
  var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
40067
40117
  var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
40118
+ var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
40068
40119
 
40069
40120
  // ../../packages/plugin-runtime/src/attached/history-sync.ts
40070
40121
  var CAPTURE_BATCH_BYTES = 1024 * 1024;