@openai/codex-security 0.1.0 → 0.1.2

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 (39) hide show
  1. package/README.md +106 -58
  2. package/_bundled_plugin/mcp/mcp-app.html.br +0 -0
  3. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  5. package/_bundled_plugin/scripts/config_preflight.py +1 -1
  6. package/_bundled_plugin/scripts/workbench_cli.py +5 -0
  7. package/_bundled_plugin/scripts/workbench_db.py +34 -98
  8. package/_bundled_plugin/scripts/workbench_feedback.py +96 -0
  9. package/_bundled_plugin/scripts/workbench_scan_history.py +11 -1
  10. package/_bundled_plugin/scripts/workbench_scan_start.py +76 -0
  11. package/_bundled_plugin/scripts/workbench_schema.py +8 -0
  12. package/_bundled_plugin/scripts/workbench_target.py +95 -0
  13. package/_bundled_plugin/scripts/workbench_validation.py +7 -0
  14. package/_bundled_plugin/skills/validation/SKILL.md +2 -0
  15. package/dist/api.d.ts +6 -3
  16. package/dist/api.d.ts.map +1 -1
  17. package/dist/api.js +107 -19
  18. package/dist/api.js.map +1 -1
  19. package/dist/cli.d.ts +7 -2
  20. package/dist/cli.d.ts.map +1 -1
  21. package/dist/cli.js +222 -48
  22. package/dist/cli.js.map +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/multiscan.d.ts.map +1 -1
  27. package/dist/multiscan.js +3 -1
  28. package/dist/multiscan.js.map +1 -1
  29. package/dist/runtime.d.ts.map +1 -1
  30. package/dist/runtime.js +6 -1
  31. package/dist/runtime.js.map +1 -1
  32. package/dist/scan-history-renderer.d.ts.map +1 -1
  33. package/dist/scan-history-renderer.js +8 -0
  34. package/dist/scan-history-renderer.js.map +1 -1
  35. package/dist/version.d.ts +14 -0
  36. package/dist/version.d.ts.map +1 -1
  37. package/dist/version.js +102 -0
  38. package/dist/version.js.map +1 -1
  39. package/package.json +2 -1
package/dist/cli.js CHANGED
@@ -11,6 +11,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
11
11
  import { Cli, z } from "incur";
12
12
  import { parse as parseToml } from "smol-toml";
13
13
  import { classifyConnectionFailure, CodexSecurity, scanAuthentication, } from "./api.js";
14
+ import { accountStatus } from "./auth.js";
14
15
  import { createBulkScanDiscoveryDependencies, runBulkScanWizard, } from "./bulk-scan-discovery.js";
15
16
  import { DEFAULT_CODEX_CONFIG, mergedCodexConfig, scanModelConfiguration, } from "./config.js";
16
17
  import { formatUsd } from "./cost.js";
@@ -20,7 +21,7 @@ import { bundledPluginRoot, codexSecurityStateDirectory, expandHome, resolveCode
20
21
  import { matchScanFindings, } from "./scan-comparison.js";
21
22
  import { renderScanHistory, } from "./scan-history-renderer.js";
22
23
  import { DiffTarget } from "./targets.js";
23
- import { BUNDLED_PLUGIN_VERSION, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, VERSION, } from "./version.js";
24
+ import { BUNDLED_PLUGIN_VERSION, checkForUpdate, CODEX_EXECUTABLE_VERSION, CODEX_SDK_VERSION, formatUpdateNotice, updateNoticeEnabled, VERSION, } from "./version.js";
24
25
  const PROGRESS_REFRESH_MILLISECONDS = 1_000;
25
26
  const MAX_CODEX_OVERRIDE_KEY_LENGTH = 1_024;
26
27
  const MAX_CODEX_OVERRIDE_VALUE_LENGTH = 64 * 1_024;
@@ -42,12 +43,21 @@ const DISPLAY_SEVERITIES = [
42
43
  ...REPORTABLE_SEVERITIES,
43
44
  "informational",
44
45
  ];
46
+ const MODEL_REASONING_EFFORTS = [
47
+ "minimal",
48
+ "low",
49
+ "medium",
50
+ "high",
51
+ "xhigh",
52
+ ];
53
+ const DEFAULT_SCAN_MODEL_CONFIGURATION = scanModelConfiguration(DEFAULT_CODEX_CONFIG);
45
54
  const EXPORT_DEFAULT_OUTPUTS = {
46
55
  csv: "findings.csv",
47
56
  json: "findings.json",
48
57
  sarif: "results.sarif",
49
58
  };
50
59
  const VALUE_OPTIONS = new Set([
60
+ "--auth",
51
61
  "--path",
52
62
  "--knowledge-base",
53
63
  "--diff",
@@ -55,6 +65,7 @@ const VALUE_OPTIONS = new Set([
55
65
  "--base",
56
66
  "--mode",
57
67
  "--model",
68
+ "--effort",
58
69
  "--output-dir",
59
70
  "--plugin-path",
60
71
  "--python",
@@ -71,13 +82,29 @@ const VALUE_OPTIONS = new Set([
71
82
  "--token-limit",
72
83
  "--token-offset",
73
84
  "--scan-root",
85
+ "--reason",
74
86
  ]);
75
87
  function optionValue(flag) {
76
88
  return z.string().min(1, `${flag} must not be empty.`);
77
89
  }
90
+ function effortOption() {
91
+ return z
92
+ .enum(MODEL_REASONING_EFFORTS, {
93
+ error: "--effort must be minimal, low, medium, high, or xhigh.",
94
+ })
95
+ .optional()
96
+ .describe(`Model reasoning effort (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.reasoningEffort}).`);
97
+ }
78
98
  const DEFAULT_DEPENDENCIES = {
79
99
  createSecurity: (config) => new CodexSecurity(config),
80
100
  environment: process.env,
101
+ checkForUpdate: () => checkForUpdate({ environment: process.env }),
102
+ hasStoredChatGPTSignIn: async () => {
103
+ const environment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "OPENAI_API_KEY" &&
104
+ name.toUpperCase() !== "CODEX_API_KEY"));
105
+ const status = await accountStatus(resolveCodexCommand(), environment);
106
+ return status.authenticated && /\bchatgpt\b/iu.test(status.details);
107
+ },
81
108
  currentDirectory: cwd,
82
109
  now: Date.now,
83
110
  setInterval: (callback, milliseconds) => setInterval(callback, milliseconds),
@@ -295,6 +322,21 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
295
322
  errorOutput.write(`codex-security: ${argumentError}\n`);
296
323
  return 2;
297
324
  }
325
+ const pendingUpdate = errorOutput.isTTY === true &&
326
+ argv.length > 0 &&
327
+ argv[0] !== "completions" &&
328
+ !argv.some((argument) => [
329
+ "--help",
330
+ "-h",
331
+ "--version",
332
+ "--llms",
333
+ "--llms-full",
334
+ "--schema",
335
+ "--dry-run",
336
+ ].includes(argument)) &&
337
+ updateNoticeEnabled(dependencies.environment)
338
+ ? dependencies.checkForUpdate().catch(() => undefined)
339
+ : undefined;
298
340
  let exitCode = 0;
299
341
  let frameworkExit;
300
342
  let frameworkOutput = "";
@@ -327,6 +369,43 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
327
369
  });
328
370
  return result;
329
371
  };
372
+ const findingFeedback = Cli.create("findings", {
373
+ description: "Review and manage saved Codex Security findings.",
374
+ }).command("false-positive", {
375
+ description: "Mark a finding as a false positive for future scans.",
376
+ destructive: true,
377
+ mcp: false,
378
+ args: z.object({
379
+ occurrenceId: z
380
+ .string()
381
+ .trim()
382
+ .min(1)
383
+ .max(256)
384
+ .describe("Finding occurrence identifier."),
385
+ }),
386
+ options: z.object({
387
+ reason: z
388
+ .string()
389
+ .trim()
390
+ .min(1, "--reason must not be empty.")
391
+ .max(2_400, "--reason must not exceed 2400 characters.")
392
+ .describe("Explanation for why the finding is a false positive."),
393
+ }),
394
+ output: z.record(z.string(), z.unknown()).optional(),
395
+ async run({ args, options }) {
396
+ return await history([
397
+ "set-finding-triage",
398
+ "--occurrence-id",
399
+ args.occurrenceId,
400
+ "--status",
401
+ "closed",
402
+ "--close-reason",
403
+ "false_positive",
404
+ "--note",
405
+ options.reason,
406
+ ]);
407
+ },
408
+ });
330
409
  const scanHistory = Cli.create("scans", {
331
410
  description: "List, inspect, rerun, match, and compare saved Codex Security scans.",
332
411
  })
@@ -535,6 +614,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
535
614
  }),
536
615
  options: z
537
616
  .object({
617
+ auth: z
618
+ .enum(["auto", "chatgpt", "api-key"])
619
+ .default("auto")
620
+ .describe("Select automatic, ChatGPT, or API-key authentication."),
538
621
  path: z
539
622
  .array(optionValue("--path"))
540
623
  .default([])
@@ -562,7 +645,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
562
645
  .describe("Scan mode."),
563
646
  model: optionValue("--model")
564
647
  .optional()
565
- .describe("Model to use for the scan."),
648
+ .describe(`OpenAI model to use (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
649
+ effort: effortOption(),
566
650
  outputDir: optionValue("--output-dir")
567
651
  .optional()
568
652
  .describe("Write scan artifacts to DIR."),
@@ -579,7 +663,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
579
663
  codex: z
580
664
  .array(optionValue("--codex"))
581
665
  .default([])
582
- .describe("Override isolated Codex config with KEY=VALUE; repeat as needed."),
666
+ .describe('Override Codex settings; e.g. model_reasoning_effort="high".'),
583
667
  failOnSeverity: z
584
668
  .enum(REPORTABLE_SEVERITIES)
585
669
  .optional()
@@ -608,6 +692,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
608
692
  examples: [
609
693
  { args: { repository: "." } },
610
694
  { args: { repository: "." }, options: { model: "gpt-5.6-terra" } },
695
+ {
696
+ args: { repository: "." },
697
+ options: { model: "gpt-5.6-terra", effort: "high" },
698
+ },
611
699
  { args: { repository: "." }, options: { path: ["src", "tests"] } },
612
700
  { args: { repository: "." }, options: { diff: "origin/main" } },
613
701
  ],
@@ -619,6 +707,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
619
707
  return;
620
708
  }
621
709
  const outcome = await runScan({
710
+ auth: options.auth,
622
711
  repository: args.repository,
623
712
  paths: options.path,
624
713
  knowledgeBasePaths: options.knowledgeBase,
@@ -628,6 +717,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
628
717
  base: options.base,
629
718
  mode: options.mode,
630
719
  model: options.model,
720
+ effort: options.effort,
631
721
  outputDir: options.outputDir,
632
722
  archiveExisting: options.archiveExisting,
633
723
  pluginPath: options.pluginPath,
@@ -645,6 +735,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
645
735
  exitCode,
646
736
  });
647
737
  }
738
+ if (!options.dryRun &&
739
+ format === "toon" &&
740
+ !argv.some((argument) => SCAN_HISTORY_OUTPUT_OPTION.test(argument))) {
741
+ return;
742
+ }
648
743
  return outcome.data;
649
744
  },
650
745
  })
@@ -714,6 +809,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
714
809
  },
715
810
  })
716
811
  .command(scanHistory)
812
+ .command(findingFeedback)
717
813
  .command("bulk-scan", {
718
814
  description: "Discover repositories and run resumable bulk security scans.",
719
815
  destructive: true,
@@ -735,7 +831,8 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
735
831
  mode: z.enum(["standard", "deep"]).default("standard"),
736
832
  model: optionValue("--model")
737
833
  .optional()
738
- .describe("Model to use for each repository."),
834
+ .describe(`OpenAI model for each repository (default: ${DEFAULT_SCAN_MODEL_CONFIGURATION.model}).`),
835
+ effort: effortOption(),
739
836
  maxAttempts: z
740
837
  .number()
741
838
  .int()
@@ -744,7 +841,10 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
744
841
  .describe("Maximum scan attempts per repository."),
745
842
  pluginPath: z.string().min(1).optional(),
746
843
  python: z.string().min(1).optional(),
747
- codex: z.array(z.string().min(1)).default([]),
844
+ codex: z
845
+ .array(z.string().min(1))
846
+ .default([])
847
+ .describe('Override Codex settings; e.g. model_reasoning_effort="high".'),
748
848
  }),
749
849
  output: z.record(z.string(), z.unknown()).optional(),
750
850
  async run({ args, options }) {
@@ -764,11 +864,25 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
764
864
  let outputDir;
765
865
  let githubHost;
766
866
  if (args.input === undefined) {
767
- if (argv[0] !== "bulk-scan" ||
768
- !(argv.length === 1 ||
769
- (argv.length === 3 && argv[1] === "--model") ||
770
- (argv.length === 2 && argv[1] === `--model=${options.model}`))) {
771
- throw new Error("Run 'codex-security bulk-scan [--model MODEL]' to discover repositories, or provide a CSV and --output-dir.");
867
+ let optionIndex = 1;
868
+ while (optionIndex < argv.length) {
869
+ const argument = argv[optionIndex];
870
+ if (argument === "--model" ||
871
+ argument === "--effort" ||
872
+ argument === "--codex") {
873
+ optionIndex += 2;
874
+ }
875
+ else if (argument.startsWith("--model=") ||
876
+ argument.startsWith("--effort=") ||
877
+ argument.startsWith("--codex=")) {
878
+ optionIndex += 1;
879
+ }
880
+ else {
881
+ break;
882
+ }
883
+ }
884
+ if (argv[0] !== "bulk-scan" || optionIndex !== argv.length) {
885
+ throw new Error("Run 'codex-security bulk-scan [--model MODEL] [--effort EFFORT] [--codex KEY=VALUE]' to discover repositories, or provide a CSV and --output-dir.");
772
886
  }
773
887
  const wizard = await runBulkScanWizard(dependencies.bulkScan ??
774
888
  createBulkScanDiscoveryDependencies({
@@ -799,7 +913,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
799
913
  config: {
800
914
  pluginPath: options.pluginPath,
801
915
  pythonPath: options.python,
802
- codexOverrides: parseCodexOverrides(options.codex, options.model),
916
+ codexOverrides: parseCodexOverrides(options.codex, options.model, options.effort),
803
917
  },
804
918
  createSecurity: dependencies.createSecurity,
805
919
  signal: controller.signal,
@@ -880,14 +994,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
880
994
  .describe("Finding text or a file containing findings."),
881
995
  }),
882
996
  options: z.object({
997
+ effort: effortOption(),
883
998
  codex: z
884
999
  .array(optionValue("--codex"))
885
1000
  .default([])
886
- .describe("Override model or model_reasoning_effort with KEY=VALUE."),
1001
+ .describe('Set model="gpt-5.6-terra" or model_reasoning_effort="high".'),
887
1002
  }),
888
1003
  async run({ options }) {
889
1004
  try {
890
- exitCode = await runSkill("validation", positionals, options.codex, output, errorOutput, dependencies);
1005
+ exitCode = await runSkill("validation", positionals, options.codex, options.effort, output, errorOutput, dependencies);
891
1006
  }
892
1007
  catch (error) {
893
1008
  exitCode = 2;
@@ -906,14 +1021,15 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
906
1021
  .describe("Issue text or a file containing issues."),
907
1022
  }),
908
1023
  options: z.object({
1024
+ effort: effortOption(),
909
1025
  codex: z
910
1026
  .array(optionValue("--codex"))
911
1027
  .default([])
912
- .describe("Override model or model_reasoning_effort with KEY=VALUE."),
1028
+ .describe('Set model="gpt-5.6-terra" or model_reasoning_effort="high".'),
913
1029
  }),
914
1030
  async run({ options }) {
915
1031
  try {
916
- exitCode = await runSkill("fix-finding", positionals, options.codex, output, errorOutput, dependencies);
1032
+ exitCode = await runSkill("fix-finding", positionals, options.codex, options.effort, output, errorOutput, dependencies);
917
1033
  }
918
1034
  catch (error) {
919
1035
  exitCode = 2;
@@ -961,6 +1077,22 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
961
1077
  errorOutput.write("To use a ChatGPT sign-in, unset OPENAI_API_KEY and CODEX_API_KEY.\n");
962
1078
  }
963
1079
  }
1080
+ else if (exitCode === 0 &&
1081
+ !options.withApiKey &&
1082
+ !options.withAccessToken) {
1083
+ const authentication = scanAuthentication(dependencies.environment);
1084
+ if (authentication.method === "api_key") {
1085
+ const configuredApiKeyVariables = Object.entries(dependencies.environment)
1086
+ .filter(([name, value]) => value?.trim() &&
1087
+ (name.toUpperCase() === "OPENAI_API_KEY" ||
1088
+ name.toUpperCase() === "CODEX_API_KEY"))
1089
+ .map(([name]) => name);
1090
+ errorOutput.write("ChatGPT login succeeded. Interactive scans will ask which account to use; " +
1091
+ `noninteractive scans will use ${authentication.source}.\n` +
1092
+ "To use your ChatGPT sign-in, pass '--auth chatgpt' or run " +
1093
+ `'unset ${configuredApiKeyVariables.join(" ")}'.\n`);
1094
+ }
1095
+ }
964
1096
  },
965
1097
  })
966
1098
  .command("logout", {
@@ -1011,7 +1143,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1011
1143
  };
1012
1144
  },
1013
1145
  });
1014
- await cli.serve([...argv], {
1146
+ await cli.serve(argv.flatMap((argument) => argument.startsWith("--format=")
1147
+ ? ["--format", argument.slice("--format=".length)]
1148
+ : [argument]), {
1015
1149
  stdout: (value) => {
1016
1150
  frameworkOutput += value;
1017
1151
  },
@@ -1019,6 +1153,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1019
1153
  frameworkExit = code;
1020
1154
  },
1021
1155
  });
1156
+ if (pendingUpdate !== undefined) {
1157
+ const notice = await pendingUpdate;
1158
+ if (notice !== undefined)
1159
+ errorOutput.write(formatUpdateNotice(notice));
1160
+ }
1022
1161
  if (frameworkExit !== undefined) {
1023
1162
  if (exitCode !== 0)
1024
1163
  return exitCode;
@@ -1145,6 +1284,7 @@ function validateCliArguments(argv, positionals) {
1145
1284
  "install-hook",
1146
1285
  "bulk-scan",
1147
1286
  "scans",
1287
+ "findings",
1148
1288
  "export",
1149
1289
  "validate",
1150
1290
  "patch",
@@ -1184,7 +1324,8 @@ function validateCliArguments(argv, positionals) {
1184
1324
  return "Markdown output is not supported for scan results.";
1185
1325
  }
1186
1326
  }
1187
- const subcommand = command === "scans" ? argv[commandIndex + 1] : undefined;
1327
+ const nestedCommand = command === "scans" || command === "findings";
1328
+ const subcommand = nestedCommand ? argv[commandIndex + 1] : undefined;
1188
1329
  if (command === "info") {
1189
1330
  const metadataFields = new Set([
1190
1331
  "sdkVersion",
@@ -1213,7 +1354,7 @@ function validateCliArguments(argv, positionals) {
1213
1354
  }
1214
1355
  }
1215
1356
  }
1216
- for (let index = commandIndex + (command === "scans" ? 2 : 1); index < argv.length; index += 1) {
1357
+ for (let index = commandIndex + (nestedCommand ? 2 : 1); index < argv.length; index += 1) {
1217
1358
  const value = argv[index];
1218
1359
  if (!value.startsWith("-")) {
1219
1360
  positionals.push(value);
@@ -1317,11 +1458,11 @@ function staysWithinWindowsDeviceRoot(input, root) {
1317
1458
  }
1318
1459
  return true;
1319
1460
  }
1320
- async function runSkill(skill, inputs, codexOverrides, stdout, stderr, dependencies) {
1461
+ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, dependencies) {
1321
1462
  if (inputs.length > MAX_SKILL_INPUT_COUNT) {
1322
1463
  throw new CodexSecurityError("Skill inputs exceed the 64-item limit.");
1323
1464
  }
1324
- const overrides = parseCodexOverrides(codexOverrides);
1465
+ const overrides = parseCodexOverrides(codexOverrides, undefined, effort);
1325
1466
  if (Object.keys(overrides).some((key) => key !== "model" && key !== "model_reasoning_effort")) {
1326
1467
  throw new CodexSecurityError("Validation and patching only support model and model_reasoning_effort overrides.");
1327
1468
  }
@@ -1561,7 +1702,6 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1561
1702
  let firstSignalAt = 0;
1562
1703
  let progress = null;
1563
1704
  let lastWorkerUpdate = "";
1564
- let workerCapacity = null;
1565
1705
  let phase = null;
1566
1706
  const preparationAbortController = new AbortController();
1567
1707
  const signalListener = (signal) => () => {
@@ -1601,6 +1741,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1601
1741
  let security = null;
1602
1742
  let result = null;
1603
1743
  let preflight = null;
1744
+ let selectedAuthentication = null;
1604
1745
  let failed = false;
1605
1746
  let failure;
1606
1747
  try {
@@ -1610,8 +1751,32 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1610
1751
  pluginPath: arguments_.pluginPath,
1611
1752
  pythonPath: arguments_.pythonPath,
1612
1753
  codexOverrides: arguments_.codexOverrides ??
1613
- parseCodexOverrides(arguments_.codex, arguments_.model),
1754
+ parseCodexOverrides(arguments_.codex, arguments_.model, arguments_.effort),
1614
1755
  };
1756
+ let auth = arguments_.auth;
1757
+ selectedAuthentication = scanAuthentication(dependencies.environment, auth);
1758
+ if ((auth === undefined || auth === "auto") &&
1759
+ !arguments_.dryRun &&
1760
+ interactive &&
1761
+ errorOutput.isTTY === true &&
1762
+ selectedAuthentication.method === "api_key") {
1763
+ const prompt = dependencies.scanAuthenticationPrompt ??
1764
+ createBulkScanDiscoveryDependencies({
1765
+ output: errorOutput,
1766
+ now: dependencies.now,
1767
+ currentDirectory: dependencies.currentDirectory,
1768
+ }).prompt;
1769
+ if (prompt.isInteractive() &&
1770
+ (await dependencies.hasStoredChatGPTSignIn?.()) === true) {
1771
+ const source = selectedAuthentication.source;
1772
+ errorOutput.write(`Both a ChatGPT sign-in and an API key from ${source} are available.\n`);
1773
+ auth = await prompt.select("How would you like to authenticate this scan?", [
1774
+ { label: "ChatGPT subscription", value: "chatgpt" },
1775
+ { label: `API key from ${source}`, value: "api-key" },
1776
+ ]);
1777
+ selectedAuthentication = scanAuthentication(dependencies.environment, auth);
1778
+ }
1779
+ }
1615
1780
  progress = new Progress(errorOutput, dependencies, interactive);
1616
1781
  const scope = scanScope(arguments_);
1617
1782
  const runningMessage = () => phase === null
@@ -1622,6 +1787,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1622
1787
  progress.startTimer(arguments_.dryRun ? "Validating scan inputs" : "Preparing scan");
1623
1788
  security = dependencies.createSecurity(config);
1624
1789
  const options = {
1790
+ auth,
1625
1791
  target,
1626
1792
  knowledgeBasePaths: arguments_.knowledgeBasePaths,
1627
1793
  mode: arguments_.mode,
@@ -1649,14 +1815,11 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1649
1815
  scanDir = path;
1650
1816
  },
1651
1817
  onAuthentication: (authentication) => {
1818
+ selectedAuthentication = authentication;
1652
1819
  progress?.stopTimer();
1653
1820
  if (authentication.method === "api_key") {
1654
1821
  progress?.stage(`Authentication: API key from ${authentication.source}.`);
1655
- if (errorOutput.isTTY === true) {
1656
- progress?.stage(process.platform === "win32"
1657
- ? "To use a ChatGPT sign-in, unset OPENAI_API_KEY and CODEX_API_KEY, then retry the scan."
1658
- : "Retry with ChatGPT: env -u OPENAI_API_KEY -u CODEX_API_KEY codex-security scan ...");
1659
- }
1822
+ progress?.stage("To use your ChatGPT sign-in, retry with --auth chatgpt.");
1660
1823
  }
1661
1824
  else {
1662
1825
  progress?.stage("Authentication: stored Codex credentials.");
@@ -1690,10 +1853,8 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1690
1853
  if (update === lastWorkerUpdate)
1691
1854
  return;
1692
1855
  lastWorkerUpdate = update;
1693
- if (status.kind === "dispatch") {
1694
- workerCapacity = { planned: status.planned, started: status.started };
1856
+ if (status.kind === "dispatch")
1695
1857
  phase = scanPhase(status.phase);
1696
- }
1697
1858
  const message = workerStatusMessage(status);
1698
1859
  if (message === null || progress === null)
1699
1860
  return;
@@ -1701,6 +1862,9 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1701
1862
  progress.stage(message);
1702
1863
  progress.startTimer(runningMessage());
1703
1864
  },
1865
+ onWarning: (warning) => {
1866
+ errorOutput.write(`codex-security: warning: ${cliErrorMessage(warning)}\n`);
1867
+ },
1704
1868
  onObserverError: (observer, error) => {
1705
1869
  errorOutput.write(`codex-security: warning: ${observer} observer failed: ${cliErrorMessage(error)}\n`);
1706
1870
  },
@@ -1739,7 +1903,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1739
1903
  if (failed) {
1740
1904
  const message = failure instanceof OutputInsideProtectedRootError
1741
1905
  ? cliErrorMessage(protectedRootErrorMessage(failure))
1742
- : scanFailureMessage(failure);
1906
+ : scanFailureMessage(failure, selectedAuthentication);
1743
1907
  if (failure instanceof OutputInsideProtectedRootError) {
1744
1908
  errorOutput.write(`${message}\n`);
1745
1909
  }
@@ -1769,7 +1933,7 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1769
1933
  const blockingCount = result.findings.findings.filter(({ severity }) => blockingSeverities.has(severity.level)).length;
1770
1934
  const incomplete = result.coverage.completeness !== "complete";
1771
1935
  progress?.stage("Scan complete");
1772
- printScanSummary(result, progress, errorOutput, workerCapacity);
1936
+ printScanSummary(result, progress, errorOutput);
1773
1937
  if (incomplete) {
1774
1938
  errorOutput.write(threshold === undefined
1775
1939
  ? `codex-security: Scan coverage is ${result.coverage.completeness}; results may be incomplete.\n`
@@ -1778,18 +1942,25 @@ async function runScan(arguments_, errorOutput, dependencies, interactive = true
1778
1942
  }
1779
1943
  return { exitCode: blockingCount > 0 ? 1 : 0, data: result.toJSON() };
1780
1944
  }
1781
- function scanFailureMessage(error) {
1945
+ function scanFailureMessage(error, authentication) {
1782
1946
  switch (classifyConnectionFailure(error)) {
1783
1947
  case "unauthorized":
1784
- return "Authentication failed. Sign in again or provide a valid API key.";
1948
+ return authentication?.method === "api_key"
1949
+ ? `Authentication failed using ${authentication.source}. ` +
1950
+ "Your ChatGPT sign-in was not used. " +
1951
+ "Retry with '--auth chatgpt' or provide a valid API key."
1952
+ : "Authentication failed using stored ChatGPT credentials. " +
1953
+ "Sign in again with 'codex-security login' or provide a valid API key.";
1785
1954
  case "forbidden":
1786
- return "The selected credentials cannot access the configured model. Use an account or API key with model access.";
1955
+ return authentication?.method === "api_key"
1956
+ ? `The API key from ${authentication.source} cannot access the configured model. ` +
1957
+ "Retry with '--auth chatgpt' or use an API key with model access."
1958
+ : "The stored ChatGPT credentials cannot access the configured model. " +
1959
+ "Use an account or API key with model access.";
1787
1960
  case "rate_limited":
1788
1961
  return "The configured account reached its rate limit. Wait and retry.";
1789
1962
  case "network_error":
1790
- return "The model service could not be reached. Check your network connection and try again.";
1791
1963
  case "timeout":
1792
- return "The connection timed out. Check your network connection and try again.";
1793
1964
  case "unknown":
1794
1965
  return cliErrorMessage(error);
1795
1966
  }
@@ -1821,7 +1992,7 @@ function scanPhase(value) {
1821
1992
  attack_path: "analyzing attack paths",
1822
1993
  }[value];
1823
1994
  }
1824
- function printScanSummary(result, progress, errorOutput, workers) {
1995
+ function printScanSummary(result, progress, errorOutput) {
1825
1996
  const severities = new Map();
1826
1997
  for (const finding of result.findings.findings) {
1827
1998
  severities.set(finding.severity.level, (severities.get(finding.severity.level) ?? 0) + 1);
@@ -1840,7 +2011,7 @@ function printScanSummary(result, progress, errorOutput, workers) {
1840
2011
  completed >= started
1841
2012
  ? Math.floor((completed - started) / 1_000)
1842
2013
  : progress?.elapsedSeconds ?? 0;
1843
- errorOutput.write(`codex-security: Elapsed: ${elapsed}s.${workers === null ? "" : ` Workers: ${workers.started}/${workers.planned}.`}\n`);
2014
+ errorOutput.write(`codex-security: Elapsed: ${elapsed}s.\n`);
1844
2015
  const tokenSummary = formatTokenUsage(result.turnResult.usage);
1845
2016
  if (tokenSummary !== null) {
1846
2017
  errorOutput.write(`codex-security: Tokens: ${tokenSummary}.\n`);
@@ -1848,11 +2019,8 @@ function printScanSummary(result, progress, errorOutput, workers) {
1848
2019
  if (result.cost !== null) {
1849
2020
  errorOutput.write(`codex-security: Estimated cost: ${formatUsd(result.cost.estimatedUsd)} USD.\n`);
1850
2021
  }
1851
- const scanDir = cliErrorMessage(result.scanDir);
1852
- errorOutput.write(`codex-security: Results: ${scanDir}\n`);
1853
- errorOutput.write(result.sarifPath === null
1854
- ? `codex-security: Next: codex-security export ${quoteCliPath(scanDir)} --export-format sarif\n`
1855
- : `codex-security: Next: review ${cliErrorMessage(result.reportPath)}\n`);
2022
+ errorOutput.write(`codex-security: Report: ${cliErrorMessage(result.reportPath)}\n`);
2023
+ errorOutput.write(`codex-security: Results: ${cliErrorMessage(result.scanDir)}\n`);
1856
2024
  }
1857
2025
  function formatTokenUsage(usage) {
1858
2026
  if (usage === null || typeof usage !== "object")
@@ -1948,10 +2116,12 @@ function targetFromArguments(arguments_) {
1948
2116
  }
1949
2117
  return "repository";
1950
2118
  }
1951
- export function parseCodexOverrides(values, model) {
2119
+ export function parseCodexOverrides(values, model, effort) {
1952
2120
  const result = Object.create(null);
1953
2121
  if (model !== undefined)
1954
2122
  result["model"] = model;
2123
+ if (effort !== undefined)
2124
+ result["model_reasoning_effort"] = effort;
1955
2125
  for (const value of values) {
1956
2126
  const separator = value.indexOf("=");
1957
2127
  const key = separator < 0 ? "" : value.slice(0, separator);
@@ -1995,9 +2165,13 @@ export function parseCodexOverrides(values, model) {
1995
2165
  }
1996
2166
  const final = parts.at(-1);
1997
2167
  if (Object.hasOwn(cursor, final)) {
1998
- throw new CodexSecurityError(model !== undefined && key === "model"
1999
- ? "--model conflicts with --codex model"
2000
- : "Duplicate --codex key");
2168
+ if (model !== undefined && key === "model") {
2169
+ throw new CodexSecurityError("--model conflicts with --codex model");
2170
+ }
2171
+ if (effort !== undefined && key === "model_reasoning_effort") {
2172
+ throw new CodexSecurityError("--effort conflicts with --codex model_reasoning_effort");
2173
+ }
2174
+ throw new CodexSecurityError("Duplicate --codex key");
2001
2175
  }
2002
2176
  cursor[final] = parsed;
2003
2177
  }