@openai/codex-security 0.8.3 → 0.9.1

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 (534) hide show
  1. package/README.md +192 -151
  2. package/_bundled_plugin/.mcp.json +5 -1
  3. package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
  4. package/_bundled_plugin/examples/completed-scan/report.md +11 -8
  5. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
  6. package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
  7. package/_bundled_plugin/mcp/helpers.mjs +2 -11
  8. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  9. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
  10. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/package.json +1 -0
  19. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
  20. package/_bundled_plugin/mcp/server.mjs +2 -11
  21. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  22. package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
  23. package/_bundled_plugin/references/default-severity-rubric.md +9 -4
  24. package/_bundled_plugin/references/final-report.md +5 -3
  25. package/_bundled_plugin/references/finding-detail-fields.md +18 -18
  26. package/_bundled_plugin/references/sarif-adapter.md +8 -2
  27. package/_bundled_plugin/references/scan-artifacts.md +21 -12
  28. package/_bundled_plugin/references/scan-contract.md +27 -33
  29. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
  30. package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
  31. package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
  32. package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
  33. package/_bundled_plugin/scripts/deep_scan_workbench.py +165 -342
  34. package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
  35. package/_bundled_plugin/scripts/finalize_scan_contract.py +153 -227
  36. package/_bundled_plugin/scripts/finding_preview.py +20 -0
  37. package/_bundled_plugin/scripts/launch_codex_security_mcp +1 -0
  38. package/_bundled_plugin/scripts/legacy_findings.py +148 -0
  39. package/_bundled_plugin/scripts/posix_scan_local_files.py +11 -0
  40. package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
  41. package/_bundled_plugin/scripts/report_projection.py +81 -43
  42. package/_bundled_plugin/scripts/review_state.py +8 -2
  43. package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
  44. package/_bundled_plugin/scripts/snapshot_sqlite.py +1 -0
  45. package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
  46. package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
  47. package/_bundled_plugin/scripts/windows_scan_local_files.py +388 -17
  48. package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
  49. package/_bundled_plugin/scripts/workbench/handoff.py +47 -0
  50. package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
  51. package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
  52. package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
  53. package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
  54. package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
  55. package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
  56. package/_bundled_plugin/scripts/workbench/storage.py +71 -7
  57. package/_bundled_plugin/scripts/workbench_cli.py +30 -12
  58. package/_bundled_plugin/scripts/workbench_constants.py +10 -0
  59. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
  60. package/_bundled_plugin/scripts/workbench_db.py +369 -137
  61. package/_bundled_plugin/scripts/workbench_feedback.py +8 -7
  62. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
  63. package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
  64. package/_bundled_plugin/scripts/workbench_native_indexes.py +12 -12
  65. package/_bundled_plugin/scripts/workbench_progress.py +10 -1
  66. package/_bundled_plugin/scripts/workbench_publication.py +14 -10
  67. package/_bundled_plugin/scripts/workbench_remediation.py +13 -0
  68. package/_bundled_plugin/scripts/workbench_saved_results.py +132 -77
  69. package/_bundled_plugin/scripts/workbench_scan_history.py +117 -55
  70. package/_bundled_plugin/scripts/workbench_scan_start.py +83 -24
  71. package/_bundled_plugin/scripts/workbench_scan_usage.py +644 -68
  72. package/_bundled_plugin/scripts/workbench_schema.py +44 -55
  73. package/_bundled_plugin/scripts/workbench_setup.py +13 -1
  74. package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
  75. package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
  76. package/_bundled_plugin/scripts/workbench_target.py +127 -56
  77. package/_bundled_plugin/scripts/workbench_target_state.py +3 -0
  78. package/_bundled_plugin/scripts/workbench_validation.py +43 -3
  79. package/_bundled_plugin/shared/workbench-history-repairs.json +19 -23
  80. package/_bundled_plugin/shared/workbench-migrations.json +34 -0
  81. package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
  82. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
  83. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -1
  84. package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -25
  85. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
  86. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
  87. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +464 -0
  88. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
  89. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
  90. package/dist/api.d.ts +39 -4
  91. package/dist/api.d.ts.map +1 -1
  92. package/dist/api.js +774 -292
  93. package/dist/api.js.map +1 -1
  94. package/dist/auth.d.ts.map +1 -1
  95. package/dist/auth.js +4 -6
  96. package/dist/auth.js.map +1 -1
  97. package/dist/bedrock-oss-pricing.d.ts +6 -0
  98. package/dist/bedrock-oss-pricing.d.ts.map +1 -0
  99. package/dist/bedrock-oss-pricing.js +58 -0
  100. package/dist/bedrock-oss-pricing.js.map +1 -0
  101. package/dist/bedrock-pricing.d.ts +15 -0
  102. package/dist/bedrock-pricing.d.ts.map +1 -0
  103. package/dist/bedrock-pricing.js +117 -0
  104. package/dist/bedrock-pricing.js.map +1 -0
  105. package/dist/blackduck-findings.d.ts.map +1 -1
  106. package/dist/blackduck-findings.js +35 -20
  107. package/dist/blackduck-findings.js.map +1 -1
  108. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  109. package/dist/bulk-scan-discovery.js +4 -4
  110. package/dist/bulk-scan-discovery.js.map +1 -1
  111. package/dist/checkmarx-evidence.d.ts +19 -0
  112. package/dist/checkmarx-evidence.d.ts.map +1 -0
  113. package/dist/checkmarx-evidence.js +36 -0
  114. package/dist/checkmarx-evidence.js.map +1 -0
  115. package/dist/checkmarx-findings.d.ts +4 -0
  116. package/dist/checkmarx-findings.d.ts.map +1 -0
  117. package/dist/checkmarx-findings.js +27 -0
  118. package/dist/checkmarx-findings.js.map +1 -0
  119. package/dist/checkmarx-one.d.ts +4 -0
  120. package/dist/checkmarx-one.d.ts.map +1 -0
  121. package/dist/checkmarx-one.js +53 -0
  122. package/dist/checkmarx-one.js.map +1 -0
  123. package/dist/checkmarx-repository.d.ts +12 -0
  124. package/dist/checkmarx-repository.d.ts.map +1 -0
  125. package/dist/checkmarx-repository.js +181 -0
  126. package/dist/checkmarx-repository.js.map +1 -0
  127. package/dist/checkmarx-xml.d.ts +12 -0
  128. package/dist/checkmarx-xml.d.ts.map +1 -0
  129. package/dist/checkmarx-xml.js +196 -0
  130. package/dist/checkmarx-xml.js.map +1 -0
  131. package/dist/classify-severity-records.d.ts +1 -9
  132. package/dist/classify-severity-records.d.ts.map +1 -1
  133. package/dist/classify-severity-records.js +3 -13
  134. package/dist/classify-severity-records.js.map +1 -1
  135. package/dist/classify-severity.d.ts.map +1 -1
  136. package/dist/classify-severity.js +2 -4
  137. package/dist/classify-severity.js.map +1 -1
  138. package/dist/cli.d.ts +11 -5
  139. package/dist/cli.d.ts.map +1 -1
  140. package/dist/cli.js +1734 -1238
  141. package/dist/cli.js.map +1 -1
  142. package/dist/cloud-publish.js +2 -2
  143. package/dist/cloud-publish.js.map +1 -1
  144. package/dist/component-scan.d.ts +16 -3
  145. package/dist/component-scan.d.ts.map +1 -1
  146. package/dist/component-scan.js +27 -2
  147. package/dist/component-scan.js.map +1 -1
  148. package/dist/config.d.ts.map +1 -1
  149. package/dist/config.js +100 -66
  150. package/dist/config.js.map +1 -1
  151. package/dist/continuum-findings.d.ts.map +1 -1
  152. package/dist/continuum-findings.js +80 -12
  153. package/dist/continuum-findings.js.map +1 -1
  154. package/dist/contract-values.d.ts +2 -0
  155. package/dist/contract-values.d.ts.map +1 -1
  156. package/dist/contract-values.js +12 -9
  157. package/dist/contract-values.js.map +1 -1
  158. package/dist/cost-model.d.ts +13 -1
  159. package/dist/cost-model.d.ts.map +1 -1
  160. package/dist/cost-model.js +66 -112
  161. package/dist/cost-model.js.map +1 -1
  162. package/dist/cost.d.ts +42 -3
  163. package/dist/cost.d.ts.map +1 -1
  164. package/dist/cost.js +483 -104
  165. package/dist/cost.js.map +1 -1
  166. package/dist/custom-publish.d.ts +4 -0
  167. package/dist/custom-publish.d.ts.map +1 -1
  168. package/dist/custom-publish.js +40 -3
  169. package/dist/custom-publish.js.map +1 -1
  170. package/dist/deduplication/local.d.ts +2 -2
  171. package/dist/deduplication/local.d.ts.map +1 -1
  172. package/dist/deduplication/local.js +2 -2
  173. package/dist/deduplication/local.js.map +1 -1
  174. package/dist/deduplication/refusal.d.ts.map +1 -1
  175. package/dist/deduplication/refusal.js +25 -5
  176. package/dist/deduplication/refusal.js.map +1 -1
  177. package/dist/deduplication/scan.d.ts +3 -0
  178. package/dist/deduplication/scan.d.ts.map +1 -1
  179. package/dist/deduplication/scan.js +1 -1
  180. package/dist/deduplication/scan.js.map +1 -1
  181. package/dist/deep-config.d.ts +0 -1
  182. package/dist/deep-config.d.ts.map +1 -1
  183. package/dist/deep-config.js +22 -33
  184. package/dist/deep-config.js.map +1 -1
  185. package/dist/deep-scan-defaults.d.ts +2 -0
  186. package/dist/deep-scan-defaults.d.ts.map +1 -1
  187. package/dist/deep-scan-defaults.js +28 -1
  188. package/dist/deep-scan-defaults.js.map +1 -1
  189. package/dist/deep-scan.d.ts +2 -0
  190. package/dist/deep-scan.d.ts.map +1 -1
  191. package/dist/deep-scan.js +28 -4
  192. package/dist/deep-scan.js.map +1 -1
  193. package/dist/default-severity-rubric.d.ts +1 -1
  194. package/dist/default-severity-rubric.d.ts.map +1 -1
  195. package/dist/default-severity-rubric.js +1 -1
  196. package/dist/default-severity-rubric.js.map +1 -1
  197. package/dist/endor-findings.d.ts +3 -1
  198. package/dist/endor-findings.d.ts.map +1 -1
  199. package/dist/endor-findings.js +103 -45
  200. package/dist/endor-findings.js.map +1 -1
  201. package/dist/errors.d.ts +1 -1
  202. package/dist/errors.d.ts.map +1 -1
  203. package/dist/errors.js +8 -1
  204. package/dist/errors.js.map +1 -1
  205. package/dist/external-findings-import.d.ts +5 -3
  206. package/dist/external-findings-import.d.ts.map +1 -1
  207. package/dist/external-findings-import.js +7 -6
  208. package/dist/external-findings-import.js.map +1 -1
  209. package/dist/external-findings-local.d.ts +7 -5
  210. package/dist/external-findings-local.d.ts.map +1 -1
  211. package/dist/external-findings-local.js +337 -89
  212. package/dist/external-findings-local.js.map +1 -1
  213. package/dist/external-findings-publish.d.ts +8 -6
  214. package/dist/external-findings-publish.d.ts.map +1 -1
  215. package/dist/external-findings-publish.js +1318 -258
  216. package/dist/external-findings-publish.js.map +1 -1
  217. package/dist/external-findings-read.d.ts +20 -2
  218. package/dist/external-findings-read.d.ts.map +1 -1
  219. package/dist/external-findings-read.js +148 -66
  220. package/dist/external-findings-read.js.map +1 -1
  221. package/dist/external-findings.d.ts +15 -3
  222. package/dist/external-findings.d.ts.map +1 -1
  223. package/dist/external-findings.js +42 -1
  224. package/dist/external-findings.js.map +1 -1
  225. package/dist/external-import-contract.d.ts +5 -1
  226. package/dist/external-import-contract.d.ts.map +1 -1
  227. package/dist/external-import-contract.js +23 -9
  228. package/dist/external-import-contract.js.map +1 -1
  229. package/dist/external-import-models.d.ts +1 -1
  230. package/dist/external-import-models.d.ts.map +1 -1
  231. package/dist/external-import-models.js.map +1 -1
  232. package/dist/feedback.d.ts.map +1 -1
  233. package/dist/feedback.js +5 -4
  234. package/dist/feedback.js.map +1 -1
  235. package/dist/finding-prompt.d.ts +5 -0
  236. package/dist/finding-prompt.d.ts.map +1 -0
  237. package/dist/finding-prompt.js +32 -0
  238. package/dist/finding-prompt.js.map +1 -0
  239. package/dist/findings-client.d.ts +1 -0
  240. package/dist/findings-client.d.ts.map +1 -1
  241. package/dist/findings-client.js +27 -3
  242. package/dist/findings-client.js.map +1 -1
  243. package/dist/github-advisories.d.ts.map +1 -1
  244. package/dist/github-advisories.js +0 -2
  245. package/dist/github-advisories.js.map +1 -1
  246. package/dist/github-dependabot-findings.d.ts.map +1 -1
  247. package/dist/github-dependabot-findings.js +15 -4
  248. package/dist/github-dependabot-findings.js.map +1 -1
  249. package/dist/github-findings.d.ts +4 -1
  250. package/dist/github-findings.d.ts.map +1 -1
  251. package/dist/github-findings.js +55 -30
  252. package/dist/github-findings.js.map +1 -1
  253. package/dist/hosted-git-remotes.d.ts +5 -0
  254. package/dist/hosted-git-remotes.d.ts.map +1 -0
  255. package/dist/hosted-git-remotes.js +285 -0
  256. package/dist/hosted-git-remotes.js.map +1 -0
  257. package/dist/hosted-git-repository.d.ts +28 -0
  258. package/dist/hosted-git-repository.d.ts.map +1 -0
  259. package/dist/hosted-git-repository.js +222 -0
  260. package/dist/hosted-git-repository.js.map +1 -0
  261. package/dist/hosted-scan-protocol.js +2 -2
  262. package/dist/hosted-scan-protocol.js.map +1 -1
  263. package/dist/hosted-scan.d.ts.map +1 -1
  264. package/dist/hosted-scan.js +16 -11
  265. package/dist/hosted-scan.js.map +1 -1
  266. package/dist/hosted-scanner-http.d.ts +21 -0
  267. package/dist/hosted-scanner-http.d.ts.map +1 -0
  268. package/dist/hosted-scanner-http.js +204 -0
  269. package/dist/hosted-scanner-http.js.map +1 -0
  270. package/dist/hosted-scanner-v1.d.ts +6 -0
  271. package/dist/hosted-scanner-v1.d.ts.map +1 -0
  272. package/dist/hosted-scanner-v1.js +60 -0
  273. package/dist/hosted-scanner-v1.js.map +1 -0
  274. package/dist/import-scan.d.ts.map +1 -1
  275. package/dist/import-scan.js +3 -0
  276. package/dist/import-scan.js.map +1 -1
  277. package/dist/index.d.ts +18 -7
  278. package/dist/index.d.ts.map +1 -1
  279. package/dist/index.js +10 -2
  280. package/dist/index.js.map +1 -1
  281. package/dist/inspector-findings.d.ts.map +1 -1
  282. package/dist/inspector-findings.js +47 -65
  283. package/dist/inspector-findings.js.map +1 -1
  284. package/dist/knowledge-base.d.ts.map +1 -1
  285. package/dist/knowledge-base.js +68 -5
  286. package/dist/knowledge-base.js.map +1 -1
  287. package/dist/local-git-metadata.d.ts +1 -1
  288. package/dist/local-git-metadata.d.ts.map +1 -1
  289. package/dist/local-git-metadata.js +1 -2
  290. package/dist/local-git-metadata.js.map +1 -1
  291. package/dist/multiscan.d.ts +6 -4
  292. package/dist/multiscan.d.ts.map +1 -1
  293. package/dist/multiscan.js +138 -65
  294. package/dist/multiscan.js.map +1 -1
  295. package/dist/native-json-findings.d.ts +2 -1
  296. package/dist/native-json-findings.d.ts.map +1 -1
  297. package/dist/native-json-findings.js +12 -2
  298. package/dist/native-json-findings.js.map +1 -1
  299. package/dist/opengrep-findings.d.ts +1 -0
  300. package/dist/opengrep-findings.d.ts.map +1 -1
  301. package/dist/opengrep-findings.js +17 -13
  302. package/dist/opengrep-findings.js.map +1 -1
  303. package/dist/operation-telemetry.d.ts +104 -0
  304. package/dist/operation-telemetry.d.ts.map +1 -0
  305. package/dist/operation-telemetry.js +293 -0
  306. package/dist/operation-telemetry.js.map +1 -0
  307. package/dist/plugin-python-probe.d.ts +4 -0
  308. package/dist/plugin-python-probe.d.ts.map +1 -0
  309. package/dist/plugin-python-probe.js +10 -0
  310. package/dist/plugin-python-probe.js.map +1 -0
  311. package/dist/private-finding-import.d.ts +97 -2
  312. package/dist/private-finding-import.d.ts.map +1 -1
  313. package/dist/private-finding-import.js +58 -34
  314. package/dist/private-finding-import.js.map +1 -1
  315. package/dist/provider-profile.d.ts +1 -1
  316. package/dist/provider-profile.d.ts.map +1 -1
  317. package/dist/provider-profile.js +8 -1
  318. package/dist/provider-profile.js.map +1 -1
  319. package/dist/publication-telemetry.d.ts +45 -0
  320. package/dist/publication-telemetry.d.ts.map +1 -0
  321. package/dist/publication-telemetry.js +50 -0
  322. package/dist/publication-telemetry.js.map +1 -0
  323. package/dist/publish.d.ts +4 -0
  324. package/dist/publish.d.ts.map +1 -1
  325. package/dist/publish.js +42 -2
  326. package/dist/publish.js.map +1 -1
  327. package/dist/reader-selection.d.ts +2 -0
  328. package/dist/reader-selection.d.ts.map +1 -1
  329. package/dist/reader-selection.js +8 -0
  330. package/dist/reader-selection.js.map +1 -1
  331. package/dist/remediation.d.ts +1 -4
  332. package/dist/remediation.d.ts.map +1 -1
  333. package/dist/remediation.js +3 -7
  334. package/dist/remediation.js.map +1 -1
  335. package/dist/request-metadata.d.ts +3 -0
  336. package/dist/request-metadata.d.ts.map +1 -1
  337. package/dist/request-metadata.js +9 -0
  338. package/dist/request-metadata.js.map +1 -1
  339. package/dist/result.d.ts +4 -0
  340. package/dist/result.d.ts.map +1 -1
  341. package/dist/result.js +1 -1
  342. package/dist/result.js.map +1 -1
  343. package/dist/retry-windows-rename.d.ts +8 -0
  344. package/dist/retry-windows-rename.d.ts.map +1 -0
  345. package/dist/retry-windows-rename.js +24 -0
  346. package/dist/retry-windows-rename.js.map +1 -0
  347. package/dist/runtime.d.ts +20 -0
  348. package/dist/runtime.d.ts.map +1 -1
  349. package/dist/runtime.js +313 -110
  350. package/dist/runtime.js.map +1 -1
  351. package/dist/saved-scan-bootstrap.d.ts +1 -0
  352. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  353. package/dist/saved-scan-bootstrap.js +18 -15
  354. package/dist/saved-scan-bootstrap.js.map +1 -1
  355. package/dist/scan-activity.d.ts.map +1 -1
  356. package/dist/scan-activity.js +141 -56
  357. package/dist/scan-activity.js.map +1 -1
  358. package/dist/scan-comparison.d.ts +10 -5
  359. package/dist/scan-comparison.d.ts.map +1 -1
  360. package/dist/scan-comparison.js +60 -15
  361. package/dist/scan-comparison.js.map +1 -1
  362. package/dist/scan-dashboard.d.ts +6 -6
  363. package/dist/scan-dashboard.d.ts.map +1 -1
  364. package/dist/scan-dashboard.js +75 -42
  365. package/dist/scan-dashboard.js.map +1 -1
  366. package/dist/scan-executor.d.ts +10 -1
  367. package/dist/scan-executor.d.ts.map +1 -1
  368. package/dist/scan-executor.js +22 -2
  369. package/dist/scan-executor.js.map +1 -1
  370. package/dist/scan-history-renderer.d.ts.map +1 -1
  371. package/dist/scan-history-renderer.js +9 -19
  372. package/dist/scan-history-renderer.js.map +1 -1
  373. package/dist/scan-logs.d.ts +12 -0
  374. package/dist/scan-logs.d.ts.map +1 -1
  375. package/dist/scan-logs.js +106 -77
  376. package/dist/scan-logs.js.map +1 -1
  377. package/dist/scan-measurement.d.ts +26 -0
  378. package/dist/scan-measurement.d.ts.map +1 -0
  379. package/dist/scan-measurement.js +77 -0
  380. package/dist/scan-measurement.js.map +1 -0
  381. package/dist/scan-progress.d.ts +1 -0
  382. package/dist/scan-progress.d.ts.map +1 -1
  383. package/dist/scan-progress.js +3 -0
  384. package/dist/scan-progress.js.map +1 -1
  385. package/dist/scan-sessions.d.ts.map +1 -1
  386. package/dist/scan-sessions.js +4 -1
  387. package/dist/scan-sessions.js.map +1 -1
  388. package/dist/scan-settings.d.ts +1 -1
  389. package/dist/scan-settings.d.ts.map +1 -1
  390. package/dist/scan-settings.js +1 -24
  391. package/dist/scan-settings.js.map +1 -1
  392. package/dist/scanner-import.d.ts +20 -2
  393. package/dist/scanner-import.d.ts.map +1 -1
  394. package/dist/scanner-import.js +200 -8
  395. package/dist/scanner-import.js.map +1 -1
  396. package/dist/scanner-repository-url.d.ts +4 -1
  397. package/dist/scanner-repository-url.d.ts.map +1 -1
  398. package/dist/scanner-repository-url.js +10 -6
  399. package/dist/scanner-repository-url.js.map +1 -1
  400. package/dist/security-policy.d.ts +1 -1
  401. package/dist/security-policy.d.ts.map +1 -1
  402. package/dist/security-policy.js.map +1 -1
  403. package/dist/semgrep-findings.d.ts +6 -3
  404. package/dist/semgrep-findings.d.ts.map +1 -1
  405. package/dist/semgrep-findings.js +107 -43
  406. package/dist/semgrep-findings.js.map +1 -1
  407. package/dist/semgrep-guardian-findings.d.ts +38 -0
  408. package/dist/semgrep-guardian-findings.d.ts.map +1 -0
  409. package/dist/semgrep-guardian-findings.js +165 -0
  410. package/dist/semgrep-guardian-findings.js.map +1 -0
  411. package/dist/semgrep-platform-collector.d.ts +26 -0
  412. package/dist/semgrep-platform-collector.d.ts.map +1 -0
  413. package/dist/semgrep-platform-collector.js +108 -0
  414. package/dist/semgrep-platform-collector.js.map +1 -0
  415. package/dist/semgrep-platform-findings.d.ts +207 -6
  416. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  417. package/dist/semgrep-platform-findings.js +983 -103
  418. package/dist/semgrep-platform-findings.js.map +1 -1
  419. package/dist/semgrep-platform-v1.d.ts +6 -0
  420. package/dist/semgrep-platform-v1.d.ts.map +1 -0
  421. package/dist/semgrep-platform-v1.js +83 -0
  422. package/dist/semgrep-platform-v1.js.map +1 -0
  423. package/dist/server/api.d.ts +1 -1
  424. package/dist/server/api.d.ts.map +1 -1
  425. package/dist/server/api.js.map +1 -1
  426. package/dist/server/embedding-tokenizer.cdx.json +33 -0
  427. package/dist/server/embedding-tokenizer.d.ts +2 -0
  428. package/dist/server/embedding-tokenizer.d.ts.map +1 -0
  429. package/dist/server/embedding-tokenizer.js +322 -0
  430. package/dist/server/embedding-tokenizer.js.map +6 -0
  431. package/dist/server/embeddings.d.ts +16 -2
  432. package/dist/server/embeddings.d.ts.map +1 -1
  433. package/dist/server/embeddings.js +35 -5
  434. package/dist/server/embeddings.js.map +1 -1
  435. package/dist/session-lines.d.ts +5 -0
  436. package/dist/session-lines.d.ts.map +1 -0
  437. package/dist/session-lines.js +60 -0
  438. package/dist/session-lines.js.map +1 -0
  439. package/dist/severity-review.d.ts +3 -1
  440. package/dist/severity-review.d.ts.map +1 -1
  441. package/dist/severity-review.js +3 -2
  442. package/dist/severity-review.js.map +1 -1
  443. package/dist/skill-authentication.d.ts +1 -0
  444. package/dist/skill-authentication.d.ts.map +1 -1
  445. package/dist/skill-authentication.js +1 -0
  446. package/dist/skill-authentication.js.map +1 -1
  447. package/dist/snyk-findings.d.ts +7 -2
  448. package/dist/snyk-findings.d.ts.map +1 -1
  449. package/dist/snyk-findings.js +93 -70
  450. package/dist/snyk-findings.js.map +1 -1
  451. package/dist/snyk-rest-findings.d.ts +76 -0
  452. package/dist/snyk-rest-findings.d.ts.map +1 -0
  453. package/dist/snyk-rest-findings.js +1051 -0
  454. package/dist/snyk-rest-findings.js.map +1 -0
  455. package/dist/snyk-rest-v1.d.ts +28 -0
  456. package/dist/snyk-rest-v1.d.ts.map +1 -0
  457. package/dist/snyk-rest-v1.js +132 -0
  458. package/dist/snyk-rest-v1.js.map +1 -0
  459. package/dist/snyk-token-origin.d.ts +4 -0
  460. package/dist/snyk-token-origin.d.ts.map +1 -0
  461. package/dist/snyk-token-origin.js +82 -0
  462. package/dist/snyk-token-origin.js.map +1 -0
  463. package/dist/sonar-collector.d.ts.map +1 -1
  464. package/dist/sonar-collector.js +0 -3
  465. package/dist/sonar-collector.js.map +1 -1
  466. package/dist/sonar-import.d.ts.map +1 -1
  467. package/dist/sonar-import.js +2 -4
  468. package/dist/sonar-import.js.map +1 -1
  469. package/dist/target-drift.d.ts +9 -0
  470. package/dist/target-drift.d.ts.map +1 -0
  471. package/dist/target-drift.js +27 -0
  472. package/dist/target-drift.js.map +1 -0
  473. package/dist/targets.d.ts +2 -0
  474. package/dist/targets.d.ts.map +1 -1
  475. package/dist/targets.js +56 -20
  476. package/dist/targets.js.map +1 -1
  477. package/dist/tenable-findings.d.ts +9 -0
  478. package/dist/tenable-findings.d.ts.map +1 -0
  479. package/dist/tenable-findings.js +122 -0
  480. package/dist/tenable-findings.js.map +1 -0
  481. package/dist/terminal-stream.d.ts +13 -0
  482. package/dist/terminal-stream.d.ts.map +1 -0
  483. package/dist/terminal-stream.js +35 -0
  484. package/dist/terminal-stream.js.map +1 -0
  485. package/dist/trivy-findings.d.ts +19 -0
  486. package/dist/trivy-findings.d.ts.map +1 -0
  487. package/dist/trivy-findings.js +435 -0
  488. package/dist/trivy-findings.js.map +1 -0
  489. package/dist/trivy-import.d.ts +19 -0
  490. package/dist/trivy-import.d.ts.map +1 -0
  491. package/dist/trivy-import.js +151 -0
  492. package/dist/trivy-import.js.map +1 -0
  493. package/dist/validation-records.js +1 -1
  494. package/dist/validation-records.js.map +1 -1
  495. package/dist/veracode-findings.d.ts +2 -0
  496. package/dist/veracode-findings.d.ts.map +1 -1
  497. package/dist/veracode-findings.js +49 -11
  498. package/dist/veracode-findings.js.map +1 -1
  499. package/dist/vertex-pricing.d.ts +8 -0
  500. package/dist/vertex-pricing.d.ts.map +1 -0
  501. package/dist/vertex-pricing.js +20 -0
  502. package/dist/vertex-pricing.js.map +1 -0
  503. package/dist/windows-path.d.ts +1 -0
  504. package/dist/windows-path.d.ts.map +1 -1
  505. package/dist/windows-path.js +26 -1
  506. package/dist/windows-path.js.map +1 -1
  507. package/dist/wiz-findings.d.ts +4 -0
  508. package/dist/wiz-findings.d.ts.map +1 -1
  509. package/dist/wiz-findings.js +57 -3
  510. package/dist/wiz-findings.js.map +1 -1
  511. package/docs/classify-severity-records.md +27 -12
  512. package/docs/cli.md +497 -550
  513. package/docs/dedupe-records.md +44 -24
  514. package/docs/findings-service.md +66 -39
  515. package/docs/hosted-remediation.md +14 -7
  516. package/docs/hosted-scans.md +50 -42
  517. package/docs/telemetry.md +236 -0
  518. package/docs/validate-records.md +78 -44
  519. package/package.json +18 -15
  520. package/schemas/external-findings.schema.json +3 -1
  521. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  522. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  523. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  524. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  525. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  526. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
  527. package/dist/external-imports-feature.d.ts +0 -6
  528. package/dist/external-imports-feature.d.ts.map +0 -1
  529. package/dist/external-imports-feature.js +0 -51
  530. package/dist/external-imports-feature.js.map +0 -1
  531. package/dist/finding-normalization.d.ts +0 -5
  532. package/dist/finding-normalization.d.ts.map +0 -1
  533. package/dist/finding-normalization.js +0 -155
  534. package/dist/finding-normalization.js.map +0 -1
