@openai/codex-security 0.1.23 → 0.1.25

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.
Files changed (135) hide show
  1. package/README.md +200 -23
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/references/scan-contract.md +10 -0
  7. package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
  8. package/_bundled_plugin/scripts/finalize_scan_contract.py +27 -78
  9. package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -8
  10. package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
  11. package/_bundled_plugin/scripts/rank_preview.py +12 -1
  12. package/_bundled_plugin/scripts/report_projection.py +8 -14
  13. package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
  14. package/_bundled_plugin/scripts/windows_scan_local_files.py +5 -15
  15. package/_bundled_plugin/scripts/workbench_cli.py +14 -1
  16. package/_bundled_plugin/scripts/workbench_dashboard.py +41 -18
  17. package/_bundled_plugin/scripts/workbench_db.py +127 -541
  18. package/_bundled_plugin/scripts/workbench_finding_workflows.py +31 -13
  19. package/_bundled_plugin/scripts/workbench_findings.py +8 -3
  20. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
  21. package/_bundled_plugin/scripts/workbench_publication.py +520 -0
  22. package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
  23. package/_bundled_plugin/scripts/workbench_saved_results.py +298 -90
  24. package/_bundled_plugin/scripts/workbench_scan_history.py +375 -68
  25. package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
  26. package/_bundled_plugin/scripts/workbench_schema.py +49 -21
  27. package/_bundled_plugin/scripts/workbench_target.py +96 -17
  28. package/_bundled_plugin/scripts/workbench_validation.py +1 -5
  29. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
  30. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
  31. package/dist/api.d.ts +18 -3
  32. package/dist/api.d.ts.map +1 -1
  33. package/dist/api.js +350 -28
  34. package/dist/api.js.map +1 -1
  35. package/dist/auth.d.ts.map +1 -1
  36. package/dist/auth.js +35 -3
  37. package/dist/auth.js.map +1 -1
  38. package/dist/cli.d.ts +2 -0
  39. package/dist/cli.d.ts.map +1 -1
  40. package/dist/cli.js +118 -35
  41. package/dist/cli.js.map +1 -1
  42. package/dist/component-plan.d.ts.map +1 -1
  43. package/dist/component-plan.js +4 -2
  44. package/dist/component-plan.js.map +1 -1
  45. package/dist/component-scan.d.ts.map +1 -1
  46. package/dist/component-scan.js +21 -6
  47. package/dist/component-scan.js.map +1 -1
  48. package/dist/config.d.ts.map +1 -1
  49. package/dist/config.js +46 -2
  50. package/dist/config.js.map +1 -1
  51. package/dist/cost.d.ts +1 -0
  52. package/dist/cost.d.ts.map +1 -1
  53. package/dist/cost.js +23 -11
  54. package/dist/cost.js.map +1 -1
  55. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  56. package/dist/deduplication/checkpointed-review.js +2 -1
  57. package/dist/deduplication/checkpointed-review.js.map +1 -1
  58. package/dist/deduplication/codex-review.d.ts +3 -0
  59. package/dist/deduplication/codex-review.d.ts.map +1 -1
  60. package/dist/deduplication/codex-review.js +122 -36
  61. package/dist/deduplication/codex-review.js.map +1 -1
  62. package/dist/deduplication/deduplication-prompts.d.ts +4 -3
  63. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  64. package/dist/deduplication/deduplication-prompts.js +18 -9
  65. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  66. package/dist/deduplication/deduplication-reviewer.d.ts +2 -7
  67. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  68. package/dist/deduplication/deduplication-reviewer.js +46 -24
  69. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  70. package/dist/deduplication/deduplication.d.ts.map +1 -1
  71. package/dist/deduplication/deduplication.js +186 -23
  72. package/dist/deduplication/deduplication.js.map +1 -1
  73. package/dist/deduplication/scan.d.ts +9 -1
  74. package/dist/deduplication/scan.d.ts.map +1 -1
  75. package/dist/deduplication/scan.js +24 -7
  76. package/dist/deduplication/scan.js.map +1 -1
  77. package/dist/deep-progress.d.ts +21 -0
  78. package/dist/deep-progress.d.ts.map +1 -0
  79. package/dist/deep-progress.js +108 -0
  80. package/dist/deep-progress.js.map +1 -0
  81. package/dist/errors.d.ts +13 -0
  82. package/dist/errors.d.ts.map +1 -1
  83. package/dist/errors.js +7 -0
  84. package/dist/errors.js.map +1 -1
  85. package/dist/index.d.ts +6 -5
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +2 -2
  88. package/dist/index.js.map +1 -1
  89. package/dist/mock-scan.d.ts +4 -0
  90. package/dist/mock-scan.d.ts.map +1 -0
  91. package/dist/mock-scan.js +210 -0
  92. package/dist/mock-scan.js.map +1 -0
  93. package/dist/publish.d.ts.map +1 -1
  94. package/dist/publish.js +2 -2
  95. package/dist/publish.js.map +1 -1
  96. package/dist/runtime.d.ts +1 -0
  97. package/dist/runtime.d.ts.map +1 -1
  98. package/dist/runtime.js +54 -14
  99. package/dist/runtime.js.map +1 -1
  100. package/dist/scan-activity.d.ts.map +1 -1
  101. package/dist/scan-activity.js +12 -2
  102. package/dist/scan-activity.js.map +1 -1
  103. package/dist/scan-comparison.d.ts +11 -2
  104. package/dist/scan-comparison.d.ts.map +1 -1
  105. package/dist/scan-comparison.js +237 -39
  106. package/dist/scan-comparison.js.map +1 -1
  107. package/dist/scan-dashboard.d.ts +3 -1
  108. package/dist/scan-dashboard.d.ts.map +1 -1
  109. package/dist/scan-dashboard.js +70 -3
  110. package/dist/scan-dashboard.js.map +1 -1
  111. package/dist/scan-history-renderer.d.ts.map +1 -1
  112. package/dist/scan-history-renderer.js +21 -0
  113. package/dist/scan-history-renderer.js.map +1 -1
  114. package/dist/server/api.d.ts +6 -0
  115. package/dist/server/api.d.ts.map +1 -0
  116. package/dist/server/api.js +4 -0
  117. package/dist/server/api.js.map +1 -0
  118. package/dist/server/dashboard/app.css +1 -1
  119. package/dist/server/embeddings.d.ts +2 -1
  120. package/dist/server/embeddings.d.ts.map +1 -1
  121. package/dist/server/embeddings.js +8 -3
  122. package/dist/server/embeddings.js.map +1 -1
  123. package/dist/server/index.js +2 -28
  124. package/dist/server/index.js.map +1 -1
  125. package/dist/server/serve.d.ts +2 -0
  126. package/dist/server/serve.d.ts.map +1 -0
  127. package/dist/server/serve.js +28 -0
  128. package/dist/server/serve.js.map +1 -0
  129. package/dist/targets.d.ts.map +1 -1
  130. package/dist/targets.js +3 -5
  131. package/dist/targets.js.map +1 -1
  132. package/dist/version.d.ts +1 -1
  133. package/dist/version.js +1 -1
  134. package/dist/version.js.map +1 -1
  135. package/package.json +10 -5
