@openai/codex-security 0.8.1 → 0.8.3

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 (396) hide show
  1. package/README.md +45 -57
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  7. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  15. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
  16. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  17. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  18. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  19. package/_bundled_plugin/references/artifact-storage.md +1 -1
  20. package/_bundled_plugin/references/core-scan.md +14 -5
  21. package/_bundled_plugin/references/default-severity-rubric.md +28 -0
  22. package/_bundled_plugin/references/finding-detail-fields.md +1 -0
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
  26. package/_bundled_plugin/scripts/finding_preview.py +5 -29
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
  28. package/_bundled_plugin/scripts/report_projection.py +87 -136
  29. package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
  30. package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
  31. package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
  32. package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
  33. package/_bundled_plugin/scripts/workbench_cli.py +102 -13
  34. package/_bundled_plugin/scripts/workbench_constants.py +9 -0
  35. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
  36. package/_bundled_plugin/scripts/workbench_db.py +187 -363
  37. package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
  38. package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
  39. package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
  44. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  45. package/_bundled_plugin/scripts/workbench_setup.py +239 -0
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
  47. package/_bundled_plugin/scripts/workbench_target.py +120 -35
  48. package/_bundled_plugin/scripts/workbench_validation.py +1 -9
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +19 -0
  51. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  52. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  53. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  54. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  55. package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
  58. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
  59. package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
  60. package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
  61. package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
  62. package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
  63. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
  64. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
  65. package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
  66. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
  67. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
  68. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
  69. package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
  70. package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
  71. package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
  72. package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
  73. package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
  74. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
  75. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  76. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  77. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
  78. package/dist/api.d.ts +6 -1
  79. package/dist/api.d.ts.map +1 -1
  80. package/dist/api.js +414 -163
  81. package/dist/api.js.map +1 -1
  82. package/dist/auth.js +7 -2
  83. package/dist/auth.js.map +1 -1
  84. package/dist/blackduck-findings.d.ts +8 -0
  85. package/dist/blackduck-findings.d.ts.map +1 -0
  86. package/dist/blackduck-findings.js +305 -0
  87. package/dist/blackduck-findings.js.map +1 -0
  88. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  89. package/dist/bulk-scan-discovery.js +51 -36
  90. package/dist/bulk-scan-discovery.js.map +1 -1
  91. package/dist/classify-severity-records.d.ts +5 -0
  92. package/dist/classify-severity-records.d.ts.map +1 -1
  93. package/dist/classify-severity-records.js +6 -8
  94. package/dist/classify-severity-records.js.map +1 -1
  95. package/dist/classify-severity.d.ts +4 -1
  96. package/dist/classify-severity.d.ts.map +1 -1
  97. package/dist/classify-severity.js +28 -9
  98. package/dist/classify-severity.js.map +1 -1
  99. package/dist/cli.d.ts +3 -0
  100. package/dist/cli.d.ts.map +1 -1
  101. package/dist/cli.js +635 -266
  102. package/dist/cli.js.map +1 -1
  103. package/dist/codex-prompt.d.ts +2 -0
  104. package/dist/codex-prompt.d.ts.map +1 -1
  105. package/dist/codex-prompt.js +6 -0
  106. package/dist/codex-prompt.js.map +1 -1
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +6 -5
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/config.d.ts +2 -1
  111. package/dist/config.d.ts.map +1 -1
  112. package/dist/config.js +162 -40
  113. package/dist/config.js.map +1 -1
  114. package/dist/continuum-findings.d.ts +7 -0
  115. package/dist/continuum-findings.d.ts.map +1 -0
  116. package/dist/continuum-findings.js +157 -0
  117. package/dist/continuum-findings.js.map +1 -0
  118. package/dist/contract-values.d.ts +28 -0
  119. package/dist/contract-values.d.ts.map +1 -0
  120. package/dist/contract-values.js +75 -0
  121. package/dist/contract-values.js.map +1 -0
  122. package/dist/contract.d.ts +2 -20
  123. package/dist/contract.d.ts.map +1 -1
  124. package/dist/contract.js +58 -669
  125. package/dist/contract.js.map +1 -1
  126. package/dist/cost-model.d.ts.map +1 -1
  127. package/dist/cost-model.js +1 -4
  128. package/dist/cost-model.js.map +1 -1
  129. package/dist/cost.d.ts +19 -1
  130. package/dist/cost.d.ts.map +1 -1
  131. package/dist/cost.js +2120 -39
  132. package/dist/cost.js.map +1 -1
  133. package/dist/custom-validation-prompt.d.ts +1 -1
  134. package/dist/custom-validation-prompt.d.ts.map +1 -1
  135. package/dist/custom-validation-prompt.js +5 -0
  136. package/dist/custom-validation-prompt.js.map +1 -1
  137. package/dist/custom-validation.d.ts +2 -0
  138. package/dist/custom-validation.d.ts.map +1 -1
  139. package/dist/custom-validation.js +6 -2
  140. package/dist/custom-validation.js.map +1 -1
  141. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  142. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  143. package/dist/deduplication/deduplication-prompts.js +2 -2
  144. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  145. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  146. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  147. package/dist/deduplication/deduplication-reviewer.js +12 -5
  148. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  149. package/dist/deduplication/deduplication.js.map +1 -1
  150. package/dist/deduplication/finding-schema.d.ts +19 -1
  151. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  152. package/dist/deduplication/finding-schema.js +25 -0
  153. package/dist/deduplication/finding-schema.js.map +1 -1
  154. package/dist/deduplication/local.d.ts.map +1 -1
  155. package/dist/deduplication/local.js +3 -8
  156. package/dist/deduplication/local.js.map +1 -1
  157. package/dist/deduplication/records.d.ts +11 -3
  158. package/dist/deduplication/records.d.ts.map +1 -1
  159. package/dist/deduplication/records.js +48 -16
  160. package/dist/deduplication/records.js.map +1 -1
  161. package/dist/deep-scan.d.ts +11 -0
  162. package/dist/deep-scan.d.ts.map +1 -1
  163. package/dist/deep-scan.js +235 -4
  164. package/dist/deep-scan.js.map +1 -1
  165. package/dist/default-severity-rubric.d.ts +1 -2
  166. package/dist/default-severity-rubric.d.ts.map +1 -1
  167. package/dist/default-severity-rubric.js +2 -66
  168. package/dist/default-severity-rubric.js.map +1 -1
  169. package/dist/endor-findings.d.ts.map +1 -1
  170. package/dist/endor-findings.js +44 -89
  171. package/dist/endor-findings.js.map +1 -1
  172. package/dist/errors.js +1 -1
  173. package/dist/errors.js.map +1 -1
  174. package/dist/external-findings-import.d.ts.map +1 -1
  175. package/dist/external-findings-import.js +11 -15
  176. package/dist/external-findings-import.js.map +1 -1
  177. package/dist/external-findings-local.d.ts +12 -1
  178. package/dist/external-findings-local.d.ts.map +1 -1
  179. package/dist/external-findings-local.js +411 -184
  180. package/dist/external-findings-local.js.map +1 -1
  181. package/dist/external-findings-publish.d.ts +15 -1
  182. package/dist/external-findings-publish.d.ts.map +1 -1
  183. package/dist/external-findings-publish.js +1238 -226
  184. package/dist/external-findings-publish.js.map +1 -1
  185. package/dist/external-findings-read.d.ts +10 -0
  186. package/dist/external-findings-read.d.ts.map +1 -1
  187. package/dist/external-findings-read.js +71 -51
  188. package/dist/external-findings-read.js.map +1 -1
  189. package/dist/external-findings.d.ts +13 -0
  190. package/dist/external-findings.d.ts.map +1 -1
  191. package/dist/external-findings.js +124 -1
  192. package/dist/external-findings.js.map +1 -1
  193. package/dist/external-import-contract.d.ts +29 -1
  194. package/dist/external-import-contract.d.ts.map +1 -1
  195. package/dist/external-import-contract.js +314 -44
  196. package/dist/external-import-contract.js.map +1 -1
  197. package/dist/external-import-models.d.ts +1 -1
  198. package/dist/external-import-models.d.ts.map +1 -1
  199. package/dist/external-import-models.js.map +1 -1
  200. package/dist/finding-normalization.d.ts +1 -1
  201. package/dist/finding-normalization.d.ts.map +1 -1
  202. package/dist/finding-normalization.js +46 -11
  203. package/dist/finding-normalization.js.map +1 -1
  204. package/dist/finding-retrieval.d.ts +3 -3
  205. package/dist/finding-retrieval.d.ts.map +1 -1
  206. package/dist/finding-retrieval.js.map +1 -1
  207. package/dist/finding-workflow.d.ts +6 -1
  208. package/dist/finding-workflow.d.ts.map +1 -1
  209. package/dist/finding-workflow.js +2 -2
  210. package/dist/finding-workflow.js.map +1 -1
  211. package/dist/git-remote.d.ts +4 -0
  212. package/dist/git-remote.d.ts.map +1 -1
  213. package/dist/git-remote.js +20 -0
  214. package/dist/git-remote.js.map +1 -1
  215. package/dist/github-advisories.d.ts +3 -12
  216. package/dist/github-advisories.d.ts.map +1 -1
  217. package/dist/github-advisories.js +9 -29
  218. package/dist/github-advisories.js.map +1 -1
  219. package/dist/github-dependabot-findings.d.ts.map +1 -1
  220. package/dist/github-dependabot-findings.js +7 -16
  221. package/dist/github-dependabot-findings.js.map +1 -1
  222. package/dist/github-findings.d.ts.map +1 -1
  223. package/dist/github-findings.js +344 -56
  224. package/dist/github-findings.js.map +1 -1
  225. package/dist/github.d.ts +17 -7
  226. package/dist/github.d.ts.map +1 -1
  227. package/dist/github.js +43 -30
  228. package/dist/github.js.map +1 -1
  229. package/dist/host-protocol.d.ts +7 -2
  230. package/dist/host-protocol.d.ts.map +1 -1
  231. package/dist/host-protocol.js +27 -3
  232. package/dist/host-protocol.js.map +1 -1
  233. package/dist/host-records-protocol.d.ts +10 -11
  234. package/dist/host-records-protocol.d.ts.map +1 -1
  235. package/dist/host-records-protocol.js +69 -9
  236. package/dist/host-records-protocol.js.map +1 -1
  237. package/dist/hosted-scan.d.ts +15 -0
  238. package/dist/hosted-scan.d.ts.map +1 -1
  239. package/dist/hosted-scan.js +55 -33
  240. package/dist/hosted-scan.js.map +1 -1
  241. package/dist/index.d.ts +8 -0
  242. package/dist/index.d.ts.map +1 -1
  243. package/dist/index.js +7 -0
  244. package/dist/index.js.map +1 -1
  245. package/dist/inspector-findings.d.ts +9 -0
  246. package/dist/inspector-findings.d.ts.map +1 -0
  247. package/dist/inspector-findings.js +512 -0
  248. package/dist/inspector-findings.js.map +1 -0
  249. package/dist/knowledge-base.js +18 -5
  250. package/dist/knowledge-base.js.map +1 -1
  251. package/dist/local-git-metadata.d.ts +5 -0
  252. package/dist/local-git-metadata.d.ts.map +1 -0
  253. package/dist/local-git-metadata.js +131 -0
  254. package/dist/local-git-metadata.js.map +1 -0
  255. package/dist/multiscan.d.ts.map +1 -1
  256. package/dist/multiscan.js +22 -12
  257. package/dist/multiscan.js.map +1 -1
  258. package/dist/opengrep-findings.d.ts.map +1 -1
  259. package/dist/opengrep-findings.js +34 -20
  260. package/dist/opengrep-findings.js.map +1 -1
  261. package/dist/patch-tui.d.ts +1 -1
  262. package/dist/patch-tui.d.ts.map +1 -1
  263. package/dist/patch-tui.js +94 -36
  264. package/dist/patch-tui.js.map +1 -1
  265. package/dist/private-finding-import.d.ts +246 -0
  266. package/dist/private-finding-import.d.ts.map +1 -0
  267. package/dist/private-finding-import.js +387 -0
  268. package/dist/private-finding-import.js.map +1 -0
  269. package/dist/project-config.d.ts.map +1 -1
  270. package/dist/project-config.js +2 -2
  271. package/dist/project-config.js.map +1 -1
  272. package/dist/provider-profile.d.ts +10 -2
  273. package/dist/provider-profile.d.ts.map +1 -1
  274. package/dist/provider-profile.js +72 -10
  275. package/dist/provider-profile.js.map +1 -1
  276. package/dist/publication.js +7 -1
  277. package/dist/publication.js.map +1 -1
  278. package/dist/reader-selection.d.ts +13 -0
  279. package/dist/reader-selection.d.ts.map +1 -0
  280. package/dist/reader-selection.js +81 -0
  281. package/dist/reader-selection.js.map +1 -0
  282. package/dist/record.d.ts +6 -1
  283. package/dist/record.d.ts.map +1 -1
  284. package/dist/record.js +53 -2
  285. package/dist/record.js.map +1 -1
  286. package/dist/remediation.d.ts +5 -0
  287. package/dist/remediation.d.ts.map +1 -1
  288. package/dist/remediation.js +30 -0
  289. package/dist/remediation.js.map +1 -1
  290. package/dist/result.d.ts +2 -0
  291. package/dist/result.d.ts.map +1 -1
  292. package/dist/result.js +3 -1
  293. package/dist/result.js.map +1 -1
  294. package/dist/runtime.d.ts +5 -3
  295. package/dist/runtime.d.ts.map +1 -1
  296. package/dist/runtime.js +110 -57
  297. package/dist/runtime.js.map +1 -1
  298. package/dist/scan-activity.js +40 -17
  299. package/dist/scan-activity.js.map +1 -1
  300. package/dist/scan-comparison.d.ts +1 -1
  301. package/dist/scan-comparison.d.ts.map +1 -1
  302. package/dist/scan-comparison.js +11 -13
  303. package/dist/scan-comparison.js.map +1 -1
  304. package/dist/scan-dashboard.d.ts +1 -0
  305. package/dist/scan-dashboard.d.ts.map +1 -1
  306. package/dist/scan-dashboard.js +37 -48
  307. package/dist/scan-dashboard.js.map +1 -1
  308. package/dist/scan-executor.d.ts +2 -0
  309. package/dist/scan-executor.d.ts.map +1 -1
  310. package/dist/scan-executor.js.map +1 -1
  311. package/dist/scan-history-renderer.d.ts.map +1 -1
  312. package/dist/scan-history-renderer.js +22 -9
  313. package/dist/scan-history-renderer.js.map +1 -1
  314. package/dist/scan-logs.d.ts.map +1 -1
  315. package/dist/scan-logs.js +5 -5
  316. package/dist/scan-logs.js.map +1 -1
  317. package/dist/scanner-import.d.ts +48 -3
  318. package/dist/scanner-import.d.ts.map +1 -1
  319. package/dist/scanner-import.js +214 -39
  320. package/dist/scanner-import.js.map +1 -1
  321. package/dist/scanner-repository-url.d.ts +14 -0
  322. package/dist/scanner-repository-url.d.ts.map +1 -0
  323. package/dist/scanner-repository-url.js +67 -0
  324. package/dist/scanner-repository-url.js.map +1 -0
  325. package/dist/semgrep-findings.d.ts.map +1 -1
  326. package/dist/semgrep-findings.js +50 -88
  327. package/dist/semgrep-findings.js.map +1 -1
  328. package/dist/semgrep-platform-findings.d.ts +12 -0
  329. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  330. package/dist/semgrep-platform-findings.js +198 -0
  331. package/dist/semgrep-platform-findings.js.map +1 -0
  332. package/dist/severity-rubric.d.ts +20 -0
  333. package/dist/severity-rubric.d.ts.map +1 -0
  334. package/dist/severity-rubric.js +73 -0
  335. package/dist/severity-rubric.js.map +1 -0
  336. package/dist/severity-store.js +15 -5
  337. package/dist/severity-store.js.map +1 -1
  338. package/dist/snyk-findings.d.ts.map +1 -1
  339. package/dist/snyk-findings.js +97 -106
  340. package/dist/snyk-findings.js.map +1 -1
  341. package/dist/sonar-collector.d.ts +16 -0
  342. package/dist/sonar-collector.d.ts.map +1 -0
  343. package/dist/sonar-collector.js +383 -0
  344. package/dist/sonar-collector.js.map +1 -0
  345. package/dist/sonar-findings.d.ts +49 -0
  346. package/dist/sonar-findings.d.ts.map +1 -0
  347. package/dist/sonar-findings.js +288 -0
  348. package/dist/sonar-findings.js.map +1 -0
  349. package/dist/sonar-import.d.ts +111 -0
  350. package/dist/sonar-import.d.ts.map +1 -0
  351. package/dist/sonar-import.js +279 -0
  352. package/dist/sonar-import.js.map +1 -0
  353. package/dist/suggest-owners.d.ts.map +1 -1
  354. package/dist/suggest-owners.js +2 -1
  355. package/dist/suggest-owners.js.map +1 -1
  356. package/dist/targets.d.ts +3 -0
  357. package/dist/targets.d.ts.map +1 -1
  358. package/dist/targets.js +18 -12
  359. package/dist/targets.js.map +1 -1
  360. package/dist/terminal-columns.d.ts +4 -0
  361. package/dist/terminal-columns.d.ts.map +1 -0
  362. package/dist/terminal-columns.js +19 -0
  363. package/dist/terminal-columns.js.map +1 -0
  364. package/dist/validation-records.d.ts +0 -3
  365. package/dist/validation-records.d.ts.map +1 -1
  366. package/dist/validation-records.js +0 -16
  367. package/dist/validation-records.js.map +1 -1
  368. package/dist/veracode-findings.d.ts +7 -0
  369. package/dist/veracode-findings.d.ts.map +1 -0
  370. package/dist/veracode-findings.js +371 -0
  371. package/dist/veracode-findings.js.map +1 -0
  372. package/dist/windows-path.d.ts.map +1 -1
  373. package/dist/windows-path.js +1 -0
  374. package/dist/windows-path.js.map +1 -1
  375. package/dist/wiz-csv.d.ts +2 -2
  376. package/dist/wiz-csv.d.ts.map +1 -1
  377. package/dist/wiz-csv.js +1 -3
  378. package/dist/wiz-csv.js.map +1 -1
  379. package/dist/wiz-findings.d.ts +10 -2
  380. package/dist/wiz-findings.d.ts.map +1 -1
  381. package/dist/wiz-findings.js +88 -49
  382. package/dist/wiz-findings.js.map +1 -1
  383. package/docs/classify-severity-records.md +1 -1
  384. package/docs/cli.md +320 -481
  385. package/docs/dedupe-records.md +27 -4
  386. package/docs/findings-service.md +21 -8
  387. package/docs/hosted-scans.md +16 -1
  388. package/package.json +9 -10
  389. package/schemas/external-findings.schema.json +12 -1
  390. package/schemas/hosted-scan-v2.fixture.json +16 -1
  391. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  392. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  393. package/dist/deduplication/records-protocol.d.ts +0 -4
  394. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  395. package/dist/deduplication/records-protocol.js +0 -35
  396. package/dist/deduplication/records-protocol.js.map +0 -1