package/dist/runtime.js CHANGED
@@ -1,6 +1,7 @@
1
- import { forwardExternalImportSetting } from "./external-imports-feature.js";
2
1
  import { executablePathForSpawn } from "./executable-path.js";
2
+ import { retryWindowsRename } from "./retry-windows-rename.js";
3
3
  export { executablePathForSpawn } from "./executable-path.js";
4
+ import { PLUGIN_PYTHON_PROBE, PLUGIN_PYTHON_PROBE_TIMEOUT_MS, PLUGIN_PYTHON_READY, } from "./plugin-python-probe.js";
4
5
  import { resolveBundledCodexExecutable } from "./codex-sdk-environment.js";
5
6
  import { gitProtectionRoots } from "./targets.js";
6
7
  import { isNonEmptyString, notify } from "./value.js";
@@ -21,7 +22,7 @@ import { parse } from "smol-toml";
21
22
  import { CodexSecurityError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, LocalPluginBootstrapError, PluginPythonUnavailableError, SandboxUnavailableError, errorMessage, abortReason, } from "./errors.js";
22
23
  import { isRecord } from "./record.js";
23
24
  import { isWithin, resolveTrustedExecutable, } from "./trusted-executable.js";
24
- import { isWindowsUnsafePathComponent, windowsUnsafePathComponent, } from "./windows-path.js";
25
+ import { isWindowsUnsafePathComponent, sqliteFilename, windowsUnsafePathComponent, } from "./windows-path.js";
25
26
  const execFile = promisify(execFileCallback);