package/dist/cli.js CHANGED
@@ -3,7 +3,7 @@ import { execFile as execFileCallback, execFileSync, spawn, } from "node:child_p
3
3
  import { createHash } from "node:crypto";
4
4
  import { accessSync, constants, createReadStream, existsSync, lstatSync, realpathSync, writeSync, } from "node:fs";
5
5
  import { chmod, lstat, mkdir, mkdtemp, open, readFile, realpath, rm, writeFile, } from "node:fs/promises";
6
- import { tmpdir } from "node:os";
6
+ import { homedir, tmpdir } from "node:os";
7
7
  import { basename, dirname, isAbsolute, join, parse, relative, resolve, sep, win32, } from "node:path";
8
8
  import { cwd } from "node:process";
9
9
  import { createInterface } from "node:readline";
@@ -13,7 +13,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
13
13
  import { promisify, stripVTControlCharacters } from "node:util";
14
14
  import { Cli, z } from "incur";
15
15
  import { parse as parseToml } from "smol-toml";
16
- import { classifyConnectionFailure, createSecurityInternal, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, } from "./api.js";
16
+ import { classifyConnectionFailure, createSecurityInternal, environmentValue, formatEnvironmentVariableRemovalGuidance, initialCredentialsAvailable, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, } from "./api.js";
17
17
  import { accountStatus } from "./auth.js";
