@openai/codex-security 0.8.3 → 0.10.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 (658) hide show
  1. package/README.md +36 -746
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +7 -1
  4. package/_bundled_plugin/examples/completed-scan/findings.json +16 -4
  5. package/_bundled_plugin/examples/completed-scan/report.md +11 -8
  6. package/_bundled_plugin/examples/completed-scan/scan-manifest.json +4 -2
  7. package/_bundled_plugin/mcp/fzstd-LICENSE.txt +21 -0
  8. package/_bundled_plugin/mcp/helpers.mjs +2 -11
  9. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  10. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +3 -210
  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/package.json +1 -0
  20. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +5 -2
  21. package/_bundled_plugin/mcp/server.mjs +2 -11
  22. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  23. package/_bundled_plugin/mcp/session-decompression.mjs +712 -0
  24. package/_bundled_plugin/references/artifact-storage.md +1 -1
  25. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  26. package/_bundled_plugin/references/core-scan.md +5 -42
  27. package/_bundled_plugin/references/default-severity-rubric.md +9 -4
  28. package/_bundled_plugin/references/final-report.md +5 -3
  29. package/_bundled_plugin/references/finding-detail-fields.md +18 -18
  30. package/_bundled_plugin/references/focused-investigator.md +13 -0
  31. package/_bundled_plugin/references/sarif-adapter.md +8 -2
  32. package/_bundled_plugin/references/scan-artifacts.md +21 -12
  33. package/_bundled_plugin/references/scan-contract.md +27 -33
  34. package/_bundled_plugin/references/scan-prologue.md +2 -2
  35. package/_bundled_plugin/references/scan-runtime.md +4 -2
  36. package/_bundled_plugin/references/security-guidance.md +14 -1
  37. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  38. package/_bundled_plugin/schemas/tools/scan-draft.schema.json +2 -2
  39. package/_bundled_plugin/scripts/check_deep_scan_target.py +97 -0
  40. package/_bundled_plugin/scripts/codex_profile.mjs +7 -1
  41. package/_bundled_plugin/scripts/deep_scan_config.py +20 -1
  42. package/_bundled_plugin/scripts/deep_scan_workbench.py +192 -352
  43. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  44. package/_bundled_plugin/scripts/filesystem_identity.py +1 -0
  45. package/_bundled_plugin/scripts/finalize_scan_contract.py +182 -230
  46. package/_bundled_plugin/scripts/finding_preview.py +20 -0
  47. package/_bundled_plugin/scripts/launch_codex_security_mcp +55 -16
  48. package/_bundled_plugin/scripts/legacy_findings.py +148 -0
  49. package/_bundled_plugin/scripts/posix_scan_local_files.py +37 -1
  50. package/_bundled_plugin/scripts/read_codex_session.mjs +21 -0
  51. package/_bundled_plugin/scripts/report_projection.py +81 -43
  52. package/_bundled_plugin/scripts/review_state.py +8 -2
  53. package/_bundled_plugin/scripts/servicenow_avit.py +20 -0
  54. package/_bundled_plugin/scripts/snapshot_sqlite.py +9 -2
  55. package/_bundled_plugin/scripts/threat_model_projection.py +22 -26
  56. package/_bundled_plugin/scripts/validate_scan_contract.py +7 -1
  57. package/_bundled_plugin/scripts/windows_scan_local_files.py +582 -20
  58. package/_bundled_plugin/scripts/workbench/__init__.py +1 -1
  59. package/_bundled_plugin/scripts/workbench/handoff.py +100 -23
  60. package/_bundled_plugin/scripts/workbench/retained_coverage.py +30 -51
  61. package/_bundled_plugin/scripts/workbench/retained_records.py +18 -30
  62. package/_bundled_plugin/scripts/workbench/runtime_toml.py +4 -1
  63. package/_bundled_plugin/scripts/workbench/saved_coverage.py +9 -17
  64. package/_bundled_plugin/scripts/workbench/saved_outputs.py +9 -0
  65. package/_bundled_plugin/scripts/workbench/saved_sources.py +47 -40
  66. package/_bundled_plugin/scripts/workbench/storage.py +91 -7
  67. package/_bundled_plugin/scripts/workbench_cli.py +54 -14
  68. package/_bundled_plugin/scripts/workbench_constants.py +12 -0
  69. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +3 -3
  70. package/_bundled_plugin/scripts/workbench_db.py +562 -303
  71. package/_bundled_plugin/scripts/workbench_feedback.py +57 -11
  72. package/_bundled_plugin/scripts/workbench_finding_index.py +1 -0
  73. package/_bundled_plugin/scripts/workbench_finding_workflows.py +4 -0
  74. package/_bundled_plugin/scripts/workbench_native_indexes.py +238 -41
  75. package/_bundled_plugin/scripts/workbench_progress.py +169 -4
  76. package/_bundled_plugin/scripts/workbench_publication.py +16 -13
  77. package/_bundled_plugin/scripts/workbench_remediation.py +155 -2
  78. package/_bundled_plugin/scripts/workbench_saved_results.py +176 -81
  79. package/_bundled_plugin/scripts/workbench_scan_history.py +398 -174
  80. package/_bundled_plugin/scripts/workbench_scan_start.py +224 -31
  81. package/_bundled_plugin/scripts/workbench_scan_usage.py +675 -73
  82. package/_bundled_plugin/scripts/workbench_schema.py +258 -63
  83. package/_bundled_plugin/scripts/workbench_setup.py +14 -2
  84. package/_bundled_plugin/scripts/workbench_source_excerpt.py +13 -0
  85. package/_bundled_plugin/scripts/workbench_source_scopes.py +18 -0
  86. package/_bundled_plugin/scripts/workbench_target.py +594 -136
  87. package/_bundled_plugin/scripts/workbench_target_state.py +1110 -21
  88. package/_bundled_plugin/scripts/workbench_validation.py +43 -3
  89. package/_bundled_plugin/shared/workbench-history-repairs.json +77 -35
  90. package/_bundled_plugin/shared/workbench-migrations.json +100 -0
  91. package/_bundled_plugin/skills/cloud-findings/SKILL.md +5 -5
  92. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +7 -50
  93. package/_bundled_plugin/skills/fix-finding/SKILL.md +2 -1
  94. package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -153
  95. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  96. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +37 -0
  97. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +3 -3
  98. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +409 -0
  99. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
  100. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  101. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  102. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  103. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  104. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  105. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  106. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  107. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  108. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +22 -1
  109. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -2
  110. package/bin/codex-security.mjs +2 -2
  111. package/dist/api.d.ts +45 -5
  112. package/dist/api.d.ts.map +1 -1
  113. package/dist/api.js +1192 -427
  114. package/dist/api.js.map +1 -1
  115. package/dist/armorcode-findings.d.ts +9 -0
  116. package/dist/armorcode-findings.d.ts.map +1 -0
  117. package/dist/armorcode-findings.js +145 -0
  118. package/dist/armorcode-findings.js.map +1 -0
  119. package/dist/artifact-export.d.ts +2 -0
  120. package/dist/artifact-export.d.ts.map +1 -1
  121. package/dist/artifact-export.js +29 -13
  122. package/dist/artifact-export.js.map +1 -1
  123. package/dist/auth.d.ts +6 -2
  124. package/dist/auth.d.ts.map +1 -1
  125. package/dist/auth.js +37 -18
  126. package/dist/auth.js.map +1 -1
  127. package/dist/batch-cost.d.ts +18 -0
  128. package/dist/batch-cost.d.ts.map +1 -0
  129. package/dist/batch-cost.js +41 -0
  130. package/dist/batch-cost.js.map +1 -0
  131. package/dist/bedrock-oss-pricing.d.ts +6 -0
  132. package/dist/bedrock-oss-pricing.d.ts.map +1 -0
  133. package/dist/bedrock-oss-pricing.js +58 -0
  134. package/dist/bedrock-oss-pricing.js.map +1 -0
  135. package/dist/bedrock-pricing.d.ts +15 -0
  136. package/dist/bedrock-pricing.d.ts.map +1 -0
  137. package/dist/bedrock-pricing.js +117 -0
  138. package/dist/bedrock-pricing.js.map +1 -0
  139. package/dist/blackduck-findings.d.ts +1 -1
  140. package/dist/blackduck-findings.d.ts.map +1 -1
  141. package/dist/blackduck-findings.js +24 -22
  142. package/dist/blackduck-findings.js.map +1 -1
  143. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  144. package/dist/bulk-scan-discovery.js +4 -4
  145. package/dist/bulk-scan-discovery.js.map +1 -1
  146. package/dist/bundled-plugin.d.ts +4 -0
  147. package/dist/bundled-plugin.d.ts.map +1 -0
  148. package/dist/bundled-plugin.js +23 -0
  149. package/dist/bundled-plugin.js.map +1 -0
  150. package/dist/checkmarx-evidence.d.ts +19 -0
  151. package/dist/checkmarx-evidence.d.ts.map +1 -0
  152. package/dist/checkmarx-evidence.js +36 -0
  153. package/dist/checkmarx-evidence.js.map +1 -0
  154. package/dist/checkmarx-findings.d.ts +4 -0
  155. package/dist/checkmarx-findings.d.ts.map +1 -0
  156. package/dist/checkmarx-findings.js +27 -0
  157. package/dist/checkmarx-findings.js.map +1 -0
  158. package/dist/checkmarx-one.d.ts +4 -0
  159. package/dist/checkmarx-one.d.ts.map +1 -0
  160. package/dist/checkmarx-one.js +53 -0
  161. package/dist/checkmarx-one.js.map +1 -0
  162. package/dist/checkmarx-repository.d.ts +12 -0
  163. package/dist/checkmarx-repository.d.ts.map +1 -0
  164. package/dist/checkmarx-repository.js +181 -0
  165. package/dist/checkmarx-repository.js.map +1 -0
  166. package/dist/checkmarx-xml.d.ts +12 -0
  167. package/dist/checkmarx-xml.d.ts.map +1 -0
  168. package/dist/checkmarx-xml.js +196 -0
  169. package/dist/checkmarx-xml.js.map +1 -0
  170. package/dist/classify-scan-severity.d.ts +1 -1
  171. package/dist/classify-scan-severity.d.ts.map +1 -1
  172. package/dist/classify-scan-severity.js +11 -3
  173. package/dist/classify-scan-severity.js.map +1 -1
  174. package/dist/classify-severity-records.d.ts +1 -9
  175. package/dist/classify-severity-records.d.ts.map +1 -1
  176. package/dist/classify-severity-records.js +3 -13
  177. package/dist/classify-severity-records.js.map +1 -1
  178. package/dist/classify-severity.d.ts.map +1 -1
  179. package/dist/classify-severity.js +11 -10
  180. package/dist/classify-severity.js.map +1 -1
  181. package/dist/cli-argument.d.ts +4 -0
  182. package/dist/cli-argument.d.ts.map +1 -0
  183. package/dist/cli-argument.js +17 -0
  184. package/dist/cli-argument.js.map +1 -0
  185. package/dist/cli-help.d.ts +1 -1
  186. package/dist/cli-help.d.ts.map +1 -1
  187. package/dist/cli-help.js +71 -29
  188. package/dist/cli-help.js.map +1 -1
  189. package/dist/cli-hook.d.ts +3 -0
  190. package/dist/cli-hook.d.ts.map +1 -0
  191. package/dist/cli-hook.js +87 -0
  192. package/dist/cli-hook.js.map +1 -0
  193. package/dist/cli-integrations.d.ts +13 -0
  194. package/dist/cli-integrations.d.ts.map +1 -0
  195. package/dist/cli-integrations.js +333 -0
  196. package/dist/cli-integrations.js.map +1 -0
  197. package/dist/cli-mcp.d.ts +15 -0
  198. package/dist/cli-mcp.d.ts.map +1 -0
  199. package/dist/cli-mcp.js +178 -0
  200. package/dist/cli-mcp.js.map +1 -0
  201. package/dist/cli-token-view.d.ts +10 -0
  202. package/dist/cli-token-view.d.ts.map +1 -0
  203. package/dist/cli-token-view.js +41 -0
  204. package/dist/cli-token-view.js.map +1 -0
  205. package/dist/cli.d.ts +16 -8
  206. package/dist/cli.d.ts.map +1 -1
  207. package/dist/cli.js +3382 -2017
  208. package/dist/cli.js.map +1 -1
  209. package/dist/cloud-publish.d.ts.map +1 -1
  210. package/dist/cloud-publish.js +35 -33
  211. package/dist/cloud-publish.js.map +1 -1
  212. package/dist/codex-sdk-environment.d.ts +6 -0
  213. package/dist/codex-sdk-environment.d.ts.map +1 -1
  214. package/dist/codex-sdk-environment.js +19 -0
  215. package/dist/codex-sdk-environment.js.map +1 -1
  216. package/dist/command-words.d.ts +3 -0
  217. package/dist/command-words.d.ts.map +1 -0
  218. package/dist/command-words.js +46 -0
  219. package/dist/command-words.js.map +1 -0
  220. package/dist/component-scan.d.ts +19 -4
  221. package/dist/component-scan.d.ts.map +1 -1
  222. package/dist/component-scan.js +67 -9
  223. package/dist/component-scan.js.map +1 -1
  224. package/dist/config.d.ts +1 -1
  225. package/dist/config.d.ts.map +1 -1
  226. package/dist/config.js +130 -67
  227. package/dist/config.js.map +1 -1
  228. package/dist/continuum-findings.d.ts +1 -1
  229. package/dist/continuum-findings.d.ts.map +1 -1
  230. package/dist/continuum-findings.js +149 -19
  231. package/dist/continuum-findings.js.map +1 -1
  232. package/dist/contract-values.d.ts +2 -0
  233. package/dist/contract-values.d.ts.map +1 -1
  234. package/dist/contract-values.js +12 -9
  235. package/dist/contract-values.js.map +1 -1
  236. package/dist/cost-model.d.ts +13 -1
  237. package/dist/cost-model.d.ts.map +1 -1
  238. package/dist/cost-model.js +66 -112
  239. package/dist/cost-model.js.map +1 -1
  240. package/dist/cost.d.ts +42 -3
  241. package/dist/cost.d.ts.map +1 -1
  242. package/dist/cost.js +484 -149
  243. package/dist/cost.js.map +1 -1
  244. package/dist/custom-publish.d.ts +4 -0
  245. package/dist/custom-publish.d.ts.map +1 -1
  246. package/dist/custom-publish.js +40 -3
  247. package/dist/custom-publish.js.map +1 -1
  248. package/dist/custom-validation-prompt.d.ts +1 -1
  249. package/dist/custom-validation-prompt.d.ts.map +1 -1
  250. package/dist/custom-validation-prompt.js +29 -19
  251. package/dist/custom-validation-prompt.js.map +1 -1
  252. package/dist/deduplication/local.d.ts +4 -2
  253. package/dist/deduplication/local.d.ts.map +1 -1
  254. package/dist/deduplication/local.js +9 -2
  255. package/dist/deduplication/local.js.map +1 -1
  256. package/dist/deduplication/refusal.d.ts.map +1 -1
  257. package/dist/deduplication/refusal.js +26 -5
  258. package/dist/deduplication/refusal.js.map +1 -1
  259. package/dist/deduplication/scan.d.ts +5 -0
  260. package/dist/deduplication/scan.d.ts.map +1 -1
  261. package/dist/deduplication/scan.js +24 -7
  262. package/dist/deduplication/scan.js.map +1 -1
  263. package/dist/deep-config.d.ts +0 -1
  264. package/dist/deep-config.d.ts.map +1 -1
  265. package/dist/deep-config.js +22 -33
  266. package/dist/deep-config.js.map +1 -1
  267. package/dist/deep-scan-defaults.d.ts +2 -0
  268. package/dist/deep-scan-defaults.d.ts.map +1 -1
  269. package/dist/deep-scan-defaults.js +28 -1
  270. package/dist/deep-scan-defaults.js.map +1 -1
  271. package/dist/deep-scan.d.ts +2 -0
  272. package/dist/deep-scan.d.ts.map +1 -1
  273. package/dist/deep-scan.js +44 -19
  274. package/dist/deep-scan.js.map +1 -1
  275. package/dist/default-severity-rubric.d.ts +1 -1
  276. package/dist/default-severity-rubric.d.ts.map +1 -1
  277. package/dist/default-severity-rubric.js +1 -1
  278. package/dist/default-severity-rubric.js.map +1 -1
  279. package/dist/endor-findings.d.ts +3 -1
  280. package/dist/endor-findings.d.ts.map +1 -1
  281. package/dist/endor-findings.js +86 -45
  282. package/dist/endor-findings.js.map +1 -1
  283. package/dist/errors.d.ts +4 -2
  284. package/dist/errors.d.ts.map +1 -1
  285. package/dist/errors.js +15 -4
  286. package/dist/errors.js.map +1 -1
  287. package/dist/executable-path.d.ts +3 -0
  288. package/dist/executable-path.d.ts.map +1 -1
  289. package/dist/executable-path.js +26 -0
  290. package/dist/executable-path.js.map +1 -1
  291. package/dist/external-findings-import.d.ts +5 -3
  292. package/dist/external-findings-import.d.ts.map +1 -1
  293. package/dist/external-findings-import.js +19 -7
  294. package/dist/external-findings-import.js.map +1 -1
  295. package/dist/external-findings-local.d.ts +69 -5
  296. package/dist/external-findings-local.d.ts.map +1 -1
  297. package/dist/external-findings-local.js +537 -108
  298. package/dist/external-findings-local.js.map +1 -1
  299. package/dist/external-findings-publish.d.ts +13 -6
  300. package/dist/external-findings-publish.d.ts.map +1 -1
  301. package/dist/external-findings-publish.js +895 -1142
  302. package/dist/external-findings-publish.js.map +1 -1
  303. package/dist/external-findings-read.d.ts +21 -2
  304. package/dist/external-findings-read.d.ts.map +1 -1
  305. package/dist/external-findings-read.js +130 -68
  306. package/dist/external-findings-read.js.map +1 -1
  307. package/dist/external-findings.d.ts +15 -3
  308. package/dist/external-findings.d.ts.map +1 -1
  309. package/dist/external-findings.js +54 -2
  310. package/dist/external-findings.js.map +1 -1
  311. package/dist/external-import-contract.d.ts +8 -12
  312. package/dist/external-import-contract.d.ts.map +1 -1
  313. package/dist/external-import-contract.js +51 -184
  314. package/dist/external-import-contract.js.map +1 -1
  315. package/dist/external-import-models.d.ts +1 -1
  316. package/dist/external-import-models.d.ts.map +1 -1
  317. package/dist/external-import-models.js.map +1 -1
  318. package/dist/feedback.d.ts.map +1 -1
  319. package/dist/feedback.js +5 -4
  320. package/dist/feedback.js.map +1 -1
  321. package/dist/finding-prompt.d.ts +5 -0
  322. package/dist/finding-prompt.d.ts.map +1 -0
  323. package/dist/finding-prompt.js +32 -0
  324. package/dist/finding-prompt.js.map +1 -0
  325. package/dist/findings-client.d.ts +1 -0
  326. package/dist/findings-client.d.ts.map +1 -1
  327. package/dist/findings-client.js +27 -3
  328. package/dist/findings-client.js.map +1 -1
  329. package/dist/github-advisories.d.ts.map +1 -1
  330. package/dist/github-advisories.js +0 -2
  331. package/dist/github-advisories.js.map +1 -1
  332. package/dist/github-dependabot-findings.d.ts.map +1 -1
  333. package/dist/github-dependabot-findings.js +18 -8
  334. package/dist/github-dependabot-findings.js.map +1 -1
  335. package/dist/github-findings.d.ts +4 -1
  336. package/dist/github-findings.d.ts.map +1 -1
  337. package/dist/github-findings.js +73 -316
  338. package/dist/github-findings.js.map +1 -1
  339. package/dist/hosted-git-remotes.d.ts +5 -0
  340. package/dist/hosted-git-remotes.d.ts.map +1 -0
  341. package/dist/hosted-git-remotes.js +285 -0
  342. package/dist/hosted-git-remotes.js.map +1 -0
  343. package/dist/hosted-git-repository.d.ts +28 -0
  344. package/dist/hosted-git-repository.d.ts.map +1 -0
  345. package/dist/hosted-git-repository.js +222 -0
  346. package/dist/hosted-git-repository.js.map +1 -0
  347. package/dist/hosted-remediation.d.ts +1 -0
  348. package/dist/hosted-remediation.d.ts.map +1 -1
  349. package/dist/hosted-remediation.js +23 -3
  350. package/dist/hosted-remediation.js.map +1 -1
  351. package/dist/hosted-scan-protocol.js +2 -2
  352. package/dist/hosted-scan-protocol.js.map +1 -1
  353. package/dist/hosted-scan.d.ts.map +1 -1
  354. package/dist/hosted-scan.js +16 -11
  355. package/dist/hosted-scan.js.map +1 -1
  356. package/dist/hosted-scanner-http.d.ts +21 -0
  357. package/dist/hosted-scanner-http.d.ts.map +1 -0
  358. package/dist/hosted-scanner-http.js +204 -0
  359. package/dist/hosted-scanner-http.js.map +1 -0
  360. package/dist/import-scan.d.ts.map +1 -1
  361. package/dist/import-scan.js +3 -0
  362. package/dist/import-scan.js.map +1 -1
  363. package/dist/index.d.ts +21 -9
  364. package/dist/index.d.ts.map +1 -1
  365. package/dist/index.js +12 -3
  366. package/dist/index.js.map +1 -1
  367. package/dist/inspector-findings.d.ts.map +1 -1
  368. package/dist/inspector-findings.js +52 -86
  369. package/dist/inspector-findings.js.map +1 -1
  370. package/dist/knowledge-base.d.ts +1 -1
  371. package/dist/knowledge-base.d.ts.map +1 -1
  372. package/dist/knowledge-base.js +102 -32
  373. package/dist/knowledge-base.js.map +1 -1
  374. package/dist/linear.d.ts +11 -0
  375. package/dist/linear.d.ts.map +1 -1
  376. package/dist/linear.js.map +1 -1
  377. package/dist/local-git-metadata.d.ts +5 -2
  378. package/dist/local-git-metadata.d.ts.map +1 -1
  379. package/dist/local-git-metadata.js +8 -5
  380. package/dist/local-git-metadata.js.map +1 -1
  381. package/dist/multiscan.d.ts +10 -4
  382. package/dist/multiscan.d.ts.map +1 -1
  383. package/dist/multiscan.js +217 -102
  384. package/dist/multiscan.js.map +1 -1
  385. package/dist/native-json-findings.d.ts +2 -1
  386. package/dist/native-json-findings.d.ts.map +1 -1
  387. package/dist/native-json-findings.js +12 -2
  388. package/dist/native-json-findings.js.map +1 -1
  389. package/dist/opengrep-findings.d.ts +5 -2
  390. package/dist/opengrep-findings.d.ts.map +1 -1
  391. package/dist/opengrep-findings.js +54 -33
  392. package/dist/opengrep-findings.js.map +1 -1
  393. package/dist/operation-telemetry.d.ts +104 -0
  394. package/dist/operation-telemetry.d.ts.map +1 -0
  395. package/dist/operation-telemetry.js +293 -0
  396. package/dist/operation-telemetry.js.map +1 -0
  397. package/dist/plugin-python-probe.d.ts +4 -0
  398. package/dist/plugin-python-probe.d.ts.map +1 -0
  399. package/dist/plugin-python-probe.js +10 -0
  400. package/dist/plugin-python-probe.js.map +1 -0
  401. package/dist/private-finding-import.d.ts +99 -9
  402. package/dist/private-finding-import.d.ts.map +1 -1
  403. package/dist/private-finding-import.js +116 -152
  404. package/dist/private-finding-import.js.map +1 -1
  405. package/dist/project-config.d.ts.map +1 -1
  406. package/dist/project-config.js +53 -13
  407. package/dist/project-config.js.map +1 -1
  408. package/dist/prompt-files.d.ts +7 -2
  409. package/dist/prompt-files.d.ts.map +1 -1
  410. package/dist/prompt-files.js +42 -20
  411. package/dist/prompt-files.js.map +1 -1
  412. package/dist/provider-profile.d.ts +1 -1
  413. package/dist/provider-profile.d.ts.map +1 -1
  414. package/dist/provider-profile.js +12 -10
  415. package/dist/provider-profile.js.map +1 -1
  416. package/dist/publication-telemetry.d.ts +45 -0
  417. package/dist/publication-telemetry.d.ts.map +1 -0
  418. package/dist/publication-telemetry.js +50 -0
  419. package/dist/publication-telemetry.js.map +1 -0
  420. package/dist/publication.d.ts +1 -1
  421. package/dist/publication.d.ts.map +1 -1
  422. package/dist/publication.js.map +1 -1
  423. package/dist/publish.d.ts +4 -0
  424. package/dist/publish.d.ts.map +1 -1
  425. package/dist/publish.js +42 -2
  426. package/dist/publish.js.map +1 -1
  427. package/dist/record.d.ts +1 -5
  428. package/dist/record.d.ts.map +1 -1
  429. package/dist/record.js +3 -51
  430. package/dist/record.js.map +1 -1
  431. package/dist/remediation.d.ts +1 -4
  432. package/dist/remediation.d.ts.map +1 -1
  433. package/dist/remediation.js +6 -8
  434. package/dist/remediation.js.map +1 -1
  435. package/dist/request-metadata.d.ts +3 -0
  436. package/dist/request-metadata.d.ts.map +1 -1
  437. package/dist/request-metadata.js +9 -0
  438. package/dist/request-metadata.js.map +1 -1
  439. package/dist/result.d.ts +4 -0
  440. package/dist/result.d.ts.map +1 -1
  441. package/dist/result.js +1 -1
  442. package/dist/result.js.map +1 -1
  443. package/dist/retry-windows-rename.d.ts +8 -0
  444. package/dist/retry-windows-rename.d.ts.map +1 -0
  445. package/dist/retry-windows-rename.js +24 -0
  446. package/dist/retry-windows-rename.js.map +1 -0
  447. package/dist/runtime.d.ts +54 -6
  448. package/dist/runtime.d.ts.map +1 -1
  449. package/dist/runtime.js +1084 -256
  450. package/dist/runtime.js.map +1 -1
  451. package/dist/saved-scan-bootstrap.d.ts +7 -1
  452. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  453. package/dist/saved-scan-bootstrap.js +269 -114
  454. package/dist/saved-scan-bootstrap.js.map +1 -1
  455. package/dist/scan-activity.d.ts.map +1 -1
  456. package/dist/scan-activity.js +141 -56
  457. package/dist/scan-activity.js.map +1 -1
  458. package/dist/scan-archive-path.d.ts +2 -0
  459. package/dist/scan-archive-path.d.ts.map +1 -0
  460. package/dist/scan-archive-path.js +5 -0
  461. package/dist/scan-archive-path.js.map +1 -0
  462. package/dist/scan-comparison.d.ts +10 -5
  463. package/dist/scan-comparison.d.ts.map +1 -1
  464. package/dist/scan-comparison.js +66 -17
  465. package/dist/scan-comparison.js.map +1 -1
  466. package/dist/scan-dashboard.d.ts +7 -6
  467. package/dist/scan-dashboard.d.ts.map +1 -1
  468. package/dist/scan-dashboard.js +92 -43
  469. package/dist/scan-dashboard.js.map +1 -1
  470. package/dist/scan-executor.d.ts +10 -1
  471. package/dist/scan-executor.d.ts.map +1 -1
  472. package/dist/scan-executor.js +24 -2
  473. package/dist/scan-executor.js.map +1 -1
  474. package/dist/scan-history-renderer.d.ts +1 -0
  475. package/dist/scan-history-renderer.d.ts.map +1 -1
  476. package/dist/scan-history-renderer.js +34 -28
  477. package/dist/scan-history-renderer.js.map +1 -1
  478. package/dist/scan-logs.d.ts +12 -0
  479. package/dist/scan-logs.d.ts.map +1 -1
  480. package/dist/scan-logs.js +131 -78
  481. package/dist/scan-logs.js.map +1 -1
  482. package/dist/scan-measurement.d.ts +26 -0
  483. package/dist/scan-measurement.d.ts.map +1 -0
  484. package/dist/scan-measurement.js +77 -0
  485. package/dist/scan-measurement.js.map +1 -0
  486. package/dist/scan-progress.d.ts +1 -0
  487. package/dist/scan-progress.d.ts.map +1 -1
  488. package/dist/scan-progress.js +3 -0
  489. package/dist/scan-progress.js.map +1 -1
  490. package/dist/scan-sessions.d.ts.map +1 -1
  491. package/dist/scan-sessions.js +4 -1
  492. package/dist/scan-sessions.js.map +1 -1
  493. package/dist/scan-settings.d.ts +1 -1
  494. package/dist/scan-settings.d.ts.map +1 -1
  495. package/dist/scan-settings.js +1 -24
  496. package/dist/scan-settings.js.map +1 -1
  497. package/dist/scanner-import.d.ts +25 -13
  498. package/dist/scanner-import.d.ts.map +1 -1
  499. package/dist/scanner-import.js +216 -97
  500. package/dist/scanner-import.js.map +1 -1
  501. package/dist/scanner-repository-url.d.ts +4 -1
  502. package/dist/scanner-repository-url.d.ts.map +1 -1
  503. package/dist/scanner-repository-url.js +10 -6
  504. package/dist/scanner-repository-url.js.map +1 -1
  505. package/dist/security-policy.d.ts +1 -1
  506. package/dist/security-policy.d.ts.map +1 -1
  507. package/dist/security-policy.js +26 -6
  508. package/dist/security-policy.js.map +1 -1
  509. package/dist/semgrep-findings.d.ts +6 -3
  510. package/dist/semgrep-findings.d.ts.map +1 -1
  511. package/dist/semgrep-findings.js +72 -42
  512. package/dist/semgrep-findings.js.map +1 -1
  513. package/dist/semgrep-guardian-findings.d.ts +38 -0
  514. package/dist/semgrep-guardian-findings.d.ts.map +1 -0
  515. package/dist/semgrep-guardian-findings.js +165 -0
  516. package/dist/semgrep-guardian-findings.js.map +1 -0
  517. package/dist/semgrep-platform-collector.d.ts +26 -0
  518. package/dist/semgrep-platform-collector.d.ts.map +1 -0
  519. package/dist/semgrep-platform-collector.js +108 -0
  520. package/dist/semgrep-platform-collector.js.map +1 -0
  521. package/dist/semgrep-platform-findings.d.ts +157 -6
  522. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  523. package/dist/semgrep-platform-findings.js +766 -103
  524. package/dist/semgrep-platform-findings.js.map +1 -1
  525. package/dist/server/api.d.ts +1 -1
  526. package/dist/server/api.d.ts.map +1 -1
  527. package/dist/server/api.js.map +1 -1
  528. package/dist/server/embedding-tokenizer.cdx.json +33 -0
  529. package/dist/server/embedding-tokenizer.d.ts +2 -0
  530. package/dist/server/embedding-tokenizer.d.ts.map +1 -0
  531. package/dist/server/embedding-tokenizer.js +322 -0
  532. package/dist/server/embedding-tokenizer.js.map +6 -0
  533. package/dist/server/embeddings.d.ts +16 -2
  534. package/dist/server/embeddings.d.ts.map +1 -1
  535. package/dist/server/embeddings.js +35 -5
  536. package/dist/server/embeddings.js.map +1 -1
  537. package/dist/session-lines.d.ts +5 -0
  538. package/dist/session-lines.d.ts.map +1 -0
  539. package/dist/session-lines.js +60 -0
  540. package/dist/session-lines.js.map +1 -0
  541. package/dist/severity-review.d.ts +3 -1
  542. package/dist/severity-review.d.ts.map +1 -1
  543. package/dist/severity-review.js +3 -2
  544. package/dist/severity-review.js.map +1 -1
  545. package/dist/skill-authentication.d.ts +1 -0
  546. package/dist/skill-authentication.d.ts.map +1 -1
  547. package/dist/skill-authentication.js +1 -0
  548. package/dist/skill-authentication.js.map +1 -1
  549. package/dist/snyk-findings.d.ts +9 -2
  550. package/dist/snyk-findings.d.ts.map +1 -1
  551. package/dist/snyk-findings.js +90 -70
  552. package/dist/snyk-findings.js.map +1 -1
  553. package/dist/snyk-rest-findings.d.ts +59 -0
  554. package/dist/snyk-rest-findings.d.ts.map +1 -0
  555. package/dist/snyk-rest-findings.js +879 -0
  556. package/dist/snyk-rest-findings.js.map +1 -0
  557. package/dist/snyk-token-origin.d.ts +4 -0
  558. package/dist/snyk-token-origin.d.ts.map +1 -0
  559. package/dist/snyk-token-origin.js +82 -0
  560. package/dist/snyk-token-origin.js.map +1 -0
  561. package/dist/sonar-collector.d.ts.map +1 -1
  562. package/dist/sonar-collector.js +0 -3
  563. package/dist/sonar-collector.js.map +1 -1
  564. package/dist/sonar-findings.d.ts +1 -1
  565. package/dist/sonar-findings.d.ts.map +1 -1
  566. package/dist/sonar-findings.js +2 -4
  567. package/dist/sonar-findings.js.map +1 -1
  568. package/dist/sonar-import.d.ts +3 -0
  569. package/dist/sonar-import.d.ts.map +1 -1
  570. package/dist/sonar-import.js +30 -34
  571. package/dist/sonar-import.js.map +1 -1
  572. package/dist/stored-finding-projection.d.ts +6 -0
  573. package/dist/stored-finding-projection.d.ts.map +1 -0
  574. package/dist/stored-finding-projection.js +104 -0
  575. package/dist/stored-finding-projection.js.map +1 -0
  576. package/dist/stored-findings-publication.d.ts +23 -0
  577. package/dist/stored-findings-publication.d.ts.map +1 -0
  578. package/dist/stored-findings-publication.js +169 -0
  579. package/dist/stored-findings-publication.js.map +1 -0
  580. package/dist/target-drift.d.ts +9 -0
  581. package/dist/target-drift.d.ts.map +1 -0
  582. package/dist/target-drift.js +27 -0
  583. package/dist/target-drift.js.map +1 -0
  584. package/dist/targets.d.ts +8 -1
  585. package/dist/targets.d.ts.map +1 -1
  586. package/dist/targets.js +131 -42
  587. package/dist/targets.js.map +1 -1
  588. package/dist/tenable-findings.d.ts +6 -0
  589. package/dist/tenable-findings.d.ts.map +1 -0
  590. package/dist/tenable-findings.js +122 -0
  591. package/dist/tenable-findings.js.map +1 -0
  592. package/dist/terminal-stream.d.ts +13 -0
  593. package/dist/terminal-stream.d.ts.map +1 -0
  594. package/dist/terminal-stream.js +35 -0
  595. package/dist/terminal-stream.js.map +1 -0
  596. package/dist/trivy-findings.d.ts +19 -0
  597. package/dist/trivy-findings.d.ts.map +1 -0
  598. package/dist/trivy-findings.js +424 -0
  599. package/dist/trivy-findings.js.map +1 -0
  600. package/dist/trivy-import.d.ts +19 -0
  601. package/dist/trivy-import.d.ts.map +1 -0
  602. package/dist/trivy-import.js +151 -0
  603. package/dist/trivy-import.js.map +1 -0
  604. package/dist/trusted-executable.d.ts +6 -0
  605. package/dist/trusted-executable.d.ts.map +1 -1
  606. package/dist/trusted-executable.js +140 -37
  607. package/dist/trusted-executable.js.map +1 -1
  608. package/dist/validation-records.js +1 -1
  609. package/dist/validation-records.js.map +1 -1
  610. package/dist/veracode-findings.d.ts +1 -1
  611. package/dist/veracode-findings.d.ts.map +1 -1
  612. package/dist/veracode-findings.js +19 -6
  613. package/dist/veracode-findings.js.map +1 -1
  614. package/dist/version.d.ts +3 -1
  615. package/dist/version.d.ts.map +1 -1
  616. package/dist/version.js +184 -32
  617. package/dist/version.js.map +1 -1
  618. package/dist/vertex-pricing.d.ts +8 -0
  619. package/dist/vertex-pricing.d.ts.map +1 -0
  620. package/dist/vertex-pricing.js +20 -0
  621. package/dist/vertex-pricing.js.map +1 -0
  622. package/dist/windows-path.d.ts +1 -0
  623. package/dist/windows-path.d.ts.map +1 -1
  624. package/dist/windows-path.js +26 -1
  625. package/dist/windows-path.js.map +1 -1
  626. package/dist/wiz-findings.d.ts +6 -2
  627. package/dist/wiz-findings.d.ts.map +1 -1
  628. package/dist/wiz-findings.js +65 -89
  629. package/dist/wiz-findings.js.map +1 -1
  630. package/docs/classify-severity-records.md +27 -12
  631. package/docs/cli.md +853 -639
  632. package/docs/dedupe-records.md +44 -24
  633. package/docs/findings-service.md +84 -44
  634. package/docs/hosted-remediation.md +27 -11
  635. package/docs/hosted-scans.md +50 -42
  636. package/docs/sdk.md +903 -0
  637. package/docs/telemetry.md +236 -0
  638. package/docs/validate-records.md +78 -44
  639. package/package.json +23 -16
  640. package/schemas/external-findings.schema.json +4 -1
  641. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  642. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  643. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  644. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  645. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  646. package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +0 -96
  647. package/dist/external-imports-feature.d.ts +0 -6
  648. package/dist/external-imports-feature.d.ts.map +0 -1
  649. package/dist/external-imports-feature.js +0 -51
  650. package/dist/external-imports-feature.js.map +0 -1
  651. package/dist/finding-normalization.d.ts +0 -5
  652. package/dist/finding-normalization.d.ts.map +0 -1
  653. package/dist/finding-normalization.js +0 -155
  654. package/dist/finding-normalization.js.map +0 -1
  655. package/dist/reader-selection.d.ts +0 -13
  656. package/dist/reader-selection.d.ts.map +0 -1
  657. package/dist/reader-selection.js +0 -81
  658. package/dist/reader-selection.js.map +0 -1