@@ -17,7 +17,7 @@ import tempfile
17
17
  import time
18
18
  import uuid
19
19
  from collections.abc import Callable
20
- from contextlib import closing, contextmanager, nullcontext
20
+ from contextlib import ExitStack, closing, contextmanager, nullcontext
21
21
  from datetime import datetime, timedelta, timezone
22
22
  from functools import partial
23
23
  from pathlib import Path, PurePosixPath
@@ -43,7 +43,6 @@ import workbench_remediation as remediation_state
43
43
  import workbench_saved_results as saved_results
44
44
  import workbench_scan_history as scan_history
45
45
  import workbench_scan_usage as scan_usage
46
- from deep_scan_config import resolve_deep_scan_setup
47
46
  from finalize_scan_contract import (
48
47
  PRODUCER_NAME,
49
48
  ContractError,
@@ -62,9 +61,6 @@ from workbench_constants import (
62
61
  ARTIFACTS,
63
62
  CLAIM_LEASE_SECONDS,
64
63
  DELIVERED_ACTION_LEASE_SECONDS,
65
- DIFF_TARGET_KINDS,
66
- EMPTY_GIT_TREE,
67
- EMPTY_GIT_TREES,
68
64
  FINDING_ABSOLUTE_PATH_BYTES,
69
65
  FINDING_LEVEL_BYTES,
70
66
  FINDING_LOCATION_PATH_BYTES,
@@ -81,7 +77,6 @@ from workbench_constants import (
81
77
  from workbench_feedback import get_scan_feedback
82
78
  from workbench_finding_index import index_findings
83
79
  from workbench_finding_workflows import finding_workflow, register_workflow_scan
84
- from workbench_local_dedupe import local_dedupe
85
80
  from workbench_scan_start import (
86
81
  archive_scan,
87
82
  insert_running_scan,
@@ -96,6 +91,17 @@ from workbench_schema import (
96
91
  from workbench_schema import (
97
92
  apply_migrations as apply_schema_migrations,
98
93
  )
94
+ from workbench_setup import (
95
+ inspect_command,
96
+ inspect_selected_setup,
97
+ inspect_setup_values,
98
+ require_diff_target,
99
+ require_review_changes_target,
100
+ require_scannable_target,
101
+ require_scope,
102
+ require_target,
103
+ resolve_git_commit,
104
+ )
99
105
  from workbench_source_excerpt import finding_source_excerpt
100
106
  from workbench_source_scopes import (
101
107
  capture_source_scopes,
@@ -108,10 +114,10 @@ from workbench_target import (
108
114
  clean_worktree_content_digest,
109
115
  copy_directory_excluding,
110
116
  copy_git_worktree_files,
117
+ diff_scope_file_count,
111
118
  diff_snapshot_digest,
112
119
  directory_content_digest,
113
120
  directory_snapshot_regular_file_count,
114
- git_bytes,
115
121
  git_command,
116
122
  git_output,
117
123
  git_revision,
@@ -119,7 +125,6 @@ from workbench_target import (
119
125
  git_target_metadata,
120
126
  git_worktree_context,
121
127
  remediation_checkout_snapshot,
122
- require_git_worktree_head,
123
128
  require_remediation_target,
124
129
  require_scan_target_identity,
125
130
  require_scan_target_unchanged,
@@ -267,168 +272,6 @@ def apply_migrations(connection: sqlite3.Connection, *, immediate: bool = False)
267
272
  )
268
273
 
269
274
 
270
- def require_target(value: str) -> Path:
271
- expanded = Path(value).expanduser()
272
- if not expanded.is_absolute():
273
- raise SystemExit("Scan target must be an absolute local directory path.")
274
- target = expanded.resolve()
275
- if not target.is_dir():
276
- raise SystemExit(f"Scan target is not a readable local directory: {target}")
277
- return target
278
-
279
-
280
- def inspect_target(target_path: str) -> dict[str, Any]:
281
- target = require_target(target_path)
282
- return {
283
- "displayName": target.name,
284
- "targetMetadata": git_target_metadata(target),
285
- "targetPath": str(target),
286
- }
287
-
288
-
289
- def resolve_git_commit(target: Path, revision: str, label: str) -> str:
290
- value = optional_text(revision, maximum=512)
291
- if not value:
292
- raise SystemExit(f"{label} is required.")
293
- resolved = git_output(
294
- target,
295
- "rev-parse",
296
- "--verify",
297
- "--end-of-options",
298
- f"{value}^{{commit}}",
299
- )
300
- if resolved is None:
301
- raise SystemExit(f"{label} does not resolve to a local Git commit: {value}")
302
- return resolved
303
-
304
-
305
- def require_diff_target(
306
- target: Path,
307
- kind: str | None,
308
- base_revision: str | None,
309
- head_revision: str | None,
310
- content_digest: str | None,
311
- ) -> dict[str, str]:
312
- current_head = require_review_changes_target(target)
313
- if kind not in DIFF_TARGET_KINDS:
314
- raise SystemExit("Choose which Git changes to review before starting a diff scan.")
315
- if kind == "working_tree":
316
- base = resolve_git_commit(target, base_revision or "HEAD", "Working-tree base")
317
- head = resolve_git_commit(target, head_revision or current_head, "Working-tree HEAD")
318
- current_digest = worktree_content_digest(target)
319
- if base != current_head or head != current_head:
320
- raise SystemExit(
321
- "Repository HEAD changed after these working-tree changes were selected. "
322
- "Select Uncommitted changes again."
323
- )
324
- if content_digest and content_digest != current_digest:
325
- raise SystemExit(
326
- "Working-tree contents changed after they were selected. "
327
- "Select Uncommitted changes again."
328
- )
329
- return {
330
- "kind": kind,
331
- "baseRevision": current_head,
332
- "headRevision": current_head,
333
- "contentDigest": current_digest,
334
- }
335
- if kind == "commit":
336
- head = resolve_git_commit(target, head_revision or "", "Commit")
337
- commit = git_bytes(target, "cat-file", "-p", head)
338
- if commit is None:
339
- raise SystemExit(f"Commit is not available in the local checkout: {head}")
340
- parent_line = next(
341
- (
342
- line
343
- for line in commit.split(b"\n\n", 1)[0].splitlines()
344
- if line.startswith(b"parent ")
345
- ),
346
- None,
347
- )
348
- if parent_line is None:
349
- parent = EMPTY_GIT_TREES[git_output(target, "rev-parse", "--show-object-format")]
350
- else:
351
- parent = resolve_git_commit(
352
- target,
353
- parent_line.removeprefix(b"parent ").decode("ascii").strip(),
354
- "Commit parent",
355
- )
356
- if base_revision and base_revision != parent:
357
- supplied_base = (
358
- base_revision
359
- if base_revision == EMPTY_GIT_TREE
360
- else resolve_git_commit(target, base_revision, "Commit base")
361
- )
362
- if supplied_base != parent:
363
- raise SystemExit("Commit base revision must match the selected commit's parent.")
364
- return {"kind": kind, "baseRevision": parent, "headRevision": head}
365
- base = resolve_git_commit(target, base_revision or "", "Base revision")
366
- head = resolve_git_commit(target, head_revision or "", "Head revision")
367
- if base == head:
368
- raise SystemExit("Base and head revisions must identify different commits.")
369
- return {"kind": kind, "baseRevision": base, "headRevision": head}
370
-
371
-
372
- def inspect_setup_values(
373
- target_path: str,
374
- scope: str,
375
- mode: str,
376
- diff_target_kind: str | None,
377
- diff_base_revision: str | None,
378
- diff_head_revision: str | None,
379
- diff_content_digest: str | None,
380
- ) -> dict[str, Any]:
381
- target = require_target(target_path)
382
- require_scannable_target(target)
383
- normalized_scope = require_scope(scope, mode, target)
384
- if mode == "diff" and normalized_scope != ".":
385
- raise SystemExit("Review changes requires the whole target; use scope '.'.")
386
- if mode != "diff" and any(
387
- value is not None
388
- for value in (
389
- diff_target_kind,
390
- diff_base_revision,
391
- diff_head_revision,
392
- diff_content_digest,
393
- )
394
- ):
395
- raise SystemExit("A Git diff target requires Review changes mode.")
396
- diff_target = (
397
- require_diff_target(
398
- target,
399
- diff_target_kind,
400
- diff_base_revision,
401
- diff_head_revision,
402
- diff_content_digest,
403
- )
404
- if mode == "diff"
405
- else None
406
- )
407
- return {
408
- "diffTarget": diff_target,
409
- "scope": normalized_scope,
410
- "target": inspect_target(str(target)),
411
- }
412
-
413
-
414
- def require_review_changes_target(target: Path) -> str:
415
- revision = require_git_worktree_head(target)
416
- repository_root = git_output(target, "rev-parse", "--show-toplevel")
417
- if repository_root is None or not Path(repository_root).samefile(target):
418
- raise SystemExit(
419
- "Review changes requires the checked-out Git repository root as the target."
420
- )
421
- return revision
422
-
423
-
424
- def require_scannable_target(target: Path) -> None:
425
- metadata = git_target_metadata(target)
426
- if metadata["isGit"] and not metadata["isWorktree"]:
427
- raise SystemExit(
428
- "Codex Security requires a checked-out worktree, not a bare Git repository."
429
- )
430
-
431
-
432
275
  def requested_scan_file_paths(scan: sqlite3.Row) -> list[str]:
433
276
  # Older scans did not record path kinds. Retain their lexical scope semantics
434
277
  # rather than infer the original target from a possibly changed checkout.
@@ -609,30 +452,6 @@ def verify_manifest_binding(scan: sqlite3.Row, manifest: dict[str, Any]) -> None
609
452
  raise SystemExit("scan-manifest.json scope must stay inside the workbench scan scope.")
610
453
 
611
454
 
612
- def require_scope(scope: str, mode: str, target: Path) -> str:
613
- value = scope if scope.strip() else "."
614
- requested_scope = Path(value)
615
- if "\\" in value and (os.name != "nt" or not requested_scope.is_absolute()):
616
- raise SystemExit("Scan scope must use repository-relative POSIX paths.")
617
- if ".." in requested_scope.parts:
618
- raise SystemExit("Scan scope must stay inside the scanned target.")
619
- try:
620
- resolved_scope = (
621
- requested_scope if requested_scope.is_absolute() else target / requested_scope
622
- ).resolve()
623
- relative_scope = resolved_scope.relative_to(target)
624
- except (RuntimeError, ValueError) as exc:
625
- raise SystemExit("Scan scope must stay inside the scanned target.") from exc
626
- normalized = relative_scope.as_posix() or "."
627
- if not normalized.strip():
628
- normalized = "./" + normalized
629
- if mode == "deep" and normalized != ".":
630
- raise SystemExit("Deep Scan is repository-wide and cannot use a scoped path.")
631
- if not resolved_scope.is_dir():
632
- raise SystemExit("Scan scope must reference an existing directory inside the target.")
633
- return normalized
634
-
635
-
636
455
  def require_workspace(connection: sqlite3.Connection, workspace_id: str) -> sqlite3.Row:
637
456
  workspace_id = require_uuid(workspace_id, "workspace-id")
638
457
  row = connection.execute("SELECT * FROM workspaces WHERE id = ?", (workspace_id,)).fetchone()
@@ -740,25 +559,6 @@ def create_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -
740
559
  return workspace_state(connection, workspace_id)
741
560
 
742
561
 
743
- def inspect_selected_setup(args: argparse.Namespace) -> dict[str, Any]:
744
- inspected = inspect_setup_values(
745
- args.target_path,
746
- args.scope,
747
- args.mode,
748
- args.diff_target_kind,
749
- args.diff_base_revision,
750
- args.diff_head_revision,
751
- args.diff_content_digest,
752
- )
753
- if args.mode == "deep":
754
- inspected["deepScanConfig"] = resolve_deep_scan_setup(
755
- os.cpu_count() or 1, args.deep_scan_project_json
756
- )
757
- elif args.deep_scan_project_json is not None:
758
- raise SystemExit("Project Deep Scan settings require Deep Scan mode.")
759
- return inspected
760
-
761
-
762
562
  def save_workspace(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
763
563
  workspace = require_workspace(connection, args.workspace_id)
764
564
  if workspace["active_scan_id"]:
@@ -820,6 +620,29 @@ def scan_target_root(scan_root: str | None, target: Path) -> Path:
820
620
  return target_root
821
621
 
822
622
 
623
+ def scan_scope_file_count(
624
+ target: Path, paths: list[str], diff_target: dict[str, str] | None
625
+ ) -> int | None:
626
+ if diff_target is not None:
627
+ return diff_scope_file_count(target, diff_target)
628
+ return sum(
629
+ 1 if (target / path).is_file() else directory_snapshot_regular_file_count(target / path)
630
+ for path in paths
631
+ )
632
+
633
+
634
+ def require_working_tree_unchanged(target: Path, diff_target: dict[str, str] | None) -> None:
635
+ if (
636
+ diff_target is not None
637
+ and diff_target["kind"] == "working_tree"
638
+ and (
639
+ git_revision(target) != diff_target["headRevision"]
640
+ or worktree_content_digest(target) != diff_target["contentDigest"]
641
+ )
642
+ ):
643
+ raise SystemExit("The selected scan target changed while the scan was starting. Try again.")
644
+
645
+
823
646
  def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict[str, Any]:
824
647
  workspace_id = require_uuid(args.workspace_id, "workspace-id")
825
648
  manages_transaction = not connection.in_transaction
@@ -858,9 +681,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
858
681
  )
859
682
  if diff_target is not None and not target_summary:
860
683
  target_summary = diff_target_summary(diff_target)
861
- scope_file_count = directory_snapshot_regular_file_count(
862
- target if scope == "." else target / scope
863
- )
684
+ scope_file_count = scan_scope_file_count(target, [scope], diff_target)
864
685
  target_identity = scan_target_identity(
865
686
  target,
866
687
  diff_target,
@@ -874,6 +695,7 @@ def start_scan(connection: sqlite3.Connection, args: argparse.Namespace) -> dict
874
695
  )
875
696
  target_root = scan_target_root(args.scan_root, target)
876
697
  create_private_directory(target_root)
698
+ require_working_tree_unchanged(target, diff_target)
877
699
  if manages_transaction:
878
700
  connection.execute("BEGIN IMMEDIATE")
879
701
  workspace = require_workspace(connection, workspace_id)
@@ -960,9 +782,7 @@ def _start_prompt_driven_scan(
960
782
  target_summary = optional_text(args.target_summary, maximum=2400)
961
783
  if diff_target is not None and not target_summary:
962
784
  target_summary = diff_target_summary(diff_target)
963
- scope_file_count = directory_snapshot_regular_file_count(
964
- target if scope == "." else target / scope
965
- )
785
+ scope_file_count = scan_scope_file_count(target, [scope], diff_target)
966
786
  diff_identity = scan_diff_identity(diff_target)
967
787
  target_identity = scan_target_identity(target, diff_target)
968
788
  source_scopes = capture_source_scopes(
@@ -1468,14 +1288,24 @@ def complete_scan_locked(
1468
1288
  )
1469
1289
  warnings.extend(warning for warning in prepared.warnings if warning not in warnings)
1470
1290
  add_warning()
1471
- if warnings != json.loads(scan["completion_warnings_json"]):
1472
- # Persist all observed warnings before output writes can fail, so
1473
- # stopped-result publication and retries retain those diagnostics.
1474
- with connection:
1291
+ with connection:
1292
+ if warnings != json.loads(scan["completion_warnings_json"]):
1293
+ # Retain pre-publication diagnostics even if output writes fail.
1475
1294
  connection.execute(
1476
1295
  "UPDATE scans SET completion_warnings_json = ? WHERE id = ? AND status = 'running'",
1477
1296
  (json.dumps(warnings), scan_id),
1478
1297
  )
1298
+ prepared_scan = prepared.manifest["scan"]
1299
+ if scan["mode"] == "deep" and (
1300
+ not prepared.was_sealed
1301
+ or "coverageRef" in prepared_scan
1302
+ or "surfaces" in prepared_scan.get("reviewState", {})
1303
+ ):
1304
+ # A summary-only seal omits surfaces. Keep the count from its first preparation.
1305
+ connection.execute(
1306
+ "UPDATE deep_scan_runs SET terminal_reviewed_surface_count = ? WHERE scan_id = ?",
1307
+ (len(prepared.coverage["surfaces"]), scan_id),
1308
+ )
1479
1309
  wrote = True
1480
1310
  manifest, findings, _ = _write_prepared_scan_finalization(
1481
1311
  prepared, projection_warnings=warnings
@@ -1657,16 +1487,8 @@ def register_cli_scan(
1657
1487
  paths or ["."],
1658
1488
  diff_target_kind=diff_target["kind"] if diff_target is not None else None,
1659
1489
  )
1660
- scope_file_count = (
1661
- directory_snapshot_regular_file_count(repository)
1662
- if not paths
1663
- else sum(
1664
- 1
1665
- if (repository / path).is_file()
1666
- else directory_snapshot_regular_file_count(repository / path)
1667
- for path in paths
1668
- )
1669
- )
1490
+ scope_file_count = scan_scope_file_count(repository, paths or ["."], diff_target)
1491
+ require_working_tree_unchanged(repository, diff_target)
1670
1492
  parent_scan_id = (
1671
1493
  require_uuid(args.parent_scan_id, "parent-scan-id")
1672
1494
  if args.parent_scan_id is not None
@@ -1678,18 +1500,43 @@ def register_cli_scan(
1678
1500
 
1679
1501
  connection.execute("BEGIN IMMEDIATE")
1680
1502
  try:
1681
- if scan_dir is None:
1682
- # Host archiving temporarily removes the output directory. Wait for
1683
- # the existing writer before inspecting its replacement.
1684
- scan_dir = require_cli_scan_directory(repository, args)
1685
- with archive_scan(
1686
- connection,
1687
- args,
1688
- scan_dir,
1689
- timestamp,
1690
- require_canonical_scan_directory,
1691
- before_archive=before_archive,
1692
- ) as archived_scan_dir:
1503
+ with ExitStack() as archive:
1504
+ deadline = None
1505
+ while True:
1506
+ if scan_dir is None:
1507
+ # Wait for any previous archive to finish before inspecting its replacement.
1508
+ scan_dir = require_cli_scan_directory(repository, args)
1509
+ try:
1510
+ archived_scan_dir = archive.enter_context(
1511
+ archive_scan(
1512
+ connection,
1513
+ args,
1514
+ scan_dir,
1515
+ timestamp,
1516
+ require_canonical_scan_directory,
1517
+ before_archive=before_archive,
1518
+ )
1519
+ )
1520
+ break
1521
+ except PermissionError as exc:
1522
+ # A Windows patch writer can temporarily pin the source of this rename.
1523
+ if (
1524
+ getattr(exc, "winerror", None) not in {5, 32}
1525
+ or exc.filename != str(scan_dir)
1526
+ or not exc.filename2
1527
+ ):
1528
+ raise
1529
+ if deadline is None:
1530
+ timeout = connection.execute("PRAGMA busy_timeout").fetchone()[0]
1531
+ deadline = time.monotonic() + timeout / 1000
1532
+ remaining = deadline - time.monotonic()
1533
+ if remaining <= 0:
1534
+ raise
1535
+ connection.rollback()
1536
+ before_archive = None # The host already acknowledged this registration.
1537
+ scan_dir = None # Revalidate the directory and its owner under the next lock.
1538
+ time.sleep(min(0.05, remaining))
1539
+ connection.execute("BEGIN IMMEDIATE")
1693
1540
  target_id = ensure_security_target(connection, str(repository))
1694
1541
  if parent_scan_id is not None:
1695
1542
  parent = require_scan(connection, parent_scan_id)
@@ -1875,16 +1722,7 @@ def set_finding_triage(connection: sqlite3.Connection, args: argparse.Namespace)
1875
1722
  timestamp = now()
1876
1723
  occurrence = require_occurrence(connection, args.occurrence_id)
1877
1724
  if args.status == "closed":
1878
- remediation = connection.execute(
1879
- """
1880
- SELECT *
1881
- FROM finding_remediation_attempts
1882
- WHERE occurrence_id = ?
1883
- ORDER BY created_at DESC, rowid DESC
1884
- LIMIT 1
1885
- """,
1886
- (occurrence["id"],),
1887
- ).fetchone()
1725
+ remediation = remediation_state.latest_attempt(connection, occurrence["id"])
1888
1726
  if (
1889
1727
  remediation is not None
1890
1728
  and remediation["pending_action"] is not None
@@ -1986,16 +1824,7 @@ def request_finding_remediation(
1986
1824
  raise SystemExit("This remediation request belongs to a different finding.")
1987
1825
  connection.commit()
1988
1826
  return scan_context(connection, occurrence["scan_id"])
1989
- latest = connection.execute(
1990
- """
1991
- SELECT *
1992
- FROM finding_remediation_attempts
1993
- WHERE occurrence_id = ?
1994
- ORDER BY created_at DESC, rowid DESC
1995
- LIMIT 1
1996
- """,
1997
- (occurrence["id"],),
1998
- ).fetchone()
1827
+ latest = remediation_state.latest_attempt(connection, occurrence["id"])
1999
1828
  if latest is not None:
2000
1829
  active_operation = latest["pending_action"] is not None or latest["state"] in {
2001
1830
  "requested",
@@ -2259,27 +2088,22 @@ def set_finding_remediation(
2259
2088
  raise SystemExit("This remediation host request is owned by a different action token.")
2260
2089
  remediation_state.require_transition(current["state"], args.state)
2261
2090
  remediation_state.require_pending_action(current, args.state)
2262
- patch_path = current["patch_path"]
2263
- if args.patch_path is not None:
2264
- requested_patch_path = require_scan_relative_file(scan, args.patch_path)
2265
- if patch_path is not None and requested_patch_path != patch_path:
2266
- raise SystemExit("A remediation attempt cannot replace its reviewed patch path.")
2267
- patch_path = requested_patch_path
2268
- patch_digest = current["patch_digest"]
2269
- if args.patch_digest is not None:
2270
- requested_patch_digest = require_sha256_digest(args.patch_digest, "patch-digest")
2271
- if patch_digest is not None and requested_patch_digest != patch_digest:
2272
- raise SystemExit("A remediation attempt cannot replace its reviewed patch digest.")
2273
- patch_digest = requested_patch_digest
2091
+ patch = sys.stdin.buffer.read() if args.patch_stdin else None
2092
+ patch_path, patch_digest = remediation_state.patch_metadata(
2093
+ current, args, patch, partial(require_scan_relative_file, scan)
2094
+ )
2274
2095
  base_revision = optional_text(args.base_revision, maximum=512)
2275
2096
  if args.state in {"generated", "applied", "verifying", "verified"}:
2276
2097
  if patch_path is None or patch_digest is None:
2277
2098
  raise SystemExit(
2278
2099
  "Generated remediation states require a scan-local patch path and digest."
2279
2100
  )
2280
- require_matching_patch_digest(scan, patch_path, patch_digest)
2101
+ if patch is None:
2102
+ require_matching_patch_digest(scan, patch_path, patch_digest)
2281
2103
  if args.state == "generated":
2282
2104
  require_remediation_checkout_unchanged(scan, current, require_base_content=True)
2105
+ if patch is not None:
2106
+ remediation_state.require_valid_patch(Path(scan["target_path"]), patch)
2283
2107
  if args.state in {"applied", "verifying", "verified"}:
2284
2108
  if base_revision != current["base_revision"]:
2285
2109
  raise SystemExit(
@@ -2300,59 +2124,80 @@ def set_finding_remediation(
2300
2124
  current,
2301
2125
  patch_path,
2302
2126
  )
2303
- connection.execute("BEGIN IMMEDIATE")
2304
- timestamp = now()
2305
- occurrence = require_occurrence(connection, args.occurrence_id)
2306
- require_finding_open(connection, occurrence["id"])
2307
- replace_failure_summary = current["state"] == "failed" and args.state != "failed"
2308
- updated = connection.execute(
2309
- """
2310
- UPDATE finding_remediation_attempts
2311
- SET state = ?, version = version + 1, patch_path = ?, patch_digest = ?,
2312
- applied_content_digest = ?,
2313
- pending_action = CASE
2314
- WHEN ? IN ('verifying', 'failed') THEN pending_action ELSE NULL
2315
- END,
2316
- pending_action_claimed_at = CASE
2317
- WHEN ? = 'verifying' THEN pending_action_claimed_at ELSE NULL
2318
- END,
2319
- pending_action_claim_token = CASE
2320
- WHEN ? = 'verifying' THEN pending_action_claim_token ELSE NULL
2321
- END,
2322
- pending_action_delivered_at = CASE
2323
- WHEN ? = 'verifying' THEN pending_action_delivered_at ELSE NULL
2324
- END,
2325
- summary = CASE WHEN ? THEN ? ELSE COALESCE(?, summary) END,
2326
- verification_summary = COALESCE(?, verification_summary),
2327
- updated_at = ?
2328
- WHERE request_id = ? AND occurrence_id = ? AND version = ?
2329
- AND pending_action_claim_token = ?
2330
- """,
2331
- (
2332
- args.state,
2333
- patch_path,
2334
- patch_digest,
2335
- applied_content_digest,
2336
- args.state,
2337
- args.state,
2338
- args.state,
2339
- args.state,
2340
- replace_failure_summary,
2341
- summary,
2342
- summary,
2343
- verification_summary,
2344
- timestamp,
2345
- request_id,
2346
- occurrence["id"],
2347
- args.expected_version,
2348
- action_token,
2349
- ),
2350
- )
2351
- if updated.rowcount != 1:
2352
- raise SystemExit(
2353
- "This remediation request changed. Refresh it before recording an update."
2127
+
2128
+ def record_update() -> None:
2129
+ connection.execute("BEGIN IMMEDIATE")
2130
+ timestamp = now()
2131
+ occurrence = require_occurrence(connection, args.occurrence_id)
2132
+ require_finding_open(connection, occurrence["id"])
2133
+ replace_failure_summary = current["state"] == "failed" and args.state != "failed"
2134
+ updated = connection.execute(
2135
+ """
2136
+ UPDATE finding_remediation_attempts
2137
+ SET state = ?, version = version + 1, patch_path = ?, patch_digest = ?,
2138
+ applied_content_digest = ?,
2139
+ pending_action = CASE
2140
+ WHEN ? IN ('verifying', 'failed') THEN pending_action ELSE NULL
2141
+ END,
2142
+ pending_action_claimed_at = CASE
2143
+ WHEN ? = 'verifying' THEN pending_action_claimed_at ELSE NULL
2144
+ END,
2145
+ pending_action_claim_token = CASE
2146
+ WHEN ? = 'verifying' THEN pending_action_claim_token ELSE NULL
2147
+ END,
2148
+ pending_action_delivered_at = CASE
2149
+ WHEN ? = 'verifying' THEN pending_action_delivered_at ELSE NULL
2150
+ END,
2151
+ summary = CASE WHEN ? THEN ? ELSE COALESCE(?, summary) END,
2152
+ verification_summary = COALESCE(?, verification_summary),
2153
+ updated_at = ?
2154
+ WHERE request_id = ? AND occurrence_id = ? AND version = ?
2155
+ AND pending_action_claim_token = ?
2156
+ """,
2157
+ (
2158
+ args.state,
2159
+ patch_path,
2160
+ patch_digest,
2161
+ applied_content_digest,
2162
+ args.state,
2163
+ args.state,
2164
+ args.state,
2165
+ args.state,
2166
+ replace_failure_summary,
2167
+ summary,
2168
+ summary,
2169
+ verification_summary,
2170
+ timestamp,
2171
+ request_id,
2172
+ occurrence["id"],
2173
+ args.expected_version,
2174
+ action_token,
2175
+ ),
2354
2176
  )
2355
- return scan_context(connection, occurrence["scan_id"])
2177
+ if updated.rowcount != 1:
2178
+ raise SystemExit(
2179
+ "This remediation request changed. Refresh it before recording an update."
2180
+ )
2181
+
2182
+ if patch is None:
2183
+ record_update()
2184
+ else:
2185
+ try:
2186
+ remediation_state.save_patch(
2187
+ _WORKBENCH_DB_CONTEXT,
2188
+ connection,
2189
+ scan["id"],
2190
+ current,
2191
+ patch_path,
2192
+ patch_digest,
2193
+ patch,
2194
+ record_update,
2195
+ )
2196
+ except (ContractError, OSError, SystemExit) as exc:
2197
+ raise SystemExit(f"Could not save the remediation patch: {exc}") from exc
2198
+ return scan_context(
2199
+ connection, occurrence["scan_id"], occurrence["id"] if patch is not None else None
2200
+ )
2356
2201
 
2357
2202
 
2358
2203
  def require_reviewed_patch_applied(
@@ -2466,20 +2311,6 @@ def require_remediation_checkout_unchanged(
2466
2311
  )
2467
2312
 
2468
2313
 
2469
- def require_sha256_digest(value: str, label: str) -> str:
2470
- normalized = optional_text(value, maximum=71)
2471
- if (
2472
- normalized is None
2473
- or not normalized.startswith("sha256:")
2474
- or len(normalized) != 71
2475
- or any(
2476
- character not in "0123456789abcdef" for character in normalized.removeprefix("sha256:")
2477
- )
2478
- ):
2479
- raise SystemExit(f"{label} must use sha256:<64 lowercase hex characters>.")
2480
- return normalized
2481
-
2482
-
2483
2314
  def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
2484
2315
  if len(value) > 4096:
2485
2316
  raise SystemExit("Text value must be no longer than 4096 characters.")
@@ -2493,11 +2324,7 @@ def require_scan_relative_file(scan: sqlite3.Row, value: str) -> str:
2493
2324
 
2494
2325
 
2495
2326
  def require_matching_patch_digest(scan: sqlite3.Row, patch_path: str, patch_digest: str) -> None:
2496
- digest = hashlib.sha256()
2497
- with open_scan_local_file(Path(scan["scan_dir"]), patch_path) as patch:
2498
- while chunk := patch.read(1024 * 1024):
2499
- digest.update(chunk)
2500
- if f"sha256:{digest.hexdigest()}" != patch_digest:
2327
+ if scan_local_file_digest(Path(scan["scan_dir"]), patch_path) != patch_digest:
2501
2328
  raise SystemExit("Patch digest does not match the scan-local patch file.")
2502
2329
 
2503
2330
 
@@ -2606,7 +2433,11 @@ def scan_context(
2606
2433
  ) -> dict[str, Any]:
2607
2434
  scan = require_scan(connection, scan_id)
2608
2435
  result = scan_result(connection, scan, occurrence_id=occurrence_id)
2609
- workspace_result = result if occurrence_id is None else scan_result(connection, scan)
2436
+ workspace_result = result
2437
+ if len(result["findings"]) > FINDINGS_RESULT_LIMIT:
2438
+ workspace_result = dict(
2439
+ result, findings=result["findings"][:FINDINGS_RESULT_LIMIT], findingsTruncated=True
2440
+ )
2610
2441
  workspace = workspace_state(
2611
2442
  connection,
2612
2443
  scan["workspace_id"],
@@ -2708,11 +2539,12 @@ def scan_result(
2708
2539
  occurrence_rows = scan_history.finding_occurrence_rows(
2709
2540
  connection, scan["id"], offset=0, limit=FINDINGS_RESULT_LIMIT
2710
2541
  )
2711
- if occurrence_id is not None and all(row["id"] != occurrence_id for row in occurrence_rows):
2542
+ if occurrence_id is not None:
2712
2543
  occurrence = require_occurrence(connection, occurrence_id)
2713
2544
  if occurrence["scan_id"] != scan["id"]:
2714
2545
  raise SystemExit("This finding does not belong to the selected scan.")
2715
- occurrence_rows.append(occurrence)
2546
+ if all(row["id"] != occurrence["id"] for row in occurrence_rows):
2547
+ occurrence_rows.append(occurrence)
2716
2548
  finding_count = connection.execute(
2717
2549
  "SELECT COUNT(*) FROM finding_occurrences WHERE scan_id = ?", (scan["id"],)
2718
2550
  ).fetchone()[0]
@@ -3248,10 +3080,8 @@ def require_canonical_scan_directory(scan_dir: Path) -> Path:
3248
3080
  scan_dir
3249
3081
  ):
3250
3082
  raise SystemExit("Scan directory must be an existing canonical non-symlink directory.")
3251
- # Re-check privacy so a shared parent cannot be used to substitute forged artifacts.
3083
+ # Re-check ownership and parents so the scan directory cannot be substituted.
3252
3084
  if os.name != "nt":
3253
- if stat.S_IMODE(metadata.st_mode) & 0o077:
3254
- raise SystemExit("Scan directory must not be accessible to other users (chmod 700).")
3255
3085
  geteuid = getattr(os, "geteuid", None)
3256
3086
  effective_uid = geteuid() if geteuid is not None else None
3257
3087
  if effective_uid is not None and metadata.st_uid != effective_uid:
@@ -3306,12 +3136,8 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3306
3136
  if args.command == "resolve-scan-root":
3307
3137
  print(json.dumps({"scanRoot": str(resolve_scan_root(args.scan_root))}))
3308
3138
  return
3309
- if args.command == "inspect-target":
3310
- result = inspect_target(args.target_path)
3311
- print(json.dumps(result, allow_nan=False, sort_keys=True))
3312
- return
3313
- if args.command == "inspect-setup":
3314
- print(json.dumps(inspect_selected_setup(args), allow_nan=False, sort_keys=True))
3139
+ if args.command in {"inspect-target", "inspect-setup"}:
3140
+ print(json.dumps(inspect_command(args), allow_nan=False, sort_keys=True))
3315
3141
  return
3316
3142
  if args.command in {"save-artifact", "read-artifact"}:
3317
3143
  print(json.dumps(saved_results.read_or_save_artifact(args)))
@@ -3447,8 +3273,6 @@ def main(*, before_archive: Callable[[], None] | None = None) -> None:
3447
3273
  )
3448
3274
  elif args.command == "database-info":
3449
3275
  result = {"databasePath": str(database_path())}
3450
- elif args.command == "local-dedupe":
3451
- result = local_dedupe(connection, json.load(sys.stdin), now())
3452
3276
  elif args.command == "finding-workflow":
3453
3277
  result = finding_workflow(connection, json.load(sys.stdin), now())
3454
3278
  else: