@openai/codex-security 0.9.1 → 0.10.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 (444) hide show
  1. package/README.md +37 -788
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +3 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  14. package/_bundled_plugin/references/access-advisory.md +1 -1
  15. package/_bundled_plugin/references/artifact-storage.md +1 -1
  16. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  17. package/_bundled_plugin/references/core-scan.md +5 -42
  18. package/_bundled_plugin/references/final-report.md +1 -1
  19. package/_bundled_plugin/references/focused-investigator.md +13 -0
  20. package/_bundled_plugin/references/scan-prologue.md +2 -2
  21. package/_bundled_plugin/references/scan-runtime.md +4 -2
  22. package/_bundled_plugin/references/security-guidance.md +14 -1
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  25. package/_bundled_plugin/scripts/deep_scan_workbench.py +30 -12
  26. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  27. package/_bundled_plugin/scripts/finalize_scan_contract.py +47 -9
  28. package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
  29. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +2 -0
  30. package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
  31. package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
  32. package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
  33. package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
  34. package/_bundled_plugin/scripts/workbench/storage.py +25 -5
  35. package/_bundled_plugin/scripts/workbench_cli.py +24 -2
  36. package/_bundled_plugin/scripts/workbench_constants.py +2 -0
  37. package/_bundled_plugin/scripts/workbench_db.py +257 -268
  38. package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
  39. package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
  40. package/_bundled_plugin/scripts/workbench_progress.py +159 -3
  41. package/_bundled_plugin/scripts/workbench_publication.py +2 -3
  42. package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
  43. package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
  44. package/_bundled_plugin/scripts/workbench_scan_history.py +291 -134
  45. package/_bundled_plugin/scripts/workbench_scan_start.py +208 -11
  46. package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
  47. package/_bundled_plugin/scripts/workbench_schema.py +220 -14
  48. package/_bundled_plugin/scripts/workbench_setup.py +1 -1
  49. package/_bundled_plugin/scripts/workbench_source_scopes.py +8 -0
  50. package/_bundled_plugin/scripts/workbench_target.py +486 -85
  51. package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
  52. package/_bundled_plugin/shared/workbench-history-repairs.json +64 -14
  53. package/_bundled_plugin/shared/workbench-migrations.json +66 -0
  54. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +4 -2
  55. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +2 -2
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +26 -160
  58. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  59. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
  60. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
  61. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  62. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  63. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  64. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  65. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  66. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  67. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  68. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  69. package/bin/codex-security.mjs +2 -2
  70. package/dist/api.d.ts +7 -1
  71. package/dist/api.d.ts.map +1 -1
  72. package/dist/api.js +459 -157
  73. package/dist/api.js.map +1 -1
  74. package/dist/armorcode-findings.d.ts +9 -0
  75. package/dist/armorcode-findings.d.ts.map +1 -0
  76. package/dist/armorcode-findings.js +145 -0
  77. package/dist/armorcode-findings.js.map +1 -0
  78. package/dist/artifact-export.d.ts +2 -0
  79. package/dist/artifact-export.d.ts.map +1 -1
  80. package/dist/artifact-export.js +29 -13
  81. package/dist/artifact-export.js.map +1 -1
  82. package/dist/auth.d.ts +6 -2
  83. package/dist/auth.d.ts.map +1 -1
  84. package/dist/auth.js +33 -12
  85. package/dist/auth.js.map +1 -1
  86. package/dist/batch-cost.d.ts +18 -0
  87. package/dist/batch-cost.d.ts.map +1 -0
  88. package/dist/batch-cost.js +41 -0
  89. package/dist/batch-cost.js.map +1 -0
  90. package/dist/blackduck-findings.d.ts +1 -1
  91. package/dist/blackduck-findings.d.ts.map +1 -1
  92. package/dist/blackduck-findings.js +5 -18
  93. package/dist/blackduck-findings.js.map +1 -1
  94. package/dist/bundled-plugin.d.ts +4 -0
  95. package/dist/bundled-plugin.d.ts.map +1 -0
  96. package/dist/bundled-plugin.js +23 -0
  97. package/dist/bundled-plugin.js.map +1 -0
  98. package/dist/classify-scan-severity.d.ts +1 -1
  99. package/dist/classify-scan-severity.d.ts.map +1 -1
  100. package/dist/classify-scan-severity.js +11 -3
  101. package/dist/classify-scan-severity.js.map +1 -1
  102. package/dist/classify-severity-diagnostics.d.ts +10 -0
  103. package/dist/classify-severity-diagnostics.d.ts.map +1 -0
  104. package/dist/classify-severity-diagnostics.js +57 -0
  105. package/dist/classify-severity-diagnostics.js.map +1 -0
  106. package/dist/classify-severity-records.d.ts +4 -0
  107. package/dist/classify-severity-records.d.ts.map +1 -1
  108. package/dist/classify-severity-records.js +35 -8
  109. package/dist/classify-severity-records.js.map +1 -1
  110. package/dist/classify-severity.d.ts.map +1 -1
  111. package/dist/classify-severity.js +9 -6
  112. package/dist/classify-severity.js.map +1 -1
  113. package/dist/cli-argument.d.ts +4 -0
  114. package/dist/cli-argument.d.ts.map +1 -0
  115. package/dist/cli-argument.js +17 -0
  116. package/dist/cli-argument.js.map +1 -0
  117. package/dist/cli-help.d.ts +1 -1
  118. package/dist/cli-help.d.ts.map +1 -1
  119. package/dist/cli-help.js +71 -29
  120. package/dist/cli-help.js.map +1 -1
  121. package/dist/cli-hook.d.ts +3 -0
  122. package/dist/cli-hook.d.ts.map +1 -0
  123. package/dist/cli-hook.js +87 -0
  124. package/dist/cli-hook.js.map +1 -0
  125. package/dist/cli-integrations.d.ts +13 -0
  126. package/dist/cli-integrations.d.ts.map +1 -0
  127. package/dist/cli-integrations.js +333 -0
  128. package/dist/cli-integrations.js.map +1 -0
  129. package/dist/cli-mcp.d.ts +15 -0
  130. package/dist/cli-mcp.d.ts.map +1 -0
  131. package/dist/cli-mcp.js +178 -0
  132. package/dist/cli-mcp.js.map +1 -0
  133. package/dist/cli-token-view.d.ts +10 -0
  134. package/dist/cli-token-view.d.ts.map +1 -0
  135. package/dist/cli-token-view.js +41 -0
  136. package/dist/cli-token-view.js.map +1 -0
  137. package/dist/cli.d.ts +8 -3
  138. package/dist/cli.d.ts.map +1 -1
  139. package/dist/cli.js +1860 -903
  140. package/dist/cli.js.map +1 -1
  141. package/dist/cloud-publish.d.ts.map +1 -1
  142. package/dist/cloud-publish.js +33 -31
  143. package/dist/cloud-publish.js.map +1 -1
  144. package/dist/codex-sdk-environment.d.ts +6 -0
  145. package/dist/codex-sdk-environment.d.ts.map +1 -1
  146. package/dist/codex-sdk-environment.js +19 -0
  147. package/dist/codex-sdk-environment.js.map +1 -1
  148. package/dist/command-words.d.ts +3 -0
  149. package/dist/command-words.d.ts.map +1 -0
  150. package/dist/command-words.js +46 -0
  151. package/dist/command-words.js.map +1 -0
  152. package/dist/component-plan.d.ts.map +1 -1
  153. package/dist/component-plan.js +3 -3
  154. package/dist/component-plan.js.map +1 -1
  155. package/dist/component-scan.d.ts +3 -1
  156. package/dist/component-scan.d.ts.map +1 -1
  157. package/dist/component-scan.js +40 -7
  158. package/dist/component-scan.js.map +1 -1
  159. package/dist/config.d.ts +1 -1
  160. package/dist/config.d.ts.map +1 -1
  161. package/dist/config.js +30 -1
  162. package/dist/config.js.map +1 -1
  163. package/dist/continuum-aws.d.ts +6 -0
  164. package/dist/continuum-aws.d.ts.map +1 -0
  165. package/dist/continuum-aws.js +202 -0
  166. package/dist/continuum-aws.js.map +1 -0
  167. package/dist/continuum-collector.d.ts +44 -0
  168. package/dist/continuum-collector.d.ts.map +1 -0
  169. package/dist/continuum-collector.js +266 -0
  170. package/dist/continuum-collector.js.map +1 -0
  171. package/dist/continuum-findings.d.ts +31 -2
  172. package/dist/continuum-findings.d.ts.map +1 -1
  173. package/dist/continuum-findings.js +497 -59
  174. package/dist/continuum-findings.js.map +1 -1
  175. package/dist/contract.d.ts +1 -0
  176. package/dist/contract.d.ts.map +1 -1
  177. package/dist/contract.js +3 -0
  178. package/dist/contract.js.map +1 -1
  179. package/dist/cost.d.ts.map +1 -1
  180. package/dist/cost.js +1 -45
  181. package/dist/cost.js.map +1 -1
  182. package/dist/crowdstrike-findings.d.ts +7 -0
  183. package/dist/crowdstrike-findings.d.ts.map +1 -0
  184. package/dist/crowdstrike-findings.js +210 -0
  185. package/dist/crowdstrike-findings.js.map +1 -0
  186. package/dist/custom-validation-prompt.d.ts +1 -1
  187. package/dist/custom-validation-prompt.d.ts.map +1 -1
  188. package/dist/custom-validation-prompt.js +29 -19
  189. package/dist/custom-validation-prompt.js.map +1 -1
  190. package/dist/deduplication/local.d.ts +3 -1
  191. package/dist/deduplication/local.d.ts.map +1 -1
  192. package/dist/deduplication/local.js +8 -1
  193. package/dist/deduplication/local.js.map +1 -1
  194. package/dist/deduplication/refusal.d.ts.map +1 -1
  195. package/dist/deduplication/refusal.js +2 -1
  196. package/dist/deduplication/refusal.js.map +1 -1
  197. package/dist/deduplication/scan.d.ts +2 -0
  198. package/dist/deduplication/scan.d.ts.map +1 -1
  199. package/dist/deduplication/scan.js +24 -7
  200. package/dist/deduplication/scan.js.map +1 -1
  201. package/dist/deep-scan.d.ts.map +1 -1
  202. package/dist/deep-scan.js +16 -15
  203. package/dist/deep-scan.js.map +1 -1
  204. package/dist/endor-findings.d.ts +2 -2
  205. package/dist/endor-findings.d.ts.map +1 -1
  206. package/dist/endor-findings.js +6 -23
  207. package/dist/endor-findings.js.map +1 -1
  208. package/dist/errors.d.ts +3 -1
  209. package/dist/errors.d.ts.map +1 -1
  210. package/dist/errors.js +7 -3
  211. package/dist/errors.js.map +1 -1
  212. package/dist/executable-path.d.ts +3 -0
  213. package/dist/executable-path.d.ts.map +1 -1
  214. package/dist/executable-path.js +26 -0
  215. package/dist/executable-path.js.map +1 -1
  216. package/dist/external-findings-import.d.ts.map +1 -1
  217. package/dist/external-findings-import.js +12 -1
  218. package/dist/external-findings-import.js.map +1 -1
  219. package/dist/external-findings-local.d.ts +66 -4
  220. package/dist/external-findings-local.d.ts.map +1 -1
  221. package/dist/external-findings-local.js +258 -59
  222. package/dist/external-findings-local.js.map +1 -1
  223. package/dist/external-findings-publish.d.ts +6 -1
  224. package/dist/external-findings-publish.d.ts.map +1 -1
  225. package/dist/external-findings-publish.js +330 -1633
  226. package/dist/external-findings-publish.js.map +1 -1
  227. package/dist/external-findings-read.d.ts +11 -2
  228. package/dist/external-findings-read.d.ts.map +1 -1
  229. package/dist/external-findings-read.js +56 -53
  230. package/dist/external-findings-read.js.map +1 -1
  231. package/dist/external-findings.d.ts +1 -1
  232. package/dist/external-findings.d.ts.map +1 -1
  233. package/dist/external-findings.js +12 -1
  234. package/dist/external-findings.js.map +1 -1
  235. package/dist/external-import-contract.d.ts +6 -11
  236. package/dist/external-import-contract.d.ts.map +1 -1
  237. package/dist/external-import-contract.js +35 -177
  238. package/dist/external-import-contract.js.map +1 -1
  239. package/dist/external-import-models.d.ts +1 -1
  240. package/dist/external-import-models.d.ts.map +1 -1
  241. package/dist/external-import-models.js.map +1 -1
  242. package/dist/finding-prompt.d.ts.map +1 -1
  243. package/dist/finding-prompt.js +2 -2
  244. package/dist/finding-prompt.js.map +1 -1
  245. package/dist/github-dependabot-findings.d.ts.map +1 -1
  246. package/dist/github-dependabot-findings.js +3 -4
  247. package/dist/github-dependabot-findings.js.map +1 -1
  248. package/dist/github-findings.d.ts.map +1 -1
  249. package/dist/github-findings.js +19 -287
  250. package/dist/github-findings.js.map +1 -1
  251. package/dist/host-protocol.d.ts +6 -0
  252. package/dist/host-protocol.d.ts.map +1 -1
  253. package/dist/host-protocol.js +11 -1
  254. package/dist/host-protocol.js.map +1 -1
  255. package/dist/host-records-protocol.d.ts +2 -0
  256. package/dist/host-records-protocol.d.ts.map +1 -1
  257. package/dist/host-records-protocol.js +4 -0
  258. package/dist/host-records-protocol.js.map +1 -1
  259. package/dist/hosted-remediation.d.ts +1 -0
  260. package/dist/hosted-remediation.d.ts.map +1 -1
  261. package/dist/hosted-remediation.js +23 -3
  262. package/dist/hosted-remediation.js.map +1 -1
  263. package/dist/index.d.ts +5 -3
  264. package/dist/index.d.ts.map +1 -1
  265. package/dist/index.js +3 -1
  266. package/dist/index.js.map +1 -1
  267. package/dist/inspector-findings.d.ts.map +1 -1
  268. package/dist/inspector-findings.js +19 -35
  269. package/dist/inspector-findings.js.map +1 -1
  270. package/dist/knowledge-base.d.ts +1 -1
  271. package/dist/knowledge-base.d.ts.map +1 -1
  272. package/dist/knowledge-base.js +34 -27
  273. package/dist/knowledge-base.js.map +1 -1
  274. package/dist/linear.d.ts +11 -0
  275. package/dist/linear.d.ts.map +1 -1
  276. package/dist/linear.js.map +1 -1
  277. package/dist/local-git-metadata.d.ts +5 -2
  278. package/dist/local-git-metadata.d.ts.map +1 -1
  279. package/dist/local-git-metadata.js +8 -4
  280. package/dist/local-git-metadata.js.map +1 -1
  281. package/dist/multiscan.d.ts +4 -0
  282. package/dist/multiscan.d.ts.map +1 -1
  283. package/dist/multiscan.js +83 -39
  284. package/dist/multiscan.js.map +1 -1
  285. package/dist/opengrep-findings.d.ts +4 -2
  286. package/dist/opengrep-findings.d.ts.map +1 -1
  287. package/dist/opengrep-findings.js +39 -22
  288. package/dist/opengrep-findings.js.map +1 -1
  289. package/dist/private-finding-import.d.ts +8 -13
  290. package/dist/private-finding-import.d.ts.map +1 -1
  291. package/dist/private-finding-import.js +69 -129
  292. package/dist/private-finding-import.js.map +1 -1
  293. package/dist/project-config-schema.d.ts +2 -0
  294. package/dist/project-config-schema.d.ts.map +1 -1
  295. package/dist/project-config-schema.js +1 -0
  296. package/dist/project-config-schema.js.map +1 -1
  297. package/dist/project-config.d.ts +1 -0
  298. package/dist/project-config.d.ts.map +1 -1
  299. package/dist/project-config.js +56 -13
  300. package/dist/project-config.js.map +1 -1
  301. package/dist/prompt-files.d.ts +7 -2
  302. package/dist/prompt-files.d.ts.map +1 -1
  303. package/dist/prompt-files.js +42 -20
  304. package/dist/prompt-files.js.map +1 -1
  305. package/dist/provider-profile.d.ts.map +1 -1
  306. package/dist/provider-profile.js +4 -9
  307. package/dist/provider-profile.js.map +1 -1
  308. package/dist/publication.d.ts +1 -1
  309. package/dist/publication.d.ts.map +1 -1
  310. package/dist/publication.js.map +1 -1
  311. package/dist/record.d.ts +1 -5
  312. package/dist/record.d.ts.map +1 -1
  313. package/dist/record.js +3 -51
  314. package/dist/record.js.map +1 -1
  315. package/dist/remediation.d.ts.map +1 -1
  316. package/dist/remediation.js +3 -1
  317. package/dist/remediation.js.map +1 -1
  318. package/dist/runtime.d.ts +35 -7
  319. package/dist/runtime.d.ts.map +1 -1
  320. package/dist/runtime.js +782 -153
  321. package/dist/runtime.js.map +1 -1
  322. package/dist/saved-scan-bootstrap.d.ts +6 -1
  323. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  324. package/dist/saved-scan-bootstrap.js +267 -115
  325. package/dist/saved-scan-bootstrap.js.map +1 -1
  326. package/dist/scan-archive-path.d.ts +2 -0
  327. package/dist/scan-archive-path.d.ts.map +1 -0
  328. package/dist/scan-archive-path.js +5 -0
  329. package/dist/scan-archive-path.js.map +1 -0
  330. package/dist/scan-comparison.d.ts +20 -2
  331. package/dist/scan-comparison.d.ts.map +1 -1
  332. package/dist/scan-comparison.js +26 -5
  333. package/dist/scan-comparison.js.map +1 -1
  334. package/dist/scan-dashboard.d.ts +1 -0
  335. package/dist/scan-dashboard.d.ts.map +1 -1
  336. package/dist/scan-dashboard.js +18 -2
  337. package/dist/scan-dashboard.js.map +1 -1
  338. package/dist/scan-executor.d.ts.map +1 -1
  339. package/dist/scan-executor.js +4 -2
  340. package/dist/scan-executor.js.map +1 -1
  341. package/dist/scan-history-renderer.d.ts +1 -0
  342. package/dist/scan-history-renderer.d.ts.map +1 -1
  343. package/dist/scan-history-renderer.js +25 -9
  344. package/dist/scan-history-renderer.js.map +1 -1
  345. package/dist/scan-logs.d.ts.map +1 -1
  346. package/dist/scan-logs.js +28 -4
  347. package/dist/scan-logs.js.map +1 -1
  348. package/dist/scan-settings.d.ts +1 -0
  349. package/dist/scan-settings.d.ts.map +1 -1
  350. package/dist/scan-settings.js +1 -0
  351. package/dist/scan-settings.js.map +1 -1
  352. package/dist/scanner-import.d.ts +5 -11
  353. package/dist/scanner-import.d.ts.map +1 -1
  354. package/dist/scanner-import.js +16 -89
  355. package/dist/scanner-import.js.map +1 -1
  356. package/dist/security-policy.d.ts.map +1 -1
  357. package/dist/security-policy.js +26 -6
  358. package/dist/security-policy.js.map +1 -1
  359. package/dist/semgrep-findings.d.ts.map +1 -1
  360. package/dist/semgrep-findings.js +14 -48
  361. package/dist/semgrep-findings.js.map +1 -1
  362. package/dist/semgrep-platform-findings.d.ts +20 -70
  363. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  364. package/dist/semgrep-platform-findings.js +116 -333
  365. package/dist/semgrep-platform-findings.js.map +1 -1
  366. package/dist/severity-review.d.ts.map +1 -1
  367. package/dist/severity-review.js +1 -0
  368. package/dist/severity-review.js.map +1 -1
  369. package/dist/snyk-findings.d.ts +2 -0
  370. package/dist/snyk-findings.d.ts.map +1 -1
  371. package/dist/snyk-findings.js +5 -8
  372. package/dist/snyk-findings.js.map +1 -1
  373. package/dist/snyk-rest-findings.d.ts +3 -20
  374. package/dist/snyk-rest-findings.d.ts.map +1 -1
  375. package/dist/snyk-rest-findings.js +45 -217
  376. package/dist/snyk-rest-findings.js.map +1 -1
  377. package/dist/sonar-findings.d.ts +1 -1
  378. package/dist/sonar-findings.d.ts.map +1 -1
  379. package/dist/sonar-findings.js +2 -4
  380. package/dist/sonar-findings.js.map +1 -1
  381. package/dist/sonar-import.d.ts +3 -0
  382. package/dist/sonar-import.d.ts.map +1 -1
  383. package/dist/sonar-import.js +28 -30
  384. package/dist/sonar-import.js.map +1 -1
  385. package/dist/stored-finding-projection.d.ts +6 -0
  386. package/dist/stored-finding-projection.d.ts.map +1 -0
  387. package/dist/stored-finding-projection.js +129 -0
  388. package/dist/stored-finding-projection.js.map +1 -0
  389. package/dist/stored-findings-publication.d.ts +23 -0
  390. package/dist/stored-findings-publication.d.ts.map +1 -0
  391. package/dist/stored-findings-publication.js +169 -0
  392. package/dist/stored-findings-publication.js.map +1 -0
  393. package/dist/targets.d.ts +8 -1
  394. package/dist/targets.d.ts.map +1 -1
  395. package/dist/targets.js +103 -23
  396. package/dist/targets.js.map +1 -1
  397. package/dist/tenable-findings.d.ts +1 -4
  398. package/dist/tenable-findings.d.ts.map +1 -1
  399. package/dist/tenable-findings.js.map +1 -1
  400. package/dist/trivy-findings.d.ts.map +1 -1
  401. package/dist/trivy-findings.js +0 -11
  402. package/dist/trivy-findings.js.map +1 -1
  403. package/dist/trusted-executable.d.ts +7 -0
  404. package/dist/trusted-executable.d.ts.map +1 -1
  405. package/dist/trusted-executable.js +148 -37
  406. package/dist/trusted-executable.js.map +1 -1
  407. package/dist/value.js +3 -1
  408. package/dist/value.js.map +1 -1
  409. package/dist/veracode-findings.d.ts +1 -3
  410. package/dist/veracode-findings.d.ts.map +1 -1
  411. package/dist/veracode-findings.js +13 -38
  412. package/dist/veracode-findings.js.map +1 -1
  413. package/dist/version.d.ts +3 -1
  414. package/dist/version.d.ts.map +1 -1
  415. package/dist/version.js +184 -32
  416. package/dist/version.js.map +1 -1
  417. package/dist/wiz-findings.d.ts +2 -2
  418. package/dist/wiz-findings.d.ts.map +1 -1
  419. package/dist/wiz-findings.js +14 -92
  420. package/dist/wiz-findings.js.map +1 -1
  421. package/docs/classify-severity-records.md +30 -0
  422. package/docs/cli.md +537 -124
  423. package/docs/findings-service.md +22 -9
  424. package/docs/hosted-remediation.md +13 -4
  425. package/docs/sdk.md +918 -0
  426. package/package.json +15 -6
  427. package/schemas/external-findings.schema.json +2 -1
  428. package/schemas/project-config.schema.json +5 -0
  429. package/dist/hosted-scanner-v1.d.ts +0 -6
  430. package/dist/hosted-scanner-v1.d.ts.map +0 -1
  431. package/dist/hosted-scanner-v1.js +0 -60
  432. package/dist/hosted-scanner-v1.js.map +0 -1
  433. package/dist/reader-selection.d.ts +0 -15
  434. package/dist/reader-selection.d.ts.map +0 -1
  435. package/dist/reader-selection.js +0 -89
  436. package/dist/reader-selection.js.map +0 -1
  437. package/dist/semgrep-platform-v1.d.ts +0 -6
  438. package/dist/semgrep-platform-v1.d.ts.map +0 -1
  439. package/dist/semgrep-platform-v1.js +0 -83
  440. package/dist/semgrep-platform-v1.js.map +0 -1
  441. package/dist/snyk-rest-v1.d.ts +0 -28
  442. package/dist/snyk-rest-v1.d.ts.map +0 -1
  443. package/dist/snyk-rest-v1.js +0 -132
  444. package/dist/snyk-rest-v1.js.map +0 -1