18
18
  import { publishScanToCustom } from "./custom-publish.js";
19
19
  import { deduplicateScanInternal } from "./deduplication/scan.js";
@@ -29,8 +29,8 @@ import { runMultiscan } from "./multiscan.js";
29
29
  import { componentPlanSchema } from "./component-plan.js";
30
30
  import { runComponentScans } from "./component-scan.js";
31
31
  import { checkScanPublication, forceTerminatePublicationProcesses as terminatePublishers, publishScan, } from "./publish.js";
32
- import { bundledPluginRoot, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, expandHome, prepareCodexSecurityCredentialHome, pythonUtf8Environment, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
33
- import { matchScanFindingsInternal, } from "./scan-comparison.js";
32
+ import { bundledPluginRoot, canonicalizeModelSafePath, codexSecurityCredentialHome, codexSecurityStateDirectory, executablePathForSpawn, expandHome, prepareCodexSecurityCredentialHome, pythonUtf8Environment, resolveCodexCommand, resolvePluginPython, runWorkbench, setCodexSecurityCredentialLogout, } from "./runtime.js";
33
+ import { comparisonFindingGroups, matchScanFindingsInternal, unionFindingGroups, } from "./scan-comparison.js";
34
34
  import { scanActivitiesFromEvent } from "./scan-activity.js";
35
35
  import { CODEX_SECURITY_THREAD_SOURCES, } from "./thread-source.js";
36
36
  import { readScanLogs } from "./scan-logs.js";
@@ -79,6 +79,7 @@ const EXPORT_DEFAULT_OUTPUTS = {
79
79
  sarif: "results.sarif",
80
80
  };
81
81
  const VALUE_OPTIONS = new Set([
82
+ "--port",
82
83
  "--workflow-id",
83
84
  "--auth",
84
85
  "--safety-identifier",
@@ -814,7 +815,9 @@ const DEFAULT_DEPENDENCIES = {
814
815
  matchFindings: (input, options) => matchScanFindingsInternal(input, options, { surface: "cli" }),
815
816
  };
816
817
  export async function runCodexSkillCommand(args, output, command = resolveCodexCommand(), processEnvironment = process.env, input) {
817
- const configuredHome = processEnvironment["CODEX_HOME"];
818
+ const configuredHome = process.platform === "win32"
819
+ ? environmentValue(processEnvironment, "CODEX_HOME")
820
+ : processEnvironment["CODEX_HOME"];
818
821
  const environment = { ...processEnvironment };
819
822
  for (const name of Object.keys(environment)) {
820
823
  if (name.toUpperCase() === "CODEX_HOME")
@@ -823,7 +826,7 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
823
826
  if (configuredHome?.trim()) {
824
827
  environment["CODEX_HOME"] = resolve(expandHome(configuredHome, processEnvironment));
825
828
  }
826
- const invocation = spawn(command.command, [...args], {
829
+ const invocation = spawn(executablePathForSpawn(command.command), [...args], {
827
830
  env: environment,
828
831
  cwd: output?.appServer?.directory ?? parse(process.execPath).root,
829
832
  stdio: output === undefined
@@ -2081,7 +2084,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2081
2084
  .number()
2082
2085
  .positive()
2083
2086
  .optional()
2084
- .describe("Stop the scan if estimated USD cost exceeds AMOUNT."),
2087
+ .describe("Stop above AMOUNT in estimated USD; the dashboard offers increases near the limit."),
2085
2088
  headless: z
2086
2089
  .boolean()
2087
2090
  .default(false)
@@ -2090,6 +2093,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2090
2093
  .boolean()
2091
2094
  .default(false)
2092
2095
  .describe("Validate local scan inputs without starting a scan."),
2096
+ mock: z
2097
+ .boolean()
2098
+ .default(false)
2099
+ .describe("Save synthetic Standard scan findings without calling an LLM."),
2093
2100
  })
2094
2101
  .refine((options) => Number(options.path.length > 0) +
2095
2102
  Number(options.diff !== undefined) +
@@ -2110,6 +2117,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2110
2117
  })
2111
2118
  .refine((options) => !options.patch || !options.dryRun, {
2112
2119
  message: "--patch cannot be combined with --dry-run.",
2120
+ })
2121
+ .refine((options) => !options.mock || (!options.dryRun && !options.patch), {
2122
+ message: "--mock cannot be combined with --dry-run or --patch.",
2113
2123
  })
2114
2124
  .refine((options) => options.mode === "deep" ||
2115
2125
  (options.workers === undefined &&
@@ -2178,6 +2188,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
2178
2188
  maxCostUsd: options.maxCost,
2179
2189
  headless: options.headless,
2180
2190
  dryRun: options.dryRun,
2191
+ mock: options.mock,
2181
2192
  }, errorOutput, dependencies, format !== "json" && format !== "jsonl");
2182
2193
  exitCode = outcome.exitCode;
2183
2194
  if (outcome.error !== undefined) {
@@ -3125,6 +3136,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3125
3136
  const credentialHome = dependencies.prepareAuthenticationHome !== undefined
3126
3137
  ? await dependencies.prepareAuthenticationHome(dependencies.environment)
3127
3138
  : await prepareCodexSecurityCredentialHome(dependencies.environment);
3139
+ if (args.action === "status" && existsSync(credentialHome)) {
3140
+ const ambientHome = environmentValue(dependencies.environment, "CODEX_HOME") ??
3141
+ join(homedir(), ".codex");
3142
+ await initialCredentialsAvailable(dependencies.environment, ambientHome, credentialHome);
3143
+ }
3128
3144
  const authenticationEnvironment = {
3129
3145
  ...dependencies.environment,
3130
3146
  CODEX_HOME: credentialHome,
@@ -3147,7 +3163,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3147
3163
  (exitCode === 0 || exitCode === 1)) {
3148
3164
  exitCode = 0;
3149
3165
  errorOutput.write(`Effective scan authentication: API key from ${authentication.source}.\n`);
3150
- errorOutput.write("To use a ChatGPT sign-in, unset OPENAI_API_KEY and CODEX_API_KEY.\n");
3166
+ errorOutput.write(`To use a ChatGPT sign-in, ${formatEnvironmentVariableRemovalGuidance(["OPENAI_API_KEY", "CODEX_API_KEY"])}.\n`);
3151
3167
  }
3152
3168
  }
3153
3169
  else if (exitCode === 0 && !options.withApiKey) {
@@ -3166,8 +3182,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3166
3182
  ? "your stored credentials"
3167
3183
  : "your ChatGPT sign-in";
3168
3184
  errorOutput.write(loginWarning +
3169
- `To use ${storedCredentials}, pass '--auth chatgpt' or run ` +
3170
- `'unset ${configuredApiKeyVariables.join(" ")}'.\n`);
3185
+ `To use ${storedCredentials}, pass '--auth chatgpt' or ` +
3186
+ `${formatEnvironmentVariableRemovalGuidance(configuredApiKeyVariables)}.\n`);
3171
3187
  }
3172
3188
  }
3173
3189
  },
@@ -3190,6 +3206,32 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
3190
3206
  await setCodexSecurityCredentialLogout(credentialHome, true);
3191
3207
  }
3192
3208
  },
3209
+ })
3210
+ .command("serve", {
3211
+ description: "Start the findings HTTP service (HOST=127.0.0.1, PORT=3000). CODEX_SECURITY_EMBEDDINGS_URL overrides the embeddings endpoint (default: https://api.openai.com/v1/embeddings).",
3212
+ destructive: true,
3213
+ mcp: false,
3214
+ options: z.object({
3215
+ port: z
3216
+ .number()
3217
+ .int()
3218
+ .min(0)
3219
+ .max(65535)
3220
+ .optional()
3221
+ .describe("Listen port (default: PORT or 3000; 0 picks a free port)."),
3222
+ }),
3223
+ async run({ options }) {
3224
+ try {
3225
+ const { serveFindings } = await import("./server/serve.js");
3226
+ await serveFindings(options.port === undefined
3227
+ ? dependencies.environment
3228
+ : { ...dependencies.environment, PORT: String(options.port) }, output);
3229
+ }
3230
+ catch (error) {
3231
+ errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
3232
+ exitCode = 1;
3233
+ }
3234
+ },
3193
3235
  })
