@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
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import argparse
6
6
  import codecs
7
7
  import hashlib
8
+ import json
8
9
  import os
9
10
  import re
10
11
  import shutil
@@ -14,18 +15,22 @@ import subprocess
14
15
  import sys
15
16
  import tempfile
16
17
  import unicodedata
18
+ from collections.abc import Iterable, Iterator
17
19
  from concurrent.futures import ThreadPoolExecutor
20
+ from contextlib import ExitStack, contextmanager
21
+ from contextvars import ContextVar
18
22
  from pathlib import Path, PurePosixPath
19
23
  from typing import Any, BinaryIO, Callable, cast
20
24
 
21
25
  # Some plugin hosts launch Python with safe-path isolation enabled.
22
26
  sys.path.insert(0, str(Path(__file__).resolve().parent))
23
- from filesystem_identity import stored_filesystem_identity_matches
27
+ from filesystem_identity import serialize_filesystem_identity, stored_filesystem_identity_matches
24
28
  from windows_scan_local_files import copy_directory_junction, pinned_root_git_marker
25
29
  from workbench_constants import GIT_REPOSITORY_ENVIRONMENT
26
30
 
27
31
  SOURCE_METADATA_DIRECTORIES = {".git", ".svn"}
28
32
  _WINDOWS = os.name == "nt"
33
+ _SCOPED_GIT: ContextVar[Callable[[Path], str] | None] = ContextVar("workbench_git", default=None)
29
34
 
30
35
 
31
36
  class UnreadableLocalFile(SystemExit):
@@ -204,8 +209,10 @@ def _stream_is_binary(output: BinaryIO, size: int, *, drain: bool = False) -> bo
204
209
 
205
210
  def _protected_repository_root(target: Path) -> Path:
206
211
  root = target.resolve()
207
- if root.is_file():
208
- root = root.parent
212
+ return _outer_checkout_root(root.parent if root.is_file() else root)
213
+
214
+
215
+ def _outer_checkout_root(root: Path) -> Path:
209
216
  protected = root
210
217
  for ancestor in (root, *root.parents):
211
218
  try:
@@ -216,9 +223,67 @@ def _protected_repository_root(target: Path) -> Path:
216
223
  return protected
217
224
 
218
225
 
226
+ def rejected_checkout_roots(value: str) -> list[str] | None:
227
+ # Retain both spellings before a checkout marker or symlink can move.
228
+ try:
229
+ lexical = Path(value).expanduser().absolute()
230
+ canonical = lexical.resolve()
231
+ lexical_root = _outer_checkout_root(lexical)
232
+ roots = {
233
+ lexical,
234
+ canonical,
235
+ lexical_root,
236
+ lexical_root.resolve(),
237
+ _protected_repository_root(canonical),
238
+ }
239
+ return sorted(map(str, roots))
240
+ except (OSError, RuntimeError):
241
+ return None
242
+
243
+
244
+ def pin_scoped_git(target: Path) -> str | None:
245
+ scoped = _SCOPED_GIT.get()
246
+ return scoped(target) if scoped is not None else None
247
+
248
+
219
249
  def trusted_git_executable(protected_root: Path) -> str | None:
220
250
  """Validate host-selected Git, or discover Git for a direct plugin invocation."""
221
251
  configured = os.environ.get("CODEX_SECURITY_GIT")
252
+ if configured is None:
253
+ configured = pin_scoped_git(protected_root)
254
+ return _resolve_git_executable(protected_root, configured)
255
+
256
+
257
+ def _historical_repository_roots(target: Path) -> Iterator[Path]:
258
+ try:
259
+ yield _protected_repository_root(target)
260
+ except (OSError, RuntimeError):
261
+ # Keep checking lexical ancestry when the saved path cannot be resolved.
262
+ pass
263
+ # A moved or unavailable descendant still excludes its lexical checkout ancestry.
264
+ root = Path(os.path.abspath(target))
265
+ protected = root
266
+ for ancestor in (root, *root.parents):
267
+ try:
268
+ (ancestor / ".git").lstat()
269
+ except (OSError, RuntimeError):
270
+ continue
271
+ protected = ancestor
272
+ yield protected
273
+ try:
274
+ yield protected.resolve()
275
+ except (OSError, RuntimeError):
276
+ # The lexical root above still excludes tools at an unavailable checkout.
277
+ pass
278
+
279
+
280
+ def _resolve_git_executable(
281
+ protected_root: Path,
282
+ configured: str | None,
283
+ *,
284
+ discovery_roots: Iterable[Path] = (),
285
+ recorded_git_roots: Iterable[Path] | None = (),
286
+ ) -> str | None:
222
287
  windows = sys.platform == "win32"
223
288
  if configured is None:
224
289
  names = ("git.exe", "git.com") if windows else ("git",)
@@ -236,7 +301,22 @@ def trusted_git_executable(protected_root: Path) -> str | None:
236
301
  candidates = iter((candidate,))
