@openai/codex-security 0.1.31 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (514) hide show
  1. package/README.md +442 -2434
  2. package/_bundled_plugin/.app.json +5 -1
  3. package/_bundled_plugin/.codex-plugin/plugin.json +9 -5
  4. package/_bundled_plugin/.mcp.json +3 -0
  5. package/_bundled_plugin/examples/completed-scan/coverage.json +0 -1
  6. package/_bundled_plugin/examples/completed-scan/report.md +28 -26
  7. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +1 -1
  8. package/_bundled_plugin/mcp/helpers.mjs +1 -0
  9. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +7 -214
  11. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  14. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  15. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  16. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  17. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  18. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  19. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +563 -0
  20. package/_bundled_plugin/mcp/server.mjs +1 -0
  21. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  22. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  23. package/_bundled_plugin/preflight/capability-profiles.toml +0 -13
  24. package/_bundled_plugin/references/artifact-storage.md +5 -5
  25. package/_bundled_plugin/references/config-preflight.md +1 -5
  26. package/_bundled_plugin/references/core-scan.md +34 -10
  27. package/_bundled_plugin/references/final-report.md +13 -13
  28. package/_bundled_plugin/references/finding-detail-fields.md +90 -80
  29. package/_bundled_plugin/references/sarif-adapter.md +1 -1
  30. package/_bundled_plugin/references/scan-artifacts.md +3 -4
  31. package/_bundled_plugin/references/scan-contract.md +11 -6
  32. package/_bundled_plugin/references/scan-prologue.md +12 -0
  33. package/_bundled_plugin/references/security-guidance.md +2 -2
  34. package/_bundled_plugin/references/standalone-validation.md +11 -0
  35. package/_bundled_plugin/references/threat-model.md +2 -2
  36. package/_bundled_plugin/schemas/coverage.schema.json +23 -47
  37. package/_bundled_plugin/schemas/definitions/artifact-common.schema.json +2 -24
  38. package/_bundled_plugin/schemas/definitions/discovery-candidate.schema.json +49 -25
  39. package/_bundled_plugin/schemas/findings.schema.json +71 -192
  40. package/_bundled_plugin/schemas/scan-manifest.schema.json +83 -95
  41. package/_bundled_plugin/schemas/tools/candidate-attack-paths.schema.json +91 -83
  42. package/_bundled_plugin/schemas/tools/candidate-validations.schema.json +35 -64
  43. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +5 -2
  44. package/_bundled_plugin/schemas/tools/discovery-candidates.schema.json +6 -55
  45. package/_bundled_plugin/schemas/tools/review-items.schema.json +2 -38
  46. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +245 -356
  47. package/_bundled_plugin/scripts/codex_profile.mjs +239 -0
  48. package/_bundled_plugin/scripts/codex_session.mjs +53 -0
  49. package/_bundled_plugin/scripts/config_preflight.py +29 -69
  50. package/_bundled_plugin/scripts/deep_scan_config.py +9 -11
  51. package/_bundled_plugin/scripts/deep_scan_workbench.py +208 -363
  52. package/_bundled_plugin/scripts/filesystem_identity.py +1 -5
  53. package/_bundled_plugin/scripts/finalize_scan_contract.py +733 -375
  54. package/_bundled_plugin/scripts/finding_preview.py +81 -91
  55. package/_bundled_plugin/scripts/generate_in_scope_files.py +48 -102
  56. package/_bundled_plugin/scripts/generate_rank_input.py +117 -888
  57. package/_bundled_plugin/scripts/launch_codex_security_mcp +35 -6
  58. package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +5 -5
  59. package/_bundled_plugin/scripts/rank_preview.py +43 -902
  60. package/_bundled_plugin/scripts/report_projection.py +143 -219
  61. package/_bundled_plugin/scripts/snapshot_sqlite.py +6 -1
  62. package/_bundled_plugin/scripts/threat_model_projection.py +161 -0
  63. package/_bundled_plugin/scripts/validate_scan_contract.py +4 -34
  64. package/_bundled_plugin/scripts/validate_tracking_source.py +3 -13
  65. package/_bundled_plugin/scripts/windows_scan_local_files.py +59 -9
  66. package/_bundled_plugin/scripts/workbench/handoff.py +25 -50
  67. package/_bundled_plugin/scripts/workbench/runtime_toml.py +22 -0
  68. package/_bundled_plugin/scripts/workbench/storage.py +21 -6
  69. package/_bundled_plugin/scripts/workbench_cli.py +99 -190
  70. package/_bundled_plugin/scripts/workbench_constants.py +6 -14
  71. package/_bundled_plugin/scripts/workbench_db.py +524 -672
  72. package/_bundled_plugin/scripts/workbench_feedback.py +6 -3
  73. package/_bundled_plugin/scripts/workbench_finding_index.py +20 -7
  74. package/_bundled_plugin/scripts/workbench_finding_workflows.py +18 -4
  75. package/_bundled_plugin/scripts/workbench_local_dedupe.py +136 -0
  76. package/_bundled_plugin/scripts/workbench_native_indexes.py +28 -18
  77. package/_bundled_plugin/scripts/workbench_progress.py +26 -92
  78. package/_bundled_plugin/scripts/workbench_publication.py +77 -116
  79. package/_bundled_plugin/scripts/workbench_remediation.py +14 -20
  80. package/_bundled_plugin/scripts/workbench_saved_results.py +1402 -263
  81. package/_bundled_plugin/scripts/workbench_scan_history.py +57 -57
  82. package/_bundled_plugin/scripts/workbench_scan_start.py +109 -52
  83. package/_bundled_plugin/scripts/workbench_scan_usage.py +30 -49
  84. package/_bundled_plugin/scripts/workbench_schema.py +71 -1370
  85. package/_bundled_plugin/scripts/workbench_source_excerpt.py +16 -7
  86. package/_bundled_plugin/scripts/workbench_target.py +526 -150
  87. package/_bundled_plugin/scripts/workbench_target_state.py +1 -5
  88. package/_bundled_plugin/scripts/workbench_validation.py +19 -44
  89. package/_bundled_plugin/shared/workbench-history-repairs.json +218 -0
  90. package/_bundled_plugin/shared/workbench-migrations.json +397 -0
  91. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +15 -4
  92. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -0
  93. package/_bundled_plugin/skills/cloud-findings/SKILL.md +54 -0
  94. package/_bundled_plugin/skills/cloud-findings/agents/openai.yaml +4 -0
  95. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +6 -6
  96. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  97. package/_bundled_plugin/skills/finding-discovery/SKILL.md +3 -3
  98. package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +50 -20
  99. package/_bundled_plugin/skills/security-diff-scan/SKILL.md +8 -14
  100. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  101. package/_bundled_plugin/skills/security-scan/SKILL.md +22 -7
  102. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  103. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +2 -2
  104. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +13 -1
  105. package/_bundled_plugin/skills/threat-model/SKILL.md +2 -2
  106. package/_bundled_plugin/skills/track-findings/SKILL.md +46 -178
  107. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  108. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +16 -24
  109. package/_bundled_plugin/skills/track-findings/references/jira.md +15 -61
  110. package/_bundled_plugin/skills/triage-finding/SKILL.md +50 -289
  111. package/_bundled_plugin/skills/triage-finding/agents/openai.yaml +2 -2
  112. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +23 -43
  113. package/_bundled_plugin/skills/triage-finding/references/triage-result-contract.md +7 -1
  114. package/bin/codex-security.mjs +9 -2
  115. package/dist/api.d.ts +63 -15
  116. package/dist/api.d.ts.map +1 -1
  117. package/dist/api.js +970 -553
  118. package/dist/api.js.map +1 -1
  119. package/dist/artifact-export.d.ts +70 -0
  120. package/dist/artifact-export.d.ts.map +1 -0
  121. package/dist/artifact-export.js +292 -0
  122. package/dist/artifact-export.js.map +1 -0
  123. package/dist/auth.d.ts +2 -6
  124. package/dist/auth.d.ts.map +1 -1
  125. package/dist/auth.js +27 -12
  126. package/dist/auth.js.map +1 -1
  127. package/dist/bulk-scan-discovery.d.ts +1 -0
  128. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  129. package/dist/bulk-scan-discovery.js +9 -9
  130. package/dist/bulk-scan-discovery.js.map +1 -1
  131. package/dist/classify-scan-severity.d.ts.map +1 -1
  132. package/dist/classify-scan-severity.js +2 -5
  133. package/dist/classify-scan-severity.js.map +1 -1
  134. package/dist/classify-severity.d.ts +28 -17
  135. package/dist/classify-severity.d.ts.map +1 -1
  136. package/dist/classify-severity.js +16 -35
  137. package/dist/classify-severity.js.map +1 -1
  138. package/dist/cli-help.d.ts +3 -0
  139. package/dist/cli-help.d.ts.map +1 -0
  140. package/dist/cli-help.js +285 -0
  141. package/dist/cli-help.js.map +1 -0
  142. package/dist/cli-signals.d.ts +8 -0
  143. package/dist/cli-signals.d.ts.map +1 -0
  144. package/dist/cli-signals.js +28 -0
  145. package/dist/cli-signals.js.map +1 -0
  146. package/dist/cli.d.ts +22 -24
  147. package/dist/cli.d.ts.map +1 -1
  148. package/dist/cli.js +1660 -1556
  149. package/dist/cli.js.map +1 -1
  150. package/dist/cloud-publish.d.ts.map +1 -1
  151. package/dist/cloud-publish.js +11 -17
  152. package/dist/cloud-publish.js.map +1 -1
  153. package/dist/codeowners.d.ts +19 -0
  154. package/dist/codeowners.d.ts.map +1 -0
  155. package/dist/codeowners.js +138 -0
  156. package/dist/codeowners.js.map +1 -0
  157. package/dist/codex-prompt.d.ts.map +1 -1
  158. package/dist/codex-prompt.js +1 -2
  159. package/dist/codex-prompt.js.map +1 -1
  160. package/dist/codex-sdk-environment.d.ts +3 -0
  161. package/dist/codex-sdk-environment.d.ts.map +1 -0
  162. package/dist/codex-sdk-environment.js +68 -0
  163. package/dist/codex-sdk-environment.js.map +1 -0
  164. package/dist/component-plan.d.ts +2 -5
  165. package/dist/component-plan.d.ts.map +1 -1
  166. package/dist/component-plan.js +38 -34
  167. package/dist/component-plan.js.map +1 -1
  168. package/dist/component-scan.d.ts +7 -5
  169. package/dist/component-scan.d.ts.map +1 -1
  170. package/dist/component-scan.js +54 -44
  171. package/dist/component-scan.js.map +1 -1
  172. package/dist/config.d.ts.map +1 -1
  173. package/dist/config.js +93 -104
  174. package/dist/config.js.map +1 -1
  175. package/dist/contract.d.ts +15 -2
  176. package/dist/contract.d.ts.map +1 -1
  177. package/dist/contract.js +124 -348
  178. package/dist/contract.js.map +1 -1
  179. package/dist/cost-model.d.ts +13 -6
  180. package/dist/cost-model.d.ts.map +1 -1
  181. package/dist/cost-model.js +75 -34
  182. package/dist/cost-model.js.map +1 -1
  183. package/dist/cost.d.ts +10 -2
  184. package/dist/cost.d.ts.map +1 -1
  185. package/dist/cost.js +116 -134
  186. package/dist/cost.js.map +1 -1
  187. package/dist/custom-validation-prompt.d.ts.map +1 -1
  188. package/dist/custom-validation-prompt.js +7 -6
  189. package/dist/custom-validation-prompt.js.map +1 -1
  190. package/dist/custom-validation.d.ts +1 -2
  191. package/dist/custom-validation.d.ts.map +1 -1
  192. package/dist/custom-validation.js +23 -16
  193. package/dist/custom-validation.js.map +1 -1
  194. package/dist/deduplication/checkpointed-review.d.ts +4 -2
  195. package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
  196. package/dist/deduplication/checkpointed-review.js +33 -20
  197. package/dist/deduplication/checkpointed-review.js.map +1 -1
  198. package/dist/deduplication/codex-review.d.ts +9 -1
  199. package/dist/deduplication/codex-review.d.ts.map +1 -1
  200. package/dist/deduplication/codex-review.js +129 -20
  201. package/dist/deduplication/codex-review.js.map +1 -1
  202. package/dist/deduplication/deduplication-prompts.d.ts +5 -2
  203. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  204. package/dist/deduplication/deduplication-prompts.js +18 -4
  205. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  206. package/dist/deduplication/deduplication-reviewer.d.ts +26 -4
  207. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  208. package/dist/deduplication/deduplication-reviewer.js +59 -47
  209. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  210. package/dist/deduplication/deduplication.d.ts.map +1 -1
  211. package/dist/deduplication/deduplication.js +59 -113
  212. package/dist/deduplication/deduplication.js.map +1 -1
  213. package/dist/deduplication/diagnostics.d.ts +17 -0
  214. package/dist/deduplication/diagnostics.d.ts.map +1 -0
  215. package/dist/deduplication/diagnostics.js +5 -0
  216. package/dist/deduplication/diagnostics.js.map +1 -0
  217. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  218. package/dist/deduplication/finding-schema.js +7 -1
  219. package/dist/deduplication/finding-schema.js.map +1 -1
  220. package/dist/deduplication/local.d.ts +31 -0
  221. package/dist/deduplication/local.d.ts.map +1 -0
  222. package/dist/deduplication/local.js +166 -0
  223. package/dist/deduplication/local.js.map +1 -0
  224. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  225. package/dist/deduplication/records-protocol.js +12 -28
  226. package/dist/deduplication/records-protocol.js.map +1 -1
  227. package/dist/deduplication/records.d.ts +188 -12
  228. package/dist/deduplication/records.d.ts.map +1 -1
  229. package/dist/deduplication/records.js +34 -24
  230. package/dist/deduplication/records.js.map +1 -1
  231. package/dist/deduplication/review.d.ts +7 -0
  232. package/dist/deduplication/review.d.ts.map +1 -1
  233. package/dist/deduplication/review.js.map +1 -1
  234. package/dist/deduplication/scan.d.ts +9 -3
  235. package/dist/deduplication/scan.d.ts.map +1 -1
  236. package/dist/deduplication/scan.js +159 -44
  237. package/dist/deduplication/scan.js.map +1 -1
  238. package/dist/deep-config.d.ts +2 -1
  239. package/dist/deep-config.d.ts.map +1 -1
  240. package/dist/deep-config.js +7 -23
  241. package/dist/deep-config.js.map +1 -1
  242. package/dist/deep-progress.d.ts +2 -1
  243. package/dist/deep-progress.d.ts.map +1 -1
  244. package/dist/deep-progress.js +32 -47
  245. package/dist/deep-progress.js.map +1 -1
  246. package/dist/deep-scan.d.ts +20 -0
  247. package/dist/deep-scan.d.ts.map +1 -0
  248. package/dist/deep-scan.js +113 -0
  249. package/dist/deep-scan.js.map +1 -0
  250. package/dist/errors.d.ts +5 -2
  251. package/dist/errors.d.ts.map +1 -1
  252. package/dist/errors.js +7 -7
  253. package/dist/errors.js.map +1 -1
  254. package/dist/feedback.d.ts.map +1 -1
  255. package/dist/feedback.js +53 -21
  256. package/dist/feedback.js.map +1 -1
  257. package/dist/finding-catalogue.d.ts.map +1 -1
  258. package/dist/finding-catalogue.js +26 -30
  259. package/dist/finding-catalogue.js.map +1 -1
  260. package/dist/finding-normalization.d.ts +5 -0
  261. package/dist/finding-normalization.d.ts.map +1 -0
  262. package/dist/finding-normalization.js +120 -0
  263. package/dist/finding-normalization.js.map +1 -0
  264. package/dist/finding-retrieval.d.ts +9 -0
  265. package/dist/finding-retrieval.d.ts.map +1 -1
  266. package/dist/finding-retrieval.js.map +1 -1
  267. package/dist/finding-workflow.d.ts +13 -8
  268. package/dist/finding-workflow.d.ts.map +1 -1
  269. package/dist/finding-workflow.js +18 -13
  270. package/dist/finding-workflow.js.map +1 -1
  271. package/dist/findings-client.d.ts +2 -1
  272. package/dist/findings-client.d.ts.map +1 -1
  273. package/dist/findings-client.js +36 -9
  274. package/dist/findings-client.js.map +1 -1
  275. package/dist/findings-errors.d.ts +16 -0
  276. package/dist/findings-errors.d.ts.map +1 -0
  277. package/dist/findings-errors.js +24 -0
  278. package/dist/findings-errors.js.map +1 -0
  279. package/dist/findings-import.d.ts +1 -1
  280. package/dist/findings-import.d.ts.map +1 -1
  281. package/dist/findings-import.js +16 -44
  282. package/dist/findings-import.js.map +1 -1
  283. package/dist/github.d.ts.map +1 -1
  284. package/dist/github.js +9 -4
  285. package/dist/github.js.map +1 -1
  286. package/dist/import-scan.d.ts.map +1 -1
  287. package/dist/import-scan.js +49 -39
  288. package/dist/import-scan.js.map +1 -1
  289. package/dist/index.d.ts +11 -5
  290. package/dist/index.d.ts.map +1 -1
  291. package/dist/index.js +2 -1
  292. package/dist/index.js.map +1 -1
  293. package/dist/knowledge-base.d.ts +7 -1
  294. package/dist/knowledge-base.d.ts.map +1 -1
  295. package/dist/knowledge-base.js +115 -47
  296. package/dist/knowledge-base.js.map +1 -1
  297. package/dist/linear.d.ts.map +1 -1
  298. package/dist/linear.js +4 -10
  299. package/dist/linear.js.map +1 -1
  300. package/dist/mock-scan.d.ts.map +1 -1
  301. package/dist/mock-scan.js +0 -1
  302. package/dist/mock-scan.js.map +1 -1
  303. package/dist/models.d.ts +24 -2
  304. package/dist/models.d.ts.map +1 -1
  305. package/dist/models.js.map +1 -1
  306. package/dist/multiscan.d.ts +9 -3
  307. package/dist/multiscan.d.ts.map +1 -1
  308. package/dist/multiscan.js +225 -153
  309. package/dist/multiscan.js.map +1 -1
  310. package/dist/owner-evidence.d.ts +10 -2
  311. package/dist/owner-evidence.d.ts.map +1 -1
  312. package/dist/owner-evidence.js +69 -14
  313. package/dist/owner-evidence.js.map +1 -1
  314. package/dist/patch-tui.d.ts.map +1 -1
  315. package/dist/patch-tui.js +5 -6
  316. package/dist/patch-tui.js.map +1 -1
  317. package/dist/project-config-schema.d.ts +10 -0
  318. package/dist/project-config-schema.d.ts.map +1 -1
  319. package/dist/project-config-schema.js +1 -0
  320. package/dist/project-config-schema.js.map +1 -1
  321. package/dist/project-config.d.ts +1 -0
  322. package/dist/project-config.d.ts.map +1 -1
  323. package/dist/project-config.js +5 -3
  324. package/dist/project-config.js.map +1 -1
  325. package/dist/prompt-files.d.ts +0 -1
  326. package/dist/prompt-files.d.ts.map +1 -1
  327. package/dist/prompt-files.js +2 -4
  328. package/dist/prompt-files.js.map +1 -1
  329. package/dist/provider-profile.d.ts +21 -0
  330. package/dist/provider-profile.d.ts.map +1 -0
  331. package/dist/provider-profile.js +133 -0
  332. package/dist/provider-profile.js.map +1 -0
  333. package/dist/publication-events.d.ts +6 -8
  334. package/dist/publication-events.d.ts.map +1 -1
  335. package/dist/publication-events.js +40 -79
  336. package/dist/publication-events.js.map +1 -1
  337. package/dist/publication-store.d.ts.map +1 -1
  338. package/dist/publication-store.js +48 -76
  339. package/dist/publication-store.js.map +1 -1
  340. package/dist/publication.d.ts +1 -2
  341. package/dist/publication.d.ts.map +1 -1
  342. package/dist/publication.js +7 -16
  343. package/dist/publication.js.map +1 -1
  344. package/dist/publish.d.ts +1 -5
  345. package/dist/publish.d.ts.map +1 -1
  346. package/dist/publish.js +138 -199
  347. package/dist/publish.js.map +1 -1
  348. package/dist/record.d.ts +2 -0
  349. package/dist/record.d.ts.map +1 -0
  350. package/dist/record.js +4 -0
  351. package/dist/record.js.map +1 -0
  352. package/dist/request-metadata.d.ts +9 -0
  353. package/dist/request-metadata.d.ts.map +1 -0
  354. package/dist/request-metadata.js +13 -0
  355. package/dist/request-metadata.js.map +1 -0
  356. package/dist/result.d.ts +4 -1
  357. package/dist/result.d.ts.map +1 -1
  358. package/dist/result.js +7 -0
  359. package/dist/result.js.map +1 -1
  360. package/dist/runtime.d.ts +25 -17
  361. package/dist/runtime.d.ts.map +1 -1
  362. package/dist/runtime.js +619 -255
  363. package/dist/runtime.js.map +1 -1
  364. package/dist/saved-scan-bootstrap.d.ts +14 -0
  365. package/dist/saved-scan-bootstrap.d.ts.map +1 -0
  366. package/dist/saved-scan-bootstrap.js +261 -0
  367. package/dist/saved-scan-bootstrap.js.map +1 -0
  368. package/dist/saved-scan.d.ts +1 -1
  369. package/dist/saved-scan.d.ts.map +1 -1
  370. package/dist/saved-scan.js +16 -32
  371. package/dist/saved-scan.js.map +1 -1
  372. package/dist/scan-activity.d.ts.map +1 -1
  373. package/dist/scan-activity.js +19 -30
  374. package/dist/scan-activity.js.map +1 -1
  375. package/dist/scan-comparison.d.ts +31 -18
  376. package/dist/scan-comparison.d.ts.map +1 -1
  377. package/dist/scan-comparison.js +307 -347
  378. package/dist/scan-comparison.js.map +1 -1
  379. package/dist/scan-dashboard.d.ts +3 -1
  380. package/dist/scan-dashboard.d.ts.map +1 -1
  381. package/dist/scan-dashboard.js +351 -92
  382. package/dist/scan-dashboard.js.map +1 -1
  383. package/dist/scan-history-renderer.d.ts.map +1 -1
  384. package/dist/scan-history-renderer.js +55 -15
  385. package/dist/scan-history-renderer.js.map +1 -1
  386. package/dist/scan-inputs.d.ts +6 -0
  387. package/dist/scan-inputs.d.ts.map +1 -0
  388. package/dist/scan-inputs.js +71 -0
  389. package/dist/scan-inputs.js.map +1 -0
  390. package/dist/scan-logs.d.ts +2 -3
  391. package/dist/scan-logs.d.ts.map +1 -1
  392. package/dist/scan-logs.js +14 -12
  393. package/dist/scan-logs.js.map +1 -1
  394. package/dist/scan-sessions.d.ts +4 -0
  395. package/dist/scan-sessions.d.ts.map +1 -1
  396. package/dist/scan-sessions.js +18 -3
  397. package/dist/scan-sessions.js.map +1 -1
  398. package/dist/scan-settings.d.ts +5 -0
  399. package/dist/scan-settings.d.ts.map +1 -1
  400. package/dist/scan-settings.js +4 -0
  401. package/dist/scan-settings.js.map +1 -1
  402. package/dist/scan-skill-paths.d.ts +8 -0
  403. package/dist/scan-skill-paths.d.ts.map +1 -0
  404. package/dist/scan-skill-paths.js +47 -0
  405. package/dist/scan-skill-paths.js.map +1 -0
  406. package/dist/security-policy-cli.d.ts.map +1 -1
  407. package/dist/security-policy-cli.js +15 -33
  408. package/dist/security-policy-cli.js.map +1 -1
  409. package/dist/security-policy.d.ts +17 -9
  410. package/dist/security-policy.d.ts.map +1 -1
  411. package/dist/security-policy.js +131 -98
  412. package/dist/security-policy.js.map +1 -1
  413. package/dist/server/api.d.ts +0 -1
  414. package/dist/server/api.d.ts.map +1 -1
  415. package/dist/server/api.js +0 -1
  416. package/dist/server/api.js.map +1 -1
  417. package/dist/server/embeddings.d.ts +3 -1
  418. package/dist/server/embeddings.d.ts.map +1 -1
  419. package/dist/server/embeddings.js +11 -3
  420. package/dist/server/embeddings.js.map +1 -1
  421. package/dist/server/errors.d.ts +5 -2
  422. package/dist/server/errors.d.ts.map +1 -1
  423. package/dist/server/errors.js +7 -0
  424. package/dist/server/errors.js.map +1 -1
  425. package/dist/server/sqlite-store.d.ts +0 -2
  426. package/dist/server/sqlite-store.d.ts.map +1 -1
  427. package/dist/server/sqlite-store.js +55 -55
  428. package/dist/server/sqlite-store.js.map +1 -1
  429. package/dist/server/storage.d.ts +0 -2
  430. package/dist/server/storage.d.ts.map +1 -1
  431. package/dist/server/storage.js.map +1 -1
  432. package/dist/severity-store.js +20 -32
  433. package/dist/severity-store.js.map +1 -1
  434. package/dist/standalone-validation-prompt.d.ts +2 -0
  435. package/dist/standalone-validation-prompt.d.ts.map +1 -0
  436. package/dist/standalone-validation-prompt.js +10 -0
  437. package/dist/standalone-validation-prompt.js.map +1 -0
  438. package/dist/suggest-owners.d.ts +6 -5
  439. package/dist/suggest-owners.d.ts.map +1 -1
  440. package/dist/suggest-owners.js +15 -10
  441. package/dist/suggest-owners.js.map +1 -1
  442. package/dist/targets.d.ts +12 -0
  443. package/dist/targets.d.ts.map +1 -1
  444. package/dist/targets.js +124 -62
  445. package/dist/targets.js.map +1 -1
  446. package/dist/trusted-executable.d.ts +6 -1
  447. package/dist/trusted-executable.d.ts.map +1 -1
  448. package/dist/trusted-executable.js +28 -9
  449. package/dist/trusted-executable.js.map +1 -1
  450. package/dist/value.d.ts +2 -0
  451. package/dist/value.d.ts.map +1 -0
  452. package/dist/value.js +27 -0
  453. package/dist/value.js.map +1 -0
  454. package/dist/version.d.ts.map +1 -1
  455. package/dist/version.js +3 -6
  456. package/dist/version.js.map +1 -1
  457. package/dist/windows-path.d.ts.map +1 -1
  458. package/dist/windows-path.js +1 -2
  459. package/dist/windows-path.js.map +1 -1
  460. package/dist/workbench-arguments.d.ts +3 -0
  461. package/dist/workbench-arguments.d.ts.map +1 -0
  462. package/dist/workbench-arguments.js +15 -0
  463. package/dist/workbench-arguments.js.map +1 -0
  464. package/dist/worker-progress.d.ts +2 -0
  465. package/dist/worker-progress.d.ts.map +1 -1
  466. package/dist/worker-progress.js +40 -46
  467. package/dist/worker-progress.js.map +1 -1
  468. package/docs/cli.md +1778 -0
  469. package/docs/dedupe-records.md +24 -0
  470. package/docs/findings-service.md +402 -0
  471. package/package.json +23 -23
  472. package/schemas/project-config.schema.json +5 -0
  473. package/_bundled_plugin/schemas/tools/worker-threat-model.schema.json +0 -18
  474. package/_bundled_plugin/scripts/normalize_candidates.py +0 -338
  475. package/_bundled_plugin/scripts/workbench_dashboard.py +0 -159
  476. package/_bundled_plugin/scripts/workbench_findings.py +0 -221
  477. package/_bundled_plugin/scripts/workbench_severity.py +0 -119
  478. package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +0 -163
  479. package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +0 -276
  480. package/dist/server/dashboard/app.css +0 -2
  481. package/dist/server/dashboard/app.js +0 -66
  482. package/dist/server/dashboard/index.html +0 -18
  483. package/dist/server/dashboard-types.d.ts +0 -48
  484. package/dist/server/dashboard-types.d.ts.map +0 -1
  485. package/dist/server/dashboard-types.js +0 -2
  486. package/dist/server/dashboard-types.js.map +0 -1
  487. package/dist/server/dashboard.d.ts +0 -6
  488. package/dist/server/dashboard.d.ts.map +0 -1
  489. package/dist/server/dashboard.js +0 -59
  490. package/dist/server/dashboard.js.map +0 -1
  491. package/dist/server/findings-service.d.ts +0 -20
  492. package/dist/server/findings-service.d.ts.map +0 -1
  493. package/dist/server/findings-service.js +0 -31
  494. package/dist/server/findings-service.js.map +0 -1
  495. package/dist/server/index.d.ts +0 -2
  496. package/dist/server/index.d.ts.map +0 -1
  497. package/dist/server/index.js +0 -6
  498. package/dist/server/index.js.map +0 -1
  499. package/dist/server/routes.d.ts +0 -6
  500. package/dist/server/routes.d.ts.map +0 -1
  501. package/dist/server/routes.js +0 -86
  502. package/dist/server/routes.js.map +0 -1
  503. package/dist/server/serve.d.ts +0 -2
  504. package/dist/server/serve.d.ts.map +0 -1
  505. package/dist/server/serve.js +0 -28
  506. package/dist/server/serve.js.map +0 -1
  507. package/dist/server/server.d.ts +0 -10
  508. package/dist/server/server.d.ts.map +0 -1
  509. package/dist/server/server.js +0 -17
  510. package/dist/server/server.js.map +0 -1
  511. package/dist/server/validation.d.ts +0 -17
  512. package/dist/server/validation.d.ts.map +0 -1
  513. package/dist/server/validation.js +0 -53
  514. package/dist/server/validation.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ #!/usr/bin/env python3
