@openai/codex-security 0.4.0 → 0.5.0

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 (180) hide show
  1. package/README.md +45 -9
  2. package/_bundled_plugin/.mcp.json +1 -0
  3. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  4. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  5. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  6. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  8. package/_bundled_plugin/references/core-scan.md +2 -0
  9. package/_bundled_plugin/references/final-report.md +5 -1
  10. package/_bundled_plugin/references/investigation-time-budget.md +11 -0
  11. package/_bundled_plugin/references/sarif-adapter.md +1 -0
  12. package/_bundled_plugin/references/scan-prologue.md +2 -6
  13. package/_bundled_plugin/references/scan-runtime.md +15 -0
  14. package/_bundled_plugin/references/threat-model.md +2 -0
  15. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +5 -1
  16. package/_bundled_plugin/scripts/deep_scan_workbench.py +7 -0
  17. package/_bundled_plugin/scripts/finalize_scan_contract.py +80 -43
  18. package/_bundled_plugin/scripts/finding_preview.py +5 -3
  19. package/_bundled_plugin/scripts/generate_rank_input.py +1 -0
  20. package/_bundled_plugin/scripts/launch_codex_security_mcp +39 -4
  21. package/_bundled_plugin/scripts/snapshot_sqlite.py +7 -0
  22. package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -1
  23. package/_bundled_plugin/scripts/workbench_cli.py +0 -3
  24. package/_bundled_plugin/scripts/workbench_constants.py +4 -0
  25. package/_bundled_plugin/scripts/workbench_db.py +56 -33
  26. package/_bundled_plugin/scripts/workbench_progress.py +0 -50
  27. package/_bundled_plugin/scripts/workbench_scan_history.py +3 -2
  28. package/_bundled_plugin/scripts/workbench_scan_start.py +12 -4
  29. package/_bundled_plugin/scripts/workbench_scan_usage.py +190 -30
  30. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  31. package/_bundled_plugin/scripts/workbench_source_excerpt.py +74 -51
  32. package/_bundled_plugin/scripts/workbench_source_scopes.py +388 -0
  33. package/_bundled_plugin/scripts/workbench_target.py +7 -5
  34. package/_bundled_plugin/scripts/workbench_validation.py +37 -1
  35. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -0
  36. package/_bundled_plugin/shared/workbench-migrations.json +5 -0
  37. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  38. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +4 -2
  39. package/_bundled_plugin/skills/security-scan/SKILL.md +3 -1
  40. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  41. package/dist/api.d.ts +3 -2
  42. package/dist/api.d.ts.map +1 -1
  43. package/dist/api.js +54 -36
  44. package/dist/api.js.map +1 -1
  45. package/dist/artifact-export.d.ts +2 -1
  46. package/dist/artifact-export.d.ts.map +1 -1
  47. package/dist/artifact-export.js +38 -23
  48. package/dist/artifact-export.js.map +1 -1
  49. package/dist/classify-severity-records.d.ts +76 -0
  50. package/dist/classify-severity-records.d.ts.map +1 -0
  51. package/dist/classify-severity-records.js +141 -0
  52. package/dist/classify-severity-records.js.map +1 -0
  53. package/dist/classify-severity.d.ts +1 -23
  54. package/dist/classify-severity.d.ts.map +1 -1
  55. package/dist/classify-severity.js +3 -24
  56. package/dist/classify-severity.js.map +1 -1
  57. package/dist/cli-help.d.ts.map +1 -1
  58. package/dist/cli-help.js +2 -0
  59. package/dist/cli-help.js.map +1 -1
  60. package/dist/cli.d.ts +4 -2
  61. package/dist/cli.d.ts.map +1 -1
  62. package/dist/cli.js +136 -147
  63. package/dist/cli.js.map +1 -1
  64. package/dist/cloud-publish.js +1 -1
  65. package/dist/cloud-publish.js.map +1 -1
  66. package/dist/codex-sdk-environment.js +1 -1
  67. package/dist/codex-sdk-environment.js.map +1 -1
  68. package/dist/config.d.ts +12 -0
  69. package/dist/config.d.ts.map +1 -1
  70. package/dist/config.js +10 -4
  71. package/dist/config.js.map +1 -1
  72. package/dist/contract.d.ts +5 -0
  73. package/dist/contract.d.ts.map +1 -1
  74. package/dist/contract.js +65 -17
  75. package/dist/contract.js.map +1 -1
  76. package/dist/cost-model.d.ts.map +1 -1
  77. package/dist/cost-model.js +7 -2
  78. package/dist/cost-model.js.map +1 -1
  79. package/dist/custom-validation-prompt.js +3 -3
  80. package/dist/custom-validation-prompt.js.map +1 -1
  81. package/dist/deduplication/deduplication-prompts.d.ts +1 -1
  82. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  83. package/dist/deduplication/deduplication-prompts.js +2 -2
  84. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  85. package/dist/deduplication/records.js +1 -1
  86. package/dist/deduplication/records.js.map +1 -1
  87. package/dist/deduplication/scan.d.ts.map +1 -1
  88. package/dist/deduplication/scan.js +10 -9
  89. package/dist/deduplication/scan.js.map +1 -1
  90. package/dist/deep-config.d.ts +4 -1
  91. package/dist/deep-config.d.ts.map +1 -1
  92. package/dist/deep-config.js +21 -1
  93. package/dist/deep-config.js.map +1 -1
  94. package/dist/findings-import.d.ts +1 -1
  95. package/dist/findings-import.d.ts.map +1 -1
  96. package/dist/findings-import.js +3 -3
  97. package/dist/findings-import.js.map +1 -1
  98. package/dist/git-remote.d.ts +10 -0
  99. package/dist/git-remote.d.ts.map +1 -0
  100. package/dist/git-remote.js +24 -0
  101. package/dist/git-remote.js.map +1 -0
  102. package/dist/github.d.ts.map +1 -1
  103. package/dist/github.js +5 -7
  104. package/dist/github.js.map +1 -1
  105. package/dist/host-protocol.js +1 -1
  106. package/dist/host-protocol.js.map +1 -1
  107. package/dist/host-records-protocol.d.ts +15 -0
  108. package/dist/host-records-protocol.d.ts.map +1 -0
  109. package/dist/host-records-protocol.js +15 -0
  110. package/dist/host-records-protocol.js.map +1 -0
  111. package/dist/hosted-scan.d.ts +1 -6
  112. package/dist/hosted-scan.d.ts.map +1 -1
  113. package/dist/hosted-scan.js +2 -2
  114. package/dist/hosted-scan.js.map +1 -1
  115. package/dist/index.d.ts +4 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +2 -0
  118. package/dist/index.js.map +1 -1
  119. package/dist/knowledge-base.d.ts.map +1 -1
  120. package/dist/knowledge-base.js +87 -7
  121. package/dist/knowledge-base.js.map +1 -1
  122. package/dist/multiscan.d.ts.map +1 -1
  123. package/dist/multiscan.js +62 -28
  124. package/dist/multiscan.js.map +1 -1
  125. package/dist/patch-publication.d.ts +26 -0
  126. package/dist/patch-publication.d.ts.map +1 -0
  127. package/dist/patch-publication.js +105 -0
  128. package/dist/patch-publication.js.map +1 -0
  129. package/dist/patch-tui.d.ts.map +1 -1
  130. package/dist/patch-tui.js +4 -1
  131. package/dist/patch-tui.js.map +1 -1
  132. package/dist/project-config-schema.d.ts +2 -0
  133. package/dist/project-config-schema.d.ts.map +1 -1
  134. package/dist/project-config-schema.js +1 -0
  135. package/dist/project-config-schema.js.map +1 -1
  136. package/dist/project-config.d.ts +1 -0
  137. package/dist/project-config.d.ts.map +1 -1
  138. package/dist/project-config.js +16 -6
  139. package/dist/project-config.js.map +1 -1
  140. package/dist/publication.d.ts.map +1 -1
  141. package/dist/publication.js +135 -19
  142. package/dist/publication.js.map +1 -1
  143. package/dist/publish.d.ts.map +1 -1
  144. package/dist/publish.js +39 -25
  145. package/dist/publish.js.map +1 -1
  146. package/dist/runtime.d.ts.map +1 -1
  147. package/dist/runtime.js +83 -22
  148. package/dist/runtime.js.map +1 -1
  149. package/dist/scan-settings.d.ts +1 -0
  150. package/dist/scan-settings.d.ts.map +1 -1
  151. package/dist/scan-settings.js +7 -1
  152. package/dist/scan-settings.js.map +1 -1
  153. package/dist/scan-time-budget.d.ts +9 -0
  154. package/dist/scan-time-budget.d.ts.map +1 -0
  155. package/dist/scan-time-budget.js +16 -0
  156. package/dist/scan-time-budget.js.map +1 -0
  157. package/dist/severity-review.d.ts +29 -0
  158. package/dist/severity-review.d.ts.map +1 -0
  159. package/dist/severity-review.js +47 -0
  160. package/dist/severity-review.js.map +1 -0
  161. package/dist/validation-records.d.ts +38 -0
  162. package/dist/validation-records.d.ts.map +1 -0
  163. package/dist/validation-records.js +76 -0
  164. package/dist/validation-records.js.map +1 -0
  165. package/dist/version.d.ts.map +1 -1
  166. package/dist/version.js +4 -2
  167. package/dist/version.js.map +1 -1
  168. package/dist/worker-progress.d.ts +2 -6
  169. package/dist/worker-progress.d.ts.map +1 -1
  170. package/dist/worker-progress.js +1 -43
  171. package/dist/worker-progress.js.map +1 -1
  172. package/docs/classify-severity-records.md +89 -0
  173. package/docs/cli.md +269 -33
  174. package/docs/validate-records.md +69 -0
  175. package/package.json +12 -10
  176. package/schemas/project-config.schema.json +7 -1
  177. package/_bundled_plugin/preflight/capability-profiles.toml +0 -76
  178. package/_bundled_plugin/references/config-preflight.md +0 -93
  179. package/_bundled_plugin/references/desktop-config-preflight.md +0 -11
  180. package/_bundled_plugin/scripts/config_preflight.py +0 -911