@@ -2,10 +2,13 @@
2
2
  # Use LF line endings so POSIX can execute this script directly from Windows-built packages.
3
3
  set -eu
4
4
 
5
- PATH="${PATH:-/usr/bin:/bin}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
6
- export PATH
5
+ # The SDK may have removed directories containing repository-owned executables.
6
+ if [ -z "${_CODEX_SECURITY_SDK_NODE_SEARCH_PATH+x}" ]; then
7
+ PATH="${PATH:-/usr/bin:/bin}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin"
8
+ export PATH
9
+ fi
7
10
 
8
- launcher_dir=$(CDPATH= cd "$(dirname "$0")" && pwd)
11
+ launcher_dir=$(CDPATH= cd "$(command -p dirname "$0")" && pwd)
9
12
  server_path=$launcher_dir/../mcp/server.mjs
10
13
  if [ "${1:-}" = "--helper" ]; then
11
14
  server_path=$launcher_dir/../mcp/helpers.mjs
@@ -16,10 +19,10 @@ launch_node() {
16
19
  if [ "${1:-}" = "--helper" ]; then
17
20
  shift
18
21
  # Preserve POSIX argv and HOME bytes without temporary files or consuming stdin.
19
- helper_stdin=-
22
+ helper_stdin_open=false
20
23
  if (exec 4<&0) 2>&-; then
21
24
  exec 4<&0
22
- helper_stdin=4
25
+ helper_stdin_open=true
23
26
  fi
24
27
  wait_helper() {
25
28
  if wait "$!" 2>&-; then exit 0; else exit $?; fi
@@ -34,8 +37,15 @@ launch_node() {
34
37
  trap 'forward_signal HUP 129' HUP
35
38
  trap 'forward_signal INT 130' INT
36
39
  trap 'forward_signal TERM 143' TERM
37
- printf '%s\000' "${HOME+x}" "${HOME-}" "$@" | od -An -v -tx1 | tr -d ' \n' |
38
- "$node_command" "$server_path" --helper 3<&0 0<&"$helper_stdin" 4<&- &
40
+ printf '%s\000' "${HOME+x}" "${HOME-}" "$@" | command -p od -An -v -tx1 | command -p tr -d ' \n' | {
41
+ # BusyBox ash requires a literal close redirection for a closed stdin.
42
+ if [ "$helper_stdin_open" = true ]; then
43
+ exec 0<&4
44
+ else
45
+ exec 0<&-
46
+ fi
47
+ exec "$node_command" "$server_path" --helper 4<&-
48
+ } 3<&0 &
39
49
  exec 4<&-
40
50
  wait_helper
41
51
  fi
@@ -55,19 +65,43 @@ fi
55
65
 
56
66
  first_node=
57
67
  can_load_native() {
68
+ selected_node=$1
58
69
  if [ -z "$first_node" ]; then
59
70
  first_node=$1
60
71
  fi
61
- # Some managed macOS runtimes enforce library validation and cannot load the
62
- # plugin's addon. Check before starting a server or helper with side effects.
72
+ # Database helpers need SQLite. On macOS, library validation can also
73
+ # prevent a managed runtime from loading the plugin's addon.
63
74
  # Capture output without opening a writable file for read-only callers.
64
- _native_probe_output=$("$1" -e '
65
- if (process.platform === "darwin") {
75
+ if _native_probe_output=$("$1" -e '
76
+ if (process.platform === "linux") {
77
+ try { require("node:sqlite"); } catch { process.exitCode = 78; }
78
+ } else if (process.platform === "darwin") {
66
79
  require("node:sqlite");
67
80
  require(require("node:path").join(process.argv[1], "native",
68
81
  `${process.platform}-${process.arch}`, "unix.node"));
69
82
  }
70
- ' "$launcher_dir/../mcp" </dev/null 2>&1)
83
+ ' "$launcher_dir/../mcp" </dev/null 2>&1); then
84
+ return 0
85
+ elif [ "$?" -ne 78 ]; then
86
+ return 1
87
+ fi
88
+
89
+ # This Linux runtime can still run helpers without SQLite. Prefer a system
90
+ # installation if available, without expanding discovery into the caller's PATH.
91
+ for system_candidate in /usr/local/bin/node /usr/bin/node /bin/node; do
92
+ if [ -n "${_CODEX_SECURITY_SDK_NODE_SEARCH_PATH+x}" ]; then
93
+ case ":$_CODEX_SECURITY_SDK_NODE_SEARCH_PATH:" in
94
+ *":${system_candidate%/*}:"*) ;;
95
+ *) continue ;;
96
+ esac
97
+ fi
98
+ if [ -x "$system_candidate" ] &&
99
+ _native_probe_output=$("$system_candidate" -e 'require("node:sqlite")' </dev/null 2>&1); then
100
+ selected_node=$system_candidate
101
+ break
102
+ fi
103
+ done
104
+ return 0
71
105
  }
72
106
 
73
107
  for candidate in \
@@ -77,16 +111,20 @@ for candidate in \
77
111
  "$cache_root/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node"
78
112
  do
79
113
  if [ -n "$candidate" ] && [ -x "$candidate" ] && can_load_native "$candidate"; then
80
- launch_node "$candidate" "$@"
114
+ launch_node "$selected_node" "$@"
81
115
  fi
82
116
  done
83
117
 
84
- remaining_path=$PATH
85
- while :; do
118
+ remaining_path=${PATH-}
119
+ if [ -n "${CODEX_SECURITY_PLUGIN_ROOT:-}" ] && [ -n "${_CODEX_SECURITY_SDK_NODE_SEARCH_PATH:-}" ]; then
120
+ # Only Node lookup uses the SDK-inspected fallback directories.
121
+ remaining_path=${remaining_path:+$remaining_path:}$_CODEX_SECURITY_SDK_NODE_SEARCH_PATH
122
+ fi
123
+ while [ -n "$remaining_path" ]; do
86
124
  path_entry=${remaining_path%%:*}
87
125
  node_path=${path_entry:-.}/node
88
126
  if [ -x "$node_path" ] && can_load_native "$node_path"; then
89
- launch_node "$node_path" "$@"
127
+ launch_node "$selected_node" "$@"
90
128
  fi
91
129
  case "$remaining_path" in
92
130
  *:*) remaining_path=${remaining_path#*:} ;;
@@ -3,6 +3,8 @@ setlocal DisableDelayedExpansion
3
3
 
4
4
  set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\server.mjs"
5
5
  if "%~1"=="--helper" (
6
+ rem An inherited ERRORLEVEL would shadow the helper exit code.
7
+ set "ERRORLEVEL="
6
8
  set "CODEX_SECURITY_MCP_SCRIPT=%~dp0..\mcp\helpers.mjs"
7
9
  goto launch
8
10
  )
@@ -84,6 +84,28 @@ def _rename_exclusive(parent_fd: int, source: str, destination: str) -> None:
84
84
  if rename(parent_fd, os.fsencode(source), parent_fd, os.fsencode(destination), flag) == 0:
85
85
  return
86
86
  code = ctypes.get_errno()
87
+ elif sys.platform == "linux":
88
+ import sysconfig
89
+
90
+ # musl omits the renameat2 wrapper. Select the syscall for the Python
91
+ # process's ABI, which can differ from the host kernel's architecture.
92
+ arch = (sysconfig.get_config_var("MULTIARCH") or "").partition("-")[0]
93
+ number = {"x86_64": 316, "aarch64": 276}.get(arch)
94
+ syscall = getattr(libc, "syscall", None)
95
+ if number is not None and ctypes.sizeof(ctypes.c_void_p) == 8 and syscall is not None:
96
+ syscall.argtypes = [ctypes.c_long]
97
+ syscall.restype = ctypes.c_long
98
+ result = syscall(
99
+ number,
100
+ ctypes.c_long(parent_fd),
101
+ ctypes.c_char_p(os.fsencode(source)),
102
+ ctypes.c_long(parent_fd),
103
+ ctypes.c_char_p(os.fsencode(destination)),
104
+ ctypes.c_long(flag),
105
+ )
106
+ if result == 0:
107
+ return
108
+ code = ctypes.get_errno()
87
109
  detail = os.strerror(code)
88
110
  if code in {errno.ENOSYS, errno.ENOTSUP, errno.EOPNOTSUPP, errno.EINVAL}:
89
111
  detail = f"cannot publish a new file atomically without hard links or exclusive rename ({detail})"
@@ -168,7 +190,10 @@ def stage_write(
168
190
  if matches:
169
191
  yield lambda _directory=None: (opened, opened.st_ctime_ns)
170
192
  return
171
- candidate = f".{name}.{secrets.token_hex(8)}.tmp"
193
+ # A valid destination may already occupy the filesystem's entire name limit.
194
+ candidate = f".{secrets.token_hex(8)}.tmp"
195
+ if name.casefold() == candidate:
196
+ candidate = "." + candidate
172
197
 
173
198
  with stage_file(parent_fd, candidate, payload, owner_read_write) as staged_fd:
174
199
  staged = os.fstat(staged_fd)
@@ -4,11 +4,18 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
+ import os
7
8
  import sqlite3
8
9
  from pathlib import Path
9
10
  from urllib.parse import quote
10
11
 
11
12
 
13
+ def readonly_sqlite_uri(path: Path) -> str:
14
+ """Escape the native filename, including separators, without introducing a URI authority."""
15
+ filename = os.fsencode(path) if os.name == "posix" else str(path)
16
+ return f"file:{quote(filename, safe='')}?mode=ro"
17
+
18
+
12
19
  def main() -> None:
13
20
  """Back up the read-only source database into a separate destination using SQLite’s backup API."""
14
21
  parser = argparse.ArgumentParser(description=__doc__)
@@ -21,8 +28,7 @@ def main() -> None:
21
28
  if destination.exists() and destination.samefile(source):
22
29
  parser.error(f"Destination must not be the same file as source: {destination}")
23
30
  destination.parent.mkdir(parents=True, exist_ok=True)
24
- source_uri = f"file:{quote(str(source), safe='')}?mode=ro"
25
- with sqlite3.connect(source_uri, uri=True) as source_connection:
31
+ with sqlite3.connect(readonly_sqlite_uri(source), uri=True) as source_connection:
26
32
  creation_destination = destination.resolve()
27
33
  try:
28
34
  creation_destination.touch(mode=0o600, exist_ok=False)
@@ -71,6 +71,7 @@ _OPEN_EXISTING = 3
71
71
  _FILE_ATTRIBUTE_DIRECTORY = 0x00000010
72
72
  _FILE_ATTRIBUTE_NORMAL = 0x00000080
73
73
  _FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
74
+ _REPARSE_TAG_NAME_SURROGATE = 0x20000000
74
75
  _FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
75
76
  _FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
76
77
 
@@ -78,6 +79,7 @@ _FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
78
79
  _FILE_RENAME_INFO_CLASS = 3
79
80
  _FILE_DISPOSITION_INFO_CLASS = 4
80
81
  _FILE_ATTRIBUTE_TAG_INFO_CLASS = 9
82
+ _FILE_ID_INFO_CLASS = 18
81
83
 
82
84
  _FILE_TYPE_DISK = 0x0001
83
85
  _FILE_NAME_OPENED = 0x00000008
@@ -130,6 +132,25 @@ class _FileAttributeTagInfo(ctypes.Structure):
130
132
  ]
131
133
 
132
134
 
135
+ class _FileIdInfo(ctypes.Structure):
136
+ _fields_ = [("VolumeSerialNumber", ctypes.c_uint64), ("FileId", ctypes.c_ubyte * 16)]
137
+
138
+
139
+ class _ByHandleFileInformation(ctypes.Structure):
140
+ _fields_ = [
141
+ ("dwFileAttributes", wintypes.DWORD),
142
+ ("ftCreationTime", wintypes.FILETIME),
143
+ ("ftLastAccessTime", wintypes.FILETIME),
144
+ ("ftLastWriteTime", wintypes.FILETIME),
145
+ ("dwVolumeSerialNumber", wintypes.DWORD),
146
+ ("nFileSizeHigh", wintypes.DWORD),
147
+ ("nFileSizeLow", wintypes.DWORD),
148
+ ("nNumberOfLinks", wintypes.DWORD),
149
+ ("nFileIndexHigh", wintypes.DWORD),
150
+ ("nFileIndexLow", wintypes.DWORD),
151
+ ]
152
+
153
+
133
154
  class _SecurityAttributes(ctypes.Structure):
134
155
  _fields_ = [
135
156
  ("length", wintypes.DWORD),
@@ -230,6 +251,12 @@ if os.name == "nt":
230
251
  wintypes.DWORD,
231
252
  ]
232
253
  _GetFileInformationByHandleEx.restype = wintypes.BOOL
254
+ _GetFileInformationByHandle = _kernel32.GetFileInformationByHandle
255
+ _GetFileInformationByHandle.argtypes = [
256
+ wintypes.HANDLE,
257
+ ctypes.POINTER(_ByHandleFileInformation),
258
+ ]
259
+ _GetFileInformationByHandle.restype = wintypes.BOOL
233
260
 
234
261
  _GetFileType = _kernel32.GetFileType
235
262
  _GetFileType.argtypes = [wintypes.HANDLE]
@@ -442,9 +469,11 @@ def _verify_handle_path(handle: int, expected_path: Path, *, opened_name: bool =
442
469
  raise _invalid_path(expected_path, "opened file resolved outside its verified scan path")
443
470
 
444
471
 
445
- def _verify_directory(handle: int, expected_path: Path) -> None:
472
+ def _verify_directory(handle: int, expected_path: Path, checkout: bool = False) -> None:
446
473
  info = _attributes(handle)
447
- if info.FileAttributes & _FILE_ATTRIBUTE_REPARSE_POINT:
474
+ if info.FileAttributes & _FILE_ATTRIBUTE_REPARSE_POINT and (
475
+ not checkout or not info.ReparseTag or info.ReparseTag & _REPARSE_TAG_NAME_SURROGATE
476
+ ):
448
477
  raise _invalid_path(expected_path, "scan-local directories must not be reparse points")
449
478
  if not info.FileAttributes & _FILE_ATTRIBUTE_DIRECTORY:
450
479
  raise _invalid_path(expected_path, "expected a scan-local directory")
@@ -480,6 +509,7 @@ def _open_directory(
480
509
  missing_ok: bool = False,
481
510
  missing_is_path_error: bool = True,
482
511
  movable: bool = False,
512
+ checkout: bool = False,
483
513
  ) -> _OwnedHandle | None:
484
514
  try:
485
515
  handle = _create_file(
@@ -500,7 +530,7 @@ def _open_directory(
500
530
  if handle is not None:
501
531
  try:
502
532
  assert handle.value is not None
503
- _verify_directory(handle.value, path)
533
+ _verify_directory(handle.value, path, checkout)
504
534
  except BaseException:
505
535
  handle.close()
506
536
  raise
@@ -550,7 +580,7 @@ def _current_user_sid() -> str:
550
580
  return _sid_text(wintypes.LPVOID.from_buffer(user))
551
581
 
552
582
 
553
- def _output_directory_grants(handle: int, path: Path) -> int:
583
+ def _output_directory_grants(handle: int, path: Path, *, expected_descriptor=None) -> int:
554
584
  """Inspect the descriptor of the opened directory, even if its pathname changes."""
555
585
  owner, acl, descriptor = wintypes.LPVOID(), wintypes.LPVOID(), wintypes.LPVOID()
556
586
  status = _advapi32.GetSecurityInfo(
@@ -566,6 +596,10 @@ def _output_directory_grants(handle: int, path: Path) -> int:
566
596
  if status:
567
597
  raise ctypes.WinError(status)
568
598
  try:
599
+ if expected_descriptor is not None and _generated_directory_policy(
600
+ descriptor
601
+ ) != _generated_directory_policy(expected_descriptor):
602
+ raise _invalid_path(path, "new scan directory lacks its private owner or DACL")
569
603
  trusted = {
570
604
  _current_user_sid(),
571
605
  "S-1-5-18",
@@ -651,8 +685,8 @@ def _require_stable_output(path: Path, parent_grants: int, child_grants: int = 0
651
685
 
652
686
 
653
687
  @contextlib.contextmanager
654
- def _checked_output_directory(path: Path) -> Iterator[tuple[int, int]]:
655
- """Hold the checked canonical chain and expose its final directory handle and grants."""
688
+ def _checked_output_directory(path: Path) -> Iterator[tuple[int | None, int, int]]:
689
+ """Hold the checked chain and expose its parent, final directory handle and grants."""
656
690
  parent_grants = 0
657
691
  parent = None
658
692
  with contextlib.ExitStack() as pins:
@@ -678,18 +712,77 @@ def _checked_output_directory(path: Path) -> Iterator[tuple[int, int]]:
678
712
  _verify_directory(handle.value, directory)
679
713
  grants = _output_directory_grants(handle.value, directory)
680
714
  _require_stable_output(directory, parent_grants, grants)
681
- parent, parent_grants = handle.value, grants
682
- yield parent, parent_grants
715
+ containing, parent, parent_grants = parent, handle.value, grants
716
+ yield containing, parent, parent_grants
683
717
 
684
718
 
685
719
  def require_windows_output_path(path: Path, *, writable_output: bool = False) -> None:
686
- with _checked_output_directory(path) as (_, grants):
720
+ with _checked_output_directory(path) as (_, _, grants):
687
721
  if writable_output and grants & _SET_REPARSE_POINT:
688
722
  raise _invalid_path(
689
723
  path, "Another user can turn the output directory into a reparse point when empty."
690
724
  )
691
725
 
692
726
 
727
+ DEEP_RESUME_DIRECTORY = ".codex-security-resume"
728
+
729
+
730
+ def deep_resume_output_identity(scan_dir: Path) -> list[int]:
731
+ """Bind the output and its protected child while every directory is pinned."""
732
+ retained = scan_dir / DEEP_RESUME_DIRECTORY
733
+ with _checked_output_directory(retained) as (parent, child, grants):
734
+ assert parent is not None
735
+ return _pinned_resume_identity(parent, child, retained, grants)
736
+
737
+
738
+ def _full_directory_id(handle: int, path: Path) -> tuple[int, int] | None:
739
+ info = _FileIdInfo()
740
+ if not _GetFileInformationByHandleEx(
741
+ handle, _FILE_ID_INFO_CLASS, ctypes.byref(info), ctypes.sizeof(info)
742
+ ):
743
+ if ctypes.get_last_error() in {50, 87}: # ERROR_NOT_SUPPORTED or ERROR_INVALID_PARAMETER.
744
+ return None
745
+ _raise_last_error("GetFileInformationByHandleEx(FileIdInfo)", path)
746
+ file_id = int.from_bytes(info.FileId, "little")
747
+ if not file_id:
748
+ raise _invalid_path(path, "The resume directory has no stable file identity.")
749
+ return info.VolumeSerialNumber, file_id
750
+
751
+
752
+ def _resume_directory_id(handle: int, path: Path) -> tuple[int, int]:
753
+ if (identity := _full_directory_id(handle, path)) is not None:
754
+ return identity
755
+ # Some filesystems expose only the legacy 64-bit file index.
756
+ legacy = _ByHandleFileInformation()
757
+ if not _GetFileInformationByHandle(handle, ctypes.byref(legacy)):
758
+ _raise_last_error("GetFileInformationByHandle", path)
759
+ file_id = (legacy.nFileIndexHigh << 32) | legacy.nFileIndexLow
760
+ if not file_id:
761
+ raise _invalid_path(path, "The resume directory has no stable file identity.")
762
+ return legacy.dwVolumeSerialNumber, file_id
763
+
764
+
765
+ @contextlib.contextmanager
766
+ def pinned_resume_checkout(target: Path) -> Iterator[tuple[int, int] | None]:
767
+ """Keep the canonical checkout fixed while reading its full native identity and snapshot."""
768
+ with contextlib.ExitStack() as pins:
769
+ for directory in (*reversed(target.parents), target):
770
+ # A source provider directory may carry a reparse tag without redirecting its name.
771
+ handle = _open_directory(directory, checkout=True)
772
+ assert handle is not None
773
+ pins.enter_context(handle)
774
+ assert handle.value is not None
775
+ yield _full_directory_id(handle.value, target)
776
+
777
+
778
+ def _pinned_resume_identity(parent: int, child: int, retained: Path, grants: int) -> list[int]:
779
+ # A nonreplaceable, protected child keeps the scan root nonempty after
780
+ # the sandbox receives Modify there. The caller holds both directories.
781
+ if grants:
782
+ raise _invalid_path(retained, "The retained resume directory must be protected.")
783
+ return [*_resume_directory_id(parent, retained.parent), *_resume_directory_id(child, retained)]
784
+
785
+
693
786
  class _UnicodeString(ctypes.Structure):
694
787
  _fields_ = [
695
788
  ("length", wintypes.USHORT),
@@ -710,7 +803,7 @@ class _ObjectAttributes(ctypes.Structure):
710
803
 
711
804
 
712
805
  def _relative_output_directory(
713
- parent: int, basename: str, descriptor=None
806
+ parent: int, basename: str, descriptor=None, *, rollback_handle: bool = False
714
807
  ) -> tuple[int, int | None]:
715
808
  """Open or create one component relative to its checked parent without reparsing it."""
716
809
  size = len(basename.encode("utf-16-le", errors="surrogatepass"))
@@ -729,12 +822,16 @@ def _relative_output_directory(
729
822
  io_status = (ctypes.c_void_p * 2)() # IO_STATUS_BLOCK
730
823
  status = _ntdll.NtCreateFile(
731
824
  ctypes.byref(handle),
732
- _FILE_TRAVERSE | _FILE_READ_ATTRIBUTES | _READ_CONTROL | 0x100000,
825
+ _FILE_TRAVERSE
826
+ | _FILE_READ_ATTRIBUTES
827
+ | _READ_CONTROL
828
+ | 0x100000
829
+ | (_DELETE if rollback_handle else 0),
733
830
  ctypes.byref(attributes),
734
831
  ctypes.byref(io_status),
735
832
  None,
736
833
  _FILE_ATTRIBUTE_NORMAL,
737
- _FILE_SHARE_READ | _FILE_SHARE_WRITE,
834
+ 0 if rollback_handle else _FILE_SHARE_READ | _FILE_SHARE_WRITE,
738
835
  1 if descriptor is None else 2, # FILE_OPEN or FILE_CREATE
739
836
  0x200021, # FILE_OPEN_REPARSE_POINT | FILE_SYNCHRONOUS_IO_NONALERT | FILE_DIRECTORY_FILE
740
837
  None,
@@ -744,7 +841,7 @@ def _relative_output_directory(
744
841
 
745
842
 
746
843
  def create_windows_output_directory(path: Path, descriptor: wintypes.LPVOID) -> int:
747
- with _checked_output_directory(path.parent) as (parent, grants):
844
+ with _checked_output_directory(path.parent) as (_, parent, grants):
748
845
  _require_stable_output(path, grants)
749
846
  error, handle = _relative_output_directory(parent, path.name, descriptor)
750
847
  if not error:
@@ -752,8 +849,8 @@ def create_windows_output_directory(path: Path, descriptor: wintypes.LPVOID) ->
752
849
  return error
753
850
 
754
851
 
755
- def create_private_directory(path: Path, *, exist_ok: bool, scan_output: bool) -> Path:
756
- """Create one Windows directory with a protected inheritable DACL."""
852
+ @contextlib.contextmanager
853
+ def _private_directory_descriptor(path: Path, *, explicit_owner: bool) -> Iterator[wintypes.LPVOID]:
757
854
  _require_windows()
758
855
  # Older supported Python releases ignore mkdir's 0700 mode on Windows.
759
856
  # Apply the same owner/SYSTEM/Administrators policy at creation so a
@@ -770,7 +867,7 @@ def create_private_directory(path: Path, *, exist_ok: bool, scan_output: bool) -
770
867
  raise ValueError("Select a directory on a Windows volume that supports ACLs.")
771
868
 
772
869
  sid = _current_user_sid()
773
- owner = "" if exist_ok else f"O:{sid}"
870
+ owner = f"O:{sid}" if explicit_owner else ""
774
871
  dacl = f"{owner}D:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;{sid})"
775
872
 
776
873
  descriptor = wintypes.LPVOID()
@@ -779,6 +876,14 @@ def create_private_directory(path: Path, *, exist_ok: bool, scan_output: bool) -
779
876
  ):
780
877
  raise ctypes.WinError(ctypes.get_last_error())
781
878
  try:
879
+ yield descriptor
880
+ finally:
881
+ _kernel32.LocalFree(descriptor)
882
+
883
+
884
+ def create_private_directory(path: Path, *, exist_ok: bool, scan_output: bool) -> Path:
885
+ """Create one Windows directory with a protected inheritable DACL."""
886
+ with _private_directory_descriptor(path, explicit_owner=not exist_ok) as descriptor:
782
887
  if scan_output:
783
888
  error = create_windows_output_directory(path, descriptor)
784
889
  else:
@@ -795,8 +900,34 @@ def create_private_directory(path: Path, *, exist_ok: bool, scan_output: bool) -
795
900
  require_windows_output_path(path)
796
901
  return path
797
902
  raise ctypes.WinError(error)
798
- finally:
799
- _kernel32.LocalFree(descriptor)
903
+
904
+
905
+ @contextlib.contextmanager
906
+ def create_deep_resume_output(scan_dir: Path, committed: Callable[[], bool]) -> Iterator[list[int]]:
907
+ """Retain the exact creation handle through verification and database commit."""
908
+ retained = scan_dir / DEEP_RESUME_DIRECTORY
909
+ with (
910
+ _private_directory_descriptor(retained, explicit_owner=True) as descriptor,
911
+ _checked_output_directory(scan_dir) as (_, parent, grants),
912
+ ):
913
+ _require_stable_output(retained, grants)
914
+ error, child = _relative_output_directory(
915
+ parent, retained.name, descriptor, rollback_handle=True
916
+ )
917
+ if error:
918
+ raise ctypes.WinError(error)
919
+ assert child is not None
920
+ with _OwnedHandle(child):
921
+ try:
922
+ _verify_directory(child, retained)
923
+ child_grants = _output_directory_grants(
924
+ child, retained, expected_descriptor=descriptor
925
+ )
926
+ yield _pinned_resume_identity(parent, child, retained, child_grants)
927
+ except BaseException:
928
+ if not committed():
929
+ _mark_handle_for_deletion(child)
930
+ raise
800
931
 
801
932
 
802
933
  def create_directory_with_same_dacl(path: Path, source: Path) -> None:
@@ -903,16 +1034,22 @@ def scan_root_identity(scan_dir: Path) -> tuple[Path, tuple[int, int]]:
903
1034
 
904
1035
 
905
1036
  @contextlib.contextmanager
906
- def pinned_root_git_marker(cwd: Path, metadata: Path) -> Iterator[Path | None]:
907
- """Bind a canonical worktree beneath a fixed-drive root to its exact .git marker."""
1037
+ def pinned_root_git_marker(
1038
+ cwd: Path, metadata: Path, *, work_tree: Path | None = None
1039
+ ) -> Iterator[Path | None]:
1040
+ """Return a short explicit worktree marker while its cwd and Git metadata are pinned."""
1041
+ if work_tree is None:
1042
+ work_tree = cwd
908
1043
  if (
909
1044
  not cwd.is_absolute()
910
1045
  or not metadata.is_absolute()
911
1046
  or len(cwd.drive) != 2
912
- or cwd.drive != metadata.drive
913
- or len(cwd.parts) < 2
1047
+ or len(metadata.drive) != 2
1048
+ or len(work_tree.parts) < 2
1049
+ or cwd.parts[: len(work_tree.parts)] != work_tree.parts
914
1050
  or len(metadata.parts) < 2
915
1051
  or _GetDriveTypeW(cwd.anchor) != _DRIVE_FIXED
1052
+ or _GetDriveTypeW(metadata.anchor) != _DRIVE_FIXED
916
1053
  ):
917
1054
  yield None
918
1055
  return
@@ -930,9 +1067,11 @@ def pinned_root_git_marker(cwd: Path, metadata: Path) -> Iterator[Path | None]:
930
1067
  assert handle.value is not None
931
1068
  if _final_path(handle.value) != _extended_path(path):
932
1069
  raise ValueError("the selected Git directory spelling is not canonical")
933
- if str(cwd / ".git") != str(metadata):
1070
+ root_marker = work_tree / ".git"
1071
+ reference = Path(os.path.relpath(root_marker, cwd))
1072
+ if str(root_marker) != str(metadata):
934
1073
  # The literal canonical root is already pinned before opening its regular file.
935
- fd, leaf = open_read_fd_with_path(cwd, ".git", "Git metadata pointer")
1074
+ fd, leaf = open_read_fd_with_path(work_tree, ".git", "Git metadata pointer")
936
1075
  pointer = pins.enter_context(os.fdopen(fd, "rb"))
937
1076
  if leaf != ".git":
938
1077
  raise ValueError("the root marker name does not match .git")
@@ -940,12 +1079,64 @@ def pinned_root_git_marker(cwd: Path, metadata: Path) -> Iterator[Path | None]:
940
1079
  value = pointer.read(len(expected) + 3).removesuffix(b"\n").removesuffix(b"\r")
941
1080
  if value.replace(b"/", b"\\") != expected:
942
1081
  raise ValueError("the root marker does not name the selected Git directory")
943
- marker = Path(".git")
1082
+ # A deep scope can make the relative spelling longer than the gitfile itself.
1083
+ if len(os.fsencode(root_marker)) < len(os.fsencode(reference)):
1084
+ reference = root_marker
1085
+ marker = reference
944
1086
  except (OSError, ValueError):
945
1087
  pins.close()
946
1088
  yield marker
947
1089
 
948
1090
 
1091
+ def pin_replay_metadata(
1092
+ pins: contextlib.ExitStack, metadata: Path | None, scratch: Path
1093
+ ) -> Path | None:
1094
+ """Bind the selected metadata and fresh private Windows scratch before copying into it."""
1095
+ if os.name != "nt" or metadata is None:
1096
+ return None
1097
+ try:
1098
+ with contextlib.ExitStack() as checked:
1099
+ checked.enter_context(_locked_parent(metadata, "HEAD", create=False))
1100
+ checked.enter_context(_locked_parent(scratch.parent, scratch.name, create=False))
1101
+ directory = _create_file(
1102
+ scratch,
1103
+ access=_FILE_TRAVERSE | _FILE_READ_ATTRIBUTES | _READ_CONTROL,
1104
+ share=_FILE_SHARE_READ | _FILE_SHARE_WRITE,
1105
+ disposition=_OPEN_EXISTING,
1106
+ flags=_FILE_FLAG_BACKUP_SEMANTICS | _FILE_FLAG_OPEN_REPARSE_POINT,
1107
+ )
1108
+ assert directory is not None and directory.value is not None
1109
+ checked.enter_context(directory)
1110
+ _verify_directory(directory.value, scratch)
1111
+ if _output_directory_grants(directory.value, scratch):
1112
+ return None
1113
+ pins.enter_context(checked.pop_all())
1114
+ except (OSError, ValueError):
1115
+ return None
1116
+ return metadata
1117
+
1118
+
1119
+ @contextlib.contextmanager
1120
+ def pinned_replay_gitfile(checkout: Path, metadata: Path) -> Iterator[Path]:
1121
+ """Keep Git's short metadata pointer outside the replay and immutable while Git uses it."""
1122
+ with _locked_parent(checkout, ".git", create=False):
1123
+ # Git reads this path relative to its unchanged worktree cwd. Both volumes'
1124
+ # literal ancestors are pinned, including the temporary directory above checkout.
1125
+ marker = checkout.parent / "reviewed.git"
1126
+ handle = _create_file(
1127
+ marker,
1128
+ access=_GENERIC_WRITE | _FILE_READ_ATTRIBUTES,
1129
+ share=_FILE_SHARE_READ,
1130
+ disposition=_CREATE_NEW,
1131
+ flags=_FILE_ATTRIBUTE_NORMAL | _FILE_FLAG_OPEN_REPARSE_POINT,
1132
+ )
1133
+ assert handle is not None and handle.value is not None
1134
+ with handle:
1135
+ _verify_regular_file(handle.value, marker)
1136
+ _write_all(handle.value, f"gitdir: {metadata.as_posix()}\n".encode("utf-8"))
1137
+ yield Path("..") / marker.name
1138
+
1139
+
949
1140
  def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
950
1141
  """Open a verified regular file and return an owned binary read descriptor."""
951
1142