@@ -1,23 +1,50 @@
1
+ import { resolve } from "node:path";
2
+ import { isDeepStrictEqual } from "node:util";
3
+ import { semgrepPlatformFindingBinding, semgrepPlatformReportScope, semgrepPlatformRepositoryReference, isSemgrepPlatformEvidence, semgrepReferenceMatches, } from "./semgrep-platform-findings.js";
4
+ import { gitPathToHttpPath, gitServiceHostname, isPublicGitHost, gitTransportBytes, hostedRepositoryMatches, normalizeHostedGitRepositoryUrl, } from "./hosted-git-repository.js";
5
+ import { checkRetainedTrivyProvider, checkTrivyReportProvider, matchTrivyCheckout, } from "./trivy-import.js";
6
+ import { readGitRemoteNames, readHostedGitRemotes, } from "./hosted-git-remotes.js";
1
7
  import { CodexSecurityError } from "./errors.js";
2
- import { forwardExternalImportSetting, requireExternalImports, } from "./external-imports-feature.js";
3
- import { cloneImportPreview, snapshotImportOptions, snapshotNormalizedFindings, snapshotSourceRepositories, } from "./external-findings.js";
4
- import { cloudRepositoryUrlKey, requireSafeJsonInteger, repositoryUrlKey, } from "./external-import-contract.js";
5
- import { localFindingRepositories } from "./external-findings-read.js";
6
- import { hasGitMetadata, localGitProtectionRoots, importGitProtectionRoots, } from "./local-git-metadata.js";
8
+ import { externalImportDisposition, NoPublishableFindingsError, cloneImportPreview, reportForJson, snapshotImportOptions, snapshotNormalizedFindings, snapshotSourceRepositories, } from "./external-findings.js";
9
+ import { cloudRepositoryUrlKey, requireSafeJsonInteger, repositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
10
+ import { EXTERNAL_FINDINGS_PROVIDERS, EXTERNAL_FINDINGS_READERS, localFindingRepositories, semgrepSarifRepositories, } from "./external-findings-read.js";
11
+ import { tenableReportFormat, tenableSourceRepository, } from "./tenable-findings.js";
12
+ import { guardianFindingRepository, guardianSelectionFormat, } from "./semgrep-guardian-findings.js";
13
+ import { hasGitMetadata, localGitProtectionRoots, commandGitProtectionRoots, } from "./local-git-metadata.js";
7
14
  import { blackDuckReportRepositories, projectedBlackDuckRepositoryUrl, } from "./blackduck-findings.js";
8
15
  import { azureReposHttpsUrl, isGitHubCloudHost, isGitHubSshOverHttps, isGitSsh, parseGitRemote, } from "./git-remote.js";
16
+ import { checkmarxSelection } from "./checkmarx-repository.js";
9
17
  import { continuumReportRepositories } from "./continuum-findings.js";
10
18
  import { veracodeReportRepositories } from "./veracode-findings.js";
11
19
  import { inspectorReportRepository } from "./inspector-findings.js";
12
20
  import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
21
+ import { armorCodeRepositoryUrl } from "./armorcode-findings.js";
13
22
  import { sonarRepositoryUrls } from "./sonar-findings.js";
14
23
  import { isRecord } from "./record.js";
15
24
  import { dependabotRepository } from "./github-dependabot-findings.js";
16
- import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, expandHome, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
25
+ import { retainedGitHubRepository } from "./github-findings.js";
26
+ import { snykRestImportRepository, snykRestCheckoutMatches, } from "./snyk-rest-findings.js";
27
+ import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, resolveInputPath, resolveParentTraversal, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
17
28
  import { abortable, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, } from "./targets.js";
18
29
  function requireIdentity(value, field) {
19
30
  if (typeof value !== "string" || !value.trim() || value.includes("\0"))
20
31
  throw new CodexSecurityError(`${field} must be nonempty and contain no NUL characters.`);
32
+ if (!value.isWellFormed())
33
+ throw new CodexSecurityError(`${field} must contain valid Unicode.`);
34
+ }
35
+ function validateFindingIds(current) {
36
+ const identities = new Set();
37
+ for (const finding of current.findings) {
38
+ requireIdentity(finding.source_finding_id, "Source finding id");
39
+ if (identities.has(finding.source_finding_id))
40
+ throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}.`);
41
+ identities.add(finding.source_finding_id);
42
+ if (!isRecord(finding.evidence))
43
+ throw new CodexSecurityError("Imported evidence must be an object.");
44
+ if (typeof finding.evidence.title !== "string" ||
45
+ typeof finding.evidence.severity !== "string")
46
+ throw new CodexSecurityError("Imported evidence requires a title and severity.");
47
+ }
21
48
  }
22
49
  function checkStoredNumber(value) {
23
50
  if (!Number.isFinite(value))
@@ -34,14 +61,9 @@ const gitTransportPorts = {
34
61
  "ftp:": "21",
35
62
  "ftps:": "990",
36
63
  };
37
- function sonarHostedGit(hostname) {
38
- return (isGitHubCloudHost(hostname) ||
39
- hostname === "gitlab.com" ||
40
- hostname === "bitbucket.org");
41
- }
42
64
  function sonarHostedHostname(hostname) {
43
- const name = hostname.toLowerCase().replace(/\.$/u, "");
44
- return sonarHostedGit(name) ||
65
+ const name = gitServiceHostname(hostname.toLowerCase());
66
+ return isPublicGitHost(name) ||
45
67
  ["ssh.github.com", "ssh.dev.azure.com", "dev.azure.com"].includes(name)
46
68
  ? name
47
69
  : undefined;
@@ -106,27 +128,19 @@ function remoteRepository(value, provider, bound, platform = provider, possibleS
106
128
  };
107
129
  }
108
130
  // Git passes the original path (including dot segments, '?' and '#') to upload-pack.
109
- const literal = (raw) => {
110
- const bytes = Buffer.from(raw).toString("latin1");
111
- return scpStyle
112
- ? bytes
113
- : bytes.replace(/%(?!00)([\da-f]{2})/giu, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
114
- };
115
131
  if (!scpStyle && !transport)
116
132
  return { key: value };
117
- const gitPath = literal(transport?.[2] ?? path);
133
+ const gitPath = gitTransportBytes(transport?.[2] ?? path, scpStyle);
118
134
  const login = scpStyle
119
135
  ? /^([^@/:\s?#]+)@/u.exec(value)?.[1]
120
136
  : /^(.*)@/u.exec(authority ?? "")?.[1];
121
137
  const homeRelative = /^\/?~(?:\/|$)/u.test(gitPath) || (scpStyle && !/^[~/]/u.test(gitPath));
122
138
  const suffix = /[?#].*$/su.exec(gitPath);
123
139
  // Express upload-pack bytes as a URL path for comparison with the HTTP source.
124
- const name = gitPath
125
- .slice(0, suffix?.index)
126
- .replace(/^\//u, "")
127
- .replace(/[%\x00-\x20\x7f-\xff]/gu, (byte) => "%" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
140
+ const name = gitPathToHttpPath(gitPath.slice(0, suffix?.index));
128
141
  // Azure's generated SCP clone URL spells spaces as %20, even though Git sends SCP paths literally.
129
- const azure = provider === "sonar" && !(scpStyle && path.startsWith("/"))
142
+ const azure = (provider === "sonar" || provider === "checkmarx") &&
143
+ !(scpStyle && path.startsWith("/"))
130
144
  ? azureReposHttpsUrl(url, scpStyle ? name.replace(/%2520/gu, "%20") : name)
131
145
  : undefined;
132
146
  const repository = suffix
@@ -136,7 +150,7 @@ function remoteRepository(value, provider, bound, platform = provider, possibleS
136
150
  : key(azure ?? origin + name);
137
151
  return {
138
152
  key: repository,
139
- account: ssh && login ? literal(login) : undefined,
153
+ account: ssh && login ? gitTransportBytes(login, scpStyle) : undefined,
140
154
  // GitHub serves the same repository path through its SCP and SSH URLs.
141
155
  homeRelative: ssh && platform !== "github" && !isGitHubCloudHost(hostname.toLowerCase())
142
156
  ? homeRelative
@@ -153,6 +167,20 @@ function matchingRemote(left, right) {
153
167
  right.account === undefined ||
154
168
  left.account === right.account));
155
169
  }
170
+ // Within one fetch key and home-relative mode, matchingRemote can use any
171
+ // account, the requested login, or an unspecified login.
172
+ function fetchAliasMatcher(rows) {
173
+ const homes = Map.groupBy(rows, ({ fetch }) => fetch.homeRelative);
174
+ const accounts = Array.from(homes.values(), (group) => new Map(group.map(({ fetch }) => [fetch.account, fetch])));
175
+ return (fetch) => accounts.some((group) => [
176
+ group.values().next().value,
177
+ group.get(fetch.account),
178
+ group.get(undefined),
179
+ ].some((candidate) => candidate !== undefined && matchingRemote(fetch, candidate)));
180
+ }
181
+ function fetchAliasMatchers(rows, key) {
182
+ return new Map(Array.from(Map.groupBy(rows, key), ([name, group]) => [name, fetchAliasMatcher(group)]));
183
+ }
156
184
  /** A credential-free Sonar repository binding from a supported Git fetch transport. */
157
185
  export function sonarRepositoryForRemote(origin) {
158
186
  try {
@@ -182,7 +210,7 @@ export function sonarRepositoryForRemote(origin) {
182
210
  else if (isGitSsh(url.protocol) &&
183
211
  url.username === "git" &&
184
212
  (!url.port || url.port === "22") &&
185
- sonarHostedGit(hostname)) {
213
+ isPublicGitHost(hostname)) {
186
214
  candidate = `https://${hostname}/${path}`;
187
215
  }
188
216
  else {
@@ -259,27 +287,13 @@ export async function configuredFetchRemotes(repository, provider, protectedRoot
259
287
  !(await boundSonarWorktree(repository, gitProtectedRoots, environment, signal)))
260
288
  return [];
261
289
  const readGit = (args) => abortable(() => gitOutput(repository, args, signal, { LC_ALL: "C" }, undefined, "utf8", gitProtectedRoots, environment), signal);
262
- let remoteNames;
263
- try {
264
- remoteNames = await readGit(["remote"]);
265
- }
266
- catch (error) {
267
- signal?.throwIfAborted();
268
- // A local source directory need not be a Git checkout.
269
- if (error instanceof Error &&
270
- "code" in error &&
271
- error.code === 128 &&
272
- "stderr" in error &&
273
- typeof error.stderr === "string" &&
274
- (error.stderr.trimEnd() ===
275
- "fatal: not a git repository (or any of the parent directories): .git" ||
276
- /^fatal: not a git repository \(or any parent up to mount point [^\r\n]+\)\r?\nStopping at filesystem boundary \(GIT_DISCOVERY_ACROSS_FILESYSTEM not set\)\.$/u.test(error.stderr.trimEnd())))
277
- return [];
278
- throw error;
279
- }
290
+ const remoteNames = await readGitRemoteNames(readGit, signal);
291
+ if (remoteNames === undefined)
292
+ return [];
280
293
  const remotes = [];
294
+ const firstUrlOnly = provider === "sonar" || provider === "checkmarx";
281
295
  for (const name of remoteNames.split(/\r?\n/u).filter(Boolean)) {
282
- if (provider === "sonar") {
296
+ if (firstUrlOnly) {
283
297
  // Git fetches from only the first URL, after insteadOf rewrites.
284
298
  const url = await readGit(["remote", "get-url", "--", name]);
285
299
  if (/[\r\n]/u.test(url))
@@ -294,17 +308,41 @@ export async function configuredFetchRemotes(repository, provider, protectedRoot
294
308
  }
295
309
  return remotes;
296
310
  }
297
- async function requireMatchingRepository(repository, provider, sources, strictSources, strictPlatformFor, protectedRoots, environment, signal, possibleSshHost, fetchRemotes) {
298
- if (sources.length === 0)
311
+ async function hostedCheckoutRemotes(repository, protectedRoots, environment, signal) {
312
+ if (!(await hasGitMetadata(repository, signal)))
313
+ return undefined;
314
+ return readHostedGitRemotes(repository, [...protectedRoots, await canonicalConfigPath(process.cwd())], environment, signal);
315
+ }
316
+ async function requireMatchingRepository(repository, provider, sources, strictSources, hostedSources, platformFor, snyk, protectedRoots, environment, signal, possibleSshHost, fetchRemotes, isCheckmarxSource) {
317
+ if (!snyk && sources.length === 0 && hostedSources.length === 0)
299
318
  return false;
319
+ let allSourcesMatched = true;
320
+ if (snyk || hostedSources.length) {
321
+ const remotes = await hostedCheckoutRemotes(repository, protectedRoots, environment, signal);
322
+ if (snyk) {
323
+ if (remotes &&
324
+ !remotes.some((remote) => snykRestCheckoutMatches(snyk, remote)))
325
+ throw new CodexSecurityError(`Imported repository ${JSON.stringify(snyk.url)} does not match a configured remote of ${repository}. Select the matching local repository.`);
326
+ return remotes !== undefined;
327
+ }
328
+ allSourcesMatched = remotes !== undefined;
329
+ if (remotes) {
330
+ for (const source of hostedSources)
331
+ if (!remotes.some((remote) => hostedRepositoryMatches(source, remote)))
332
+ throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured remote of ${repository}. Select the matching local repository.`);
333
+ }
334
+ if (!sources.length)
335
+ return allSourcesMatched;
336
+ }
337
+ const remoteProvider = (checkmarx) => checkmarx && provider !== "sonar" ? "checkmarx" : provider;
300
338
  const remotes = fetchRemotes ??
301
- (await configuredFetchRemotes(repository, provider, protectedRoots, environment, signal));
339
+ (await configuredFetchRemotes(repository, remoteProvider(Boolean(isCheckmarxSource)), protectedRoots, environment, signal));
302
340
  const boundProvider = provider === "sonar" ||
341
+ provider === "checkmarx" ||
303
342
  provider === "continuum" ||
304
343
  provider === "inspector" ||
305
344
  provider === "blackduck" ||
306
345
  provider === "veracode";
307
- const loosePlatformFor = localRepositoryPlatform(provider, sources, false);
308
346
  const comparable = [];
309
347
  const unverified = [];
310
348
  for (const { url: remote } of remotes) {
@@ -314,13 +352,11 @@ async function requireMatchingRepository(repository, provider, sources, strictSo
314
352
  else if (!/[\s\\\p{Cc}?#]/u.test(remote))
315
353
  unverified.push(remote);
316
354
  }
317
- let allSourcesMatched = true;
318
355
  for (const source of sources) {
319
356
  const bound = boundProvider || strictSources.has(source.url);
320
- const platform = bound
321
- ? (strictSources.get(source.url) ?? strictPlatformFor(source))
322
- : loosePlatformFor(source);
323
- const identity = (url) => remoteRepository(url, provider, bound, platform);
357
+ const platform = strictSources.get(source.url) ?? platformFor(source, bound);
358
+ const sourceProvider = remoteProvider(isCheckmarxSource?.(source.url));
359
+ const identity = (url, fallbackHost) => remoteRepository(url, sourceProvider, bound, platform, fallbackHost);
324
360
  const targets = comparable.flatMap((remote) => identity(remote) ?? []);
325
361
  const target = identity(source.url);
326
362
  if (target && targets.some((remote) => matchingRemote(remote, target)))
@@ -328,8 +364,7 @@ async function requireMatchingRepository(repository, provider, sources, strictSo
328
364
  allSourcesMatched = false;
329
365
  // A custom SSH upstream can agree with a manual mapping even when a
330
366
  // recognized HTTPS remote points at a fork. It cannot prove a Cloud binding.
331
- const configured = unverified.flatMap((remote) => remoteRepository(remote, provider, bound, platform, possibleSshHost) ??
332
- []);
367
+ const configured = unverified.flatMap((remote) => identity(remote, possibleSshHost) ?? []);
333
368
  if (target && configured.some((remote) => matchingRemote(remote, target)))
334
369
  continue;
335
370
  if (targets.length || configured.length)
@@ -338,27 +373,34 @@ async function requireMatchingRepository(repository, provider, sources, strictSo
338
373
  return allSourcesMatched;
339
374
  }
340
375
  export function sonarCheckoutMatchesSource(repository, url, protectedRoots, environment, signal) {
341
- return requireMatchingRepository(repository, "sonar", [{ url }], new Map(), () => "sonar", [...protectedRoots], environment, signal);
376
+ return requireMatchingRepository(repository, "sonar", [{ url }], new Map(), [], () => "sonar", undefined, [...protectedRoots], environment, signal);
342
377
  }
378
+ /** @internal Resolve and protect the local checkout and workbench state directory. */
343
379
  async function localContext(selectedRepository, dependencies, mode = "import") {
344
380
  dependencies.signal?.throwIfAborted();
345
- const selected = dependencies.environment ?? process.env;
346
- const environment = workbenchEnvironment(selected);
347
- forwardExternalImportSetting(selected, environment);
348
- requireExternalImports(environment);
349
- const path = expandHome(selectedRepository, environment);
381
+ const environment = workbenchEnvironment(dependencies.environment ?? process.env);
382
+ const requested = resolveInputPath(selectedRepository, process.cwd(), environment);
383
+ const path = await abortable(() => resolveParentTraversal(requested), dependencies.signal);
350
384
  const repository = mode === "read"
351
385
  ? await abortable(() => canonicalConfigPath(path), dependencies.signal)
352
386
  : await normalizeRepository(path, dependencies.signal);
387
+ const lexicalPath = resolve(requested);
388
+ const lexicalRepository = lexicalPath === resolve(path)
389
+ ? repository
390
+ : await abortable(() => canonicalConfigPath(lexicalPath), dependencies.signal);
353
391
  const protectedRoot = [
354
392
  ...new Set([
355
393
  repository,
356
- ...(await abortable(() => importGitProtectionRoots(path, environment, dependencies.signal), dependencies.signal)),
394
+ ...(mode === "read" ? [lexicalRepository] : []),
395
+ ...(await abortable(() => commandGitProtectionRoots(path, environment, dependencies.signal, {
396
+ requestedPaths: [lexicalPath, lexicalRepository],
397
+ }), dependencies.signal)),
357
398
  ]),
358
399
  ];
359
400
  requireOutputOutsideRepositories(protectedRoot, await abortable(() => canonicalizeModelSafePath(environment.CODEX_SECURITY_STATE_DIR), dependencies.signal), "runtime");
360
401
  return {
361
402
  repository,
403
+ selectedPath: path,
362
404
  options: {
363
405
  pluginRoot: await abortable(() => bundledPluginRoot(), dependencies.signal),
364
406
  environment,
@@ -370,23 +412,95 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
370
412
  }
371
413
  /** Prepare scanner evidence without writing state or performing a security assessment. */
372
414
  export async function prepareNormalizedLocalImport(input, options, dependencies = {}) {
373
- dependencies.signal?.throwIfAborted();
374
- requireExternalImports(dependencies.environment);
375
- return prepareLocalImport(input, snapshotImportOptions(options), dependencies);
415
+ const { signal } = dependencies;
416
+ signal?.throwIfAborted();
417
+ const settings = snapshotImportOptions(options);
418
+ const reader = EXTERNAL_FINDINGS_READERS.find((name) => name === settings.provider);
419
+ if (reader)
420
+ return prepareLocalImport(input, { ...settings, provider: EXTERNAL_FINDINGS_PROVIDERS[reader] }, dependencies);
421
+ const references = snapshotSourceRepositories(dependencies.sourceRepositories);
422
+ requireIdentity(settings.provider, "Provider");
423
+ requireIdentity(settings.sourceKey, "Source key");
424
+ const current = snapshotNormalizedFindings(input, checkStoredNumber);
425
+ validateFindingIds(current);
426
+ if (current.report !== undefined && !isRecord(current.report))
427
+ throw new CodexSecurityError("Report metadata must be an object.");
428
+ if (current.read !== current.findings.length + current.excluded.length)
429
+ throw new CodexSecurityError("Every source record must be accounted for by a finding or exclusion.");
430
+ const positions = new Set();
431
+ for (const { position, source_finding_id, reason } of current.excluded) {
432
+ if (!Number.isSafeInteger(position) ||
433
+ position < 1 ||
434
+ position > current.read ||
435
+ positions.has(position))
436
+ throw new CodexSecurityError("An excluded position must be unique and within the reported record count.");
437
+ positions.add(position);
438
+ requireIdentity(reason, "Exclusion reason");
439
+ if (source_finding_id !== null)
440
+ requireIdentity(source_finding_id, "Excluded source finding id");
441
+ }
442
+ const platform = references.find((ref) => ref.platform)?.platform;
443
+ const urls = new Set(references.map(({ url }) => url));
444
+ if (settings.sourceRepositoryUrl !== undefined)
445
+ urls.add(settings.sourceRepositoryUrl);
446
+ for (const finding of current.findings) {
447
+ finding.evidence = validateExternalEvidence(finding.evidence, "local");
448
+ const repository = finding.evidence.details?.repository;
449
+ if (repository)
450
+ urls.add(repository.url);
451
+ }
452
+ const sources = Array.from(urls, (url) => ({
453
+ url: declaredScannerRepositoryUrl(url, settings.provider, "local"),
454
+ platform,
455
+ }));
456
+ const [source] = sources;
457
+ const context = await localContext(settings.repository, dependencies);
458
+ let matched = false;
459
+ if (source) {
460
+ if (references.some((ref) => ref.platform && ref.platform !== platform) ||
461
+ sources.some(({ url }) => !hostedRepositoryMatches(source, url)))
462
+ throw new CodexSecurityError("The findings declare conflicting source repositories.");
463
+ const remotes = await hostedCheckoutRemotes(context.repository, context.options.protectedRoot, context.options.environment, signal);
464
+ matched =
465
+ remotes?.some((remote) => hostedRepositoryMatches(source, remote)) ??
466
+ false;
467
+ if (!matched &&
468
+ remotes?.some((remote) => /^https?:\/\//iu.test(normalizeHostedGitRepositoryUrl(remote, undefined, platform !== undefined))))
469
+ throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured fetch remote of ${context.repository}.`);
470
+ }
471
+ return preparedLocalStorage(current, settings, context, dependencies, matched, { sourceRepositories: sources });
472
+ }
473
+ // A scanner can repeat the same repository reference for every finding in a run.
474
+ export function distinctSourceRepositories(sources) {
475
+ const seen = new Map();
476
+ return sources.filter(({ url, platform }) => {
477
+ const urls = seen.get(platform) ?? new Set();
478
+ if (urls.has(url))
479
+ return false;
480
+ urls.add(url);
481
+ seen.set(platform, urls);
482
+ return true;
483
+ });
376
484
  }
377
485
  /** @internal Prepare evidence using settings captured by either local import entrypoint. */
378
- export async function prepareLocalImport(input, options, dependencies, readerSources = snapshotSourceRepositories(dependencies.sourceRepositories), parsedSources = [], fetchRemotes) {
486
+ export async function prepareLocalImport(input, options, dependencies, readerSources = distinctSourceRepositories(snapshotSourceRepositories(dependencies.sourceRepositories)), parsedInput, fetchRemotes) {
379
487
  requireIdentity(options.sourceKey, "Source key");
380
- const current = snapshotNormalizedFindings(input, checkStoredNumber);
488
+ const parsedSources = distinctSourceRepositories(parsedInput ?? []);
489
+ // File readers interpret their source option while parsing. For normalized
490
+ // input the caller declares one repository for the whole selection.
491
+ const normalizedSource = parsedInput === undefined && options.sourceRepositoryUrl !== undefined
492
+ ? declaredScannerRepositoryUrl(options.sourceRepositoryUrl, options.provider, "local")
493
+ : undefined;
494
+ const current = snapshotNormalizedFindings(input, checkStoredNumber, "local", options.provider);
495
+ if (options.provider !== "tenable" &&
496
+ (current.report?.["format"] === tenableReportFormat ||
497
+ current.findings.some((row) => row.evidence?.source_data?.["format"] === tenableReportFormat)))
498
+ throw new CodexSecurityError("Retained Tenable evidence requires the tenable provider.");
499
+ checkTrivyReportProvider(options.provider, current.report);
381
500
  let dependabotSource;
382
- const identities = new Set();
501
+ validateFindingIds(current);
383
502
  for (const finding of current.findings) {
384
- requireIdentity(finding.source_finding_id, "Source finding id");
385
- if (identities.has(finding.source_finding_id))
386
- throw new CodexSecurityError(`Duplicate source finding id ${JSON.stringify(finding.source_finding_id)}.`);
387
- identities.add(finding.source_finding_id);
388
- if (!isRecord(finding.evidence))
389
- throw new CodexSecurityError("Imported evidence must be an object.");
503
+ checkRetainedTrivyProvider(options.provider, finding, "local");
390
504
  if (options.provider !== "github")
391
505
  continue;
392
506
  const native = dependabotRepository(finding);
@@ -400,15 +514,26 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
400
514
  throw new CodexSecurityError("Select Dependabot alerts from only one GitHub host and repository.");
401
515
  dependabotSource = native;
402
516
  }
403
- const { repository, options: workbenchOptions } = await localContext(options.repository, dependencies);
517
+ const context = await localContext(options.repository, dependencies);
518
+ if (options.provider === "tenable") {
519
+ const source = tenableSourceRepository(current, options.sourceRepositoryUrl, [...readerSources, ...parsedSources]);
520
+ const remotes = await hostedCheckoutRemotes(context.repository, context.options.protectedRoot, context.options.environment, dependencies.signal);
521
+ if (!remotes?.some((remote) => hostedRepositoryMatches(source, remote)))
522
+ throw new CodexSecurityError("Tenable's source repository must match a configured Git fetch remote of the selected checkout.");
523
+ return preparedLocalStorage(current, options, context, dependencies, true, {
524
+ sourceRepositories: [source],
525
+ });
526
+ }
527
+ const { repository, options: workbenchOptions } = context;
404
528
  const sources = new Map();
405
529
  const references = [...readerSources, ...parsedSources];
406
530
  const inspector = inspectorReportRepository(options.provider, current.findings, "local", options.inspectorProjectMap);
407
- const projected = options.provider === "blackduck"
408
- ? []
409
- : current.findings.filter((finding) => projectedBlackDuckRepositoryUrl(finding, "local"));
531
+ const checkmarx = checkmarxSelection(options.provider, current.findings, current.report, "local");
532
+ const projected = current.findings.filter((finding) => (options.provider !== "blackduck" &&
533
+ projectedBlackDuckRepositoryUrl(finding, "local")) ||
534
+ checkmarx.projections.has(finding));
410
535
  const mixed = projected.length > 0 && readerSources.length > 0;
411
- const nativeSources = new Map((mixed ? current.findings : projected)
536
+ const nativeSources = new Map((mixed || normalizedSource ? current.findings : projected)
412
537
  .filter(({ evidence }) => options.provider !== "endor" ||
413
538
  isRecord(evidence.source_data?.["runContext"]))
414
539
  .map((finding) => [
@@ -430,6 +555,7 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
430
555
  const operatorPlatform = localRepositoryPlatform(options.provider, readerSources, true);
431
556
  const sameRepositories = (urls) => sameScannerRepositories(Array.from(urls, identify));
432
557
  const bound = blackDuckReportRepositories(options.provider, current.findings, "local", sameRepositories);
558
+ const checkmarxRepository = checkmarx.repositories(sameRepositories);
433
559
  for (const repositories of [
434
560
  veracodeReportRepositories,
435
561
  continuumReportRepositories,
@@ -439,19 +565,107 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
439
565
  }
440
566
  }
441
567
  const strictSources = new Map();
568
+ const checkmarxKeys = new Set();
569
+ const hostedSources = new Map();
570
+ const semgrepReportScope = semgrepPlatformReportScope(current, options.provider, readerSources);
571
+ const semgrepPlatformRepositoryUrl = semgrepReportScope?.url;
572
+ function addSemgrepSource(url) {
573
+ if (options.provider !== "semgrep")
574
+ throw new CodexSecurityError("Use the semgrep provider for Semgrep Platform findings.");
575
+ const source = semgrepPlatformRepositoryReference(url, readerSources);
576
+ if (semgrepPlatformRepositoryUrl &&
577
+ semgrepPlatformRepositoryUrl !== url &&
578
+ !semgrepReferenceMatches(source, semgrepPlatformRepositoryUrl))
579
+ throw new CodexSecurityError("The Semgrep report repository does not match the native finding's project.");
580
+ hostedSources.set(source.url, source);
581
+ }
582
+ function addGuardianSource(value) {
583
+ if (options.provider !== "semgrep")
584
+ throw new CodexSecurityError("Use the semgrep provider for Guardian findings.");
585
+ const url = declaredScannerRepositoryUrl(value, "Guardian", "local");
586
+ const source = hostedSources.get(url) ??
587
+ semgrepPlatformRepositoryReference(url, readerSources);
588
+ hostedSources.set(url, source);
589
+ return source;
590
+ }
591
+ const guardianReport = current.report?.["format"] === guardianSelectionFormat
592
+ ? addGuardianSource(current.report["repositoryUrl"])
593
+ : undefined;
594
+ if (semgrepPlatformRepositoryUrl)
595
+ addSemgrepSource(semgrepPlatformRepositoryUrl);
442
596
  const known = new Set(parsedSources.map(({ url }) => url));
597
+ const hasPlatformEvidence = options.provider === "semgrep" &&
598
+ (semgrepReportScope !== undefined ||
599
+ current.findings.some((row) => isSemgrepPlatformEvidence(row, options.provider)));
600
+ let hasOrdinaryRows = false;
601
+ let ordinaryRowNeedsReferences = false;
443
602
  for (const finding of current.findings) {
444
- const { evidence, source_finding_id: id } = finding;
445
- const url = evidence.details?.repository?.url;
446
- if (url)
447
- sources.set(url, { url });
448
- const retained = bound.get(id);
603
+ const retained = bound.get(finding.source_finding_id) ?? checkmarxRepository(finding);
449
604
  const native = nativeSources.get(finding) ?? [];
450
- if (retained) {
605
+ const sarif = hasPlatformEvidence ||
606
+ (normalizedSource && options.provider === "semgrep")
607
+ ? semgrepSarifRepositories(finding)
608
+ : [];
609
+ if (normalizedSource)
610
+ for (const source of sarif)
611
+ known.add(source.url);
612
+ const semgrep = semgrepPlatformFindingBinding(finding, options.provider, readerSources, semgrepReportScope, [retained, ...native, ...sarif]);
613
+ if (semgrep) {
614
+ addSemgrepSource(semgrep.url);
615
+ if (semgrep.sourceData)
616
+ finding.evidence.source_data = semgrep.sourceData;
617
+ if (semgrep.migration)
618
+ Object.assign(finding.evidence, semgrep.migration);
619
+ }
620
+ const { evidence } = finding;
621
+ if (options.provider === "armorcode") {
622
+ const nativeUrl = armorCodeRepositoryUrl(evidence.source_data, "local");
623
+ if (nativeUrl)
624
+ sources.set(nativeUrl, { url: nativeUrl });
625
+ }
626
+ if (options.provider === "github") {
627
+ const source = retainedGitHubRepository(finding, (url) => identify(url).key);
628
+ if (source)
629
+ sources.set(source, { url: source, platform: "github" });
630
+ }
631
+ const guardian = guardianFindingRepository(finding, "local");
632
+ const url = evidence.details?.repository?.url;
633
+ if (guardian) {
634
+ const source = addGuardianSource(guardian);
635
+ if ((guardianReport &&
636
+ !semgrepReferenceMatches(guardianReport, source.url)) ||
637
+ (url &&
638
+ !semgrepReferenceMatches(source, declaredScannerRepositoryUrl(url, "Guardian", "local"))))
639
+ throw new CodexSecurityError("The Guardian finding repository does not match its recorded selection.");
640
+ }
641
+ else if (!semgrep) {
642
+ hasOrdinaryRows = true;
643
+ if (url)
644
+ sources.set(url, { url });
645
+ }
646
+ if (hasPlatformEvidence &&
647
+ !semgrep &&
648
+ !guardian &&
649
+ !retained &&
650
+ !native.length) {
651
+ for (const source of sarif)
652
+ sources.set(source.url, source);
653
+ if (!url && !sarif.length)
654
+ ordinaryRowNeedsReferences = true;
655
+ if (!url && references.length) {
656
+ for (const source of sarif) {
657
+ const claim = identify(source.url);
658
+ if (!references.some((ref) => matchingRemote(claim, identify(ref.url))))
659
+ throw new CodexSecurityError(`The reader must supply the projected Semgrep SARIF repository ${JSON.stringify(source.url)} for the configured remote.`);
660
+ }
661
+ }
662
+ }
663
+ const projectedCheckmarx = checkmarx.projections.has(finding);
664
+ if (retained || (projectedCheckmarx && native.length)) {
665
+ const rowSources = retained ? [retained, ...native] : native;
451
666
  const claims = [
452
- retained.url,
667
+ ...rowSources.map((ref) => ref.url),
453
668
  ...(url ? [url] : []),
454
- ...native.map((ref) => ref.url),
455
669
  ];
456
670
  const rowPlatform = (claim) => options.provider !== "wiz"
457
671
  ? platformFor({ url: claim })
@@ -462,9 +676,11 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
462
676
  key: claim,
463
677
  })))
464
678
  throw new CodexSecurityError("The retained scanner repository does not match the original provider finding.");
465
- for (const source of [retained, ...native])
679
+ for (const source of rowSources)
466
680
  sources.set(source.url, source);
467
681
  for (const claim of claims) {
682
+ if (projectedCheckmarx)
683
+ checkmarxKeys.add(identify(claim).key);
468
684
  const platform = rowPlatform(claim);
469
685
  if (!strictSources.has(claim) || platform !== "github")
470
686
  strictSources.set(claim, platform);
@@ -473,12 +689,54 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
473
689
  for (const source of native)
474
690
  known.add(source.url);
475
691
  }
692
+ // Match references for native Platform rows using their hosted Git identity.
693
+ const hosted = Array.from(hostedSources.values());
694
+ const hostedReferences = new Set(references.filter((ref) => hosted.some((source) => semgrepReferenceMatches(source, ref.url))));
695
+ const sharedReferences = new Set();
696
+ const ordinaryReferences = new Set();
697
+ if (hostedReferences.size) {
698
+ const readerPlatform = localRepositoryPlatform(options.provider, [...sources.values(), ...references], false);
699
+ const ordinaryIdentity = (url) => remoteRepository(url, options.provider, false, readerPlatform({ url })) ?? { key: url };
700
+ const aliases = references.map((ref) => ({
701
+ ref,
702
+ fetch: identify(ref.url),
703
+ ordinary: ordinaryIdentity(ref.url).key,
704
+ }));
705
+ const claims = Map.groupBy(Array.from(sources.keys(), (url) => ({
706
+ fetch: identify(url),
707
+ ordinary: strictSources.has(url)
708
+ ? undefined
709
+ : ordinaryIdentity(url).key,
710
+ })), (claim) => claim.fetch.key);
711
+ for (const [key, refs] of Map.groupBy(aliases, (alias) => alias.fetch.key)) {
712
+ const hosted = refs.filter(({ ref }) => hostedReferences.has(ref));
713
+ const group = claims.get(key);
714
+ if (!hosted.length || !group)
715
+ continue;
716
+ const shared = fetchAliasMatcher(group);
717
+ const readers = fetchAliasMatchers(refs, (alias) => alias.ordinary);
718
+ // Keep a sole fetch alias subject to checkout validation. A redundant
719
+ // Platform spelling can be dropped when another reference serves the reader.
720
+ const required = fetchAliasMatchers(group, ({ fetch, ordinary }) => ordinary !== undefined && readers.get(ordinary)?.(fetch)
721
+ ? ordinary
722
+ : undefined);
723
+ for (const alias of hosted) {
724
+ if (!shared(alias.fetch))
725
+ continue;
726
+ sharedReferences.add(alias.ref);
727
+ if (required.get(undefined)?.(alias.fetch) ||
728
+ required.get(alias.ordinary)?.(alias.fetch))
729
+ ordinaryReferences.add(alias.ref);
730
+ }
731
+ }
732
+ }
476
733
  if (mixed) {
477
- // A caller reference with no matching row spelling can still be a Git alias.
734
+ // Other caller references must identify an ordinary row or one of its Git aliases.
478
735
  const rows = [...sources.keys(), ...known].map(identify);
479
736
  const byKey = Map.groupBy(rows, (remote) => remote.key);
480
737
  const represented = new Set(rows.map((remote) => JSON.stringify(remote)));
481
738
  const aliases = readerSources
739
+ .filter((ref) => !hostedReferences.has(ref) || sharedReferences.has(ref))
482
740
  .map(({ url }) => identify(url))
483
741
  .filter((remote) => !represented.has(JSON.stringify(remote)));
484
742
  for (const [key, group] of Map.groupBy(aliases, (remote) => remote.key)) {
@@ -490,11 +748,15 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
490
748
  if (strictSources.size && options.provider !== "blackduck") {
491
749
  const keys = new Set(Array.from(strictSources.keys(), (url) => identify(url).key));
492
750
  for (const source of references)
493
- if (!strictSources.has(source.url) && keys.has(identify(source.url).key))
751
+ if (!strictSources.has(source.url) &&
752
+ keys.has(identify(source.url).key)) {
494
753
  strictSources.set(source.url, platformFor(source));
754
+ if (sharedReferences.has(source))
755
+ ordinaryReferences.add(source);
756
+ }
495
757
  }
496
758
  if (inspector) {
497
- const platform = inspector.platform ?? options.provider;
759
+ const platform = inspector.platform === "github" ? "github" : options.provider;
498
760
  const native = remoteRepository(inspector.url, options.provider, true, platform);
499
761
  for (const url of sources.keys()) {
500
762
  if (!native ||
@@ -503,11 +765,42 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
503
765
  throw new CodexSecurityError(`Imported repository ${JSON.stringify(url)} does not match the retained Inspector repository ${JSON.stringify(inspector.url)}.`);
504
766
  }
505
767
  }
768
+ if (readerSources.length &&
769
+ hosted.length &&
770
+ ((!hasOrdinaryRows &&
771
+ !readerSources.every((ref) => hostedReferences.has(ref))) ||
772
+ hosted.some((source) => !readerSources.some((ref) => semgrepReferenceMatches(source, ref.url)))))
773
+ throw new CodexSecurityError("The reader's source repository does not match the selected Semgrep project.");
506
774
  for (const source of [...(inspector ? [inspector] : []), ...references]) {
775
+ if (!ordinaryRowNeedsReferences &&
776
+ hostedReferences.has(source) &&
777
+ !ordinaryReferences.has(source))
778
+ continue;
507
779
  // A reader's platform must not loosen an operator-supplied Inspector map.
508
780
  if (sources.get(source.url)?.platform !== "github")
509
781
  sources.set(source.url, options.inspectorProjectMap ? { url: source.url } : source);
510
782
  }
783
+ const reportUrl = checkmarx.reportUrl;
784
+ if (reportUrl) {
785
+ const source = sources.get(reportUrl) ?? { url: reportUrl };
786
+ sources.set(reportUrl, source);
787
+ checkmarxKeys.add(identify(reportUrl).key);
788
+ if (!strictSources.has(reportUrl))
789
+ strictSources.set(reportUrl, platformFor(source));
790
+ }
791
+ if (((options.provider === "checkmarx" || reportUrl) &&
792
+ !sameRepositories(sources.keys())) ||
793
+ (reportUrl &&
794
+ hosted.some((source) => !semgrepReferenceMatches(source, reportUrl))))
795
+ throw new Error("The retained Checkmarx report repository does not match the finding repository.");
796
+ if (options.provider === "armorcode") {
797
+ if (options.sourceRepositoryUrl !== undefined) {
798
+ const url = declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "ArmorCode", "local");
799
+ sources.set(url, { url });
800
+ }
801
+ if (!sameRepositories(sources.keys()))
802
+ throw new CodexSecurityError("ArmorCode findings must belong to a single source repository.");
803
+ }
511
804
  const sonarSources = sonarRepositoryUrls(options.provider, current.findings, current.report, "local");
512
805
  const manualSource = options.provider === "sonar" && options.sourceRepositoryUrl
513
806
  ? declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "Sonar", "local")
@@ -531,18 +824,105 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
531
824
  url: dependabotSource,
532
825
  platform: "github",
533
826
  });
827
+ const snyk = snykRestImportRepository(current, options.provider, [
828
+ ...sources.keys(),
829
+ ...(options.sourceRepositoryUrl === undefined
830
+ ? []
831
+ : [options.sourceRepositoryUrl]),
832
+ ], readerSources, (finding, source) => {
833
+ finding.evidence.source_data = source;
834
+ });
835
+ if (snyk) {
836
+ // Preserve reader display fields while validating their complete native evidence.
837
+ for (const { evidence } of current.findings)
838
+ validateExternalEvidence(structuredClone(evidence), "local");
839
+ }
840
+ else if (options.provider === "snyk" && current.sourceRepositoryUrl) {
841
+ const declared = { url: current.sourceRepositoryUrl };
842
+ const native = current.findings.flatMap((finding) => localFindingRepositories("snyk", finding));
843
+ for (const source of [declared, ...native])
844
+ if (!sources.has(source.url))
845
+ sources.set(source.url, source);
846
+ if (!sameRepositories(sources.keys()))
847
+ throw new CodexSecurityError("The normalized repository does not match the Snyk reader's repository.");
848
+ }
849
+ if (normalizedSource && !snyk) {
850
+ if (!sameRepositories([normalizedSource, ...sources.keys(), ...known]) ||
851
+ hosted.some((source) => !semgrepReferenceMatches(source, normalizedSource)))
852
+ throw new CodexSecurityError("The declared repository does not match the normalized finding source.");
853
+ if (!hosted.length && !sources.size)
854
+ sources.set(normalizedSource, { url: normalizedSource });
855
+ }
856
+ const ordinarySources = [...sources.values()];
857
+ // A reader can identify the VCS for both a hosted project and an ordinary row.
858
+ const loosePlatformFor = localRepositoryPlatform(options.provider, [...ordinarySources, ...hostedReferences], false);
534
859
  const selected = manualSource ? new URL(manualSource) : undefined;
535
- const matchesRepositoryRemote = await requireMatchingRepository(repository, options.provider, [...sources.values()], strictSources, platformFor, workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal, selected?.protocol === "https:" ? selected.hostname : undefined, fetchRemotes);
860
+ const matchesRepositoryRemote = options.provider === "trivy"
861
+ ? await matchTrivyCheckout(repository, current, references, workbenchOptions)
862
+ : await requireMatchingRepository(repository, options.provider, ordinarySources, strictSources, hosted, (source, bound) => bound ? platformFor(source) : loosePlatformFor(source), snyk, workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal, selected?.protocol === "https:" ? selected.hostname : undefined, fetchRemotes, checkmarx.projections.size
863
+ ? (url) => checkmarxKeys.has(identify(url).key)
864
+ : undefined);
865
+ let storedSources = [...references, ...ordinarySources, ...hosted];
866
+ const [project] = hosted;
867
+ if (options.provider === "semgrep" &&
868
+ !hasOrdinaryRows &&
869
+ !ordinarySources.length &&
870
+ hosted.length === 1 &&
871
+ project &&
872
+ references.every(({ url }) => url === project.url)) {
873
+ // A typed hint and a bare URL can be two witnesses for the same native
874
+ // project. Keep the hint if any stored occurrence needs it to verify its scope.
875
+ storedSources = [project];
876
+ const native = semgrepPlatformRepositoryReference(project.url, []);
877
+ if (native.platform !== project.platform) {
878
+ try {
879
+ if (current.findings.every((finding) => {
880
+ const binding = semgrepPlatformFindingBinding(finding, "semgrep", [
881
+ native,
882
+ ]);
883
+ return (binding?.url === native.url &&
884
+ !binding.migration &&
885
+ isDeepStrictEqual(binding.sourceData, finding.evidence.source_data));
886
+ }))
887
+ storedSources = [native];
888
+ }
889
+ catch {
890
+ // A private SCM alias or SSH mapping can require the reader's platform.
891
+ }
892
+ }
893
+ }
894
+ if (snyk)
895
+ storedSources.push({
896
+ url: snyk.url,
897
+ platform: snyk.platform === "github"
898
+ ? "github"
899
+ : snyk.gitlab
900
+ ? "gitlab"
901
+ : undefined,
902
+ });
903
+ return preparedLocalStorage(current, options, context, dependencies, matchesRepositoryRemote, {
904
+ sourceRepositories: distinctSourceRepositories(storedSources),
905
+ inspectorProjectMap: options.inspectorProjectMap
906
+ ? [...options.inspectorProjectMap]
907
+ : undefined,
908
+ });
909
+ }
910
+ /** @internal Prepare the transactional write after validating the report and repository. */
911
+ function preparedLocalStorage(current, { provider, sourceKey }, { repository, options: workbenchOptions, }, dependencies, matchesRepositoryRemote, provenance) {
536
912
  dependencies.signal?.throwIfAborted();
537
913
  const preview = {
538
914
  ...cloneImportPreview(current),
539
915
  repository,
540
- source: { provider: options.provider, source_key: options.sourceKey },
916
+ source: { provider, source_key: sourceKey },
541
917
  };
542
918
  const payload = JSON.stringify({
543
919
  repository,
544
- provider: options.provider,
545
- sourceKey: options.sourceKey,
920
+ provider,
921
+ sourceKey,
922
+ read: current.read,
923
+ excluded: current.excluded,
924
+ report: reportForJson(current.report),
925
+ provenance,
546
926
  findings: current.findings.map(({ source_finding_id, evidence }) => ({
547
927
  source_finding_id,
548
928
  evidence,
@@ -553,6 +933,25 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
553
933
  preview,
554
934
  async import() {
555
935
  dependencies.signal?.throwIfAborted();
936
+ const disposition = externalImportDisposition(current);
937
+ if (disposition === "failed")
938
+ throw new NoPublishableFindingsError(cloneImportPreview(current));
939
+ const summary = {
940
+ repository,
941
+ read: current.read,
942
+ ...(current.report === undefined
943
+ ? {}
944
+ : snapshotNormalizedFindings({ report: current.report })),
945
+ ready: current.findings.length,
946
+ excluded: structuredClone(current.excluded),
947
+ };
948
+ if (disposition !== "ready") {
949
+ return {
950
+ ...summary,
951
+ findings: [],
952
+ counts: { created: 0, updated: 0, unchanged: 0 },
953
+ };
954
+ }
556
955
  const protectedRoot = [
557
956
  ...new Set([
558
957
  ...workbenchOptions.protectedRoot,
@@ -565,13 +964,8 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
565
964
  return (dependencies.runWorkbench ?? runWorkbench)({ ...workbenchOptions, protectedRoot }, ["store-external-findings"], payload);
566
965
  }, dependencies.signal);
567
966
  return {
568
- repository,
569
- read: current.read,
570
- ...(current.report === undefined
571
- ? {}
572
- : snapshotNormalizedFindings({ report: current.report })),
573
- ready: current.findings.length,
574
- excluded: structuredClone(current.excluded),
967
+ ...summary,
968
+ importId: result["importId"],
575
969
  findings: result["findings"],
576
970
  counts: result["counts"],
577
971
  };
@@ -580,15 +974,50 @@ export async function prepareLocalImport(input, options, dependencies, readerSou
580
974
  }
581
975
  /** Read imported source records, including evidence that has not been assessed by Codex. */
582
976
  export async function listLocalExternalFindings(selection, dependencies = {}) {
977
+ return (await readLocalExternalFindings(selection, dependencies)).findings;
978
+ }
979
+ export async function readLocalExternalFindings(selection, dependencies) {
583
980
  dependencies.signal?.throwIfAborted();
584
- requireExternalImports(dependencies.environment);
585
981
  if (selection.id !== undefined)
586
982
  requireIdentity(selection.id, "Finding id");
587
- const { repository, options } = await localContext(selection.repository, dependencies, "read");
983
+ const { selectedPath, result } = await runLocalFindingWorkbench(selection.repository, "read-external-findings", { id: selection.id }, dependencies);
984
+ return {
985
+ repository: selectedPath,
986
+ findings: result["findings"],
987
+ };
988
+ }
989
+ /** Read the precise versions selected by the caller or captured by an earlier import. */
990
+ export async function selectLocalExternalFindings(selection, dependencies = {}) {
991
+ const { repository, importId, findings } = selection;
992
+ if ((importId === undefined) === (findings === undefined))
993
+ throw new CodexSecurityError("Select one import ID or a list of versioned findings.");
994
+ const { result } = await runLocalFindingWorkbench(repository, "read-external-findings", importId !== undefined
995
+ ? { importId, ifCurrent: selection.ifCurrent }
996
+ : { findings: findings.map(({ id, version }) => ({ id, version })) }, dependencies);
997
+ return result;
998
+ }
999
+ /** List this checkout's nonempty imports, most recent first. */
1000
+ export async function listLocalExternalImports({ repository }, dependencies = {}) {
1001
+ const { result } = await runLocalFindingWorkbench(repository, "list-external-imports", {}, dependencies);
1002
+ return result["imports"];
1003
+ }
1004
+ /** @internal Attach Cloud acknowledgements to the versions that were submitted. */
1005
+ export async function recordExternalFindingPublications(input, dependencies = {}) {
1006
+ const { repository, ...receipt } = input;
1007
+ await runLocalFindingWorkbench(repository, "record-external-finding-publications", receipt, dependencies);
1008
+ }
1009
+ /** Read the destination and receipt for each acknowledged finding version. */
1010
+ export async function listLocalFindingPublications({ repository, id }, dependencies = {}) {
1011
+ const { result } = await runLocalFindingWorkbench(repository, "list-external-finding-publications", { id }, dependencies);
1012
+ return result["publications"];
1013
+ }
1014
+ /** @internal Run a command against the workbench for the selected checkout. */
1015
+ async function runLocalFindingWorkbench(path, command, selection, dependencies) {
1016
+ const { repository, selectedPath, options } = await localContext(path, dependencies, "read");
588
1017
  const result = await abortable(() => {
589
1018
  dependencies.signal?.throwIfAborted();
590
- return (dependencies.runWorkbench ?? runWorkbench)(options, ["list-external-findings"], JSON.stringify({ repository, id: selection.id }));
1019
+ return (dependencies.runWorkbench ?? runWorkbench)(options, [command], JSON.stringify({ repository, ...selection }));
591
1020
  }, dependencies.signal);
592
- return result["findings"];
1021
+ return { selectedPath, result };
593
1022
  }
594
1023
  //# sourceMappingURL=external-findings-local.js.map