package/dist/runtime.js CHANGED
@@ -9,7 +9,7 @@ import { chmodSync, constants, createWriteStream, } from "node:fs";
9
9
  import { chmod, cp, copyFile, link, lstat, mkdir, mkdtemp, open, readFile, readdir, realpath, rename, rm, rmdir, stat, utimes, writeFile, } from "node:fs/promises";
10
10
  import { homedir, tmpdir } from "node:os";
11
11
  import { createRequire } from "node:module";
12
- import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, } from "node:path";
12
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep, win32, } from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
14
  import { promisify } from "node:util";
15
15
  import { pipeline } from "node:stream/promises";
@@ -55,6 +55,7 @@ const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
55
55
  "CODEX_API_KEY",
56
56
  "OPENROUTER_API_KEY",
57
57
  "FIREWORKS_API_KEY",
58
+ "CHEAPER_INFERENCE_API_KEY",
58
59
  ]);
59
60
  const PREPARE_SCAN_ARTIFACT_RESTORER_PROGRAM = `
60
61
  from pathlib import Path
@@ -217,10 +218,7 @@ function windowsCredentialAclFailure(error) {
217
218
  const detail = typeof stderr === "string" && stderr.trim() !== ""
218
219
  ? stderr
219
220
  : errorMessage(error);
220
- const normalized = errorMessage(detail)
221
- .replace(/\s+/gu, " ")
222
- .trim()
223
- .slice(0, 512);
221
+ const normalized = errorMessage(detail).replace(/\s+/gu, " ").trim();
224
222
  return normalized === "" ? "" : `. ${normalized}`;
225
223
  }
226
224
  const WINDOWS_SYSTEM_SID = "S-1-5-18";
@@ -525,9 +523,9 @@ export async function streamWindowsCredentialAclDescriptors(command, args, inspe
525
523
  }
526
524
  }
527
525
  export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid, options) {
528
- let ancestors = 0;
526
+ const ancestors = [];
529
527
  for (let ancestor = dirname(path);; ancestor = dirname(ancestor)) {
530
- ancestors += 1;
528
+ ancestors.push(ancestor);
531
529
  if (ancestor === dirname(ancestor))
532
530
  break;
533
531
  }
@@ -552,17 +550,26 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
552
550
  const index = inspected;
553
551
  inspected += 1;
554
552
  await options.resolveDescriptorAliases?.(descriptor);
555
- if (index < ancestors) {
556
- const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
557
- resolvedAliases: options.resolvedAliases,
558
- scope: "ancestor",
559
- });
560
- if (ancestor.untrustedPrincipals.length !== 0) {
561
- throw new Error("Windows credential-home ancestor allows another identity to replace the directory");
553
+ if (index < ancestors.length) {
554
+ const ancestorPath = ancestors[index];
555
+ try {
556
+ const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
557
+ resolvedAliases: options.resolvedAliases,
558
+ scope: "ancestor",
559
+ });
560
+ if (ancestor.untrustedPrincipals.length !== 0) {
561
+ throw new Error("Windows credential-home ancestor allows another identity to replace the directory");
562
+ }
563
+ }
564
+ catch (error) {
565
+ const guidance = ancestorPath === dirname(ancestorPath)
566
+ ? "This volume root is unsupported. Choose a location on a volume with trusted ancestry; another directory on the same volume will not resolve this."
567
+ : "Choose a location outside this ancestor with trusted ownership and permissions.";
568
+ throw new Error(`Windows private-directory ancestor could not be trusted: ${ancestorPath}. ${errorMessage(error)}. ${guidance}`, { cause: error });
562
569
  }
563
570
  return;
564
571
  }
565
- if (index === ancestors) {
572
+ if (index === ancestors.length) {
566
573
  try {
567
574
  home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
568
575
  resolvedAliases: options.resolvedAliases,
@@ -591,7 +598,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
591
598
  continue;
592
599
  throw error;
593
600
  }
594
- if (inspected <= ancestors) {
601
+ if (inspected <= ancestors.length) {
595
602
  throw new Error("Windows credential-home ancestry could not be verified");
596
603
  }
597
604
  if (!completed) {
@@ -1389,7 +1396,10 @@ export async function planOutputArchive(outputDirectory) {
1389
1396
  const entries = await readdir(outputDirectory).catch(nullIfMissingFileError);
1390
1397
  if (entries === null || entries.length === 0)
1391
1398
  return null;
1392
- return `${outputDirectory}.previous-${new Date()
1399
+ return `${outputDirectory}${outputArchiveSuffix()}`;
1400
+ }
1401
+ function outputArchiveSuffix() {
1402
+ return `.previous-${new Date()
1393
1403
  .toISOString()
1394
1404
  .replaceAll(/[-:]/g, "")
1395
1405
  .replace(/\.\d{3}Z$/, "")}-${randomUUID().slice(0, 8)}`;
@@ -1442,10 +1452,22 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1442
1452
  const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
1443
1453
  validateLocation?.(path ?? (await realpath(temporaryRoot)));
1444
1454
  if (path === null) {
1445
- const created = await mkdtemp(join(temporaryRoot, `codex-security-${safePrefix(repositoryName)}-`));
1446
- if ((process.umask() & 0o700) !== 0)
1447
- await chmod(created, 0o700);
1455
+ const prefix = `codex-security-${safePrefix(repositoryName)}`;
1456
+ let created;
1457
+ if (process.platform === "win32") {
1458
+ const suffix = `-${randomUUID()}`;
1459
+ // Reserve room within NTFS's 255-unit component limit for later archival.
1460
+ // The SDK suffix is longer than the workbench's .previous-<tempname> suffix.
1461
+ const prefixLength = 255 - suffix.length - outputArchiveSuffix().length;
1462
+ created = join(temporaryRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
1463
+ await createWindowsOutputDirectory(created, false);
1464
+ }
1465
+ else {
1466
+ created = await mkdtemp(join(temporaryRoot, `${prefix}-`));
1467
+ }
1448
1468
  try {
1469
+ if ((process.umask() & 0o700) !== 0)
1470
+ await chmod(created, 0o700);
1449
1471
  return await validatePreparedOutputDir(created, validateLocation);
1450
1472
  }
1451
1473
  catch (error) {
@@ -1465,7 +1487,10 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1465
1487
  }
1466
1488
  }
1467
1489
  if (existing === null) {
1468
- createdRoot = await mkdir(path, { recursive: true, mode: 0o700 });
1490
+ createdRoot =
1491
+ process.platform === "win32"
1492
+ ? await createWindowsOutputDirectory(path, true)
1493
+ : await mkdir(path, { recursive: true, mode: 0o700 });
1469
1494
  if ((process.umask() & 0o700) !== 0)
1470
1495
  await chmod(path, 0o700);
1471
1496
  }
@@ -1482,6 +1507,26 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1482
1507
  });
1483
1508
  }
1484
1509
  }
1510
+ async function createWindowsOutputDirectory(path, recursive) {
1511
+ const native = createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
1512
+ const create = async (target) => {
1513
+ const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"));
1514
+ let error = createOne();
1515
+ let firstCreated;
1516
+ if (recursive &&
1517
+ (error === 2 || error === 3) &&
1518
+ dirname(target) !== target) {
1519
+ firstCreated = await create(dirname(target));
1520
+ error = createOne();
1521
+ }
1522
+ if (error === 0)
1523
+ return firstCreated ?? target;
1524
+ if (recursive && error === 183 && (await stat(target)).isDirectory())
1525
+ return firstCreated;
1526
+ throw new OutputDirectoryError(`Unable to create private Windows output directory (Windows error ${error}): ${target}`);
1527
+ };
1528
+ return create(path);
1529
+ }
1485
1530
  export async function validatePreparedOutputDir(path, validateLocation, allowNonempty = false) {
1486
1531
  const metadata = await lstat(path);
1487
1532
  if (!metadata.isDirectory()) {
@@ -2239,12 +2284,13 @@ export async function cleanupSdkDirectory(path) {
2239
2284
  export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
2240
2285
  const cancellation = archiveHandshake ? new AbortController() : undefined;
2241
2286
  const abort = () => cancellation?.abort(signal?.reason);
2287
+ const commandSignal = cancellation?.signal ?? signal;
2242
2288
  let awaitingArchive = archiveHandshake;
2243
2289
  const child = spawn(executablePathForSpawn(command.command), [...(command.args ?? []), ...args], {
2244
2290
  env: environment,
2245
2291
  stdio: ["pipe", "pipe", "pipe"],
2246
2292
  windowsHide: true,
2247
- signal: cancellation?.signal ?? signal,
2293
+ signal: commandSignal,
2248
2294
  });
2249
2295
  let stdout = "";
2250
2296
  let stderr = "";
@@ -2280,6 +2326,19 @@ export async function runCodexCommand(command, args, environment, input, signal,
2280
2326
  ? resolve({ success: exitCode === 0, exitCode, stdout, stderr })
2281
2327
  : reject(processError));
2282
2328
  });
2329
+ const releaseCanceledPipes = () => {
2330
+ if (!commandSignal?.aborted)
2331
+ return;
2332
+ if (child.exitCode === null && child.signalCode === null)
2333
+ return;
2334
+ child.stdin.destroy();
2335
+ child.stdout.destroy();
2336
+ child.stderr.destroy();
2337
+ };
2338
+ commandSignal?.addEventListener("abort", releaseCanceledPipes, {
2339
+ once: true,
2340
+ });
2341
+ child.once("exit", releaseCanceledPipes);
2283
2342
  if (archiveHandshake) {
2284
2343
  signal?.addEventListener("abort", abort, { once: true });
2285
2344
  if (signal?.aborted)
@@ -2297,6 +2356,8 @@ export async function runCodexCommand(command, args, environment, input, signal,
2297
2356
  finally {
2298
2357
  if (archiveHandshake)
2299
2358
  signal?.removeEventListener("abort", abort);
2359
+ commandSignal?.removeEventListener("abort", releaseCanceledPipes);
2360
+ child.removeListener("exit", releaseCanceledPipes);
2300
2361
  }
2301
2362
  }
2302
2363
  export async function probeCodexSandbox(command, environment, signal) {