2
+ """Render saved structured or Markdown threat models without running analysis."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ import sys
9
+ from collections.abc import Callable
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ # Keep sibling helpers importable when Python starts in isolated mode.
14
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
15
+ import report_projection as report
16
+
17
+ _STRUCTURED_SECTIONS = (
18
+ ("Assets", "assets"),
19
+ ("Trust Boundaries", "trustBoundaries"),
20
+ ("Attacker Capabilities", "attackerCapabilities"),
21
+ ("Security Objectives", "securityObjectives"),
22
+ ("Assumptions", "assumptions"),
23
+ )
24
+
25
+
26
+ def _is_structured_model(model: dict[str, Any]) -> bool:
27
+ summary = model.get("summary")
28
+ return (
29
+ isinstance(summary, str)
30
+ and bool(summary)
31
+ and all(
32
+ isinstance(values := model.get(key, []), list)
33
+ and all(isinstance(value, str) and value for value in values)
34
+ for _, key in _STRUCTURED_SECTIONS
35
+ )
36
+ )
37
+
38
+
39
+ def _markdown_content(model: dict[str, Any]) -> str | None:
40
+ content = model.get("content")
41
+ if model.get("format") == "markdown" and isinstance(content, str) and content.strip():
42
+ return content
43
+ return None
44
+
45
+
46
+ def threat_model_body(model: dict[str, Any]) -> str:
47
+ """Keep authored Markdown intact, including summaries from older scans."""
48
+ content = _markdown_content(model)
49
+ if content is not None:
50
+ # The structured schema permits legacy metadata as extension fields.
51
+ if _is_structured_model(model):
52
+ return content
53
+ if "origin" in model and model["origin"] not in (
54
+ "generated",
55
+ "provided",
56
+ "reconciled",
57
+ "recovered",
58
+ ):
59
+ raise ValueError("threatModel.origin: unsupported value")
60
+ if "scope" in model:
61
+ scope = model["scope"]
62
+ if not isinstance(scope, dict) or "includePaths" not in scope:
63
+ raise ValueError("threatModel.scope: expected an object with includePaths")
64
+ for key in ("includePaths", "excludePaths"):
65
+ if key in scope and (
66
+ not isinstance(scope[key], list)
67
+ or not all(isinstance(path, str) and path for path in scope[key])
68
+ ):
69
+ raise ValueError(
70
+ f"threatModel.scope.{key}: expected an array of non-empty strings"
71
+ )
72
+ if "summary" in scope and (
73
+ not isinstance(scope["summary"], str) or not scope["summary"]
74
+ ):
75
+ raise ValueError("threatModel.scope.summary: expected a non-empty string")
76
+ return content
77
+ summary = model.get("summary")
78
+ if not isinstance(summary, str) or not summary:
79
+ if model.get("format") == "markdown":
80
+ raise ValueError("threatModel.content: expected non-empty Markdown")
81
+ raise ValueError("threatModel.summary: expected a non-empty string")
82
+ sections = [
83
+ summary if summary.strip() else "No explicit canonical threat-model summary was recorded."
84
+ ]
85
+ for heading, key in _STRUCTURED_SECTIONS:
86
+ values = model.get(key, [])
87
+ if not isinstance(values, list):
88
+ raise ValueError(f"threatModel.{key}: expected an array")
89
+ if not values:
90
+ continue
91
+ for index, value in enumerate(values):
92
+ if not isinstance(value, str) or not value:
93
+ raise ValueError(f"threatModel.{key}[{index}]: expected a non-empty string")
94
+ sections.append(f"## {heading}")
95
+ sections.append("\n".join("- " + value.replace("\n", "\n ") for value in values))
96
+ return "\n\n".join(sections)
97
+
98
+
99
+ def _scope_lines(scope: Any, label: str, text: Callable[[Any, str], str]) -> list[str]:
100
+ # Older structured models may use these extension names for unrelated data.
101
+ included = scope.get("includePaths") if isinstance(scope, dict) else None
102
+ if not isinstance(included, list) or not all(isinstance(path, str) for path in included):
103
+ return [f"- {label}: not recorded"]
104
+ lines = [f"- {label}: {text(', '.join(included), 'none')}"]
105
+ excluded = scope.get("excludePaths")
106
+ if isinstance(excluded, list) and excluded and all(isinstance(path, str) for path in excluded):
107
+ lines.append(f"- {label} exclusions: {text(', '.join(excluded), 'none')}")
108
+ summary = scope.get("summary")
109
+ if isinstance(summary, str) and summary:
110
+ lines.append(f"- {label} description: {text(summary, 'not recorded')}")
111
+ return lines
112
+
113
+
114
+ def render_threat_model(model: dict[str, Any], provenance: dict[str, Any] | None = None) -> bytes:
115
+ """Render a portable document with authored content and recorded provenance."""
116
+ body = threat_model_body(model)
117
+ if _markdown_content(model) is None:
118
+ body = "# Threat Model\n\n" + body
119
+ text = report._text
120
+ provenance = provenance or {}
121
+ footer = ["---", "", "## Saved Model Context", ""]
122
+ for key, label in (
123
+ ("source", "Source"),
124
+ ("scanId", "Scan"),
125
+ ("target", "Target"),
126
+ ("revision", "Revision"),
127
+ ("snapshotDigest", "Snapshot"),
128
+ ("status", "Result status"),
129
+ ):
130
+ if provenance.get(key):
131
+ footer.append(f"- {label}: {text(str(provenance[key]), 'not recorded')}")
132
+ footer.append(
133
+ f"- Model origin: {text(str(model.get('origin', 'not recorded')), 'not recorded')}"
134
+ )
135
+ footer.extend(_scope_lines(model.get("scope"), "Model scope", text))
136
+ scan_scope = provenance.get("scanScope")
137
+ if isinstance(scan_scope, dict):
138
+ footer.extend(_scope_lines(scan_scope, "Scan scope", text))
139
+ if provenance.get("provisional"):
140
+ footer.extend(["", "This is a provisional model saved before successful completion."])
141
+ return (body + ("\n" if body.endswith("\n") else "\n\n") + "\n".join(footer) + "\n").encode(
142
+ "utf-8"
143
+ )
144
+
145
+
146
+ def main() -> int:
147
+ parser = argparse.ArgumentParser(description=__doc__)
148
+ parser.add_argument("--input-json-stdin", action="store_true", required=True)
149
+ parser.parse_args()
150
+ try:
151
+ payload = json.load(sys.stdin)
152
+ sys.stdout.buffer.write(
153
+ render_threat_model(payload["threatModel"], payload.get("provenance"))
154
+ )
155
+ except (KeyError, TypeError, ValueError) as exc:
156
+ parser.error(str(exc))
157
+ return 0
158
+
159
+
160
+ if __name__ == "__main__":
161
+ raise SystemExit(main())
@@ -4,25 +4,14 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
- import importlib.util
8
7
  import json
9
8
  import sys
10
9
  from pathlib import Path
11
- from types import ModuleType
12
10
  from typing import Any
13
11
 
14
-
15
- def _load_finalizer() -> ModuleType:
16
- script = Path(__file__).resolve().with_name("finalize_scan_contract.py")
17
- spec = importlib.util.spec_from_file_location("codex_security_scan_contract", script)
18
- if spec is None or spec.loader is None:
19
- raise RuntimeError(f"could not load scan contract validator: {script}")
20
- module = importlib.util.module_from_spec(spec)
21
- spec.loader.exec_module(module)
22
- return module
23
-
24
-
25
- FINALIZER = _load_finalizer()
12
+ # Keep sibling helpers importable when Python starts in isolated mode.
13
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
14
+ import finalize_scan_contract as FINALIZER
26
15
 
27
16
 
28
17
  def validate_contract(scan_dir: Path) -> dict[str, Any]:
@@ -39,26 +28,7 @@ def validate_contract(scan_dir: Path) -> dict[str, Any]:
39
28
  FINALIZER.validate_against_schema(manifest, schema_dir / "scan-manifest.schema.json")
40
29
 
41
30
  scan = FINALIZER._require_dict(manifest, "scan", "manifest")
42
- findings_ref = scan["findingsRef"]
43
- coverage_ref = scan["coverageRef"]
44
- findings, findings_bytes = FINALIZER._read_scan_local_json_bytes(
45
- scan_dir,
46
- findings_ref,
47
- findings_ref,
48
- )
49
- coverage, coverage_bytes = FINALIZER._read_scan_local_json_bytes(
50
- scan_dir,
51
- coverage_ref,
52
- coverage_ref,
53
- )
54
- FINALIZER._validate_existing_seal(
55
- scan_dir,
56
- scan,
57
- artifact_contents={
58
- findings_ref: findings_bytes,
59
- coverage_ref: coverage_bytes,
60
- },
61
- )
31
+ findings, coverage, _ = FINALIZER._read_sealed_artifacts(scan_dir, scan)
62
32
  findings_for_validation = FINALIZER._legacy_sealed_findings_for_validation(findings)
63
33
  FINALIZER._validate_findings(manifest, findings_for_validation)
64
34
  FINALIZER._validate_derived_finding_identities(manifest, findings)
@@ -4,24 +4,14 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import argparse
7
- import importlib.util
8
7
  import sys
9
8
  from pathlib import Path
10
- from types import ModuleType
11
9
  from typing import Any
12
10
 
11
+ # Keep sibling helpers importable when Python starts in isolated mode.
12
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
13
+ import validate_scan_contract as SCAN_CONTRACT
13
14
 
14
- def _load_scan_contract_validator() -> ModuleType:
15
- script = Path(__file__).resolve().with_name("validate_scan_contract.py")
16
- spec = importlib.util.spec_from_file_location("codex_security_scan_validator", script)
17
- if spec is None or spec.loader is None:
18
- raise RuntimeError(f"could not load scan contract validator: {script}")
19
- module = importlib.util.module_from_spec(spec)
20
- spec.loader.exec_module(module)
21
- return module
22
-
23
-
24
- SCAN_CONTRACT = _load_scan_contract_validator()
25
15
  FINALIZER = SCAN_CONTRACT.FINALIZER
26
16
  validate_contract = SCAN_CONTRACT.validate_contract
27
17
 
@@ -4,13 +4,16 @@ Windows does not implement Python's descriptor-relative ``dir_fd`` APIs or
4
4
  ``O_NOFOLLOW``. This module provides the three operations needed by the scan
5
5
  finalizer without falling back to check-then-use path validation.
6
6
 
7
- The implementation opens every directory with ``FILE_FLAG_OPEN_REPARSE_POINT``
8
- and rejects all reparse points, including junctions. Directory handles remain
9
- open without ``FILE_SHARE_DELETE`` for the full operation, which prevents an
7
+ Scan-local reads, writes, and deletes open every directory with
8
+ ``FILE_FLAG_OPEN_REPARSE_POINT`` and reject all reparse points, including junctions.
9
+ Directory handles remain open without ``FILE_SHARE_DELETE`` for the full
10
+ operation, which prevents an
10
11
  already-validated ancestor from being renamed or replaced during a read,
11
12
  write, or delete. Writes rename the exact temporary-file handle into place so
12
13
  an attacker cannot substitute another file at the temporary name.
13
14
 
15
+ The snapshot helper copies junction metadata without opening the link target.
16
+
14
17
  Importing this module and comparing streams work on every platform. Filesystem
15
18
  operations raise ``WindowsScanLocalFileError`` outside Windows.
16
19
  """