26
27
  export const MARKETPLACE_NAME = "codex-security-sdk";
27
28
  export const PLUGIN_NAME = "codex-security";
@@ -56,6 +57,7 @@ const PLUGIN_HELPER_SECRET_ENVIRONMENT_VARIABLES = new Set([
56
57
  "OPENROUTER_API_KEY",
57
58
  "FIREWORKS_API_KEY",
58
59
  "CHEAPER_INFERENCE_API_KEY",
60
+ "HF_TOKEN",
59
61
  ]);
60
62
  const PREPARE_SCAN_ARTIFACT_RESTORER_PROGRAM = `
61
63
  from pathlib import Path
@@ -281,6 +283,7 @@ const WINDOWS_PRINCIPAL_ALIASES = {
281
283
  HA: "S-1-5-32-578",
282
284
  AA: "S-1-5-32-579",
283
285
  };
286
+ const WINDOWS_ACCOUNT_SID = /^S-1-5-21-(?:\d+-){3}\d+$/u;
284
287
  const WINDOWS_SID = /^S-1-(?:\d+-)*\d+$/u;
285
288
  const WINDOWS_GUID = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu;
286
289
  const WINDOWS_SDDL_SID = "(?:S-1-(?:\\d+-)*\\d+|[A-Z]{2})";
@@ -367,7 +370,10 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
367
370
  if (type === "A" || type === "OA" || type === "XA" || type === "ZA") {
368
371
  if (!trustedPrincipal(principal)) {
369
372
  if (options.scope !== "ancestor" ||
370
- windowsAceAllowsAncestorReplacement(rights, inheritanceFlags)) {
373
+ // OWNER RIGHTS applies to the owner already verified above. Every
374
+ // descendant is inspected with its own security descriptor.
375
+ (principal !== WINDOWS_OWNER_RIGHTS_SID &&
376
+ windowsAceAllowsAncestorReplacement(rights, inheritanceFlags))) {
371
377
  untrustedPrincipals.add(principal);
372
378
  }
373
379
  }
@@ -387,7 +393,9 @@ export function inspectWindowsCredentialAcl(descriptor, currentUserSid, options
387
393
  }
388
394
  }
389
395
  }
390
- else {
396
+ else if (principal === currentUserSid ||
397
+ !WINDOWS_ACCOUNT_SID.test(principal) ||
398
+ (options.currentGroupSids?.has(principal) ?? true)) {
391
399
  deniedPrincipals.add(principal);
392
400
  }
393
401
  remaining = rest;
@@ -584,6 +592,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
584
592
  const ancestorPath = ancestors[index];
585
593
  try {
586
594
  const ancestor = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
595
+ currentGroupSids: options.currentGroupSids,
587
596
  resolvedAliases: options.resolvedAliases,
588
597
  scope: "ancestor",
589
598
  });
@@ -605,6 +614,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
605
614
  if (index === ancestors.length) {
606
615
  try {
607
616
  home = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
617
+ currentGroupSids: options.currentGroupSids,
608
618
  resolvedAliases: options.resolvedAliases,
609
619
  });
610
620
  }
@@ -617,6 +627,7 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
617
627
  return;
618
628
  }
619
629
  const descendant = inspectWindowsCredentialAcl(descriptor, currentUserSid, {
630
+ currentGroupSids: options.currentGroupSids,
620
631
  resolvedAliases: options.resolvedAliases,
621
632
  scope: "file",
622
633
  });
@@ -644,17 +655,45 @@ export async function inspectWindowsCredentialAclSnapshot(path, currentUserSid,
644
655
  }
645
656
  throw new Error("Windows credential descendants could not be verified");
646
657
  }
658
+ /** A file server may add its own groups to the client's token. */
659
+ export async function isLocalWindowsCredentialVolume(path, readDriveType) {
660
+ const drive = /^\\\\[?.]\\([A-Z]:)\\/iu.exec(win32.toNamespacedPath(path))?.[1];
661
+ if (!drive)
662
+ return false;
663
+ // Win32_LogicalDisk reports removable, local disk, and RAM disk as 2, 3, 6.
664
+ return ["2", "3", "6"].includes((await readDriveType(drive)).trim());
665
+ }
666
+ /** Keep every token group, including groups used only for deny ACEs. */
667
+ export function parseWindowsTokenGroupSids(output) {
668
+ const groups = new Set();
669
+ for (const row of output.trim().split(/\r?\n/u)) {
670
+ const sid = /^"(?:[^"]|"")*","(?:[^"]|"")*","(S-1-(?:\d+-)*\d+)","(?:[^"]|"")*"$/u.exec(row)?.[1];
671
+ if (!sid)
672
+ throw new Error("Unable to identify Windows token group SIDs");
673
+ groups.add(sid);
674
+ }
675
+ return groups;
676
+ }
647
677
  async function secureWindowsCredentialHome(path) {
648
678
  const ancestorAclScript = windowsCredentialAncestorAclScript(path);
679
+ const treePath = win32.toNamespacedPath(path);
649
680
  const systemRoot = process.env["SystemRoot"] ?? "C:\\Windows";
650
681
  const systemDirectory = join(systemRoot, "System32");
651
- const powershell = join(systemDirectory, "WindowsPowerShell", "v1.0", "powershell.exe");
682
+ const powershellDirectory = join(systemDirectory, "WindowsPowerShell", "v1.0");
683
+ const powershell = join(powershellDirectory, "powershell.exe");
684
+ const powershellArgs = [
685
+ "-NoLogo",
686
+ "-NoProfile",
687
+ "-NonInteractive",
688
+ "-Command",
689
+ ];
652
690
  const inheritedEnvironment = Object.fromEntries(Object.entries(process.env).filter(([name]) => name.toUpperCase() !== "PSMODULEPATH"));
653
691
  const processOptions = {
654
692
  env: {
655
693
  ...inheritedEnvironment,
656
694
  CODEX_SECURITY_CREDENTIAL_ACL_PATH: path,
657
- PSModulePath: join(systemDirectory, "WindowsPowerShell", "v1.0", "Modules"),
695
+ CODEX_SECURITY_CREDENTIAL_TREE_PATH: treePath,
696
+ PSModulePath: join(powershellDirectory, "Modules"),
658
697
  },
659
698
  encoding: "utf8",
660
699
  windowsHide: true,
@@ -672,30 +711,47 @@ async function secureWindowsCredentialHome(path) {
672
711
  const script = [
673
712
  "$ErrorActionPreference = 'Stop'",
674
713
  "$script:descriptorCount = 0",
675
- "function Write-CredentialAcl($path) { $descriptor = Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $path | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl; if (-not $descriptor) { throw 'Windows credential ACL could not be verified' }; $script:descriptorCount += 1; $descriptor }",
714
+ "function Write-CredentialAcl($path) {",
715
+ " $descriptors = @(Microsoft.PowerShell.Security\\Get-Acl -LiteralPath $path | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Sddl)",
716
+ " if ($descriptors.Count -ne @($path).Count) { throw 'Windows credential ACL could not be verified' }",
717
+ " foreach ($descriptor in $descriptors) { if (-not $descriptor) { throw 'Windows credential ACL could not be verified' }; $script:descriptorCount += 1; $descriptor }",
718
+ "}",
676
719
  "function Read-CredentialDescendants($path) {",
677
720
  " try { $entries = @(Microsoft.PowerShell.Management\\Get-ChildItem -LiteralPath $path -Force) } catch {",
678
721
  // A child can disappear while an existing directory is being enumerated.
679
722
  // Retry that incomplete listing before accepting a vanished descendant.
680
723
  ` if ($_.FullyQualifiedErrorId -eq 'System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetChildItemCommand') { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
681
- " if ($path -ne $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH -and $_.CategoryInfo.Category -eq 'ObjectNotFound') { return }",
724
+ " if ($path -ne $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH -and $_.CategoryInfo.Category -eq 'ObjectNotFound') { return }",
682
725
  " throw",
683
726
  " }",
684
- " foreach ($entry in $entries) {",
727
+ " $children = @(foreach ($entry in $entries) {",
685
728
  " if (($entry.Attributes -band 1024) -and ($entry.LinkType -in @('SymbolicLink', 'Junction'))) { throw 'Windows credential home contains a symbolic link or junction' }",
686
729
  " if ($entry.PSObject.TypeNames -notcontains 'System.IO.DirectoryInfo' -and $entry.PSObject.TypeNames -notcontains 'System.IO.FileInfo') { throw 'Windows credential home contains an unsafe entry' }",
687
- " try { Write-CredentialAcl $entry.FullName } catch {",
688
- // A descendant can disappear inside Get-Acl after it was enumerated.
689
- ` if ($_.FullyQualifiedErrorId -eq 'System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand' -or $_.FullyQualifiedErrorId -eq 'GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand') { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
690
- " if ($_.FullyQualifiedErrorId -like 'GetAcl_PathNotFound,*') { continue }",
691
- " throw",
730
+ // Keep the extended-length path when Windows PowerShell returns child names.
731
+ ' "$path\\$($entry.Name)"',
732
+ " })",
733
+ " if ($children.Count -eq 0) { return }",
734
+ " try { Write-CredentialAcl $children } catch {",
735
+ // A vanished path is the only reason to retry the batch one child at a time.
736
+ " if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw }",
737
+ " for ($i = 0; $i -lt $children.Count; $i++) {",
738
+ " try { Write-CredentialAcl $children[$i] } catch {",
739
+ " if ($_.FullyQualifiedErrorId -notlike 'GetAcl_PathNotFound,*') { throw }",
740
+ " $children[$i] = $null",
741
+ " }",
692
742
  " }",
693
- " if ($entry.PSIsContainer) { Read-CredentialDescendants $entry.FullName }",
743
+ " }",
744
+ " for ($i = 0; $i -lt $children.Count; $i++) {",
745
+ " if ($children[$i] -and $entries[$i].PSIsContainer) { Read-CredentialDescendants $children[$i] }",
694
746
  " }",
695
747
  "}",
696
748
  ancestorAclScript,
697
749
  "Write-CredentialAcl $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
698
- "Read-CredentialDescendants $env:CODEX_SECURITY_CREDENTIAL_ACL_PATH",
750
+ "try { Read-CredentialDescendants $env:CODEX_SECURITY_CREDENTIAL_TREE_PATH } catch {",
751
+ // Either a batch or a single-child Get-Acl may report an incomplete listing.
752
+ ` if ($_.FullyQualifiedErrorId -in @('System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand', 'GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand')) { exit ${WINDOWS_CREDENTIAL_DESCENDANTS_CHANGED_EXIT_CODE} }`,
753
+ " throw",
754
+ "}",
699
755
  `"${WINDOWS_CREDENTIAL_ACL_COMPLETE_PREFIX}$script:descriptorCount"`,
700
756
  ].join("\n");
701
757
  const resolvePrincipalScript = [
@@ -704,31 +760,40 @@ async function secureWindowsCredentialHome(path) {
704
760
  "Microsoft.PowerShell.Utility\\ConvertFrom-SddlString -Sddl $descriptor | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty RawDescriptor | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Owner | Microsoft.PowerShell.Utility\\Select-Object -ExpandProperty Value",
705
761
  ].join("; ");
706
762
  const resolvedAliases = {};
763
+ function requireNumericSid(value) {
764
+ if (!WINDOWS_SID.test(value))
765
+ throw new Error("Windows credential ACL contains an unresolvable identity");
766
+ return value;
767
+ }
707
768
  const resolvePrincipal = async (principal) => {
708
769
  if (!/^[A-Z]{2}$/u.test(principal) ||
709
770
  WINDOWS_PRINCIPAL_ALIASES[principal] !== undefined ||
710
771
  resolvedAliases[principal] !== undefined) {
711
772
  return;
712
773
  }
713
- const resolved = await execFile(powershell, [
714
- "-NoLogo",
715
- "-NoProfile",
716
- "-NonInteractive",
717
- "-Command",
718
- resolvePrincipalScript,
719
- ], {
774
+ const resolved = await execFile(powershell, [...powershellArgs, resolvePrincipalScript], {
720
775
  ...processOptions,
721
776
  env: {
722
777
  ...processOptions.env,
723
778
  CODEX_SECURITY_CREDENTIAL_PRINCIPAL: principal,
724
779
  },
725
780
  });
726
- const numeric = resolved.stdout.trim();
727
- if (!WINDOWS_SID.test(numeric)) {
728
- throw new Error("Windows credential ACL contains an unresolvable identity");
729
- }
730
- resolvedAliases[principal] = numeric;
781
+ resolvedAliases[principal] = requireNumericSid(resolved.stdout.trim());
731
782
  };
783
+ const loadLocalGroupSids = async () => {
784
+ const local = await isLocalWindowsCredentialVolume(treePath, async (drive) => {
785
+ const volume = await execFile(powershell, [
786
+ ...powershellArgs,
787
+ `$ErrorActionPreference = 'Stop'; (CimCmdlets\\Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID = '${drive}'").DriveType`,
788
+ ], processOptions);
789
+ return volume.stdout;
790
+ });
791
+ if (!local)
792
+ return null;
793
+ const groups = await execFile(join(systemDirectory, "whoami.exe"), ["/groups", "/fo", "csv", "/nh"], processOptions);
794
+ return parseWindowsTokenGroupSids(groups.stdout);
795
+ };
796
+ let currentGroupSids;
732
797
  const resolveDescriptorAliases = async (descriptor) => {
733
798
  const header = WINDOWS_SECURITY_DESCRIPTOR.exec(descriptor.trim());
734
799
  if (header === null)
@@ -737,9 +802,18 @@ async function secureWindowsCredentialHome(path) {
737
802
  let remaining = header[3];
738
803
  while (remaining.startsWith("(")) {
739
804
  const { rule, rest } = windowsSecurityDescriptorRule(remaining);
740
- const principal = rule.split(";")[5];
741
- if (principal !== undefined)
805
+ const fields = rule.split(";");
806
+ const principal = fields[5];
807
+ if (principal !== undefined) {
742
808
  await resolvePrincipal(principal);
809
+ const trustee = resolvedAliases[principal] ?? principal;
810
+ if (currentGroupSids === undefined &&
811
+ ["D", "OD", "XD"].includes(fields[0]) &&
812
+ trustee !== sid &&
813
+ WINDOWS_ACCOUNT_SID.test(trustee)) {
814
+ currentGroupSids = await loadLocalGroupSids();
815
+ }
816
+ }
743
817
  remaining = rest;
744
818
  }
745
819
  };
@@ -747,25 +821,19 @@ async function secureWindowsCredentialHome(path) {
747
821
  const readAcl = async () => {
748
822
  const snapshot = await inspectWindowsCredentialAclSnapshot(path, sid, {
749
823
  command: powershell,
750
- args: ["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", script],
824
+ args: [...powershellArgs, script],
751
825
  environment: processOptions.env,
826
+ get currentGroupSids() {
827
+ return currentGroupSids ?? undefined;
828
+ },
752
829
  resolvedAliases,
753
830
  resolveDescriptorAliases,
754
831
  });
755
832
  descendantsArePrivate = snapshot.descendantsArePrivate;
756
833
  return snapshot.home;
757
834
  };
758
- const icacls = join(systemDirectory, "icacls.exe");
759
- const installTrustedAcl = async (target = path) => {
760
- await execFile(icacls, [
761
- target,
762
- "/inheritance:r",
763
- "/grant:r",
764
- `*${sid}:(OI)(CI)F`,
765
- `*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`,
766
- `*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`,
767
- ], processOptions);
768
- };
835
+ const icacls = (target, ...args) => execFile(join(systemDirectory, "icacls.exe"), [target, ...args], processOptions);
836
+ const installTrustedAcl = () => icacls(path, "/inheritance:r", "/grant:r", `*${sid}:(OI)(CI)F`, `*${WINDOWS_SYSTEM_SID}:(OI)(CI)F`, `*${WINDOWS_ADMINISTRATORS_SID}:(OI)(CI)F`);
769
837
  let existing;
770
838
  for (let attempt = 0; existing === undefined && attempt < 3; attempt += 1) {
771
839
  try {
@@ -773,7 +841,7 @@ async function secureWindowsCredentialHome(path) {
773
841
  }
774
842
  catch (error) {
775
843
  if (error instanceof RepairableWindowsCredentialOwnerError) {
776
- await execFile(icacls, [path, "/setowner", `*${sid}`], processOptions);
844
+ await icacls(path, "/setowner", `*${sid}`);
777
845
  }
778
846
  else if (error instanceof RepairableWindowsCredentialAclError) {
779
847
  await installTrustedAcl();
@@ -789,7 +857,7 @@ async function secureWindowsCredentialHome(path) {
789
857
  if (existing.grantsCurrentUserAccess &&
790
858
  existing.untrustedPrincipals.length === 0 &&
791
859
  !existing.protected) {
792
- await execFile(icacls, [path, "/inheritance:d"], processOptions);
860
+ await icacls(path, "/inheritance:d");
793
861
  existing = await readAcl();
794
862
  }
795
863
  let verified = existing;
@@ -798,17 +866,12 @@ async function secureWindowsCredentialHome(path) {
798
866
  verified.untrustedPrincipals.length !== 0) {
799
867
  await installTrustedAcl();
800
868
  verified = await readAcl();
801
- for (const principal of verified.untrustedPrincipals) {
802
- if (!WINDOWS_SID.test(principal)) {
803
- throw new Error("Windows credential ACL contains an unresolvable identity");
804
- }
805
- await execFile(icacls, [path, "/remove:g", `*${principal}`], processOptions);
806
- }
807
- for (const principal of verified.deniedPrincipals) {
808
- if (!WINDOWS_SID.test(principal)) {
809
- throw new Error("Windows credential ACL contains an unresolvable identity");
810
- }
811
- await execFile(icacls, [path, "/remove:d", `*${principal}`], processOptions);
869
+ for (const [remove, principals] of [
870
+ ["/remove:g", verified.untrustedPrincipals],
871
+ ["/remove:d", verified.deniedPrincipals],
872
+ ]) {
873
+ for (const principal of principals)
874
+ await icacls(path, remove, `*${requireNumericSid(principal)}`);
812
875
  }
813
876
  if (verified.untrustedPrincipals.length !== 0 ||
814
877
  verified.deniedPrincipals.length !== 0) {
@@ -825,13 +888,32 @@ async function secureWindowsCredentialHome(path) {
825
888
  throw new Error("Windows credential ACL grants access to another identity");
826
889
  }
827
890
  if (!descendantsArePrivate) {
828
- await execFile(icacls, [join(path, "*"), "/reset", "/t", "/q"], processOptions);
891
+ await icacls(join(treePath, "*"), "/reset", "/t", "/q");
829
892
  await readAcl();
830
893
  if (!descendantsArePrivate) {
831
894
  throw new Error("Windows credential descendants remain accessible");
832
895
  }
833
896
  }
834
897
  }
898
+ export function sqliteDatabaseOpener(access = "read-write") {
899
+ const require = createRequire(import.meta.url);
900
+ const bun = process.versions["bun"] !== undefined;
901
+ const Database = (bun ? require("bun:sqlite").Database : require("node:sqlite").DatabaseSync);
902
+ return (path) => {
903
+ const filename = sqliteFilename(path);
904
+ if (access === "read-write")
905
+ return new Database(filename);
906
+ // Apple's SQLite requires write access to initialize missing WAL sidecars.
907
+ // The history reader sets PRAGMA query_only on this existing-file connection.
908
+ return new Database(filename, bun
909
+ ? {
910
+ readonly: process.platform !== "darwin",
911
+ readwrite: process.platform === "darwin",
912
+ create: false,
913
+ }
914
+ : { readOnly: true });
915
+ };
916
+ }
835
917
  export async function withCredentialHomeLock(codexHome, operation, signal) {
836
918
  const release = await acquireCodexSecurityCredentialHomeLock(codexHome, signal);
837
919
  try {
@@ -854,17 +936,11 @@ export async function acquireCodexSecurityCredentialHomeLock(codexHome, signal,
854
936
  if (existingDatabaseMetadata !== null) {
855
937
  requireCredentialLockDatabaseFile(existingDatabaseMetadata, databasePath);
856
938
  }
857
- const require = createRequire(import.meta.url);
858
- // Both supported runtimes bundle SQLite. Keep the transaction in the process
859
- // doing the protected work, so pausing it cannot expire its lock.
860
- const Database = process.versions["bun"]
861
- ? require("bun:sqlite")
862
- .Database
863
- : require("node:sqlite").DatabaseSync;
939
+ const openDatabase = sqliteDatabaseOpener();
864
940
  // Let SQLite create a missing guard so no separate descriptor can close after
865
941
  // another connection acquires its process-owned POSIX lock. Keep the guard
866
942
  // across releases so every contender locks the same inode.
867
- const database = new Database(databasePath);
943
+ const database = openDatabase(databasePath);
868
944
  let databaseLocked = false;
869
945
  try {
870
946
  // SQLite creates new databases with the process umask. Tighten or repair
@@ -1035,6 +1111,51 @@ async function recoverStaleCredentialHomeLock(lock) {
1035
1111
  await rm(quarantine, { recursive: true, force: true });
1036
1112
  return true;
1037
1113
  }
1114
+ function sameInode(left, right) {
1115
+ return left.dev === right.dev && left.ino === right.ino;
1116
+ }
1117
+ /** Distinguish two hard links from two paths to the same directory entry. */
1118
+ async function hasSeparateAmbientLink(localPath, ambientHome) {
1119
+ try {
1120
+ const local = await lstat(localPath, { bigint: true });
1121
+ if (!local.isFile() || local.nlink < 2n || local.ino === 0n)
1122
+ return false;
1123
+ const ambient = await lstat(join(ambientHome, "auth.json"), {
1124
+ bigint: true,
1125
+ });
1126
+ if (!ambient.isFile() || !sameInode(local, ambient))
1127
+ return false;
1128
+ const [localDir, ambientDir] = await Promise.all([
1129
+ stat(dirname(localPath), { bigint: true }),
1130
+ stat(ambientHome, { bigint: true }),
1131
+ ]);
1132
+ return (localDir.ino !== 0n &&
1133
+ ambientDir.ino !== 0n &&
1134
+ !sameInode(localDir, ambientDir));
1135
+ }
1136
+ catch {
1137
+ // Without a verified second link, leave logout to the configured native store.
1138
+ return false;
1139
+ }
1140
+ }
1141
+ /** Run under the credential-home lock so status cannot reimport the sign-in during logout. */
1142
+ export async function logoutCredentialHome(home, ambientHome, nativeLogout, onLoggedOut) {
1143
+ const localPath = join(home, "auth.json");
1144
+ const shared = await hasSeparateAmbientLink(localPath, ambientHome);
1145
+ const recordLogout = async () => {
1146
+ await setCodexSecurityCredentialLogout(home, true);
1147
+ if (shared)
1148
+ await rm(localPath);
1149
+ onLoggedOut?.();
1150
+ };
1151
+ // Detach before native logout can revoke a shared token, even if native cleanup fails.
1152
+ if (shared)
1153
+ await recordLogout();
1154
+ const status = await nativeLogout();
1155
+ if (!shared && (status === undefined || status === 0))
1156
+ await recordLogout();
1157
+ return status;
1158
+ }
1038
1159
  export async function setCodexSecurityCredentialLogout(codexHome, loggedOut) {
1039
1160
  await requireSecureCredentialHome(codexHome);
1040
1161
  const marker = join(codexHome, CREDENTIAL_LOGOUT_MARKER);
@@ -1142,7 +1263,8 @@ export async function preserveCodexSecurityPluginRegistration(codexHome, config)
1142
1263
  }
1143
1264
  export function requireOutputOutsideRepository(repository, outputDirectory, pathKind = "output") {
1144
1265
  if (isWithin(repository, outputDirectory) ||
1145
- (pathKind === "output" && isWithin(outputDirectory, repository))) {
1266
+ ((pathKind === "output" || pathKind === "state") &&
1267
+ isWithin(outputDirectory, repository))) {
1146
1268
  throw new OutputInsideProtectedRootError(outputDirectory, repository, pathKind);
1147
1269
  }
1148
1270
  }
@@ -1248,7 +1370,17 @@ export async function runWorkbench(options, args, input) {
1248
1370
  ? ARCHIVE_REGISTRATION_PROGRAM
1249
1371
  : WORKBENCH_SCRIPT_PROGRAM),
1250
1372
  script,
1251
- ], pluginHelperEnvironment(node?.environment ?? options.environment),
1373
+ ], pluginHelperEnvironment({
1374
+ ...(node?.environment ?? options.environment),
1375
+ // Python's compressed-rollout reader needs the selected Node even when
1376
+ // this SDK was launched by absolute path without Node on PATH.
1377
+ ...(!native &&
1378
+ !process.versions["bun"] &&
1379
+ environmentValue(options.environment, "CODEX_MCP_NODE_PATH") ===
1380
+ undefined
1381
+ ? { CODEX_MCP_NODE_PATH: process.execPath }
1382
+ : {}),
1383
+ }),
1252
1384
  // The SDK owns configuration normalization; the helper receives its resolved location.
1253
1385
  nativeLocalDedupe
1254
1386
  ? `{"stateDirectory":${JSON.stringify(stateDirectory)},"payload":${input ?? "null"}}`
@@ -1329,8 +1461,9 @@ export async function validateOutputDir(outputDirectory, archiveExisting = false
1329
1461
  throw new OutputDirectoryNotEmptyError(path);
1330
1462
  }
1331
1463
  requireOutputDirectoryOwnership(metadata, path);
1332
- await requireSecureOutputAncestry(path);
1333
- const canonical = await realpath(path);
1464
+ const writableLeaf = !archiveExisting ||
1465
+ (process.platform === "win32" && (await readdir(path)).length === 0);
1466
+ const canonical = await checkedOutputPath(path, writableLeaf);
1334
1467
  requireModelSafeOutputDir(canonical);
1335
1468
  return canonical;
1336
1469
  }
@@ -1486,13 +1619,12 @@ export async function prepareScanRegistrationOutput(outputDirectory, repositoryN
1486
1619
  return prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, archiveExisting ? "preserve" : "reject");
1487
1620
  }
1488
1621
  async function prepareOutputDirectory(outputDirectory, repositoryName, temporaryRoot, validateLocation, existingOutput, onOutputArchived) {
1489
- if (outputDirectory === undefined) {
1490
- requireModelSafeOutputDir(temporaryRoot);
1491
- requireModelSafeOutputDir(await realpath(temporaryRoot));
1492
- }
1493
1622
  const path = await validateOutputDir(outputDirectory, existingOutput !== "reject");
1494
- validateLocation?.(path ?? (await realpath(temporaryRoot)));
1495
1623
  if (path === null) {
1624
+ requireModelSafeOutputDir(temporaryRoot);
1625
+ const canonicalRoot = await realpath(temporaryRoot);
1626
+ requireModelSafeOutputDir(canonicalRoot);
1627
+ validateLocation?.(canonicalRoot);
1496
1628
  const prefix = `codex-security-${safePrefix(repositoryName)}`;
1497
1629
  let created;
1498
1630
  if (process.platform === "win32") {
@@ -1500,11 +1632,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1500
1632
  // Reserve room within NTFS's 255-unit component limit for later archival.
1501
1633
  // The SDK suffix is longer than the workbench's .previous-<tempname> suffix.
1502
1634
  const prefixLength = 255 - suffix.length - outputArchiveSuffix().length;
1503
- created = join(temporaryRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
1635
+ created = join(canonicalRoot, `${prefix.slice(0, prefixLength)}${suffix}`);
1504
1636
  await createWindowsOutputDirectory(created, false);
1505
1637
  }
1506
1638
  else {
1507
- created = await mkdtemp(join(temporaryRoot, `${prefix}-`));
1639
+ created = await mkdtemp(join(canonicalRoot, `${prefix}-`));
1508
1640
  }
1509
1641
  try {
1510
1642
  if ((process.umask() & 0o700) !== 0)
@@ -1516,6 +1648,7 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1516
1648
  throw error;
1517
1649
  }
1518
1650
  }
1651
+ validateLocation?.(path);
1519
1652
  let createdRoot;
1520
1653
  try {
1521
1654
  let existing = await lstat(path).catch(nullIfMissingFileError);
@@ -1535,7 +1668,11 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1535
1668
  if ((process.umask() & 0o700) !== 0)
1536
1669
  await chmod(path, 0o700);
1537
1670
  }
1538
- return await validatePreparedOutputDir(path, validateLocation, existingOutput === "preserve");
1671
+ // Registration retains a populated scan for archival. An empty Windows
1672
+ // directory must still satisfy the checks for a writable scan output.
1673
+ const preserveContents = existingOutput === "preserve" &&
1674
+ (process.platform !== "win32" || (await readdir(path)).length !== 0);
1675
+ return await validatePreparedOutputDir(path, validateLocation, preserveContents);
1539
1676
  }
1540
1677
  catch (error) {
1541
1678
  if (createdRoot !== undefined) {
@@ -1548,10 +1685,19 @@ async function prepareOutputDirectory(outputDirectory, repositoryName, temporary
1548
1685
  });
1549
1686
  }
1550
1687
  }
1688
+ async function windowsOutputBinding() {
1689
+ return createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
1690
+ }
1691
+ export async function requireWindowsOutputPath(path, writableLeaf, retainedDirectory) {
1692
+ const native = await windowsOutputBinding();
1693
+ const error = native.validateWindowsOutputPath(Buffer.from(win32.toNamespacedPath(path), "utf16le"), writableLeaf, retainedDirectory);
1694
+ if (error !== 0)
1695
+ throw new OutputDirectoryError(`Scan output directory or its parent could not be trusted (Windows error ${error}): ${path}`);
1696
+ }
1551
1697
  export async function createWindowsOutputDirectory(path, recursive) {
1552
- const native = createRequire(import.meta.url)(join(await bundledPluginRoot(), "mcp", "native", `win32-${process.arch}`, "windows.node"));
1698
+ const native = await windowsOutputBinding();
1553
1699
  const create = async (target) => {
1554
- const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"));
1700
+ const createOne = () => native.createPrivateWindowsDirectory(Buffer.from(win32.toNamespacedPath(target), "utf16le"), true);
1555
1701
  let error = createOne();
1556
1702
  let firstCreated;
1557
1703
  if (recursive &&
@@ -1562,8 +1708,10 @@ export async function createWindowsOutputDirectory(path, recursive) {
1562
1708
  }
1563
1709
  if (error === 0)
1564
1710
  return firstCreated ?? target;
1565
- if (recursive && error === 183 && (await stat(target)).isDirectory())
1711
+ if (recursive && error === 183 && (await stat(target)).isDirectory()) {
1712
+ await requireWindowsOutputPath(target, target === path);
1566
1713
  return firstCreated;
1714
+ }
1567
1715
  throw new OutputDirectoryError(`Unable to create private Windows output directory (Windows error ${error}): ${target}`);
1568
1716
  };
1569
1717
  return create(path);
@@ -1573,14 +1721,42 @@ export async function validatePreparedOutputDir(path, validateLocation, allowNon
1573
1721
  if (!metadata.isDirectory()) {
1574
1722
  throw new OutputDirectoryError(`Scan output is not a directory: ${path}`);
1575
1723
  }
1576
- const canonical = await realpath(path);
1724
+ const canonical = await checkedOutputPath(path, !allowNonempty);
1577
1725
  requireModelSafeOutputDir(canonical);
1578
1726
  validateLocation?.(canonical);
1579
1727
  if (!allowNonempty && (await readdir(canonical)).length !== 0) {
1580
1728
  throw new OutputDirectoryError(`Scan output directory must be empty: ${path}`);
1581
1729
  }
1582
1730
  requireOutputDirectoryOwnership(metadata, path);
1583
- await requireSecureOutputAncestry(canonical);
1731
+ return canonical;
1732
+ }
1733
+ async function checkedOutputPath(path, writableLeaf) {
1734
+ if (process.platform === "win32") {
1735
+ // Keep the selected leaf for the no-follow check, including across an
1736
+ // in-place directory change between lstat and canonicalization.
1737
+ const directory = dirname(path);
1738
+ const parent = await realpath(directory);
1739
+ const selected = join(parent, relative(directory, path));
1740
+ await requireWindowsOutputPath(selected, writableLeaf);
1741
+ const canonical = await realpath(selected);
1742
+ if (canonical === selected)
1743
+ return selected;
1744
+ // Accept a canonical leaf spelling (case or short name) within the checked parent.
1745
+ if (dirname(canonical) === parent) {
1746
+ const [leaf, resolved] = await Promise.all([
1747
+ lstat(selected, { bigint: true }),
1748
+ lstat(canonical, { bigint: true }),
1749
+ ]);
1750
+ if (leaf.isDirectory() && leaf.ino !== 0n && sameInode(leaf, resolved)) {
1751
+ return canonical;
1752
+ }
1753
+ }
1754
+ throw new OutputDirectoryError(`Scan output directory changed during preparation: ${path}`);
1755
+ }
1756
+ await requireSecureOutputAncestry(path);
1757
+ const canonical = await realpath(path);
1758
+ if (canonical !== path)
1759
+ await requireSecureOutputAncestry(canonical);
1584
1760
  return canonical;
1585
1761
  }
1586
1762
  export function requirePrivateOutputDirectory(metadata, path, effectiveUid = process.geteuid?.()) {
@@ -1601,7 +1777,7 @@ export function requireOutputDirectoryOwnership(metadata, path, effectiveUid = p
1601
1777
  /** Reject shared parents whose owner can rename or replace scan output. */
1602
1778
  export async function requireSecureOutputAncestry(path, effectiveUid = process.geteuid?.()) {
1603
1779
  if (process.platform === "win32")
1604
- return;
1780
+ return requireWindowsOutputPath(path);
1605
1781
  let current = dirname(resolve(path));
1606
1782
  while (true) {
1607
1783
  try {
@@ -1736,6 +1912,7 @@ export async function extractPluginZip(archive, destination, signal) {
1736
1912
  const archivePath = resolve(expandHome(archive));
1737
1913
  await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
1738
1914
  const staging = await realpath(await mkdtemp(join(dirname(destination), ".codex-security-plugin-")));
1915
+ let publishingOnWindows = false;
1739
1916
  try {
1740
1917
  throwIfSignalAborted(signal);
1741
1918
  let expandedSize = 0;
@@ -1798,12 +1975,29 @@ export async function extractPluginZip(archive, destination, signal) {
1798
1975
  const pluginRoot = await discoverPluginRoot(staging);
1799
1976
  throwIfSignalAborted(signal);
1800
1977
  const relativeRoot = relative(staging, pluginRoot);
1801
- await rename(staging, destination);
1978
+ if (process.platform === "win32") {
1979
+ publishingOnWindows = true;
1980
+ await retryWindowsRename(async () => {
1981
+ throwIfSignalAborted(signal);
1982
+ if (await lstat(destination).catch(nullIfMissingFileError))
1983
+ throw new Error(`Destination already exists: ${destination}`);
1984
+ await rename(staging, destination);
1985
+ }, undefined, signal);
1986
+ publishingOnWindows = false;
1987
+ }
1988
+ else {
1989
+ await rename(staging, destination);
1990
+ }
1802
1991
  return await validatePluginRoot(join(destination, relativeRoot));
1803
1992
  }
1804
1993
  catch (error) {
1805
- await rm(staging, { recursive: true, force: true }).catch(() => undefined);
1994
+ let cleanupDiagnostic = "";
1995
+ await rm(staging, { recursive: true, force: true }).catch((cleanupError) => {
1996
+ cleanupDiagnostic = `\nCould not remove staging directory ${staging}: ${errorMessage(cleanupError)}`;
1997
+ });
1806
1998
  throwIfSignalAborted(signal);
1999
+ if (publishingOnWindows)
2000
+ throw new PluginBootstrapError(`Could not publish extracted plugin ZIP: ${errorMessage(error)}${cleanupDiagnostic}`, { cause: error });
1807
2001
  if (error instanceof PluginBootstrapError)
1808
2002
  throw error;
1809
2003
  throw new PluginBootstrapError(`Invalid plugin ZIP: ${archivePath}`, {
@@ -2103,9 +2297,18 @@ export async function bootstrapPlugin(codexHome, pluginRoot, options = {}) {
2103
2297
  const previous = await readFile(installRecord, "utf8")
2104
2298
  .then((value) => JSON.parse(value))
2105
2299
  .catch((error) => {
2106
- if (nodeErrorCode(error) === "ENOENT" || error instanceof SyntaxError) {
2300
+ const code = nodeErrorCode(error);
2301
+ if (code === "ENOENT" || error instanceof SyntaxError) {
2107
2302
  return null;
2108
2303
  }
2304
+ if (process.platform === "win32" &&
2305
+ error instanceof Error &&
2306
+ (code === "EACCES" || code === "EPERM")) {
2307
+ // Keep the original system error, including its path, code and syscall.
2308
+ error.message +=
2309
+ " If the SDK created this plugin installation receipt but cannot reopen it, " +
2310
+ "check its read permissions and the permissions new files inherit from the sdk-marketplace directory.";
2311
+ }
2109
2312
  throw error;
2110
2313
  });
2111
2314
  const plugins = configuration["plugins"];
@@ -2261,11 +2464,9 @@ export async function resolvePluginPython(options = {}) {
2261
2464
  if (inherited) {
2262
2465
  return await requirePython(inherited, "PYTHON", environment, isPythonPathCandidate(inherited) ? protectedRoot : discoveryRoots, options.signal);
2263
2466
  }
2264
- const home = options.homeDirectory ?? homedir();
2265
- const cacheDirectory = environmentValue(environment, "XDG_CACHE_HOME", true) ||
2266
- join(home, ".cache");
2267
2467
  const managedRoots = options.managedRuntimeRoots ?? [
2268
- join(cacheDirectory, "codex-runtimes", "codex-primary-runtime"),
2468
+ join(environmentValue(environment, "XDG_CACHE_HOME", true) ||
2469
+ join(options.homeDirectory ?? homedir(), ".cache"), "codex-runtimes", "codex-primary-runtime"),
2269
2470
  ];
2270
2471
  const relativeCandidates = process.platform === "win32"
2271
2472
  ? [
@@ -2296,14 +2497,12 @@ export async function resolvePluginPython(options = {}) {
2296
2497
  "Set pythonPath, --python, or PYTHON, install the Codex managed runtime, or add python3/python (py on Windows) to PATH.");
2297
2498
  }
2298
2499
  export function pluginExecutionEnvironment(python, environment = process.env) {
2299
- const child = {
2500
+ return {
2300
2501
  ...pythonUtf8Environment(environment),
2301
2502
  PYTHON: python,
2302
2503
  CODEX_SECURITY_PYTHON_COMMAND: python,
2303
2504
  CODEX_CLI_PATH: resolveCodexCommand(environment).command,
2304
2505
  };
2305
- forwardExternalImportSetting(environment, child);
2306
- return child;
2307
2506
  }
2308
2507
  export function environmentWithGit(environment, git) {
2309
2508
  if (git === undefined)
@@ -2334,6 +2533,16 @@ function pluginHelperEnvironment(environment) {
2334
2533
  export async function cleanupSdkDirectory(path) {
2335
2534
  await rm(path, { recursive: true, force: true });
2336
2535
  }
2536
+ // A child can finish or reject a request before the parent finishes writing it.
2537
+ export function isDisconnectedChildStdin(error) {
2538
+ return [
2539
+ "EPIPE",
2540
+ "ECONNRESET",
2541
+ "ENOTCONN",
2542
+ "EOF",
2543
+ "ERR_STREAM_DESTROYED",
2544
+ ].includes(error.code ?? "");
2545
+ }
2337
2546
  export async function runCodexCommand(command, args, environment, input, signal, archiveHandshake = false, stdinPrefix) {
2338
2547
  const cancellation = archiveHandshake ? new AbortController() : undefined;
2339
2548
  const abort = () => cancellation?.abort(signal?.reason);
@@ -2372,7 +2581,7 @@ export async function runCodexCommand(command, args, environment, input, signal,
2372
2581
  processError = error;
2373
2582
  });
2374
2583
  child.stdin.on("error", (error) => {
2375
- if (!["EPIPE", "ECONNRESET", "EOF", "ERR_STREAM_DESTROYED"].includes(error.code ?? ""))
2584
+ if (!isDisconnectedChildStdin(error))
2376
2585
  processError = error;
2377
2586
  });
2378
2587
  child.once("close", (exitCode) => processError === undefined
@@ -2437,6 +2646,8 @@ export async function probeCodexSandbox(command, environment, signal) {
2437
2646
  }
2438
2647
  catch (error) {
2439
2648
  signal?.throwIfAborted();
2649
+ if (timeout.aborted)
2650
+ throw new SandboxUnavailableError(`Codex sandbox probe timed out after ${SANDBOX_PROBE_TIMEOUT_MILLISECONDS / 1000} seconds.`, { cause: error });
2440
2651
  detail = processErrorDetail(error);
2441
2652
  }
2442
2653
  const guidance = process.platform === "linux"
@@ -2476,7 +2687,7 @@ async function validatePluginRoot(root) {
2476
2687
  await pluginMetadata(root);
2477
2688
  return await realpath(root);
2478
2689
  }
2479
- async function copyPluginTree(source, destination, signal) {
2690
+ export async function copyPluginTree(source, destination, signal) {
2480
2691
  await mkdir(dirname(destination), { recursive: true, mode: 0o700 });
2481
2692
  try {
2482
2693
  await cp(source, destination, {
@@ -2543,21 +2754,14 @@ async function usablePython(candidate, environment = process.env, protectedRoot
2543
2754
  if (command === null)
2544
2755
  return null;
2545
2756
  try {
2546
- const { stdout } = await execFile(command.executable, [
2547
- "-I",
2548
- "-c",
2549
- "import importlib.util,sys\nif sys.version_info < (3, 10): raise SystemExit(1)\nif sys.version_info < (3, 11) and importlib.util.find_spec('tomli') is None: raise SystemExit(1)\nprint('codex-security-python-ok')",
2550
- ], {
2757
+ const { stdout } = await execFile(command.executable, ["-I", "-c", PLUGIN_PYTHON_PROBE], {
2551
2758
  env: command.environment,
2552
2759
  encoding: "utf8",
2553
- // Cold Python startup can exceed five seconds on busy Windows hosts.
2554
- timeout: 30_000,
2760
+ timeout: PLUGIN_PYTHON_PROBE_TIMEOUT_MS,
2555
2761
  windowsHide: true,
2556
2762
  signal,
2557
2763
  });
2558
- return stdout.trim() === "codex-security-python-ok"
2559
- ? command.executable
2560
- : null;
2764
+ return stdout.trim() === PLUGIN_PYTHON_READY ? command.executable : null;
2561
2765
  }
2562
2766
  catch (error) {
2563
2767
  if (signal?.aborted)
@@ -2577,8 +2781,7 @@ export function sameFile(left, right) {
2577
2781
  return Promise.all([
2578
2782
  stat(left, { bigint: true }),
2579
2783
  stat(right, { bigint: true }),
2580
- ]).then(([leftMetadata, rightMetadata]) => leftMetadata.dev === rightMetadata.dev &&
2581
- leftMetadata.ino === rightMetadata.ino, () => false);
2784
+ ]).then(([leftMetadata, rightMetadata]) => sameInode(leftMetadata, rightMetadata), () => false);
2582
2785
  }
2583
2786
  function expandExecutableHome(value, environment) {
2584
2787
  const path = value.startsWith("~\\") ? value.replaceAll("\\", "/") : value;
@@ -2588,17 +2791,17 @@ function expandExecutableHome(value, environment) {
2588
2791
  : expandHome(path, environment);
2589
2792
  }
2590
2793
  export function expandHome(value, environment = process.env) {
2591
- const home = (process.platform === "win32"
2794
+ const home = () => (process.platform === "win32"
2592
2795
  ? (environmentValue(environment, "USERPROFILE") ??
2593
2796
  environmentValue(environment, "HOME"))
2594
2797
  : (environmentValue(environment, "HOME") ??
2595
2798
  environmentValue(environment, "USERPROFILE"))) ?? homedir();
2596
2799
  if (value === "~")
2597
- return home;
2800
+ return home();
2598
2801
  if (value.startsWith("~/"))
2599
- return join(home, value.slice(2));
2802
+ return join(home(), value.slice(2));
2600
2803
  if (value.startsWith("~\\")) {
2601
- return join(home, ...value.slice(2).split("\\"));
2804
+ return join(home(), ...value.slice(2).split("\\"));
2602
2805
  }
2603
2806
  return value;
2604
2807
  }