3194
3236
  .command("info", {
3195
3237
  description: "Show read-only SDK and bundled-plugin metadata.",
@@ -3381,6 +3423,7 @@ function scanArgumentsFromRecipe(recipe, parentScanId, validationPromptFile) {
3381
3423
  maxCostUsd,
3382
3424
  dryRun: false,
3383
3425
  parentScanId,
3426
+ ...(recipe["mock"] === true ? { mock: true } : {}),
3384
3427
  expectedPluginVersion: typeof recipe["pluginVersion"] === "string"
3385
3428
  ? recipe["pluginVersion"]
3386
3429
  : undefined,
@@ -3404,6 +3447,7 @@ function validateCliArguments(argv, positionals) {
3404
3447
  "patch",
3405
3448
  "login",
3406
3449
  "logout",
3450
+ "serve",
3407
3451
  "info",
3408
3452
  ].includes(value));
3409
3453
  if (commandIndex < 0)
@@ -3418,7 +3462,7 @@ function validateCliArguments(argv, positionals) {
3418
3462
  argv[index + 1] === "json" ||
3419
3463
  argv[index + 1] === "jsonl")));
3420
3464
  if (structuredOutput &&
3421
- ["validate", "login", "logout"].includes(command) &&
3465
+ ["validate", "login", "logout", "serve"].includes(command) &&
3422
3466
  !argv.includes("--schema")) {
3423
3467
  return `${command} does not support noninteractive JSON output; run it without --json, --format json, or --format jsonl.`;
3424
3468
  }