@@ -202,6 +205,19 @@ if os.name == "nt":
202
205
  ]
203
206
  _WriteFile.restype = wintypes.BOOL
204
207
 
208
+ _DeviceIoControl = _kernel32.DeviceIoControl
209
+ _DeviceIoControl.argtypes = [
210
+ wintypes.HANDLE,
211
+ wintypes.DWORD,
212
+ wintypes.LPVOID,
213
+ wintypes.DWORD,
214
+ wintypes.LPVOID,
215
+ wintypes.DWORD,
216
+ ctypes.POINTER(wintypes.DWORD),
217
+ wintypes.LPVOID,
218
+ ]
219
+ _DeviceIoControl.restype = wintypes.BOOL
220
+
205
221
  _FlushFileBuffers = _kernel32.FlushFileBuffers
206
222
  _FlushFileBuffers.argtypes = [wintypes.HANDLE]
207
223
  _FlushFileBuffers.restype = wintypes.BOOL
@@ -309,6 +325,34 @@ def _create_file(
309
325
  return _OwnedHandle(int(handle))
310
326
 
311
327
 
328
+ def copy_directory_junction(source: Path, destination: Path) -> None:
329
+ """Copy raw junction data to an empty directory without opening the link target."""
330
+ # MAXIMUM_REPARSE_DATA_BUFFER_SIZE, including the reparse data header.
331
+ data = ctypes.create_string_buffer(16 * 1024)
332
+ size = wintypes.DWORD()
333
+ for path, write in ((source, False), (destination, True)):
334
+ handle = _create_file(
335
+ path,
336
+ access=_GENERIC_WRITE if write else _FILE_READ_ATTRIBUTES,
337
+ share=_FILE_SHARE_READ | _FILE_SHARE_WRITE,
338
+ disposition=_OPEN_EXISTING,
339
+ flags=_FILE_FLAG_BACKUP_SEMANTICS | _FILE_FLAG_OPEN_REPARSE_POINT,
340
+ )
341
+ assert handle is not None
342
+ with handle:
343
+ if not _DeviceIoControl(
344
+ handle.value,
345
+ 0x000900A4 if write else 0x000900A8, # FSCTL_SET/GET_REPARSE_POINT.
346
+ data if write else None,
347
+ size.value if write else 0,
348
+ None if write else data,
349
+ 0 if write else len(data),
350
+ ctypes.byref(size),
351
+ None,
352
+ ):
353
+ _raise_last_error("Copy directory junction", path)
354
+
355
+
312
356
  def _attributes(handle: int) -> _FileAttributeTagInfo:
313
357
  info = _FileAttributeTagInfo()
314
358
  if not _GetFileInformationByHandleEx(
@@ -453,6 +497,12 @@ def scan_root_identity(scan_dir: Path) -> tuple[Path, tuple[int, int]]:
453
497
  def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
454
498
  """Open a verified regular file and return an owned binary read descriptor."""
455
499
 
500
+ return open_read_fd_with_path(scan_dir, relative_path, context)[0]
501
+
502
+
503
+ def open_read_fd_with_path(scan_dir: Path, relative_path: str, context: str) -> tuple[int, str]:
504
+ """Return the descriptor and its filename while the verified parents are held."""
505
+
456
506
  try:
457
507
  with _locked_parent(scan_dir, relative_path, create=False) as (parent_path, leaf_name):
458
508
  path = parent_path / leaf_name
@@ -467,10 +517,13 @@ def open_read_fd(scan_dir: Path, relative_path: str, context: str) -> int:
467
517
  assert handle is not None and handle.value is not None
468
518
  with handle:
469
519
  _verify_regular_file(handle.value, path)
520
+ filename = Path(_final_path(handle.value)).name
521
+ resolved_path = PurePosixPath(relative_path).with_name(filename).as_posix()
470
522
  raw_handle = handle.detach()
471
523
  try:
472
524
  assert _msvcrt is not None
473
- return _msvcrt.open_osfhandle(raw_handle, os.O_RDONLY | os.O_BINARY)
525
+ descriptor = _msvcrt.open_osfhandle(raw_handle, os.O_RDONLY | os.O_BINARY)
526
+ return descriptor, resolved_path
474
527
  except BaseException:
475
528
  _close_handle(raw_handle)
476
529
  raise
@@ -654,6 +707,7 @@ def atomic_write(
654
707
  try:
655
708
  _mark_handle_for_deletion(temp_handle.value)
656
709
  except OSError:
710
+ # Cleanup must not replace the original write or rename failure.
657
711
  pass
658
712
  raise
659
713
 
@@ -686,9 +740,5 @@ def unlink_if_exists(scan_dir: Path, relative_path: str) -> None:
686
740
  _mark_handle_for_deletion(handle.value)
687
741
 
688
742
 
689
- def main() -> None:
690
- argparse.ArgumentParser(description=__doc__).parse_args()
691
-
692
-
693
743
  if __name__ == "__main__":
694
- main()
744
+ argparse.ArgumentParser(description=__doc__).parse_args()
@@ -4,7 +4,6 @@ from __future__ import annotations
4
4
 
5
5
  import argparse
6
6
  import sqlite3
7
- from collections.abc import Callable
8
7
  from typing import Any
9
8
 
10
9
  from workbench_validation import optional_text, require_uuid
@@ -51,21 +50,17 @@ def validate_handoff_delivery_thread(
51
50
 
52
51
 
53
52
  def claim_handoff_delivery(
53
+ wb: Any,
54
54
  connection: sqlite3.Connection,
55
55
  args: argparse.Namespace,
56
- *,
57
- now: Callable[[], str],
58
- require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row],
59
- stale_claim_before: Callable[[], str],
60
- workspace_state: Callable[[sqlite3.Connection, str], dict[str, Any]],
61
56
  ) -> dict[str, Any]:
62
57
  scan_id = require_uuid(args.scan_id, "scan-id")
63
58
  claim_token = require_handoff_claim_token(args.claim_token)
64
- timestamp = now()
59
+ timestamp = wb.now()
65
60
  with connection:
66
- scan = require_scan(connection, scan_id)
61
+ scan = wb.require_scan(connection, scan_id)
67
62
  if scan["handoff_status"] != "pending" or scan["handoff_claim_token"] == claim_token:
68
- return workspace_state(connection, scan["workspace_id"])
63
+ return wb.workspace_state(connection, scan["workspace_id"])
69
64
  updated = connection.execute(
70
65
  """
71
66
  UPDATE scans
@@ -94,27 +89,24 @@ def claim_handoff_delivery(
94
89
  timestamp,
95
90
  scan["id"],
96
91
  int(args.take_over_stale),
97
- stale_claim_before(),
92
+ wb.stale_claim_before(),
98
93
  ),
99
94
  )
100
95
  if updated.rowcount != 1:
101
- return workspace_state(connection, scan["workspace_id"])
102
- return workspace_state(connection, scan["workspace_id"])
96
+ return wb.workspace_state(connection, scan["workspace_id"])
97
+ return wb.workspace_state(connection, scan["workspace_id"])
103
98
 
104
99
 
105
100
  def release_handoff_delivery(
101
+ wb: Any,
106
102
  connection: sqlite3.Connection,
107
103
  args: argparse.Namespace,
108
- *,
109
- now: Callable[[], str],
110
- require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row],
111
- workspace_state: Callable[[sqlite3.Connection, str], dict[str, Any]],
112
104
  ) -> dict[str, Any]:
113
105
  scan_id = require_uuid(args.scan_id, "scan-id")
114
106
  claim_token = require_handoff_claim_token(args.claim_token)
115
- timestamp = now()
107
+ timestamp = wb.now()
116
108
  with connection:
117
- scan = require_scan(connection, scan_id)
109
+ scan = wb.require_scan(connection, scan_id)
118
110
  connection.execute(
119
111
  """
120
112
  UPDATE scans
@@ -126,16 +118,13 @@ def release_handoff_delivery(
126
118
  """,
127
119
  (timestamp, scan["id"], claim_token),
128
120
  )
129
- return workspace_state(connection, scan["workspace_id"])
121
+ return wb.workspace_state(connection, scan["workspace_id"])
130
122
 
131
123
 
132
124
  def attach_scan_continuation_thread(
125
+ wb: Any,
133
126
  connection: sqlite3.Connection,
134
127
  args: argparse.Namespace,
135
- *,
136
- now: Callable[[], str],
137
- require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row],
138
- workspace_state: Callable[[sqlite3.Connection, str], dict[str, Any]],
139
128
  ) -> dict[str, Any]:
140
129
  scan_id = require_uuid(args.scan_id, "scan-id")
141
130
  claim_token = require_handoff_claim_token(args.claim_token)
@@ -143,9 +132,9 @@ def attach_scan_continuation_thread(
143
132
  if thread_id is None:
144
133
  raise SystemExit("Codex Security continuation thread ID is required.")
145
134
  connection.execute("BEGIN IMMEDIATE")
146
- try:
147
- timestamp = now()
148
- scan = require_scan(connection, scan_id)
135
+ with connection:
136
+ timestamp = wb.now()
137
+ scan = wb.require_scan(connection, scan_id)
149
138
  if scan["handoff_claim_token"] != claim_token:
150
139
  raise SystemExit("Codex Security continuation thread claim token does not match.")
151
140
  if scan["continuation_thread_id"] is not None:
@@ -154,8 +143,8 @@ def attach_scan_continuation_thread(
154
143
  "Codex Security scan continuation is owned by another continuation."
155
144
  )
156
145
  connection.commit()
157
- return workspace_state(connection, scan["workspace_id"])
158
- updated = connection.execute(
146
+ return wb.workspace_state(connection, scan["workspace_id"])
147
+ connection.execute(
159
148
  """
160
149
  UPDATE scans
161
150
  SET continuation_thread_id = ?,
@@ -168,33 +157,23 @@ def attach_scan_continuation_thread(
168
157
  """,
169
158
  (thread_id, thread_id, timestamp, scan["id"], claim_token),
170
159
  )
171
- if updated.rowcount != 1:
172
- raise SystemExit("Codex Security continuation thread could not be attached.")
173
- connection.commit()
174
- except BaseException:
175
- connection.rollback()
176
- raise
177
- return workspace_state(connection, scan["workspace_id"])
160
+ return wb.workspace_state(connection, scan["workspace_id"])
178
161
 
179
162
 
180
163
  def mark_handoff_delivered(
164
+ wb: Any,
181
165
  connection: sqlite3.Connection,
182
166
  args: argparse.Namespace,
183
- *,
184
- now: Callable[[], str],
185
- require_scan: Callable[[sqlite3.Connection, str], sqlite3.Row],
186
- require_workspace: Callable[[sqlite3.Connection, str], sqlite3.Row],
187
- workspace_state: Callable[[sqlite3.Connection, str], dict[str, Any]],
188
167
  ) -> dict[str, Any]:
189
168
  scan_id = require_uuid(args.scan_id, "scan-id")
190
169
  claim_token = require_handoff_claim_token(args.claim_token)
191
170
  thread_id = optional_text(args.thread_id, maximum=512)
192
171
  connection.execute("BEGIN IMMEDIATE")
193
- try:
194
- timestamp = now()
195
- scan = require_scan(connection, scan_id)
172
+ with connection:
173
+ timestamp = wb.now()
174
+ scan = wb.require_scan(connection, scan_id)
196
175
  if thread_id is not None:
197
- workspace = require_workspace(connection, scan["workspace_id"])
176
+ workspace = wb.require_workspace(connection, scan["workspace_id"])
198
177
  validate_handoff_delivery_thread(
199
178
  scan["continuation_thread_id"] or workspace["thread_id"],
200
179
  thread_id,
@@ -206,7 +185,7 @@ def mark_handoff_delivered(
206
185
  "Codex Security handoff delivery is owned by another continuation."
207
186
  )
208
187
  connection.commit()
209
- return workspace_state(connection, scan["workspace_id"])
188
+ return wb.workspace_state(connection, scan["workspace_id"])
210
189
  updated = connection.execute(
211
190
  """
212
191
  UPDATE scans
@@ -231,8 +210,4 @@ def mark_handoff_delivered(
231
210
  """,
232
211
  (timestamp, scan["id"]),
233
212
  )
234
- connection.commit()
235
- except BaseException:
236
- connection.rollback()
237
- raise
238
- return workspace_state(connection, scan["workspace_id"])
213
+ return wb.workspace_state(connection, scan["workspace_id"])
@@ -0,0 +1,22 @@
1
+ """Load TOML using the supported Python runtime."""
2
+
3
+ import sys
4
+
5
+ __all__ = ["tomllib"]
6
+
7
+ if sys.version_info < (3, 10):
8
+ raise SystemExit(
9
+ "Codex Security requires Python 3.10 or later. Update the Codex managed runtime "
10
+ "or set PYTHON to a supported interpreter, then restart Codex."
11
+ )
12
+
13
+ try:
14
+ import tomllib as tomllib
15
+ except ModuleNotFoundError: # Python 3.10
16
+ try:
17
+ import tomli as tomllib
18
+ except ModuleNotFoundError as exc:
19
+ raise SystemExit(
20
+ "Codex Security requires tomli with Python 3.10. Install tomli for the selected "
21
+ "interpreter or set PYTHON to Python 3.11 or later, then restart Codex."
22
+ ) from exc
@@ -6,13 +6,28 @@ import os
6
6
  from pathlib import Path
7
7
 
8
8
 
9
- def state_dir() -> Path:
10
- state_dir = os.environ.get("CODEX_SECURITY_STATE_DIR")
11
- if state_dir:
12
- return Path(state_dir).expanduser().resolve()
13
- codex_home = Path(os.environ.get("CODEX_HOME", "~/.codex")).expanduser()
14
- return (codex_home / "state" / "plugins" / "codex-security").resolve()
9
+ def state_dir(*, canonical: bool = True) -> Path:
10
+ configured = os.environ.get("CODEX_SECURITY_STATE_DIR")
11
+ if configured:
12
+ path = Path(configured).expanduser()
13
+ else:
14
+ codex_home = Path(
15
+ os.environ["CODEX_HOME"] if os.environ.get("CODEX_HOME", "").strip() else "~/.codex"
16
+ ).expanduser()
17
+ path = codex_home / "state" / "plugins" / "codex-security"
18
+ return path.resolve() if canonical else path.absolute()
15
19
 
16
20
 
17
21
  def resolve_scan_root(scan_root: str | None) -> Path:
18
22
  return Path(scan_root).expanduser().resolve() if scan_root else state_dir() / "scans"
23
+
24
+
25
+ def create_private_directory(path: Path) -> None:
26
+ """Create missing directories privately without changing existing permissions."""
27
+ try:
28
+ path.mkdir(mode=0o700, exist_ok=True)
29
+ except FileNotFoundError:
30
+ if path.parent == path:
31
+ raise
32
+ create_private_directory(path.parent)
33
+ path.mkdir(mode=0o700, exist_ok=True)