237
302
 
238
303
  try:
239
- repository = _protected_repository_root(protected_root)
304
+ repositories = [_protected_repository_root(protected_root)]
305
+ if configured is None:
306
+ # A legacy Git target has no trustworthy boundary to exclude from PATH.
307
+ if recorded_git_roots is None:
308
+ return None
309
+ saved_boundaries = tuple(recorded_git_roots)
310
+ for root in saved_boundaries:
311
+ repositories.extend(_historical_repository_roots(root))
312
+ for root in discovery_roots:
313
+ for repository in _historical_repository_roots(root):
314
+ if not repository.is_dir() and not any(
315
+ repository.is_relative_to(boundary) for boundary in saved_boundaries
316
+ ):
317
+ # Its former checkout is neither discoverable nor already excluded.
318
+ return None
319
+ repositories.append(repository)
240
320
  except (OSError, RuntimeError):
241
321
  return None
242
322
 
@@ -261,6 +341,7 @@ def trusted_git_executable(protected_root: Path) -> str | None:
261
341
  continue
262
342
  if any(
263
343
  path == repository or repository in path.parents
344
+ for repository in repositories
264
345
  for path in (lexical, invocation, canonical)
265
346
  ):
266
347
  if configured is not None:
@@ -270,6 +351,39 @@ def trusted_git_executable(protected_root: Path) -> str | None:
270
351
  return None
271
352
 
272
353
 