@@ -3501,7 +3545,7 @@ function validateCliArguments(argv, positionals) {
3501
3545
  command !== "verify-fix" &&
3502
3546
  command !== "patch" &&
3503
3547
  positionals.length >
3504
- (command === "logout" || command === "info"
3548
+ (command === "logout" || command === "info" || command === "serve"
3505
3549
  ? 0
3506
3550
  : subcommand === "compare" || subcommand === "match"
3507
3551
  ? 2
@@ -3519,11 +3563,23 @@ async function matchAllScans(dependencies, force) {
3519
3563
  const { repository, scanCount, unavailableScans, skippedPairs, batches } = result;
3520
3564
  let matchedPairs = 0;
3521
3565
  let findingMatches = 0;
3522
- for (const { afterScanId, afterFindings, beforeScans } of batches) {
3566
+ const newlyMatchedGroups = [];
3567
+ for (const { afterScanId, afterFindings, beforeScans, knownFindingGroups = [], } of batches) {
3523
3568
  const before = beforeScans.flatMap(({ findings }) => findings);
3569
+ const knownGroups = unionFindingGroups([
3570
+ ...knownFindingGroups,
3571
+ ...newlyMatchedGroups,
3572
+ ]);
3573
+ const input = {
3574
+ before,
3575
+ after: afterFindings,
3576
+ ...(knownGroups.length === 0 ? {} : { knownFindingGroups: knownGroups }),
3577
+ };
3524
3578
  const matching = before.length === 0 || afterFindings.length === 0
3525
3579
  ? { matches: [], uncertain: [] }
3526
- : await dependencies.matchFindings({ before, after: afterFindings }, { allowHistoricalUncertainty: true });
3580
+ : await dependencies.matchFindings(input, {
3581
+ allowHistoricalUncertainty: true,
3582
+ });
3527
3583
  const comparisons = beforeScans.map(({ scanId, findings }) => {
3528
3584
  const beforeIds = new Set(findings.map(({ occurrenceId }) => occurrenceId));
3529
3585
  const matches = matching.matches.flatMap((match) => {
@@ -3533,13 +3589,14 @@ async function matchAllScans(dependencies, force) {
3533
3589
  : [{ ...match, beforeOccurrenceIds }];
3534
3590
  });
3535
3591
  const uncertain = matching.uncertain.filter(({ beforeOccurrenceId }) => beforeIds.has(beforeOccurrenceId));
3592
+ const related = matching.related?.filter(({ beforeOccurrenceId }) => beforeIds.has(beforeOccurrenceId));
3536
3593
  const matchedAfter = new Set(matches.flatMap(({ afterOccurrenceIds }) => afterOccurrenceIds));
3537
3594
  if (uncertain.some(({ afterOccurrenceId }) => matchedAfter.has(afterOccurrenceId))) {
3538
3595
  throw new CodexSecurityError("Scan matching returned conflicting confirmed and uncertain findings.");
3539
3596
  }
3540
- return { scanId, matches, uncertain };
3597
+ return { scanId, matches, uncertain, related };
3541
3598
  });
3542
- for (const { scanId, matches, uncertain } of comparisons) {
3599
+ for (const { scanId, matches, uncertain, related } of comparisons) {
3543
3600
  await dependencies.runWorkbench([
3544
3601
  "save-scan-comparison",
3545
3602
  "--before-scan-id",
@@ -3547,10 +3604,11 @@ async function matchAllScans(dependencies, force) {
3547
3604
  "--after-scan-id",
3548
3605
  afterScanId,
3549
3606
  "--matches-json-stdin",
3550
- ], JSON.stringify({ matches, uncertain }));
3607
+ ], JSON.stringify({ matches, uncertain, related }));
3551
3608
  matchedPairs += 1;
3552
3609
  findingMatches += matches.reduce((count, { beforeOccurrenceIds, afterOccurrenceIds }) => count + beforeOccurrenceIds.length * afterOccurrenceIds.length, 0);
3553
3610
  }
3611
+ newlyMatchedGroups.push(...comparisonFindingGroups(input, matching));
3554
3612
  }
3555
3613
  return {
3556
3614
  repository,
@@ -4567,6 +4625,7 @@ async function withTerminalErrorsHandled(errorOutput, operation) {
4567
4625
  }
4568
4626
  async function executeScan(arguments_, errorOutput, dependencies, interactive = true) {
4569
4627
  let scanDir = null;
4628
+ const scanInput = dependencies.scanInput ?? process.stdin;
4570
4629
  let requestedSignal = null;
4571
4630
  let firstSignalAt = 0;
4572
4631
  let progress = null;
@@ -4576,6 +4635,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4576
4635
  let workerCapacity = null;
4577
4636
  let fileProgress = null;
4578
4637
  let runningCost = null;
4638
+ let maxCostUsd = arguments_.maxCostUsd;
4579
4639
  let phase = null;
4580
4640
  const targetWarnings = [];
4581
4641
  const configuredLogLevel = dependencies.environment["CODEX_SECURITY_LOG_LEVEL"]?.trim() ||
@@ -4675,7 +4735,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4675
4735
  ({ model: effectiveModel, reasoningEffort: effectiveReasoningEffort } =
4676
4736
  scanModelConfiguration(effectiveConfiguration));
4677
4737
  const provider = scanModelProvider(effectiveConfiguration);
4678
- const auth = !arguments_.dryRun && interactive
4738
+ const auth = !arguments_.dryRun && !arguments_.mock && interactive
4679
4739
  ? await chooseInteractiveAuthentication({
4680
4740
  auth: arguments_.auth,
4681
4741
  provider,
@@ -4689,7 +4749,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4689
4749
  providerConfiguration: effectiveConfiguration["model_providers"]?.[provider],
4690
4750
  };
4691
4751
  }
4692
- selectedAuthentication = scanAuthentication(dependencies.environment, auth, provider);
4752
+ selectedAuthentication = arguments_.mock
4753
+ ? null
4754
+ : scanAuthentication(dependencies.environment, auth, provider);
4693
4755
  diagnostic("scan.configuration", {
4694
4756
  cli_version: VERSION,
4695
4757
  bundled_plugin_version: BUNDLED_PLUGIN_VERSION,
@@ -4706,6 +4768,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4706
4768
  : "repository",
4707
4769
  requested_auth: auth ?? "auto",
4708
4770
  dry_run: arguments_.dryRun,
4771
+ mock: arguments_.mock,
4709
4772
  profile: typeof selectedProfileName === "string"
4710
4773
  ? selectedProfileName
4711
4774
  : undefined,
@@ -4727,7 +4790,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4727
4790
  clock: dependencies,
4728
4791
  color: dependencies.environment["NO_COLOR"] === undefined,
4729
4792
  sanitize: safeErrorMessage,
4730
- input: process.stdin,
4793
+ input: scanInput,
4731
4794
  onInterrupt,
4732
4795
  });
4733
4796
  }
@@ -4771,7 +4834,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4771
4834
  }
4772
4835
  }
4773
4836
  security = dependencies.createSecurity(config);
4837
+ if (arguments_.mock) {
4838
+ errorOutput.write("codex-security: Mock scan: generating synthetic findings; no security analysis or LLM calls.\n");
4839
+ }
4774
4840
  const options = {
4841
+ ...(arguments_.mock ? { mock: true } : {}),
4775
4842
  ...(arguments_.workflowId === undefined
4776
4843
  ? {}
4777
4844
  : { workflowId: arguments_.workflowId }),
@@ -4792,7 +4859,11 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4792
4859
  expectedPluginVersion: arguments_.expectedPluginVersion,
4793
4860
  failureSeverity: arguments_.failOnSeverity,
4794
4861
  maxCostUsd: arguments_.maxCostUsd,
4795
- onCost: (cost) => {
4862
+ onCost: (cost, limit = maxCostUsd) => {
4863
+ if (limit !== maxCostUsd && limit !== undefined) {
4864
+ dashboard?.note(`Total cost limit increased to ${formatUsd(limit)}.`);
4865
+ }
4866
+ maxCostUsd = limit;
4796
4867
  diagnostic("cost.updated", {
4797
4868
  model: cost.model,
4798
4869
  estimated_usd: cost.estimatedUsd,
@@ -4800,15 +4871,15 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4800
4871
  cached_input_tokens: cost.cachedInputTokens,
4801
4872
  cache_write_input_tokens: cost.cacheWriteInputTokens,
4802
4873
  output_tokens: cost.outputTokens,
4803
- max_cost_usd: arguments_.maxCostUsd,
4874
+ max_cost_usd: maxCostUsd,
4804
4875
  });
4805
4876
  runningCost = cost;
4806
4877
  if (dashboard !== null) {
4807
- dashboard.setCost(cost);
4878
+ dashboard.setCost(cost, maxCostUsd);
4808
4879
  return;
4809
4880
  }
4810
4881
  progress?.stopTimer();
4811
- if (arguments_.maxCostUsd === undefined) {
4882
+ if (maxCostUsd === undefined) {
4812
4883
  const tokens = formatTokenUsage({
4813
4884
  input_tokens: cost.inputTokens,
4814
4885
  cached_input_tokens: cost.cachedInputTokens,
@@ -4817,13 +4888,15 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4817
4888
  progress?.stage(`${tokens === null ? "" : `Tokens: ${tokens}. `}Estimated cost: ${formatUsd(cost.estimatedUsd)} USD.`);
4818
4889
  }
4819
4890
  else {
4820
- progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(arguments_.maxCostUsd)} limit`);
4891
+ progress?.stage(`Estimated cost: ${formatUsd(cost.estimatedUsd)} of ${formatUsd(maxCostUsd)} limit`);
4821
4892
  }
4822
- if (arguments_.maxCostUsd === undefined ||
4823
- cost.estimatedUsd <= arguments_.maxCostUsd) {
4893
+ if (maxCostUsd === undefined || cost.estimatedUsd <= maxCostUsd) {
4824
4894
  progress?.startTimer(runningMessage());
4825
4895
  }
4826
4896
  },
4897
+ onBudgetApproaching: scanInput.isTTY === true
4898
+ ? dashboard?.requestBudgetIncrease.bind(dashboard)
4899
+ : undefined,
4827
4900
  onOutputArchived: (archiveDir) => {
4828
4901
  diagnostic("scan.output_archived", { archive_dir: archiveDir });
4829
4902
  if (dashboard !== null) {
@@ -4843,9 +4916,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4843
4916
  diagnostic("authentication.selected", {
4844
4917
  requested: auth ?? "auto",
4845
4918
  method: authentication.method,
4846
- source: authentication.method !== "stored_credentials"
4847
- ? authentication.source
4848
- : undefined,
4919
+ source: "source" in authentication ? authentication.source : undefined,
4849
4920
  verified: authentication.verified,
4850
4921
  });
4851
4922
  if (dashboard !== null) {
@@ -4853,7 +4924,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4853
4924
  ? `Using API key from ${authentication.source}`
4854
4925
  : authentication.method === "aws_credentials"
4855
4926
  ? `Using AWS credentials from ${authentication.source}`
4856
- : "Using stored Codex credentials");
4927
+ : authentication.method === "command"
4928
+ ? "Using native Codex command authentication"
4929
+ : "Using stored Codex credentials");
4857
4930
  return;
4858
4931
  }
4859
4932
  progress?.stopTimer();
@@ -4864,6 +4937,9 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4864
4937
  else if (authentication.method === "aws_credentials") {
4865
4938
  progress?.stage(`Authentication: AWS credentials from ${authentication.source}.`);
4866
4939
  }
4940
+ else if (authentication.method === "command") {
4941
+ progress?.stage("Authentication: native Codex command.");
4942
+ }
4867
4943
  else {
4868
4944
  progress?.stage("Authentication: stored Codex credentials.");
4869
4945
  }
@@ -4917,7 +4993,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
4917
4993
  dashboard.setStage("inspecting repository files");
4918
4994
  }
4919
4995
  },
4920
- onSessionEvent: process.stdin.isTTY === true
4996
+ onSessionEvent: scanInput.isTTY === true
4921
4997
  ? dashboard?.recordDetails.bind(dashboard)
4922
4998
  : undefined,
4923
4999
  onProgress: (update) => {
@@ -5080,7 +5156,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
5080
5156
  model: effectivePreflight.model,
5081
5157
  reasoning_effort: effectivePreflight.reasoningEffort,
5082
5158
  method: effectivePreflight.authentication.method,
5083
- source: effectivePreflight.authentication.method !== "stored_credentials"
5159
+ source: "source" in effectivePreflight.authentication
5084
5160
  ? effectivePreflight.authentication.source
5085
5161
  : undefined,
5086
5162
  verified: effectivePreflight.authentication.verified,
@@ -5105,7 +5181,7 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
5105
5181
  const incomplete = result.coverage.completeness !== "complete";
5106
5182
  let deepScanStop;
5107
5183
  if (arguments_.mode === "deep") {
5108
- deepScanStop = (await readDeepScanStop(result, arguments_.maxCostUsd, dependencies.runWorkbench).catch(() => undefined)) ?? {
5184
+ deepScanStop = (await readDeepScanStop(result, maxCostUsd, dependencies.runWorkbench).catch(() => undefined)) ?? {
5109
5185
  reason: "Stop reason unavailable. See the report for details.",
5110
5186
  };
5111
5187
  }
@@ -5138,7 +5214,8 @@ async function executeScan(arguments_, errorOutput, dependencies, interactive =
5138
5214
  ? arguments_.patchSeverity ?? "low"
5139
5215
  : undefined;
5140
5216
  let patchSelection = null;
5141
- if (actionableFindings.length > 0 &&
5217
+ if (!arguments_.mock &&
5218
+ actionableFindings.length > 0 &&
5142
5219
  arguments_.patchSeverity === undefined &&
5143
5220
  progress?.interactive === true &&
5144
5221
  (dependencies.patchEditor !== undefined || process.stdin.isTTY === true)) {
@@ -5272,6 +5349,9 @@ function scanFailureMessage(error, authentication) {
5272
5349
  }
5273
5350
  switch (classifyConnectionFailure(error)) {
5274
5351
  case "unauthorized":
5352
+ if (authentication?.method === "command") {
5353
+ return "Native Codex command authentication failed. Check the configured provider auth command.";
5354
+ }
5275
5355
  if (authentication?.method === "aws_credentials") {
5276
5356
  return (`Authentication failed using AWS credentials from ${authentication.source}. ` +
5277
5357
  "Check your Amazon Bedrock bearer token or AWS credential chain.");
@@ -5282,6 +5362,9 @@ function scanFailureMessage(error, authentication) {
5282
5362
  : "Authentication failed using stored ChatGPT credentials. " +
5283
5363
  "Sign in again with 'codex-security login' or provide a valid API key.";
5284
5364
  case "forbidden":
5365
+ if (authentication?.method === "command") {
5366
+ return "The configured Codex provider denied access. Check the command credentials and provider permissions.";
5367
+ }
5285
5368
  if (authentication?.method === "aws_credentials") {
5286
5369
  return (`The AWS credentials from ${authentication.source} cannot access the configured Amazon Bedrock model. ` +
5287
5370
  "Check your AWS identity and Bedrock model permissions.");