@openai/codex-security 0.1.8 → 0.1.9

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.
package/README.md CHANGED
@@ -212,6 +212,7 @@ npx @openai/codex-security scan /path/to/repository --mode deep --workers 2 --su
212
212
  npx @openai/codex-security install-hook
213
213
  npx @openai/codex-security bulk-scan
214
214
  npx @openai/codex-security bulk-scan --model gpt-5.6-terra --effort high
215
+ npx @openai/codex-security bulk-scan --workers 4 --mode deep --max-attempts 3
215
216
  npx @openai/codex-security bulk-scan repositories.csv --output-dir /path/outside/repositories/security-scans --workers 4 --knowledge-base /path/to/threat-models --knowledge-base /path/to/architecture.pdf
216
217
  npx @openai/codex-security bulk-scan repositories.csv --output-dir /path/outside/repositories/security-scans --scan-prompt-file scan.md --post-scan-prompt-file follow-up.md
217
218
  npx @openai/codex-security scans list /path/to/repository
@@ -463,9 +464,7 @@ including cached input and cache writes; fees and surcharges are not included.
463
464
 
464
465
  Use `--max-cost USD` to stop a scan, including its delegated workers, when its
465
466
  running cost exceeds the limit. Partial results are preserved. Requests
466
- already in progress can finish above the limit. Cost tracking accepts Codex
467
- session events up to 1 MiB; an oversized event stops the scan because its
468
- running cost can no longer be verified safely.
467
+ already in progress can finish above the limit.
469
468
 
470
469
  Run `npx @openai/codex-security scan --help` or `npx @openai/codex-security bulk-scan --help`
471
470
  for the complete CLI references.
@@ -478,6 +477,11 @@ Private checkouts reuse your GitHub CLI sign-in without changing your global Git
478
477
  configuration. The selected repositories are saved to
479
478
  `<output-dir>/repositories.csv` for review or resumption.
480
479
 
480
+ Interactive discovery accepts the same `--workers`, `--mode`, `--max-attempts`,
481
+ `--model`, `--effort`, `--plugin-path`, `--python`, and `--codex` settings as
482
+ CSV-driven scans. It prompts for the output directory; `--output-dir` is only
483
+ valid when a repository CSV is supplied.
484
+
481
485
  To use an existing repository list or run in CI, pass a CSV with required `id`,
482
486
  `repository`, and `revision` columns. Revisions must be full commit hashes;
483
487
  optional `scope`, `mode`, and `prompt` columns customize individual scans:
@@ -490,7 +494,8 @@ service,https://github.com/acme/service.git,0123456789abcdef0123456789abcdef0123
490
494
  Use `--scan-prompt-file PATH` to add instructions to a scan or every bulk scan.
491
495
  Bulk scans append each repository's CSV `prompt` after the shared instructions.
492
496
  Use `--post-scan-prompt-file PATH` to run a follow-up in the same authenticated
493
- session after each completed scan has been validated.
497
+ session after each scan, including incomplete or failed scans. Canceled scans
498
+ and scans stopped at their configured cost limit do not start another turn.
494
499
 
495
500
  `--workers` limits concurrent scans and `--max-attempts` retries failures.
496
501
  Results remain under `--output-dir`; rerun the same command to resume.
@@ -580,11 +585,7 @@ text. Both commands operate on the current directory, use the scan model
580
585
  and reasoning defaults, ignore unrelated user configuration and plugins, and
581
586
  print the final response without the underlying Codex event stream. Override
582
587
  the model with `--codex 'model="gpt-5.6-sol"'` and the reasoning effort with
583
- `--effort high` or `--codex 'model_reasoning_effort="high"'`. Inputs are
584
- limited to 64 items and 1 MiB total.
585
-
586
- Canonical scan documents are limited to 16 MiB for the manifest, 128 MiB for
587
- findings, and 32 MiB for coverage. Oversized scans are rejected before sealing.
588
+ `--effort high` or `--codex 'model_reasoning_effort="high"'`.
588
589
 
589
590
  Exit codes are `0` for a completed report-only scan or a passing policy, `1`