354
+ @contextmanager
355
+ def scoped_git_discovery(
356
+ protected_roots: Callable[[], Iterable[Path]],
357
+ *,
358
+ recorded_git_roots: Callable[[], Iterable[Path] | None] = lambda: (),
359
+ ) -> Iterator[None]:
360
+ """Pin ambient Git when an operation first needs to inspect repository targets."""
361
+ if os.environ.get("CODEX_SECURITY_GIT") is not None:
362
+ yield
363
+ return
364
+ executable: str | None = None
365
+
366
+ def resolve_once(target: Path) -> str:
367
+ nonlocal executable
368
+ if executable is None:
369
+ executable = (
370
+ _resolve_git_executable(
371
+ Path.cwd(),
372
+ None,
373
+ discovery_roots=(*protected_roots(), target),
374
+ recorded_git_roots=recorded_git_roots(),
375
+ )
376
+ or ""
377
+ )
378
+ return executable
379
+
380
+ token = _SCOPED_GIT.set(resolve_once)
381
+ try:
382
+ yield
383
+ finally:
384
+ _SCOPED_GIT.reset(token)
385
+
386
+
273
387
  def git_command(
274
388
  target: Path,
275
389
  *args: str,
@@ -279,6 +393,7 @@ def git_command(
279
393
  work_tree: Path | None = None,
280
394
  stdout_file: BinaryIO | None = None,
281
395
  environment_overrides: dict[str, str] | None = None,
396
+ inherit_git_environment: bool = True,
282
397
  offline: bool = False,
283
398
  ) -> subprocess.CompletedProcess[str] | subprocess.CompletedProcess[bytes]:
284
399
  """Run Git against target and return the completed process with its exit status.
@@ -289,7 +404,13 @@ def git_command(
289
404
  """
290
405
  if (git_dir is None) != (work_tree is None):
291
406
  raise ValueError("git_dir and work_tree must be provided together")
292
- environment = os.environ.copy()
407
+ environment = (
408
+ os.environ.copy()
409
+ if inherit_git_environment
410
+ else {
411
+ name: value for name, value in os.environ.items() if not name.upper().startswith("GIT_")
412
+ }
413
+ )
293
414
  for name in GIT_REPOSITORY_ENVIRONMENT:
294
415
  environment.pop(name, None)
295
416
  environment["GIT_LITERAL_PATHSPECS"] = "1"
@@ -427,7 +548,9 @@ def git_changed_paths(repo: Path, base: str, head: str, mode: str) -> list[tuple
427
548
  raise SystemExit(f"Unknown diff mode: {mode}")
428
549
 
429
550
 
430
- def diff_scope_file_count(target: Path, diff_target: dict[str, str]) -> int | None:
551
+ def diff_scope_file_count(
552
+ target: Path, diff_target: dict[str, str], exclusions: tuple[str, ...] | list[str] = ()
553
+ ) -> int | None:
431
554
  base, head = diff_target["baseRevision"], diff_target["headRevision"]
432
555
  local = diff_target["kind"] == "working_tree"
433
556
  selected: list[str] = []
@@ -439,6 +562,8 @@ def diff_scope_file_count(target: Path, diff_target: dict[str, str]) -> int | No
439
562
  return None
440
563
  for path, status in changes:
441
564
  name = path.relative_to(target).as_posix()
565
+ if any(PurePosixPath(name).is_relative_to(PurePosixPath(scope)) for scope in exclusions):
566
+ continue
442
567
  if not local or status == "D":
443
568
  committed[name] = f"{base if status == 'D' else head}:{name}"
444
569
  else:
@@ -575,6 +700,56 @@ def _visible_git_character(char: str) -> str:
575
700
  return ascii(char)[1:-1]
576
701
 
577
702
 
703
+ def _canonical_patch_chunks(output: BinaryIO) -> Iterator[bytes]:
704
+ """Drop Git's optional function label while preserving hunk coordinates and content."""
705
+ line_start = True
706
+ # Limit each read even when source lines are arbitrarily large.
707
+ for part in iter(lambda: output.readline(1024 * 1024), b""):
708
+ next_line_start = part.endswith(b"\n")
709
+ if line_start and part.startswith(b"@@ "):
710
+ coordinates, end, _ = part.partition(b" @@")
711
+ if end:
712
+ part = coordinates + end + b"\n"
713
+ yield part
714
+ line_start = next_line_start
715
+
716
+
717
+ @contextmanager
718
+ def _diff_driver_config(
719
+ target: Path, git_dir: Path | None, work_tree: Path | None
720
+ ) -> Iterator[tuple[str, ...]]:
721
+ names = git_command(
722
+ target,
723
+ "config",
724
+ "--name-only",
725
+ "--null",
726
+ "--get-regexp",
727
+ r"^diff\..+\.binary$",
728
+ text=False,
729
+ git_dir=git_dir,
730
+ work_tree=work_tree,
731
+ environment_overrides={"LC_ALL": "C"},
732
+ )
733
+ if names.returncode == 1: # Git returns 1 when there are no matching keys.
734
+ yield ()
735
+ return
736
+ if names.returncode:
737
+ raise SystemExit(
738
+ os.fsdecode(names.stderr) or "Could not inspect Git diff-driver configuration."
739
+ )
740
+ # A private command-scope include preserves case and arbitrary driver-name bytes
741
+ # without putting an unbounded number of keys on the command line.
742
+ with tempfile.TemporaryDirectory(prefix="codex-security-diff-") as directory:
743
+ config = Path(directory) / "drivers"
744
+ with config.open("wb") as stream:
745
+ for key in names.stdout.split(b"\0"):
746
+ if key:
747
+ driver = key.removeprefix(b"diff.").removesuffix(b".binary")
748
+ escaped = driver.replace(b"\\", b"\\\\").replace(b'"', b'\\"')
749
+ stream.write(b'[diff "' + escaped + b'"]\n\tbinary = auto\n')
750
+ yield "-c", f"include.path={config}"
751
+
752
+
578
753
  def _update_digest_field_from_git(
579
754
  digest: Any,
580
755
  label: bytes,
@@ -582,15 +757,24 @@ def _update_digest_field_from_git(
582
757
  *args: str,
583
758
  git_dir: Path | None = None,
584
759
  work_tree: Path | None = None,
760
+ environment_overrides: dict[str, str] | None = None,
761
+ stable_display: bool = False,
585
762
  ) -> None:
586
- with tempfile.TemporaryFile() as output:
763
+ with tempfile.TemporaryFile() as output, ExitStack() as stack:
764
+ driver_config = (
765
+ stack.enter_context(_diff_driver_config(target, git_dir, work_tree))
766
+ if stable_display
767
+ else ()
768
+ )
587
769
  completed = git_command(
588
770
  target,
771
+ *driver_config,
589
772
  *args,
590
773
  text=False,
591
774
  git_dir=git_dir,
592
775
  work_tree=work_tree,
593
776
  stdout_file=output,
777
+ environment_overrides=environment_overrides,
594
778
  )
595
779
  if completed.returncode != 0:
596
780
  detail = completed.stderr.decode("utf-8", errors="backslashreplace").replace(
@@ -600,41 +784,52 @@ def _update_digest_field_from_git(
600
784
  raise SystemExit(
601
785
  f"Could not snapshot the selected working-tree changes.\n{detail}".rstrip("\n")
602
786
  )
603
- output.seek(0, os.SEEK_END)
604
- value_size = output.tell()
787
+ if stable_display:
788
+ output.seek(0)
789
+ value_size = sum(len(part) for part in _canonical_patch_chunks(output))
790
+ else:
791
+ value_size = output.seek(0, os.SEEK_END)
605
792
  _update_digest_field_header(digest, label, value_size)
606
793
  output.seek(0)
607
- for chunk in iter(lambda: output.read(1024 * 1024), b""):
794
+ chunks = (
795
+ _canonical_patch_chunks(output)
796
+ if stable_display
797
+ else iter(lambda: output.read(1024 * 1024), b"")
798
+ )
799
+ for chunk in chunks:
608
800
  digest.update(chunk)
609
801
 
610
802
 
611
- def worktree_content_digest(target: Path) -> str:
803
+ def worktree_content_digest(target: Path, *, expected_digest: str | None = None) -> str:
612
804
  """Return the worktree digest for the selected path after checking the state of its submodules."""
613
805
  require_clean_submodule_worktrees(target)
614
806
  repository, pathspec = git_worktree_context(target)
615
- return worktree_content_digest_for_context(repository, pathspec)
807
+ return worktree_content_digest_for_context(
808
+ repository, pathspec, expected_digest=expected_digest
809
+ )
616
810
 
617
811
 
618
812
  def remediation_checkout_snapshot(
619
813
  scan: sqlite3.Row,
620
814
  *,
621
815
  expected_revision: str | None = None,
816
+ expected_digest: str | None = None,
622
817
  head_changed_message: str = (
623
818
  "Repository HEAD changed. Regenerate the remediation patch against the current checkout."
624
819
  ),
625
820
  ) -> tuple[str, str | None]:
626
821
  """Return the current revision and content digest after verifying the recorded checkout identity and required revision."""
627
- target = require_scan_target_identity(scan)
628
- revision = git_revision(target)
629
- required_revision = expected_revision or scan["target_revision"]
630
- if revision != required_revision:
631
- raise SystemExit(head_changed_message)
632
- content_digest = (
633
- worktree_content_digest(target)
634
- if revision != "unversioned"
635
- else directory_content_digest(target, excluded=(Path(scan["scan_dir"]),))
636
- )
637
- return revision, content_digest
822
+ with checked_scan_target(scan) as target:
823
+ revision = git_revision(target)
824
+ required_revision = expected_revision or scan["target_revision"]
825
+ if revision != required_revision:
826
+ raise SystemExit(head_changed_message)
827
+ content_digest = (
828
+ worktree_content_digest(target, expected_digest=expected_digest)
829
+ if revision != "unversioned"
830
+ else directory_content_digest(target, excluded=(Path(scan["scan_dir"]),))
831
+ )
832
+ return revision, content_digest
638
833
 
639
834
 
640
835
  def require_scan_target_unchanged(scan: sqlite3.Row) -> None:
@@ -646,28 +841,33 @@ def require_scan_target_unchanged(scan: sqlite3.Row) -> None:
646
841
  and scan["target_revision"] != "unversioned"
647
842
  ):
648
843
  # Legacy Git records bind only the revision, not working-tree contents.
649
- target = require_scan_target_identity(scan)
650
- if git_revision(target) != scan["target_revision"]:
651
- raise SystemExit(head_changed_message)
652
- require_clean_submodule_worktrees(target)
844
+ with checked_scan_target(scan) as target:
845
+ if git_revision(target) != scan["target_revision"]:
846
+ raise SystemExit(head_changed_message)
847
+ require_clean_submodule_worktrees(target)
653
848
  return
654
- _, current_digest = remediation_checkout_snapshot(
655
- scan, head_changed_message=head_changed_message
656
- )
657
849
  if scan["diff_target_kind"] == "working_tree":
658
850
  expected_digest = scan["diff_content_digest"]
659
851
  elif scan["diff_target_kind"] in {"commit", "range"}:
660
- tracked = git_bytes(Path(scan["target_path"]), "ls-files", "-t", "-z")
852
+ expected_digest = clean_worktree_content_digest()
853
+ else:
854
+ expected_digest = scan["target_snapshot_digest"]
855
+ _, current_digest = remediation_checkout_snapshot(
856
+ scan, expected_digest=expected_digest, head_changed_message=head_changed_message
857
+ )
858
+ if scan["diff_target_kind"] in {"commit", "range"}:
859
+ target = Path(scan["target_path"])
860
+ tracked = git_bytes(target, "ls-files", "-v", "-z")
661
861
  if tracked is None:
662
862
  raise SystemExit("Could not inspect tracked files in the scan target.")
663
- if any(entry.startswith(b"S ") for entry in tracked.split(b"\0")):
863
+ entries = tracked.split(b"\0")
864
+ if any(entry.startswith((b"S ", b"s ")) for entry in entries):
664
865
  raise SystemExit(
665
866
  "Committed-diff scans require a full repository checkout. "
666
867
  "Sparse checkouts are not supported; materialize skipped tracked files and retry."
667
868
  )
668
- expected_digest = clean_worktree_content_digest()
669
- else:
670
- expected_digest = scan["target_snapshot_digest"]
869
+ if any(entry.startswith(b"h ") for entry in entries):
870
+ verify_assumed_unchanged_files(target)
671
871
  if current_digest != expected_digest:
672
872
  raise SystemExit(
673
873
  "Scan target contents changed since the scan. "
@@ -675,12 +875,67 @@ def require_scan_target_unchanged(scan: sqlite3.Row) -> None:
675
875
  )
676
876
 
677
877
 
878
+ def verify_assumed_unchanged_files(target: Path) -> None:
879
+ index = git_output(target, "rev-parse", "--path-format=absolute", "--git-path", "index")
880
+ if index is None:
881
+ raise SystemExit("Could not locate the Git index for the scan target.")
882
+ with tempfile.TemporaryDirectory(prefix="codex-security-git-index-") as directory:
883
+ # Refresh a private index without running checkout hooks or updating its shared index.
884
+ index_copy = Path(directory) / "index"
885
+ shutil.copyfile(index, index_copy)
886
+ result = git_command(
887
+ target,
888
+ "-c",
889
+ f"core.hooksPath={directory}",
890
+ "-c",
891
+ "core.splitIndex=false",
892
+ "update-index",
893
+ "--really-refresh",
894
+ text=False,
895
+ environment_overrides={"GIT_INDEX_FILE": str(index_copy)},
896
+ # A repository's clean filter can run while Git compares working-tree bytes.
897
+ inherit_git_environment=False,
898
+ offline=True,
899
+ )
900
+ if result.returncode == 1:
901
+ raise SystemExit(
902
+ "A tracked file marked assume-unchanged changed since the scan. "
903
+ "Run a new scan before validating its findings."
904
+ )
905
+ if result.returncode != 0:
906
+ raise SystemExit(
907
+ os.fsdecode(result.stderr) or "Could not refresh the scan target's Git index."
908
+ )
909
+
910
+
678
911
  def worktree_content_digest_for_context(
679
912
  repository: Path,
680
913
  pathspec: str,
681
914
  *,
682
915
  git_dir: Path | None = None,
683
916
  work_tree: Path | None = None,
917
+ expected_digest: str | None = None,
918
+ ) -> str:
919
+ def calculate(stable_display: bool) -> str:
920
+ return _git_content_digest(repository, pathspec, git_dir, work_tree, stable_display)
921
+
922
+ current = calculate(True)
923
+ # Older sealed snapshots may have included the user's Git display settings.
924
+ if (
925
+ expected_digest is not None
926
+ and current != expected_digest
927
+ and calculate(False) == expected_digest
928
+ ):
929
+ return expected_digest
930
+ return current
931
+
932
+
933
+ def _git_content_digest(
934
+ repository: Path,
935
+ pathspec: str,
936
+ git_dir: Path | None,
937
+ work_tree: Path | None,
938
+ stable_display: bool,
684
939
  ) -> str:
685
940
  digest = hashlib.sha256()
686
941
  update_digest_field(digest, b"format", b"codex-security-snapshot/v1")
@@ -689,12 +944,44 @@ def worktree_content_digest_for_context(
689
944
  ":(top,glob,exclude)**/.svn",
690
945
  ":(top,glob,exclude)**/.svn/**",
691
946
  ]
947
+ config = (
948
+ (
949
+ "-c",
950
+ "core.quotePath=true",
951
+ "-c",
952
+ "diff.suppressBlankEmpty=false",
953
+ "-c",
954
+ "core.compression=1", # Git uses the fastest zlib level for binary patches by default.
955
+ )
956
+ if stable_display
957
+ else ()
958
+ )
959
+ display = (
960
+ (
961
+ "--no-color",
962
+ "--src-prefix=a/",
963
+ "--dst-prefix=b/",
964
+ "--unified=3",
965
+ "--diff-algorithm=myers",
966
+ "--indent-heuristic",
967
+ "--inter-hunk-context=0",
968
+ "--find-renames=50%",
969
+ "-l1000", # Git's default inexact rename limit.
970
+ "--submodule=short",
971
+ "-O",
972
+ os.devnull,
973
+ )
974
+ if stable_display
975
+ else ()
976
+ )
692
977
  _update_digest_field_from_git(
693
978
  digest,
694
979
  b"tracked-diff",
695
980
  repository,
981
+ *config,
696
982
  "--no-literal-pathspecs",
697
983
  "diff",
984
+ *display,
698
985
  "--binary",
699
986
  "--full-index",
700
987
  "--no-ext-diff",
@@ -705,6 +992,9 @@ def worktree_content_digest_for_context(
705
992
  *source_pathspecs,
706
993
  git_dir=git_dir,
707
994
  work_tree=work_tree,
995
+ # GIT_DIFF_OPTS overrides even an explicit --unified option.
996
+ environment_overrides={"GIT_DIFF_OPTS": ""} if stable_display else None,
997
+ stable_display=stable_display,
708
998
  )
709
999
  untracked = git_bytes(
710
1000
  repository,
@@ -869,7 +1159,7 @@ def _windows_inventory_query(
869
1159
  input_data: bytes | None = None,
870
1160
  environment_overrides: dict[str, str] | None = None,
871
1161
  ) -> subprocess.CompletedProcess[bytes]:
872
- """Retry a root inventory's metadata length error with its verified literal marker."""
1162
+ """Retry an inventory's metadata length error with its verified worktree marker."""
873
1163
 
874
1164
  def query(
875
1165
  directory: Path, environment: dict[str, str] | None
@@ -891,7 +1181,7 @@ def _windows_inventory_query(
891
1181
  if (
892
1182
  result.returncode != 128
893
1183
  or result.stdout
894
- or str(target) != str(work_tree)
1184
+ or not target.is_relative_to(work_tree)
895
1185
  or b"GIT_DIR" not in result.stderr
896
1186
  ):
897
1187
  return result
@@ -901,7 +1191,7 @@ def _windows_inventory_query(
901
1191
  probe = query(git_dir, {**(environment_overrides or {}), "LC_ALL": "C", "LANGUAGE": "C"})
902
1192
  if probe.returncode != 128 or probe.stdout or diagnostic not in probe.stderr.splitlines():
903
1193
  return result
904
- with pinned_root_git_marker(target, git_dir) as marker:
1194
+ with pinned_root_git_marker(target, git_dir, work_tree=work_tree) as marker:
905
1195
  if marker is not None:
906
1196
  retry = query(marker, environment_overrides)
907
1197
  if retry.returncode == 0 or (retry.returncode == 1 and "check-ignore" in args):
@@ -909,11 +1199,16 @@ def _windows_inventory_query(
909
1199
  return result
910
1200
 
911
1201
 
912
- def git_directory_snapshot_paths(target: Path) -> list[Path] | None:
913
- repository_root = git_output(target, "rev-parse", "--show-toplevel")
914
- if repository_root is None:
915
- return None
916
- repository, pathspec = git_worktree_context(target)
1202
+ def git_directory_snapshot_paths(
1203
+ target: Path, *, replay_git_dir: Path | None = None
1204
+ ) -> list[Path] | None:
1205
+ if replay_git_dir is None:
1206
+ if git_output(target, "rev-parse", "--show-toplevel") is None:
1207
+ return None
1208
+ repository, pathspec = git_worktree_context(target)
1209
+ else:
1210
+ # The temporary copy of an unborn repository uses the selected Git config and index.
1211
+ repository, pathspec = target, "."
917
1212
  scope = repository / pathspec
918
1213
  scope_depth = len(Path(pathspec).parts)
919
1214
  matching_prefixes: dict[str, bool] = {}
@@ -941,6 +1236,8 @@ def git_directory_snapshot_paths(target: Path) -> list[Path] | None:
941
1236
  "-z",
942
1237
  "--",
943
1238
  inventory_pathspec,
1239
+ git_dir=replay_git_dir,
1240
+ work_tree=repository if replay_git_dir else None,
944
1241
  )
945
1242
  if listed is None:
946
1243
  raise SystemExit("Could not inspect files in the selected Git working tree.")
@@ -999,7 +1296,7 @@ def git_directory_snapshot_paths(target: Path) -> list[Path] | None:
999
1296
  if _WINDOWS:
1000
1297
  # Git omits empty untracked directories from its file listing. Inventory
1001
1298
  # junction identities independently of whether their targets contain files.
1002
- git_directory = git_output(target, "rev-parse", "--absolute-git-dir")
1299
+ git_directory = replay_git_dir or git_output(target, "rev-parse", "--absolute-git-dir")
1003
1300
  if git_directory is None:
1004
1301
  raise SystemExit("Could not inspect the selected Git working tree.")
1005
1302
  directories = _windows_inventory_query(
@@ -1116,6 +1413,7 @@ def directory_content_digest(
1116
1413
  excluded: tuple[Path, ...] = (),
1117
1414
  include_ignored: bool = False,
1118
1415
  include_git_metadata: bool = False,
1416
+ replay_git_dir: Path | None = None,
1119
1417
  ) -> str:
1120
1418
  def raise_walk_error(error: OSError) -> None:
1121
1419
  raise error
@@ -1128,7 +1426,7 @@ def directory_content_digest(
1128
1426
  target, excluded, include_git_metadata=include_git_metadata, onerror=raise_walk_error
1129
1427
  )
1130
1428
  if include_ignored
1131
- else git_directory_snapshot_paths(target)
1429
+ else git_directory_snapshot_paths(target, replay_git_dir=replay_git_dir)
1132
1430
  )
1133
1431
  if paths is None:
1134
1432
  paths = source_directory_snapshot_paths(target, excluded)
@@ -1166,19 +1464,47 @@ def directory_content_digest(
1166
1464
  return f"codex-security-snapshot/v1:sha256:{digest.hexdigest()}"
1167
1465
 
1168
1466
 
1169
- def directory_snapshot_regular_file_count(target: Path) -> int:
1467
+ def directory_snapshot_regular_files(target: Path) -> Iterator[Path]:
1170
1468
  paths = git_directory_snapshot_paths(target)
1171
1469
  if paths is None:
1172
1470
  paths = source_directory_snapshot_paths(target)
1173
- count = 0
1174
1471
  for path in paths:
1175
1472
  try:
1176
1473
  metadata = path.lstat()
1177
1474
  except OSError as exc:
1178
1475
  raise SystemExit(f"Could not inspect local file: {path.relative_to(target)}") from exc
1179
1476
  if stat.S_ISREG(metadata.st_mode):
1180
- count += 1
1181
- return count
1477
+ yield path
1478
+
1479
+
1480
+ def directory_snapshot_regular_file_count(target: Path) -> int:
1481
+ return sum(1 for _ in directory_snapshot_regular_files(target))
1482
+
1483
+
1484
+ def scoped_regular_file_count(
1485
+ repository: Path, scopes: list[str], exclusions: tuple[str, ...] | list[str] = ()
1486
+ ) -> int:
1487
+ # Count directory entries once while retaining explicitly requested ignored files.
1488
+ names: set[str] = set()
1489
+ for scope in scopes:
1490
+ selected = (repository / scope).resolve(strict=True)
1491
+ if not selected.is_relative_to(repository):
1492
+ raise SystemExit("Requested scope must be inside the repository.")
1493
+ if not SOURCE_METADATA_DIRECTORIES.isdisjoint(selected.relative_to(repository).parts):
1494
+ continue
1495
+ if selected.is_file():
1496
+ names.add(selected.as_posix())
1497
+ elif selected.is_dir():
1498
+ names.update(path.as_posix() for path in directory_snapshot_regular_files(selected))
1499
+ return sum(
1500
+ not any(
1501
+ PurePosixPath(Path(name).relative_to(repository).as_posix()).is_relative_to(
1502
+ PurePosixPath(scope)
1503
+ )
1504
+ for scope in exclusions
1505
+ )
1506
+ for name in names
1507
+ )
1182
1508
 
1183
1509
 
1184
1510
  def copy_directory_excluding(
@@ -1369,7 +1695,10 @@ def require_remediation_target(value: str) -> Path:
1369
1695
  raise SystemExit("Remediation target must be an absolute local directory path.")
1370
1696
  try:
1371
1697
  resolved = stored.resolve(strict=True)
1372
- except (FileNotFoundError, OSError) as exc:
1698
+ except NotADirectoryError:
1699
+ # A component of the recorded checkout path now names a non-directory.
1700
+ resolved = None
1701
+ except OSError as exc:
1373
1702
  raise SystemExit(
1374
1703
  "Remediation is unavailable because the selected checkout is no longer accessible."
1375
1704
  ) from exc
@@ -1380,9 +1709,78 @@ def require_remediation_target(value: str) -> Path:
1380
1709
  return stored
1381
1710
 
1382
1711
 
1383
- def require_scan_target_identity(scan: sqlite3.Row) -> Path:
1384
- """Return the recorded checkout path or raise SystemExit if it no longer identifies the original directory."""
1712
+ @contextmanager
1713
+ def verified_windows_checkout(
1714
+ scan: sqlite3.Row, target: Path, *, replaced_message: str
1715
+ ) -> Iterator[None]:
1716
+ """Bind a Windows Deep checkout for the full operation, including legacy stat-width changes."""
1717
+ from windows_scan_local_files import pinned_resume_checkout
1718
+
1719
+ binding = scan["windows_resume_target_identity"]
1720
+ stored = (scan["target_device"], scan["target_inode"])
1721
+ if binding is None:
1722
+
1723
+ def stat_identity() -> tuple[int | str, int | str]:
1724
+ try:
1725
+ metadata = target.stat()
1726
+ except OSError as exc:
1727
+ raise SystemExit(f"Cannot verify the original Windows checkout: {exc}") from exc
1728
+ return serialize_filesystem_identity(metadata.st_dev), serialize_filesystem_identity(
1729
+ metadata.st_ino
1730
+ )
1731
+
1732
+ if stat_identity() == stored:
1733
+ yield
1734
+ if stat_identity() != stored:
1735
+ raise SystemExit(replaced_message)
1736
+ return
1737
+
1738
+ with pinned_resume_checkout(target) as native:
1739
+ if binding is not None:
1740
+ if native is None:
1741
+ raise SystemExit("Cannot verify the original Windows checkout identity.")
1742
+ if list(native) != json.loads(binding):
1743
+ raise SystemExit(replaced_message)
1744
+ # Legacy stat returned at most a 32-bit volume and 64-bit file index.
1745
+ elif (
1746
+ native is None
1747
+ or (native[0] < 1 << 32 and native[1] < 1 << 64)
1748
+ or tuple(map(serialize_filesystem_identity, native)) != stored
1749
+ ):
1750
+ raise SystemExit(
1751
+ "Cannot verify the saved Windows checkout identity with this Python runtime. "
1752
+ "Use its original Python runtime or start a new scan with "
1753
+ f"'codex-security scans rerun {scan['id']}'."
1754
+ )
1755
+ yield
1756
+
1757
+
1758
+ @contextmanager
1759
+ def checked_scan_target(scan: sqlite3.Row) -> Iterator[Path]:
1760
+ """Keep any recorded Windows checkout binding intact while a caller reads the target."""
1385
1761
  target = require_remediation_target(scan["target_path"])
1762
+ replaced = "Remediation is unavailable because the selected checkout path was replaced. Start a new scan."
1763
+ if (
1764
+ os.name == "nt"
1765
+ and "windows_resume_target_identity" in scan.keys()
1766
+ and (
1767
+ scan["windows_resume_target_identity"] is not None
1768
+ or (
1769
+ scan["mode"] == "deep"
1770
+ and scan["launch_kind"] == "scan"
1771
+ and scan["recipe_json"] is not None
1772
+ )
1773
+ )
1774
+ ):
1775
+ with ExitStack() as pins:
1776
+ try:
1777
+ pins.enter_context(
1778
+ verified_windows_checkout(scan, target, replaced_message=replaced)
1779
+ )
1780
+ except OSError as exc:
1781
+ raise SystemExit(f"Cannot verify the original Windows checkout: {exc}") from exc
1782
+ yield target
1783
+ return
1386
1784
  expected_inode = scan["target_inode"]
1387
1785
  if expected_inode is None:
1388
1786
  raise SystemExit(
@@ -1396,11 +1794,14 @@ def require_scan_target_identity(scan: sqlite3.Row) -> Path:
1396
1794
  "Remediation is unavailable because the selected checkout is no longer accessible."
1397
1795
  ) from exc
1398
1796
  if not stored_filesystem_identity_matches(expected_inode, metadata.st_ino):
1399
- raise SystemExit(
1400
- "Remediation is unavailable because the selected checkout path was replaced. "
1401
- "Start a new scan."
1402
- )
1403
- return target
1797
+ raise SystemExit(replaced)
1798
+ yield target
1799
+
1800
+
1801
+ def require_scan_target_identity(scan: sqlite3.Row) -> Path:
1802
+ """Return the recorded checkout path after checking its filesystem identity."""
1803
+ with checked_scan_target(scan) as target:
1804
+ return target
1404
1805
 
1405
1806
 
1406
1807
  def require_git_worktree_head(target: Path) -> str:
@@ -1414,37 +1815,37 @@ def scan_target_warning(scan: sqlite3.Row) -> str | None:
1414
1815
  if scan["diff_target_kind"] != "working_tree" and not scan["target_snapshot_digest"]:
1415
1816
  return None
1416
1817
  try:
1417
- target = require_scan_target_identity(scan)
1418
- if scan["target_revision"] == "unversioned":
1419
- if (
1420
- directory_content_digest(target, excluded=(Path(scan["scan_dir"]),))
1421
- != scan["target_snapshot_digest"]
1422
- ):
1818
+ with checked_scan_target(scan) as target:
1819
+ if scan["target_revision"] == "unversioned":
1820
+ if (
1821
+ directory_content_digest(target, excluded=(Path(scan["scan_dir"]),))
1822
+ != scan["target_snapshot_digest"]
1823
+ ):
1824
+ return (
1825
+ "Directory contents changed while the scan was running; "
1826
+ "results were saved for the original snapshot."
1827
+ )
1828
+ return None
1829
+ if git_revision(target) == "unversioned":
1423
1830
  return (
1424
- "Directory contents changed while the scan was running; "
1425
- "results were saved for the original snapshot."
1831
+ "The scanned Git repository became unavailable while the scan was running; "
1832
+ "results were saved for the original revision."
1426
1833
  )
1427
- return None
1428
- if git_revision(target) == "unversioned":
1429
- return (
1430
- "The scanned Git repository became unavailable while the scan was running; "
1431
- "results were saved for the original revision."
1432
- )
1433
- working_tree = scan["diff_target_kind"] == "working_tree"
1434
- expected_head = scan["diff_head_revision"] if working_tree else scan["target_revision"]
1435
- if require_git_worktree_head(target) != expected_head:
1436
- return (
1437
- "Repository HEAD changed while the scan was running; "
1438
- "results were saved for the original revision."
1439
- )
1440
- expected_digest = (
1441
- scan["diff_content_digest"] if working_tree else scan["target_snapshot_digest"]
1442
- )
1443
- if worktree_content_digest(target) != expected_digest:
1444
- return (
1445
- "Working-tree contents changed while the scan was running; "
1446
- "results were saved for the original snapshot."
1834
+ working_tree = scan["diff_target_kind"] == "working_tree"
1835
+ expected_head = scan["diff_head_revision"] if working_tree else scan["target_revision"]
1836
+ if require_git_worktree_head(target) != expected_head:
1837
+ return (
1838
+ "Repository HEAD changed while the scan was running; "
1839
+ "results were saved for the original revision."
1840
+ )
1841
+ expected_digest = (
1842
+ scan["diff_content_digest"] if working_tree else scan["target_snapshot_digest"]
1447
1843
  )
1844
+ if worktree_content_digest(target, expected_digest=expected_digest) != expected_digest:
1845
+ return (
1846
+ "Working-tree contents changed while the scan was running; "
1847
+ "results were saved for the original snapshot."
1848
+ )
1448
1849
  except (OSError, SystemExit) as error:
1449
1850
  return (
1450
1851
  f"Could not verify the scan target after scanning: {error}; "