590
591
  for a completed policy violation, `2` for invalid input, incomplete coverage, or
@@ -632,6 +633,10 @@ device login remains in `state/`. For unattended scans, set `OPENAI_API_KEY`
632
633
  or `CODEX_API_KEY` instead. Set `GH_TOKEN` or `GITHUB_TOKEN` for private
633
634
  GitHub repositories.
634
635
 
636
+ The container accepts the repository CSV before or after bulk-scan options.
637
+ Interactive repository discovery remains disabled, including when global CLI
638
+ options appear before `bulk-scan`.
639
+
635
640
  On Ubuntu hosts that restrict unprivileged user namespaces, an administrator
636
641
  can install the optional, narrowly scoped AppArmor profile once:
637
642
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-security",
3
- "version": "0.1.15",
3
+ "version": "0.1.16",
4
4
  "description": "Codex Security workflows for security scans, analysis, and investigation.",
5
5
  "author": {
6
6
  "name": "OpenAI"
@@ -288,10 +288,36 @@ def path_is_excluded(path: Path) -> bool:
288
288
  return path.name.endswith((".min.js", ".map"))
289
289
 
290
290
 
291
- def resolve_scope(repo: Path, scope: str, *, expand_user: bool = True) -> Path:
291
+ def resolve_scope(
292
+ repo: Path,
293
+ scope: str,
294
+ *,
295
+ expand_user: bool = True,
296
+ reject_symlinks: bool = False,
297
+ ) -> Path:
292
298
  scope_path = Path(scope).expanduser() if expand_user else Path(scope)
293
299
  if not scope_path.is_absolute():
294
300
  scope_path = repo / scope_path
301
+ if reject_symlinks:
302
+ repository = repo.resolve()
303
+ try:
304
+ relative = scope_path.relative_to(repository)
305
+ except ValueError as exc:
306
+ raise SystemExit(f"Scope must be inside repo: {scope_path}") from exc
307
+ ancestor = repository
308
+ for part in relative.parts:
309
+ if part == "..":
310
+ if ancestor == repository:
311
+ raise SystemExit(f"Scope must be inside repo: {scope_path}")
312
+ ancestor = ancestor.parent
313
+ continue
314
+ ancestor /= part
315
+ try:
316
+ metadata = ancestor.stat(follow_symlinks=False)
317
+ except OSError as exc:
318
+ raise SystemExit(f"Scope path not found: {ancestor}") from exc
319
+ if ancestor.is_symlink() or getattr(metadata, "st_reparse_tag", 0) & 0x20000000:
320
+ raise SystemExit(f"Requested scope must not contain symbolic links: {ancestor}")
295
321
  scope_path = scope_path.resolve()
296
322
  repo_resolved = repo.resolve()
297
323
  try:
@@ -481,7 +507,7 @@ def make_repo_scope_input(args: argparse.Namespace) -> None:
481
507
  scopes = load_scopes_file(Path(args.scopes_file).expanduser())
482
508
  rows_by_path: dict[str, JsonRow] = {}
483
509
  for scope in scopes:
484
- scope_path = resolve_scope(repo, scope, expand_user=False)
510
+ scope_path = resolve_scope(repo, scope, expand_user=False, reject_symlinks=True)
485
511
  if scope_path.is_file():
486
512
  candidates = (scope_path,)
487
513
  else:
@@ -39,7 +39,6 @@ SQLITE_RETRY_ATTEMPTS = 5
39
39
  CLAIM_LEASE_SECONDS = 120
40
40
  DELIVERED_ACTION_LEASE_SECONDS = 900
41
41
  PATCH_PREVIEW_BYTES = 16_000
42
- PATCH_ARTIFACT_MAX_BYTES = 2 * 1024 * 1024
43
42
  FINDINGS_RESULT_LIMIT = 20
44
43
  FINDINGS_PAGE_MAX = 20
45
44
  FINDING_DETAILS_PREVIEW_BYTES = 16_000
@@ -74,7 +74,6 @@ from workbench_constants import (
74
74
  FINDING_TITLE_BYTES,
75
75
  FINDINGS_PAGE_MAX,
76
76
  FINDINGS_RESULT_LIMIT,
77
- PATCH_ARTIFACT_MAX_BYTES,
78
77
  PATCH_PREVIEW_BYTES,
79
78
  SQLITE_RETRY_ATTEMPTS,
80
79
  )
@@ -2442,18 +2441,12 @@ def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
2442
2441
  def require_matching_patch_digest(scan: sqlite3.Row, patch_path: str, patch_digest: str) -> None:
2443
2442
  digest = hashlib.sha256()
2444
2443
  with open_scan_local_file(Path(scan["scan_dir"]), patch_path) as patch:
2445
- require_bounded_patch_artifact(patch)
2446
2444
  while chunk := patch.read(1024 * 1024):
2447
2445
  digest.update(chunk)
2448
2446
  if f"sha256:{digest.hexdigest()}" != patch_digest:
2449
2447
  raise SystemExit("Patch digest does not match the scan-local patch file.")
2450
2448
 
2451
2449
 
2452
- def require_bounded_patch_artifact(patch: Any) -> None:
2453
- if os.fstat(patch.fileno()).st_size > PATCH_ARTIFACT_MAX_BYTES:
2454
- raise SystemExit("Patch artifact must be no larger than 2 MiB.")
2455
-
2456
-
2457
2450
  def open_scan_local_file(scan_dir: Path, relative_path: str) -> Any:
2458
2451
  parsed = PurePosixPath(relative_path)
2459
2452
  if parsed.is_absolute() or not parsed.parts or ".." in parsed.parts:
@@ -3150,7 +3143,6 @@ def patch_artifact_preview(
3150
3143
  at_line_start = True
3151
3144
  try:
3152
3145
  with open_scan_local_file(scan_dir, relative_path) as patch:
3153
- require_bounded_patch_artifact(patch)
3154
3146
  while chunk := patch.readline(1024 * 1024):
3155
3147
  digest.update(chunk)
3156
3148
  if len(preview) <= PATCH_PREVIEW_BYTES:
@@ -256,7 +256,7 @@ def list_unmatched_scan_pairs(
256
256
  }
257
257
  batches = []
258
258
  skipped = 0
259
- backfilled: set[str] = set()
259
+ matching_findings: dict[str, list[dict[str, Any]]] = {}
260
260
  for index, after in enumerate(available):
261
261
  previous = [
262
262
  before
@@ -267,21 +267,19 @@ def list_unmatched_scan_pairs(
267
267
  if not previous:
268
268
  continue
269
269
  for scan in (*previous, after):
270
- if scan["id"] not in backfilled:
270
+ if scan["id"] not in matching_findings:
271
271
  backfill_finding_details(connection, scan)
272
- backfilled.add(scan["id"])
272
+ matching_findings[scan["id"]] = [
273
+ _matching_input(row)
274
+ for row in _scan_findings(connection, scan["id"]).values()
275
+ ]
273
276
  batches.append(
274
277
  {
275
- "afterFindings": [
276
- _matching_input(row) for row in _scan_findings(connection, after["id"]).values()
277
- ],
278
+ "afterFindings": matching_findings[after["id"]],
278
279
  "afterScanId": after["id"],
279
280
  "beforeScans": [
280
281
  {
281
- "findings": [
282
- _matching_input(row)
283
- for row in _scan_findings(connection, before["id"]).values()
284
- ],
282
+ "findings": matching_findings[before["id"]],
285
283
  "scanId": before["id"],
286
284
  }
287
285
  for before in previous
package/dist/api.d.ts CHANGED
@@ -138,7 +138,7 @@ export declare function runScanEvents(options: ScanEventRunOptions): Promise<Sca
138
138
  export declare function scanAuthentication(environment: ProcessEnvironment, auth?: ScanAuthMode, modelProvider?: unknown): ScanAuthentication;
139
139
  export declare function classifyConnectionFailure(error: unknown): "rate_limited" | "unauthorized" | "forbidden" | "network_error" | "timeout" | "unknown";
140
140
  export declare function scanRuntimeCodexConfig(config: JsonObject, stateDirectory: string, protectedCredentialHome?: string): JsonObject;
141
- export declare function scanPreflightCodexConfig(config: JsonObject, activeProjectPath?: string): JsonObject;
141
+ export declare function scanPreflightCodexConfig(config: JsonObject): JsonObject;
142
142
  export declare function environmentValue(environment: ProcessEnvironment, requested: string): string | undefined;
143
143
  export {};
144
144
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAoBA,OAAO,EAEL,gBAAgB,EAGhB,KAAK,aAAa,EACnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAML,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAqC,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAgBvB,OAAO,EAAE,UAAU,EAA2B,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAA2B,KAAK,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAQL,iBAAiB,EAejB,KAAK,kBAAkB,EAGxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAML,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,UAAU,EAGhB,MAAM,cAAc,CAAC;AAEtB,UAAU,eAAe;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CACT,KAAK,EAAE,MAAM,EACb,OAAO,EAAE;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,GAC/B,OAAO,CAAC;QAAE,MAAM,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;KAAE,CAAC,CAAC;CACnD;AAED,UAAU,SAAS;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACjC;AAqBD,MAAM,WAA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AAU,CAAC,CAwKrB;AAiSD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,kBAAkB,EAC/B,IAAI,GAAE,YAAqB,EAC3B,aAAa,CAAC,EAAE,OAAO,GACtB,kBAAkB,CAkCpB;AAyJD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,OAAO,GAEZ,cAAc,GACd,cAAc,GACd,WAAW,GACX,eAAe,GACf,SAAS,GACT,SAAS,CAmCZ;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,UAAU,EAClB,cAAc,EAAE,MAAM,EACtB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,UAAU,CAwBZ;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAyHvE;AAmDD,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,kBAAkB,EAC/B,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAcpB"}
package/dist/api.js CHANGED
@@ -105,6 +105,7 @@ export class CodexSecurity {
105
105
  let scanFailure = false;
106
106
  let completionCost = null;
107
107
  let preparedTargetWarnings = [];
108
+ let runPostScan = null;
108
109
  let activeScan = null;
109
110
  const workbench = this.#dependencies.runWorkbench ?? runWorkbench;
110
111
  try {
@@ -158,7 +159,7 @@ export class CodexSecurity {
158
159
  }
159
160
  const effectiveConfig = runtime.effectiveConfig ?? requestedConfig;
160
161
  if (runtime.configPath !== undefined) {
161
- await writeCodexConfig(runtime.configPath, scanPreflightCodexConfig(effectiveConfig, repo));
162
+ await writeCodexConfig(runtime.configPath, scanPreflightCodexConfig(effectiveConfig));
162
163
  }
163
164
  const runtimeHome = await realpath(runtime.codexHome);
164
165
  requireOutputOutsideRepository(protectedRoot, runtimeHome, "runtime");
@@ -252,26 +253,35 @@ export class CodexSecurity {
252
253
  reviewedFileCount = progress.filesCompleted;
253
254
  notifyObserver("onProgress", options.onProgress, options.onObserverError, { ...progress, filesTotal: scopeFileCount });
254
255
  };
256
+ const reportTrackingError = (error) => {
257
+ if (options.maxCostUsd !== undefined) {
258
+ costAbortController.abort(error);
259
+ return;
260
+ }
261
+ notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not track scan activity: ${redactedErrorMessage(error)}`);
262
+ };
255
263
  const tracker = new ScanCostTracker({
256
264
  codexHome: runtime.codexHome,
257
265
  model,
258
266
  repository: repo,
259
267
  maxCostUsd: options.maxCostUsd,
260
- onActivity: (activity) => {
261
- notifyObserver("onActivity", options.onActivity, options.onObserverError, activity);
262
- },
263
- onProgress: reportProgress,
264
- onCost: (cost) => {
265
- notifyObserver("onCost", options.onCost, options.onObserverError, cost);
266
- if (options.maxCostUsd !== undefined &&
267
- cost.estimatedUsd > options.maxCostUsd) {
268
- costAbortController.abort(new ScanCostLimitExceededError(options.maxCostUsd, cost, scanDir));
269
- }
270
- },
271
- onError: (error) => costAbortController.abort(error),
268
+ onActivity: options.onActivity === undefined
269
+ ? undefined
270
+ : (activity) => notifyObserver("onActivity", options.onActivity, options.onObserverError, activity),
271
+ onProgress: options.onProgress === undefined ? undefined : reportProgress,
272
+ onCost: options.onCost === undefined && options.maxCostUsd === undefined
273
+ ? undefined
274
+ : (cost) => {
275
+ notifyObserver("onCost", options.onCost, options.onObserverError, cost);
276
+ if (options.maxCostUsd !== undefined &&
277
+ cost.estimatedUsd > options.maxCostUsd) {
278
+ costAbortController.abort(new ScanCostLimitExceededError(options.maxCostUsd, cost, scanDir));
279
+ }
280
+ },
281
+ onError: reportTrackingError,
272
282
  });
273
283
  costTracker = tracker;
274
- const recipe = scanRecipe(repo, protectedRoot, normalized, mode, expectation.repositoryRevision, runtime.plugin.version, effectiveConfig, options.failureSeverity, knowledgeBase?.sources, options.maxCostUsd, deepScanOptions(options));
284
+ const recipe = scanRecipe(repo, normalized, mode, expectation.repositoryRevision, runtime.plugin.version, effectiveConfig, options.failureSeverity, knowledgeBase?.sources, options.maxCostUsd, deepScanOptions(options));
275
285
  const workbenchOptions = {
276
286
  python,
277
287
  pluginRoot: runtime.plugin.pluginRoot,
@@ -451,6 +461,10 @@ export class CodexSecurity {
451
461
  await chmod(targetPathsFile, 0o400);
452
462
  }
453
463
  checkOpen();
464
+ const postScanPrompt = options.postScanPrompt;
465
+ if (postScanPrompt?.trim()) {
466
+ runPostScan = () => thread.runStreamed(postScanPrompt, { signal });
467
+ }
454
468
  const { events } = await thread.runStreamed(prompt, {
455
469
  signal,
456
470
  });
@@ -467,7 +481,12 @@ export class CodexSecurity {
467
481
  model,
468
482
  onThreadStarted: (threadId) => tracker.start(threadId),
469
483
  onFinalize: async (usage) => {
470
- const snapshot = await tracker.stop(usage);
484
+ const snapshot = await tracker.stop(usage).catch((error) => {
485
+ if (options.maxCostUsd !== undefined)
486
+ throw error;
487
+ reportTrackingError(error);
488
+ return { usage, cost: estimateScanCost(model, usage) };
489
+ });
471
490
  throwIfAborted(signal, scanDir);
472
491
  if (options.maxCostUsd !== undefined && snapshot.cost === null) {
473
492
  notifyObserver("onWarning", options.onWarning, options.onObserverError, "Scan completed, but its cost limit could not be verified because model pricing or token usage is unavailable.");
@@ -527,14 +546,12 @@ export class CodexSecurity {
527
546
  }
528
547
  }
529
548
  }
530
- if (options.postScanPrompt?.trim() &&
531
- result.coverage.completeness === "complete") {
532
- const followUp = await thread.runStreamed(options.postScanPrompt, {
533
- signal,
534
- });
549
+ if (runPostScan !== null) {
550
+ const followUp = runPostScan;
551
+ runPostScan = null;
535
552
  await runScanEvents({
536
553
  thread,
537
- events: followUp.events,
554
+ events: (await followUp()).events,
538
555
  signal,
539
556
  scanDir,
540
557
  pluginRoot: runtime.plugin.installedRoot,
@@ -573,6 +590,18 @@ export class CodexSecurity {
573
590
  }
574
591
  catch { }
575
592
  }
593
+ if (runPostScan !== null && !signal.aborted) {
594
+ try {
595
+ for await (const event of (await runPostScan()).events) {
596
+ if (event.type === "turn.failed") {
597
+ throw new CodexSecurityError(turnFailureMessage(event["error"]));
598
+ }
599
+ }
600
+ }
601
+ catch (postScanError) {
602
+ notifyObserver("onWarning", options.onWarning, options.onObserverError, `Could not run post-scan instructions: ${redactedErrorMessage(postScanError)}`);
603
+ }
604
+ }
576
605
  if (this.#closed)
577
606
  this.#requireOpen();
578
607
  if (signal.aborted && !(failure instanceof ScanInterruptedError)) {
@@ -1237,7 +1266,7 @@ function targetInstruction(target) {
1237
1266
  }
1238
1267
  return `Scan target: staged and unstaged working-tree changes against ${target.base}.`;
1239
1268
  }
1240
- function scanRecipe(repository, activeProjectPath, target, mode, repositoryRevision, pluginVersion, effectiveConfig, failOnSeverity, knowledgeBasePaths, maxCostUsd, deepScan) {
1269
+ function scanRecipe(repository, target, mode, repositoryRevision, pluginVersion, effectiveConfig, failOnSeverity, knowledgeBasePaths, maxCostUsd, deepScan) {
1241
1270
  return {
1242
1271
  repository,
1243
1272
  target: {
@@ -1251,7 +1280,7 @@ function scanRecipe(repository, activeProjectPath, target, mode, repositoryRevis
1251
1280
  mode,
1252
1281
  ...(repositoryRevision === null ? {} : { repositoryRevision }),
1253
1282
  pluginVersion,
1254
- config: scanPreflightCodexConfig(effectiveConfig, activeProjectPath),
1283
+ config: scanPreflightCodexConfig(effectiveConfig),
1255
1284
  ...(failOnSeverity === undefined ? {} : { failOnSeverity }),
1256
1285
  ...(knowledgeBasePaths === undefined ? {} : { knowledgeBasePaths }),
1257
1286
  ...(maxCostUsd === undefined ? {} : { maxCostUsd }),
@@ -1497,17 +1526,12 @@ export function scanRuntimeCodexConfig(config, stateDirectory, protectedCredenti
1497
1526
  },
1498
1527
  };
1499
1528
  }
1500
- export function scanPreflightCodexConfig(config, activeProjectPath) {
1501
- const safeString = (value, maxLength) => typeof value === "string" &&
1529
+ export function scanPreflightCodexConfig(config) {
1530
+ const safeString = (value) => typeof value === "string" &&
1502
1531
  value.length > 0 &&
1503
- value.length <= maxLength &&
1504
- !/[\u0000-\u001f\u007f]/u.test(value) &&
1505
- !/(?:^|[^a-z0-9])(?:api[_-]?key|access[_-]?key(?:[_-]?id)?|key|secret|token|env|mcp|set|password|passwd|credential|authorization|bearer)(?:[^a-z0-9]|$)/iu.test(value);
1506
- const safeProfileName = (value) => safeString(value, 128) && /^[A-Za-z0-9_-]+$/u.test(value);
1507
- const safeInteger = (value) => typeof value === "number" &&
1508
- Number.isSafeInteger(value) &&
1509
- value >= 0 &&
1510
- value <= 1_000_000;
1532
+ !/[\u0000-\u001f\u007f]/u.test(value);
1533
+ const safeProfileName = (value) => safeString(value) && /^[A-Za-z0-9_-]+$/u.test(value);
1534
+ const safeInteger = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
1511
1535
  const capabilityFeatures = (value) => {
1512
1536
  if (!isRecord(value))
1513
1537
  return {};
@@ -1544,7 +1568,7 @@ export function scanPreflightCodexConfig(config, activeProjectPath) {
1544
1568
  "service_tier",
1545
1569
  ]) {
1546
1570
  const value = source[key];
1547
- if (safeString(value, 512))
1571
+ if (safeString(value))
1548
1572
  result[key] = value;
1549
1573
  }
1550
1574
  const features = capabilityFeatures(source["features"]);
@@ -1569,16 +1593,6 @@ export function scanPreflightCodexConfig(config, activeProjectPath) {
1569
1593
  }
1570
1594
  return result;
1571
1595
  };
1572
- const prioritizedEntries = (value, priority) => {
1573
- const entries = Object.entries(value);
1574
- if (priority === undefined || !Object.hasOwn(value, priority)) {
1575
- return entries;
1576
- }
1577
- return [
1578
- [priority, value[priority]],
1579
- ...entries.filter(([key]) => key !== priority),
1580
- ];
1581
- };
1582
1596
  const result = executionConfig(config);
1583
1597
  const selectedProfile = safeProfileName(config["profile"])
1584
1598
  ? config["profile"]
@@ -1589,17 +1603,13 @@ export function scanPreflightCodexConfig(config, activeProjectPath) {
1589
1603
  const profiles = config["profiles"];
1590
1604
  if (isRecord(profiles)) {
1591
1605
  const sanitized = {};
1592
- let accepted = 0;
1593
- for (const [name, profile] of prioritizedEntries(profiles, selectedProfile)) {
1606
+ for (const [name, profile] of Object.entries(profiles)) {
1594
1607
  if (!safeProfileName(name) || !isRecord(profile))
1595
1608
  continue;
1596
1609
  const projected = executionConfig(profile);
1597
1610
  if (Object.keys(projected).length === 0)
1598
1611
  continue;
1599
1612
  sanitized[name] = projected;
1600
- accepted += 1;
1601
- if (accepted === 256)
1602
- break;
1603
1613
  }
1604
1614
  if (Object.keys(sanitized).length > 0)
1605
1615
  result["profiles"] = sanitized;
@@ -1618,7 +1628,7 @@ export function scanPreflightCodexConfig(config, activeProjectPath) {
1618
1628
  const sanitized = {};
1619
1629
  for (const key of ["region", "profile"]) {
1620
1630
  const value = aws[key];
1621
- if (safeString(value, 512))
1631
+ if (safeString(value))
1622
1632
  sanitized[key] = value;
1623
1633
  }
1624
1634
  if (Object.keys(sanitized).length > 0) {
@@ -1630,45 +1640,23 @@ export function scanPreflightCodexConfig(config, activeProjectPath) {
1630
1640
  }
1631
1641
  const rootMarkers = config["project_root_markers"];
1632
1642
  if (Array.isArray(rootMarkers)) {
1633
- result["project_root_markers"] = rootMarkers
1634
- .filter((value) => safeString(value, 256))
1635
- .slice(0, 64);
1643
+ result["project_root_markers"] = rootMarkers.filter(safeString);
1636
1644
  }
1637
1645
  const projects = config["projects"];
1638
1646
  if (isRecord(projects)) {
1639
1647
  const sanitized = {};
1640
- let accepted = 0;
1641
- const activeProjectRoot = activeProjectPath === undefined
1642
- ? undefined
1643
- : Object.keys(projects)
1644
- .filter((path) => {
1645
- if (!safeString(path, 4096) || !isAbsolute(path))
1646
- return false;
1647
- const remaining = relative(path, activeProjectPath);
1648
- return (remaining === "" ||
1649
- (remaining !== ".." &&
1650
- !remaining.startsWith(`..${sep}`) &&
1651
- !isAbsolute(remaining)));
1652
- })
1653
- .sort((left, right) => right.length - left.length)[0];
1654
- for (const [path, project] of prioritizedEntries(projects, activeProjectRoot ?? activeProjectPath)) {
1655
- if (!safeString(path, 4096) || !isAbsolute(path) || !isRecord(project)) {
1648
+ for (const [path, project] of Object.entries(projects)) {
1649
+ if (!safeString(path) || !isAbsolute(path) || !isRecord(project)) {
1656
1650
  continue;
1657
1651
  }
1658
1652
  const trust = project["trust_level"];
1659
1653
  if (trust !== "trusted" && trust !== "untrusted")
1660
1654
  continue;
1661
1655
  sanitized[path] = { trust_level: trust };
1662
- accepted += 1;
1663
- if (accepted === 256)
1664
- break;
1665
1656
  }
1666
1657
  if (Object.keys(sanitized).length > 0)
1667
1658
  result["projects"] = sanitized;
1668
1659
  }
1669
- if (Buffer.byteLength(JSON.stringify(result), "utf8") > 256 * 1024) {
1670
- throw new CodexSecurityError("The sanitized Codex Security preflight config exceeds the size limit.");
1671
- }
1672
1660
  return result;
1673
1661
  }
1674
1662
  function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {