@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,10 +1,13 @@
1
1
  import type { ExternalFinding, ExternalSourceRepository } from "./external-findings.js";
2
2
  import type { Provider } from "./external-import-models.js";
3
- /** File reader names mapped to their stored and Cloud source provider. */
3
+ export type LocalFindingProvider = Provider | "tenable";
4
+ /** File reader names mapped to the provider stored with each finding. */
4
5
  export declare const EXTERNAL_FINDINGS_PROVIDERS: {
5
6
  readonly wiz: "wiz";
7
+ readonly armorcode: "armorcode";
6
8
  readonly snyk: "snyk";
7
9
  readonly semgrep: "semgrep";
10
+ readonly trivy: "trivy";
8
11
  readonly opengrep: "semgrep";
9
12
  readonly endor: "endor";
10
13
  readonly github: "github";
@@ -13,15 +16,31 @@ export declare const EXTERNAL_FINDINGS_PROVIDERS: {
13
16
  readonly veracode: "veracode";
14
17
  readonly sonar: "sonar";
15
18
  readonly continuum: "continuum";
19
+ readonly checkmarx: "checkmarx";
20
+ readonly tenable: "tenable";
16
21
  };
17
22
  export type ExternalFindingsReader = keyof typeof EXTERNAL_FINDINGS_PROVIDERS;
23
+ export type CloudFindingsReader = Exclude<ExternalFindingsReader, "tenable">;
24
+ export declare function requireCloudReader(options: ExternalFindingsReaderOptions): asserts options is ExternalFindingsReaderOptions & {
25
+ provider: CloudFindingsReader;
26
+ };
18
27
  export declare const EXTERNAL_FINDINGS_READERS: ExternalFindingsReader[];
19
- /** File readers available in this SDK, shared by local and Cloud imports. */
28
+ /** File readers available in this SDK. Cloud supports a subset of these readers. */
20
29
  export interface ExternalFindingsReaderOptions {
21
30
  provider: ExternalFindingsReader;
22
31
  sourceRepositoryUrl?: string;
23
32
  inspectorProjectMap?: ReadonlyMap<string, string>;
33
+ trivyScanRoot?: string;
24
34
  }
25
35
  /** Repository references retained by a provider's individual finding. */
26
36
  export declare function localFindingRepositories(provider: Provider, finding: ExternalFinding): ExternalSourceRepository[];
37
+ /** Repository claims retained by the Semgrep SARIF reader. */
38
+ export declare function semgrepSarifRepositories({ evidence }: ExternalFinding, allowPartialCloudUrl?: boolean): {
39
+ url: string;
40
+ branch?: string;
41
+ }[];
42
+ /** Repository claims from every project or SARIF run, even those with no findings. */
43
+ export declare function snykFileRepositories(input: unknown): {
44
+ url: string;
45
+ }[];
27
46
  //# sourceMappingURL=external-findings-read.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings-read.d.ts","sourceRoot":"","sources":["../src/external-findings-read.ts"],"names":[],"mappings":"AAAA,OAA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AS;CACqC,CAAC;AAE1D,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,2BAA2B,CAAC;AAC9E,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,sBAAsB,EAAE,SAAS,CAAC,CAAC;AAE7E,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,OAAO,IAAI,6BAA6B,GAAG;IACpD,QAAQ,EAAE,mBAAmB,CAAC;CAC/B,CAKA;AAED,eAAO,MAAM,yBAAyB,EAEjC,sBAAsB,EAAE,CAAC;AAE9B,oFAAoF;AACpF,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,sBAAsB,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAQD,yEAAyE;AACzE,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,eAAe,GACvB,wBAAwB,EAAE,CAiB5B;AAED,8DAA8D;AAC9D,wBAAgB,wBAAwB,CACtC,EAAE,QAAQ,EAAE,EAAE,eAAe,EAC7B,oBAAoB,UAAQ,GAC3B;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,CAkCpC;AAeD,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO;;IAIlD"}
@@ -1,21 +1,30 @@
1
- import { readSnykFindings, snykRepositoryUrls } from "./snyk-findings.js";
2
- import { readSemgrepFindings } from "./semgrep-findings.js";
3
- import { readOpenGrepFindings } from "./opengrep-findings.js";
4
- import { readEndorFindings, endorRepositoryUrls } from "./endor-findings.js";
1
+ import { readScannerJson, sarifRunRepositories } from "./scanner-import.js";
2
+ import { CodexSecurityError } from "./errors.js";
3
+ import { readTenableFindings } from "./tenable-findings.js";
5
4
  import { dependabotRepository } from "./github-dependabot-findings.js";
5
+ import { normalizeSnykFile, emptySnykReportRepositories, snykRepositoryUrls, } from "./snyk-findings.js";
6
+ import { isSemgrepSarifDriver, normalizeSemgrepFindings, readSemgrepReport, } from "./semgrep-findings.js";
7
+ import { semgrepPlatformReportRepository } from "./semgrep-platform-findings.js";
8
+ import { normalizeTrivyFindings } from "./trivy-findings.js";
9
+ import { readOpenGrepFindings } from "./opengrep-findings.js";
10
+ import { normalizeEndorFindings, endorRepositoryUrls, } from "./endor-findings.js";
6
11
  import { readGitHubFindings } from "./github-findings.js";
7
12
  import { readSonarFindings } from "./sonar-findings.js";
8
- import { readVeracodeFindings } from "./veracode-findings.js";
9
- import { readBlackDuckFindings } from "./blackduck-findings.js";
10
- import { readContinuumFindings } from "./continuum-findings.js";
11
- import { readInspectorFindings } from "./inspector-findings.js";
13
+ import { normalizeVeracodeFindings } from "./veracode-findings.js";
14
+ import { normalizeBlackDuckFindings } from "./blackduck-findings.js";
15
+ import { normalizeContinuumFindings } from "./continuum-findings.js";
16
+ import { readCheckmarxFindings } from "./checkmarx-findings.js";
17
+ import { normalizeInspectorFindings } from "./inspector-findings.js";
12
18
  import { isRecord } from "./record.js";
13
- import { readLocalWizFindings, readVendorFindingsForPublication, wizFindingRepository, } from "./wiz-findings.js";
14
- /** File reader names mapped to their stored and Cloud source provider. */
19
+ import { readWizSelection, wizFindingRepository } from "./wiz-findings.js";
20
+ import { normalizeArmorCodeFindings } from "./armorcode-findings.js";
21
+ /** File reader names mapped to the provider stored with each finding. */
15
22
  export const EXTERNAL_FINDINGS_PROVIDERS = {
16
23
  wiz: "wiz",
24
+ armorcode: "armorcode",
17
25
  snyk: "snyk",
18
26
  semgrep: "semgrep",
27
+ trivy: "trivy",
19
28
  // OpenGrep uses the existing SAST contract; evidence retains its scanner origin.
20
29
  opengrep: "semgrep",
21
30
  endor: "endor",
@@ -25,7 +34,13 @@ export const EXTERNAL_FINDINGS_PROVIDERS = {
25
34
  veracode: "veracode",
26
35
  sonar: "sonar",
27
36
  continuum: "continuum",
37
+ checkmarx: "checkmarx",
38
+ tenable: "tenable",
28
39
  };
40
+ export function requireCloudReader(options) {
41
+ if (options.provider === "tenable")
42
+ throw new CodexSecurityError("Tenable findings require a local import (--to local).");
43
+ }
29
44
  export const EXTERNAL_FINDINGS_READERS = Object.keys(EXTERNAL_FINDINGS_PROVIDERS);
30
45
  /** Repository references retained by a provider's individual finding. */
31
46
  export function localFindingRepositories(provider, finding) {
@@ -47,81 +62,128 @@ export function localFindingRepositories(provider, finding) {
47
62
  }
48
63
  return [];
49
64
  }
65
+ /** Repository claims retained by the Semgrep SARIF reader. */
66
+ export function semgrepSarifRepositories({ evidence }, allowPartialCloudUrl = false) {
67
+ const data = evidence.source_data;
68
+ const document = data?.["documentContext"];
69
+ const driver = data?.["driverContext"];
70
+ const partial = allowPartialCloudUrl && document === undefined;
71
+ if ((!partial && (!isRecord(document) || document["version"] !== "2.1.0")) ||
72
+ !isRecord(driver) ||
73
+ typeof driver["name"] !== "string" ||
74
+ !isSemgrepSarifDriver(driver["name"]) ||
75
+ !isRecord(data?.["result"]))
76
+ return [];
77
+ const context = data["runContext"];
78
+ const references = isRecord(context)
79
+ ? context["versionControlProvenance"]
80
+ : undefined;
81
+ return Array.isArray(references)
82
+ ? references.flatMap((reference) => isRecord(reference) &&
83
+ typeof reference["repositoryUri"] === "string" &&
84
+ reference["repositoryUri"].trim()
85
+ ? [
86
+ {
87
+ url: reference["repositoryUri"],
88
+ ...(!partial &&
89
+ typeof reference["branch"] === "string" && {
90
+ branch: reference["branch"],
91
+ }),
92
+ },
93
+ ]
94
+ : [])
95
+ : [];
96
+ }
97
+ /** A run may name a repository even when it produces no findings. */
98
+ function sarifFileRepositories(input, producer) {
99
+ if (isRecord(input) &&
100
+ input["version"] === "2.1.0" &&
101
+ Array.isArray(input["runs"]))
102
+ return input["runs"].flatMap((run) => sarifRunRepositories(run, producer));
103
+ }
104
+ /** Repository claims from every project or SARIF run, even those with no findings. */
105
+ export function snykFileRepositories(input) {
106
+ return (sarifFileRepositories(input, "Snyk") ?? emptySnykReportRepositories(input));
107
+ }
50
108
  /** @internal Read vendor evidence for the local and Cloud import entrypoints. */
51
- export async function readExternalFindings(path, options, target = "cloud") {
52
- if (options.provider === "sonar") {
53
- const url = options.sourceRepositoryUrl;
54
- const findings = await readSonarFindings(path, url ?? "", target);
109
+ export async function readExternalFindings(path, options, target = "cloud", references = []) {
110
+ const { provider } = options;
111
+ const url = options.sourceRepositoryUrl ?? "";
112
+ if (provider === "tenable") {
113
+ if (target === "cloud")
114
+ requireCloudReader(options);
115
+ return { findings: await readTenableFindings(path, url) };
116
+ }
117
+ if (provider === "sonar") {
118
+ const findings = await readSonarFindings(path, url, target);
55
119
  const binding = findings.report?.["repositoryUrl"];
56
120
  return {
57
121
  findings,
58
122
  sourceRepositories: typeof binding === "string" ? [{ url: binding }] : [],
59
123
  };
60
124
  }
61
- if (options.provider === "opengrep") {
62
- const sourceRepositoryUrl = options.sourceRepositoryUrl ?? "";
63
- return {
64
- findings: await readOpenGrepFindings(path, { sourceRepositoryUrl }, target),
65
- sourceRepositories: [{ url: sourceRepositoryUrl }],
66
- };
125
+ if (provider === "opengrep" || provider === "checkmarx") {
126
+ const findings = provider === "opengrep"
127
+ ? await readOpenGrepFindings(path, { sourceRepositoryUrl: url }, target)
128
+ : await readCheckmarxFindings(path, url, target);
129
+ return { findings, sourceRepositories: [{ url }] };
67
130
  }
68
- if (options.provider === "snyk" || options.provider === "endor") {
69
- const provider = options.provider;
70
- const findings = provider === "snyk"
71
- ? await readSnykFindings(path, target)
72
- : await readEndorFindings(path, target);
73
- return {
74
- findings,
75
- sourceRepositories: findings.findings.flatMap((finding) => localFindingRepositories(provider, finding)),
76
- };
131
+ if (provider === "snyk") {
132
+ const input = await readScannerJson(path);
133
+ const findings = await normalizeSnykFile(input, target, references);
134
+ return { findings, sourceRepositories: snykFileRepositories(input) };
77
135
  }
78
- if (options.provider === "semgrep") {
79
- const findings = await readSemgrepFindings(path, {
80
- sourceRepositoryUrl: options.sourceRepositoryUrl ?? "",
136
+ if (provider === "semgrep") {
137
+ const input = await readSemgrepReport(path);
138
+ const findings = normalizeSemgrepFindings(input, {
139
+ sourceRepositoryUrl: options.sourceRepositoryUrl,
140
+ sourceRepositories: references,
81
141
  }, target);
82
- const sourceRepositories = findings.findings.flatMap(({ evidence }) => {
83
- const context = evidence.source_data?.["runContext"];
84
- const references = isRecord(context)
85
- ? context["versionControlProvenance"]
86
- : undefined;
87
- return Array.isArray(references)
88
- ? references.flatMap((reference) => isRecord(reference) &&
89
- typeof reference["repositoryUri"] === "string" &&
90
- reference["repositoryUri"].trim()
91
- ? [{ url: reference["repositoryUri"] }]
92
- : [])
93
- : [];
94
- });
142
+ if (semgrepPlatformReportRepository(findings))
143
+ return { findings };
144
+ const sourceRepositories = sarifFileRepositories(input, "Semgrep") ?? [];
145
+ if (!sourceRepositories.length && options.sourceRepositoryUrl)
146
+ sourceRepositories.push({ url: options.sourceRepositoryUrl });
95
147
  return { findings, sourceRepositories };
96
148
  }
97
- if (options.provider === "github")
149
+ if (provider === "armorcode") {
150
+ const input = await readScannerJson(path);
151
+ return {
152
+ findings: normalizeArmorCodeFindings(input, target, options.sourceRepositoryUrl),
153
+ };
154
+ }
155
+ if (provider === "github")
98
156
  return { findings: await readGitHubFindings(path, target) };
99
- if (options.provider === "inspector" ||
100
- options.provider === "continuum" ||
101
- options.provider === "blackduck" ||
102
- options.provider === "veracode") {
103
- const url = options.sourceRepositoryUrl ?? "";
104
- const read = {
105
- inspector: readInspectorFindings,
106
- continuum: readContinuumFindings,
107
- blackduck: readBlackDuckFindings,
108
- veracode: readVeracodeFindings,
109
- }[options.provider];
157
+ if (provider === "wiz") {
158
+ const wiz = await readWizSelection(path, target);
159
+ const sourceRepositories = wiz.findings.findings.flatMap((finding) => localFindingRepositories("wiz", finding));
110
160
  return {
111
- findings: await read(path, url, target, options.inspectorProjectMap),
112
- sourceRepositories: [{ url }],
161
+ findings: wiz.findings,
162
+ sourceRepositories: [...wiz.sourceRepositories, ...sourceRepositories],
163
+ };
164
+ }
165
+ const input = await readScannerJson(path);
166
+ if (provider === "trivy")
167
+ return {
168
+ findings: normalizeTrivyFindings(input, target, options.trivyScanRoot),
169
+ };
170
+ if (provider === "endor") {
171
+ const findings = normalizeEndorFindings(input, target);
172
+ return {
173
+ findings,
174
+ sourceRepositories: sarifFileRepositories(input, "Endor") ??
175
+ findings.findings.flatMap((row) => localFindingRepositories(provider, row)),
113
176
  };
114
177
  }
115
- // A new reader must choose its parser before reaching the Wiz replay path.
116
- options.provider;
117
- const wiz = target === "local"
118
- ? await readLocalWizFindings(path)
119
- : await readVendorFindingsForPublication(path, target);
120
- const sourceRepositories = wiz.current.findings.flatMap((finding) => localFindingRepositories("wiz", finding));
178
+ const normalize = {
179
+ inspector: normalizeInspectorFindings,
180
+ continuum: normalizeContinuumFindings,
181
+ blackduck: normalizeBlackDuckFindings,
182
+ veracode: normalizeVeracodeFindings,
183
+ }[provider];
121
184
  return {
122
- findings: wiz.current,
123
- ...("legacy" in wiz && { publication: wiz }),
124
- sourceRepositories: [...wiz.sourceRepositories, ...sourceRepositories],
185
+ findings: normalize(input, url, target, options.inspectorProjectMap),
186
+ sourceRepositories: [{ url }],
125
187
  };
126
188
  }
127
189
  //# sourceMappingURL=external-findings-read.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings-read.js","sourceRoot":"","sources":["../src/external-findings-read.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAA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AAC,QAAwB,CAAC;IACjC,MAAM,GAAG,GACP,MAAM,KAAK,OAAO;QAChB,CAAC,CAAC,MAAM,oBAAoB,CAAC,IAAI,CAAC;QAClC,CAAC,CAAC,MAAM,gCAAgC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAClE,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CACzC,CAAC;IACF,OAAO;QACL,QAAQ,EAAE,GAAG,CAAC,OAAO;QACrB,GAAG,CAAC,QAAQ,IAAI,GAAG,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;QAC5C,kBAAkB,EAAE,CAAC,GAAG,GAAG,CAAC,kBAAkB,EAAE,GAAG,kBAAkB,CAAC;KACvE,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ExternalFinding,\n ExternalFindings,\n ExternalPublicationInput,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport type { Provider } from \"./external-import-models.js\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { readSnykFindings, snykRepositoryUrls } from \"./snyk-findings.js\";\nimport { readSemgrepFindings } from \"./semgrep-findings.js\";\nimport { readOpenGrepFindings } from \"./opengrep-findings.js\";\nimport { readEndorFindings, endorRepositoryUrls } from \"./endor-findings.js\";\nimport { dependabotRepository } from \"./github-dependabot-findings.js\";\nimport { readGitHubFindings } from \"./github-findings.js\";\nimport { readSonarFindings } from \"./sonar-findings.js\";\nimport { readVeracodeFindings } from \"./veracode-findings.js\";\nimport { readBlackDuckFindings } from \"./blackduck-findings.js\";\nimport { readContinuumFindings } from \"./continuum-findings.js\";\nimport { readInspectorFindings } from \"./inspector-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n readLocalWizFindings,\n readVendorFindingsForPublication,\n wizFindingRepository,\n} from \"./wiz-findings.js\";\n\n/** File reader names mapped to their stored and Cloud source provider. */\nexport const EXTERNAL_FINDINGS_PROVIDERS = {\n wiz: \"wiz\",\n snyk: \"snyk\",\n semgrep: \"semgrep\",\n // OpenGrep uses the existing SAST contract; evidence retains its scanner origin.\n opengrep: \"semgrep\",\n endor: \"endor\",\n github: \"github\",\n inspector: \"inspector\",\n blackduck: \"blackduck\",\n veracode: \"veracode\",\n sonar: \"sonar\",\n continuum: \"continuum\",\n} as const satisfies Record<string, Provider>;\n\nexport type ExternalFindingsReader = keyof typeof EXTERNAL_FINDINGS_PROVIDERS;\n\nexport const EXTERNAL_FINDINGS_READERS = Object.keys(\n EXTERNAL_FINDINGS_PROVIDERS,\n) as ExternalFindingsReader[];\n\n/** File readers available in this SDK, shared by local and Cloud imports. */\nexport interface ExternalFindingsReaderOptions {\n provider: ExternalFindingsReader;\n sourceRepositoryUrl?: string;\n inspectorProjectMap?: ReadonlyMap<string, string>;\n}\n\n/** @internal Shared parser output, including immutable Cloud retry projections. */\nexport interface ReadExternalFindings {\n findings: ExternalFindings;\n /** Preserve previous Wiz projections when resuming immutable Cloud requests. */\n publication?: ExternalPublicationInput;\n sourceRepositories?: ExternalSourceRepository[];\n}\n\n/** Repository references retained by a provider's individual finding. */\nexport function localFindingRepositories(\n provider: Provider,\n finding: ExternalFinding,\n): ExternalSourceRepository[] {\n const { evidence } = finding;\n if (provider === \"snyk\")\n return snykRepositoryUrls(evidence.source_data, {\n normalizeGitRemote: false,\n }).map((url) => ({ url }));\n if (provider === \"endor\")\n return endorRepositoryUrls(evidence.source_data).map((url) => ({ url }));\n if (provider === \"wiz\") {\n const repository = wizFindingRepository(evidence);\n return repository ? [repository] : [];\n }\n if (provider === \"github\") {\n const url = dependabotRepository(finding);\n if (url) return [{ url, platform: \"github\" }];\n }\n return [];\n}\n\n/** @internal Read vendor evidence for the local and Cloud import entrypoints. */\nexport async function readExternalFindings(\n path: string,\n options: ExternalFindingsReaderOptions,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ReadExternalFindings> {\n if (options.provider === \"sonar\") {\n const url = options.sourceRepositoryUrl;\n const findings = await readSonarFindings(path, url ?? \"\", target);\n const binding = findings.report?.[\"repositoryUrl\"];\n return {\n findings,\n sourceRepositories: typeof binding === \"string\" ? [{ url: binding }] : [],\n };\n }\n if (options.provider === \"opengrep\") {\n const sourceRepositoryUrl = options.sourceRepositoryUrl ?? \"\";\n return {\n findings: await readOpenGrepFindings(\n path,\n { sourceRepositoryUrl },\n target,\n ),\n sourceRepositories: [{ url: sourceRepositoryUrl }],\n };\n }\n if (options.provider === \"snyk\" || options.provider === \"endor\") {\n const provider = options.provider;\n const findings =\n provider === \"snyk\"\n ? await readSnykFindings(path, target)\n : await readEndorFindings(path, target);\n return {\n findings,\n sourceRepositories: findings.findings.flatMap((finding) =>\n localFindingRepositories(provider, finding),\n ),\n };\n }\n if (options.provider === \"semgrep\") {\n const findings = await readSemgrepFindings(\n path,\n {\n sourceRepositoryUrl: options.sourceRepositoryUrl ?? \"\",\n },\n target,\n );\n const sourceRepositories = findings.findings.flatMap(({ evidence }) => {\n const context = evidence.source_data?.[\"runContext\"];\n const references = isRecord(context)\n ? context[\"versionControlProvenance\"]\n : undefined;\n return Array.isArray(references)\n ? references.flatMap((reference) =>\n isRecord(reference) &&\n typeof reference[\"repositoryUri\"] === \"string\" &&\n reference[\"repositoryUri\"].trim()\n ? [{ url: reference[\"repositoryUri\"] }]\n : [],\n )\n : [];\n });\n return { findings, sourceRepositories };\n }\n if (options.provider === \"github\")\n return { findings: await readGitHubFindings(path, target) };\n if (\n options.provider === \"inspector\" ||\n options.provider === \"continuum\" ||\n options.provider === \"blackduck\" ||\n options.provider === \"veracode\"\n ) {\n const url = options.sourceRepositoryUrl ?? \"\";\n const read = {\n inspector: readInspectorFindings,\n continuum: readContinuumFindings,\n blackduck: readBlackDuckFindings,\n veracode: readVeracodeFindings,\n }[options.provider];\n return {\n findings: await read(path, url, target, options.inspectorProjectMap),\n sourceRepositories: [{ url }],\n };\n }\n // A new reader must choose its parser before reaching the Wiz replay path.\n options.provider satisfies \"wiz\";\n const wiz =\n target === \"local\"\n ? await readLocalWizFindings(path)\n : await readVendorFindingsForPublication(path, target);\n const sourceRepositories = wiz.current.findings.flatMap((finding) =>\n localFindingRepositories(\"wiz\", finding),\n );\n return {\n findings: wiz.current,\n ...(\"legacy\" in wiz && { publication: wiz }),\n sourceRepositories: [...wiz.sourceRepositories, ...sourceRepositories],\n };\n}\n"]}
1
+ {"version":3,"file":"external-findings-read.js","sourceRoot":"","sources":["../src/external-findings-read.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;A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,EAAE,yBAAyB;KACpC,CAAC,QAAQ,CAAC,CAAC;IACZ,OAAO;QACL,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,mBAAmB,CAAC;QACpE,kBAAkB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ExternalFinding,\n ExternalFindings,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport { readScannerJson, sarifRunRepositories } from \"./scanner-import.js\";\nimport type { Provider } from \"./external-import-models.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { readTenableFindings } from \"./tenable-findings.js\";\nimport type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { dependabotRepository } from \"./github-dependabot-findings.js\";\nimport {\n normalizeSnykFile,\n emptySnykReportRepositories,\n snykRepositoryUrls,\n} from \"./snyk-findings.js\";\nimport {\n isSemgrepSarifDriver,\n normalizeSemgrepFindings,\n readSemgrepReport,\n} from \"./semgrep-findings.js\";\nimport { semgrepPlatformReportRepository } from \"./semgrep-platform-findings.js\";\nimport { normalizeTrivyFindings } from \"./trivy-findings.js\";\nimport { readOpenGrepFindings } from \"./opengrep-findings.js\";\nimport {\n normalizeEndorFindings,\n endorRepositoryUrls,\n} from \"./endor-findings.js\";\nimport { readGitHubFindings } from \"./github-findings.js\";\nimport { readSonarFindings } from \"./sonar-findings.js\";\nimport { normalizeVeracodeFindings } from \"./veracode-findings.js\";\nimport { normalizeBlackDuckFindings } from \"./blackduck-findings.js\";\nimport { normalizeContinuumFindings } from \"./continuum-findings.js\";\nimport { readCheckmarxFindings } from \"./checkmarx-findings.js\";\nimport { normalizeInspectorFindings } from \"./inspector-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport { readWizSelection, wizFindingRepository } from \"./wiz-findings.js\";\nimport { normalizeArmorCodeFindings } from \"./armorcode-findings.js\";\n\nexport type LocalFindingProvider = Provider | \"tenable\";\n\n/** File reader names mapped to the provider stored with each finding. */\nexport const EXTERNAL_FINDINGS_PROVIDERS = {\n wiz: \"wiz\",\n armorcode: \"armorcode\",\n snyk: \"snyk\",\n semgrep: \"semgrep\",\n trivy: \"trivy\",\n // OpenGrep uses the existing SAST contract; evidence retains its scanner origin.\n opengrep: \"semgrep\",\n endor: \"endor\",\n github: \"github\",\n inspector: \"inspector\",\n blackduck: \"blackduck\",\n veracode: \"veracode\",\n sonar: \"sonar\",\n continuum: \"continuum\",\n checkmarx: \"checkmarx\",\n tenable: \"tenable\",\n} as const satisfies Record<string, LocalFindingProvider>;\n\nexport type ExternalFindingsReader = keyof typeof EXTERNAL_FINDINGS_PROVIDERS;\nexport type CloudFindingsReader = Exclude<ExternalFindingsReader, \"tenable\">;\n\nexport function requireCloudReader(\n options: ExternalFindingsReaderOptions,\n): asserts options is ExternalFindingsReaderOptions & {\n provider: CloudFindingsReader;\n} {\n if (options.provider === \"tenable\")\n throw new CodexSecurityError(\n \"Tenable findings require a local import (--to local).\",\n );\n}\n\nexport const EXTERNAL_FINDINGS_READERS = Object.keys(\n EXTERNAL_FINDINGS_PROVIDERS,\n) as ExternalFindingsReader[];\n\n/** File readers available in this SDK. Cloud supports a subset of these readers. */\nexport interface ExternalFindingsReaderOptions {\n provider: ExternalFindingsReader;\n sourceRepositoryUrl?: string;\n inspectorProjectMap?: ReadonlyMap<string, string>;\n trivyScanRoot?: string;\n}\n\n/** @internal Normalized file contents and any repository claims supplied by its reader. */\nexport interface ReadExternalFindings {\n findings: ExternalFindings;\n sourceRepositories?: ExternalSourceRepository[];\n}\n\n/** Repository references retained by a provider's individual finding. */\nexport function localFindingRepositories(\n provider: Provider,\n finding: ExternalFinding,\n): ExternalSourceRepository[] {\n const { evidence } = finding;\n if (provider === \"snyk\")\n return snykRepositoryUrls(evidence.source_data, {\n normalizeGitRemote: false,\n }).map((url) => ({ url }));\n if (provider === \"endor\")\n return endorRepositoryUrls(evidence.source_data).map((url) => ({ url }));\n if (provider === \"wiz\") {\n const repository = wizFindingRepository(evidence);\n return repository ? [repository] : [];\n }\n if (provider === \"github\") {\n const url = dependabotRepository(finding);\n if (url) return [{ url, platform: \"github\" }];\n }\n return [];\n}\n\n/** Repository claims retained by the Semgrep SARIF reader. */\nexport function semgrepSarifRepositories(\n { evidence }: ExternalFinding,\n allowPartialCloudUrl = false,\n): { url: string; branch?: string }[] {\n const data = evidence.source_data;\n const document = data?.[\"documentContext\"];\n const driver = data?.[\"driverContext\"];\n const partial = allowPartialCloudUrl && document === undefined;\n if (\n (!partial && (!isRecord(document) || document[\"version\"] !== \"2.1.0\")) ||\n !isRecord(driver) ||\n typeof driver[\"name\"] !== \"string\" ||\n !isSemgrepSarifDriver(driver[\"name\"]) ||\n !isRecord(data?.[\"result\"])\n )\n return [];\n const context = data[\"runContext\"];\n const references = isRecord(context)\n ? context[\"versionControlProvenance\"]\n : undefined;\n return Array.isArray(references)\n ? references.flatMap((reference) =>\n isRecord(reference) &&\n typeof reference[\"repositoryUri\"] === \"string\" &&\n reference[\"repositoryUri\"].trim()\n ? [\n {\n url: reference[\"repositoryUri\"],\n ...(!partial &&\n typeof reference[\"branch\"] === \"string\" && {\n branch: reference[\"branch\"],\n }),\n },\n ]\n : [],\n )\n : [];\n}\n\n/** A run may name a repository even when it produces no findings. */\nfunction sarifFileRepositories(\n input: unknown,\n producer: \"Endor\" | \"Semgrep\" | \"Snyk\",\n) {\n if (\n isRecord(input) &&\n input[\"version\"] === \"2.1.0\" &&\n Array.isArray(input[\"runs\"])\n )\n return input[\"runs\"].flatMap((run) => sarifRunRepositories(run, producer));\n}\n\n/** Repository claims from every project or SARIF run, even those with no findings. */\nexport function snykFileRepositories(input: unknown) {\n return (\n sarifFileRepositories(input, \"Snyk\") ?? emptySnykReportRepositories(input)\n );\n}\n\n/** @internal Read vendor evidence for the local and Cloud import entrypoints. */\nexport async function readExternalFindings(\n path: string,\n options: ExternalFindingsReaderOptions,\n target: ExternalImportTarget = \"cloud\",\n references: readonly ExternalSourceRepository[] = [],\n): Promise<ReadExternalFindings> {\n const { provider } = options;\n const url = options.sourceRepositoryUrl ?? \"\";\n if (provider === \"tenable\") {\n if (target === \"cloud\") requireCloudReader(options);\n return { findings: await readTenableFindings(path, url) };\n }\n if (provider === \"sonar\") {\n const findings = await readSonarFindings(path, url, target);\n const binding = findings.report?.[\"repositoryUrl\"];\n return {\n findings,\n sourceRepositories: typeof binding === \"string\" ? [{ url: binding }] : [],\n };\n }\n if (provider === \"opengrep\" || provider === \"checkmarx\") {\n const findings =\n provider === \"opengrep\"\n ? await readOpenGrepFindings(path, { sourceRepositoryUrl: url }, target)\n : await readCheckmarxFindings(path, url, target);\n return { findings, sourceRepositories: [{ url }] };\n }\n if (provider === \"snyk\") {\n const input = await readScannerJson(path);\n const findings = await normalizeSnykFile(input, target, references);\n return { findings, sourceRepositories: snykFileRepositories(input) };\n }\n if (provider === \"semgrep\") {\n const input = await readSemgrepReport(path);\n const findings = normalizeSemgrepFindings(\n input,\n {\n sourceRepositoryUrl: options.sourceRepositoryUrl,\n sourceRepositories: references,\n },\n target,\n );\n if (semgrepPlatformReportRepository(findings)) return { findings };\n const sourceRepositories = sarifFileRepositories(input, \"Semgrep\") ?? [];\n if (!sourceRepositories.length && options.sourceRepositoryUrl)\n sourceRepositories.push({ url: options.sourceRepositoryUrl });\n return { findings, sourceRepositories };\n }\n if (provider === \"armorcode\") {\n const input = await readScannerJson(path);\n return {\n findings: normalizeArmorCodeFindings(\n input,\n target,\n options.sourceRepositoryUrl,\n ),\n };\n }\n if (provider === \"github\")\n return { findings: await readGitHubFindings(path, target) };\n if (provider === \"wiz\") {\n const wiz = await readWizSelection(path, target);\n const sourceRepositories = wiz.findings.findings.flatMap((finding) =>\n localFindingRepositories(\"wiz\", finding),\n );\n return {\n findings: wiz.findings,\n sourceRepositories: [...wiz.sourceRepositories, ...sourceRepositories],\n };\n }\n const input = await readScannerJson(path);\n if (provider === \"trivy\")\n return {\n findings: normalizeTrivyFindings(input, target, options.trivyScanRoot),\n };\n if (provider === \"endor\") {\n const findings = normalizeEndorFindings(input, target);\n return {\n findings,\n sourceRepositories:\n sarifFileRepositories(input, \"Endor\") ??\n findings.findings.flatMap((row) =>\n localFindingRepositories(provider, row),\n ),\n };\n }\n const normalize = {\n inspector: normalizeInspectorFindings,\n continuum: normalizeContinuumFindings,\n blackduck: normalizeBlackDuckFindings,\n veracode: normalizeVeracodeFindings,\n }[provider];\n return {\n findings: normalize(input, url, target, options.inspectorProjectMap),\n sourceRepositories: [{ url }],\n };\n}\n"]}
@@ -1,4 +1,5 @@
1
- import type { ExternalPublicationOptions } from "./external-findings-publish.js";
1
+ import { CodexSecurityError } from "./errors.js";
2
+ import type { LocalExternalImportOptions } from "./external-findings-import.js";
2
3
  import type { ExternalFindingEvidence } from "./external-import-models.js";
3
4
  /** A provider occurrence and its evidence, independent of a Codex assessment. */
4
5
  export interface ExternalFinding {
@@ -8,7 +9,7 @@ export interface ExternalFinding {
8
9
  /** Repository provenance retained by a reader outside the published evidence. */
9
10
  export interface ExternalSourceRepository {
10
11
  url: string;
11
- platform?: "github";
12
+ platform?: "github" | "gitlab";
12
13
  }
13
14
  export declare function snapshotSourceRepositories(references?: readonly ExternalSourceRepository[]): ExternalSourceRepository[];
14
15
  export interface ExternalFindings {
@@ -22,15 +23,26 @@ export interface ExternalFindings {
22
23
  reason: string;
23
24
  }[];
24
25
  }
26
+ export declare function hasNoExternalRecords(input: ExternalFindings): boolean;
27
+ /** Classify a reader selection before deciding whether to store, publish, or report it. */
28
+ export declare function externalImportDisposition(input: ExternalFindings): "ready" | "empty" | "excluded" | "failed";
29
+ /** No findings can be imported. The selection retains every reader exclusion and diagnostic. */
30
+ export declare class NoPublishableFindingsError extends CodexSecurityError {
31
+ readonly selection: ExternalFindings;
32
+ readonly summary: string;
33
+ constructor(selection: ExternalFindings);
34
+ }
35
+ export declare function reportForJson(report: ExternalFindings["report"]): Record<string, unknown> | undefined;
25
36
  export declare const nativeErrorStackGetter: (() => any) | undefined;
26
37
  /** Capture the caller's import settings before reading an export or resolving its destination. */
27
- export declare function snapshotImportOptions<P extends ExternalPublicationOptions["provider"]>({ repository, provider, sourceKey, sourceRepositoryUrl, inspectorProjectMap, }: ExternalPublicationOptions & {
38
+ export declare function snapshotImportOptions<P extends string>({ repository, provider, sourceKey, sourceRepositoryUrl, trivyScanRoot, inspectorProjectMap, }: Omit<LocalExternalImportOptions, "provider"> & {
28
39
  provider: P;
29
40
  }): {
30
41
  repository: string;
31
42
  provider: P;
32
43
  sourceKey: string;
33
44
  sourceRepositoryUrl: string | undefined;
45
+ trivyScanRoot: string | undefined;
34
46
  inspectorProjectMap: Map<string, string> | undefined;
35
47
  };
36
48
  //# sourceMappingURL=external-findings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings.d.ts","sourceRoot":"","sources":["../src/external-findings.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAQjF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,iFAAiF;AACjF,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,uBAAuB,CAAC;CACnC;AAED,iFAAiF;AACjF,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,0BAA0B,CACxC,UAAU,GAAE,SAAS,wBAAwB,EAAO,GACnD,wBAAwB,EAAE,CAE5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE;QACR,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,MAAM,G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;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAErE;AAED,2FAA2F;AAC3F,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,gBAAgB,GACtB,OAAO,GAAG,OAAO,GAAG,UAAU,GAAG,QAAQ,CAM3C;AAED,gGAAgG;AAChG,qBAAa,0BAA2B,SAAQ,kBAAkB;aAGpC,SAAS,EAAE,gBAAgB;IAFvD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,YAA4B,SAAS,EAAE,gBAAgB,EAWtD;CACF;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,uCAO/D;AAGD,eAAO,MAAM,sBAAsB,yBAG7B,CAAC;AAuIP,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EAAE,EACtD,UAAU,EACV,QAAQ,EACR,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,mBAAmB,GACpB,EAAE,IAAI,CAAC,0BAA0B,EAAE,UAAU,CAAC,GAAG;IAAE,QAAQ,EAAE,CAAC,CAAA;CAAE;;;;;;;EAqBhE"}
@@ -4,6 +4,42 @@ import { checkEmittedJsonNumber, checkReportNumber, requireCloudEvidenceDepth, r
4
4
  export function snapshotSourceRepositories(references = []) {
5
5
  return references.map(({ url, platform }) => ({ url, platform }));
6
6
  }
7
+ export function hasNoExternalRecords(input) {
8
+ return input.read === 0 && !input.findings.length && !input.excluded.length;
9
+ }
10
+ /** Classify a reader selection before deciding whether to store, publish, or report it. */
11
+ export function externalImportDisposition(input) {
12
+ if (input.findings.length)
13
+ return "ready";
14
+ const errors = input.report?.["errors"];
15
+ if (Array.isArray(errors) && errors.length)
16
+ return "failed";
17
+ if (hasNoExternalRecords(input))
18
+ return "empty";
19
+ return input.read === input.excluded.length ? "excluded" : "failed";
20
+ }
21
+ /** No findings can be imported. The selection retains every reader exclusion and diagnostic. */
22
+ export class NoPublishableFindingsError extends CodexSecurityError {
23
+ selection;
24
+ summary;
25
+ constructor(selection) {
26
+ const diagnostics = reportForJson(selection.report)?.["errors"];
27
+ const summary = externalImportDisposition(selection) === "empty"
28
+ ? "No supported findings are ready to publish: the report is empty."
29
+ : `No supported findings are ready to publish (${selection.read} read, ${selection.excluded.length} excluded).${Array.isArray(diagnostics) && diagnostics.length ? ` Scanner diagnostics: ${JSON.stringify(diagnostics)}` : ""}`;
30
+ const reasons = selection.excluded.map((item) => `Item ${item.position}: ${item.reason}`);
31
+ super([summary, ...reasons].join(" "));
32
+ this.selection = selection;
33
+ this.summary = summary;
34
+ }
35
+ }
36
+ export function reportForJson(report) {
37
+ const errors = report?.["errors"];
38
+ if (!Array.isArray(errors))
39
+ return report;
40
+ const json = JSON.stringify(errors, (_key, entry) => entry instanceof Error ? { ...entry, message: entry.message } : entry);
41
+ return { ...report, errors: JSON.parse(json) };
42
+ }
7
43
  const isScannerError = Error.isError ?? isNativeError;
8
44
  export const nativeErrorStackGetter = Object.getOwnPropertyDescriptor(new Error(), "stack")?.get;
9
45
  function cloneScannerDiagnostic(source) {
@@ -33,7 +69,7 @@ function cloneScannerDiagnostic(source) {
33
69
  }
34
70
  }
35
71
  /** @internal Capture fresh input once, so preview, limits and storage use the same JSON. */
36
- export function snapshotNormalizedFindings(input, checkEvidenceNumber = (value) => requireJsonNumber(value, "Evidence"), target = "local") {
72
+ export function snapshotNormalizedFindings(input, checkEvidenceNumber = (value) => requireJsonNumber(value, "Evidence"), target = "local", provider) {
37
73
  const fields = new Map();
38
74
  const errors = [];
39
75
  let root;
@@ -99,6 +135,17 @@ export function snapshotNormalizedFindings(input, checkEvidenceNumber = (value)
99
135
  Object.defineProperties(error, Object.getOwnPropertyDescriptors(parent[key]));
100
136
  parent[key] = error;
101
137
  }
138
+ // Reader scope can live on a getter. Do not evaluate enumerable getters twice.
139
+ if (provider !== undefined) {
140
+ const keys = ["sourceFormat", "semgrepPlatformScope", "snykRestContext"];
141
+ if (provider === "semgrep" || provider === "snyk")
142
+ keys.push("sourceRepositoryUrl", "sourceRepositoryPlatform");
143
+ for (const key of keys)
144
+ if (!(key in result) &&
145
+ key in input &&
146
+ !Object.prototype.propertyIsEnumerable.call(input, key))
147
+ result[key] = structuredClone(Reflect.get(input, key));
148
+ }
102
149
  return result;
103
150
  }
104
151
  /** @internal Clone owned values without serializing the evidence again in every preview view. */
@@ -111,7 +158,11 @@ export function cloneImportPreview(input) {
111
158
  };
112
159
  }
113
160
  /** Capture the caller's import settings before reading an export or resolving its destination. */
114
- export function snapshotImportOptions({ repository, provider, sourceKey, sourceRepositoryUrl, inspectorProjectMap, }) {
161
+ export function snapshotImportOptions({ repository, provider, sourceKey, sourceRepositoryUrl, trivyScanRoot, inspectorProjectMap, }) {
162
+ if (provider === "trivy" && sourceRepositoryUrl !== undefined)
163
+ throw new CodexSecurityError("Trivy reads repository provenance from the report; do not supply --source-repository-url.");
164
+ if (trivyScanRoot !== undefined && provider !== "trivy")
165
+ throw new CodexSecurityError("--trivy-scan-root applies only to --provider trivy.");
115
166
  if (inspectorProjectMap !== undefined && provider !== "inspector")
116
167
  throw new CodexSecurityError("An Inspector project map requires the inspector provider.");
117
168
  return {
@@ -119,6 +170,7 @@ export function snapshotImportOptions({ repository, provider, sourceKey, sourceR
119
170
  provider,
120
171
  sourceKey,
121
172
  sourceRepositoryUrl,
173
+ trivyScanRoot,
122
174
  inspectorProjectMap: inspectorProjectMap && new Map(inspectorProjectMap),
123
175
  };
124
176
  }
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings.js","sourceRoot":"","sources":["../src/external-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AAevC,MAAM,UAAU,0BAA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AC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,kBAAkB,CAA6B,KAAQ;IACrE,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;QAAE,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9D,OAAO;QACL,GAAG,eAAe,CAAC,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QACnD,GAAG,0BAA0B,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC;AAUD,kGAAkG;AAClG,MAAM,UAAU,qBAAqB,CAEnC,EACA,UAAU,EACV,QAAQ,EACR,SAAS,EACT,mBAAmB,EACnB,mBAAmB,GAC0B;IAC7C,IAAI,mBAAmB,KAAK,SAAS,IAAI,QAAQ,KAAK,WAAW;QAC/D,MAAM,IAAI,kBAAkB,CAC1B,2DAA2D,CAC5D,CAAC;IACJ,OAAO;QACL,UAAU;QACV,QAAQ;QACR,SAAS;QACT,mBAAmB;QACnB,mBAAmB,EAAE,mBAAmB,IAAI,IAAI,GAAG,CAAC,mBAAmB,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["import { isNativeError, isNumberObject } from \"node:util/types\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { ExternalPublicationOptions } from \"./external-findings-publish.js\";\nimport {\n checkEmittedJsonNumber,\n checkReportNumber,\n requireCloudEvidenceDepth,\n requireJsonNumber,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindingEvidence } from \"./external-import-models.js\";\n\n/** A provider occurrence and its evidence, independent of a Codex assessment. */\nexport interface ExternalFinding {\n source_finding_id: string;\n evidence: ExternalFindingEvidence;\n}\n\n/** Repository provenance retained by a reader outside the published evidence. */\nexport interface ExternalSourceRepository {\n url: string;\n platform?: \"github\";\n}\n\nexport function snapshotSourceRepositories(\n references: readonly ExternalSourceRepository[] = [],\n): ExternalSourceRepository[] {\n return references.map(({ url, platform }) => ({ url, platform }));\n}\n\nexport interface ExternalFindings {\n read: number;\n /** Reader-retained run metadata, including diagnostics for empty reports. */\n report?: Record<string, unknown>;\n findings: ExternalFinding[];\n excluded: {\n position: number;\n source_finding_id: string | null;\n reason: string;\n }[];\n}\n\nconst isScannerError = Error.isError ?? isNativeError;\nexport const nativeErrorStackGetter = Object.getOwnPropertyDescriptor(\n new Error(),\n \"stack\",\n)?.get;\n\nfunction cloneScannerDiagnostic(source: Error): Error {\n const message = Object.getOwnPropertyDescriptor(source, \"message\");\n const stack = Object.getOwnPropertyDescriptor(source, \"stack\");\n try {\n if (\n (!message || Object.hasOwn(message, \"value\")) &&\n (!stack?.get || stack.get === nativeErrorStackGetter)\n )\n return structuredClone(source);\n // Keep the native error type and data-valued cause without running a\n // caller-supplied message or stack getter while restoring diagnostics.\n const cause = Object.getOwnPropertyDescriptor(source, \"cause\");\n const clean = new Error(message?.value, { cause: cause?.value });\n const name = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(source),\n \"name\",\n )?.value;\n if (typeof name === \"string\") clean.name = name;\n if (!message?.get && nativeErrorStackGetter) {\n const nativeStack: unknown = nativeErrorStackGetter.call(source);\n if (typeof nativeStack === \"string\") clean.stack = nativeStack;\n }\n return structuredClone(clean);\n } catch {\n // A noncloneable cause does not prevent JSON export.\n return new Error(message?.value);\n }\n}\n\n/** @internal Capture fresh input once, so preview, limits and storage use the same JSON. */\nexport function snapshotNormalizedFindings<T extends Partial<ExternalFindings>>(\n input: T,\n checkEvidenceNumber = (value: number) => requireJsonNumber(value, \"Evidence\"),\n target: ExternalImportTarget = \"local\",\n): T {\n const fields = new Map<string, unknown>();\n const errors: { path: string[]; error: Error }[] = [];\n let root: unknown;\n\n function captureField(field: string, observed: unknown): string | undefined {\n const parents: { key: string; value: object }[] = [];\n // The outer traversal already called this field's toJSON with its real key.\n // Returning that value from the wrapper keeps JSON from calling it twice.\n return JSON.stringify(\n { toJSON: () => observed },\n function (this: object, key, value: unknown) {\n while (parents.length && parents.at(-1)!.value !== this) parents.pop();\n const evidence = field === \"findings\" && parents[2]?.key === \"evidence\";\n if (evidence && target === \"cloud\")\n requireCloudEvidenceDepth(parents.length - 2, this, value);\n if (isNumberObject(value)) value = +value;\n if (field === \"report\") checkReportNumber(value);\n if (evidence) checkEmittedJsonNumber(value, checkEvidenceNumber);\n if (value !== null && typeof value === \"object\") {\n if (value === root) {\n const path = [field, ...parents.slice(1).map((p) => p.key)];\n if (parents.length) path.push(key);\n throw new TypeError(\n `Converting circular structure to JSON at ${JSON.stringify(path)}`,\n );\n }\n if (\n field === \"report\" &&\n parents[1]?.key === \"errors\" &&\n Array.isArray(parents[1].value) &&\n isScannerError(value)\n ) {\n errors.push({\n path: [field, ...parents.slice(1).map((p) => p.key), key],\n error: value,\n });\n }\n parents.push({ key, value });\n }\n return value;\n },\n );\n }\n\n // Capture each member in native property order. A report and a findings\n // payload can each fit in a string while their combined JSON does not.\n const envelope = JSON.stringify(\n input,\n function (this: object, field, value: unknown) {\n if (this !== root) {\n root = value;\n return value;\n }\n const json = captureField(field, value);\n if (json === undefined) return undefined;\n fields.set(field, JSON.parse(json));\n return null;\n },\n );\n const result = JSON.parse(envelope);\n for (const [key, value] of fields) result[key] = value;\n for (const { path, error: source } of errors) {\n const key = path.pop()!;\n let parent = result as unknown as Record<string, unknown>;\n for (const field of path) parent = parent[field] as Record<string, unknown>;\n const error = cloneScannerDiagnostic(source);\n Object.defineProperties(\n error,\n Object.getOwnPropertyDescriptors(parent[key] as object),\n );\n parent[key] = error;\n }\n return result;\n}\n\n/** @internal Clone owned values without serializing the evidence again in every preview view. */\nexport function cloneImportPreview<T extends ExternalFindings>(input: T): T {\n if (input.report === undefined) return structuredClone(input);\n return {\n ...structuredClone({ ...input, report: undefined }),\n ...snapshotNormalizedFindings({ report: input.report }),\n };\n}\n\n/** @internal Keep earlier provider projections only for immutable request replay. */\nexport interface ExternalPublicationInput {\n current: ExternalFindings;\n legacy: ExternalFindings;\n currentIdentity: unknown;\n legacyIdentity: unknown;\n}\n\n/** Capture the caller's import settings before reading an export or resolving its destination. */\nexport function snapshotImportOptions<\n P extends ExternalPublicationOptions[\"provider\"],\n>({\n repository,\n provider,\n sourceKey,\n sourceRepositoryUrl,\n inspectorProjectMap,\n}: ExternalPublicationOptions & { provider: P }) {\n if (inspectorProjectMap !== undefined && provider !== \"inspector\")\n throw new CodexSecurityError(\n \"An Inspector project map requires the inspector provider.\",\n );\n return {\n repository,\n provider,\n sourceKey,\n sourceRepositoryUrl,\n inspectorProjectMap: inspectorProjectMap && new Map(inspectorProjectMap),\n };\n}\n"]}
1
+ {"version":3,"file":"external-findings.js","sourceRoot":"","sources":["../src/external-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,GAElB,MAAM,+BAA+B,CAAC;AAevC,MAAM,UAAU,0BAA0B,CACxC,UAAU,GAAwC,EAAE;IAEpD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC;AAcD,MAAM,UAAU,oBAAoB,CAAC,KAAuB;IAC1D,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;AAC9E,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,yBAAyB,CACvC,KAAuB;IAEvB,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAC1C,MAAM,MAAM,GA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AE,KAAK,CAAC,MAAM,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,qBAAqB,CAAmB,EACtD,UAAU,EACV,QAAQ,EACR,SAAS,EACT,mBAAmB,EACnB,aAAa,EACb,mBAAmB,GAC4C;IAC/D,IAAI,QAAQ,KAAK,OAAO,IAAI,mBAAmB,KAAK,SAAS;QAC3D,MAAM,IAAI,kBAAkB,CAC1B,2FAA2F,CAC5F,CAAC;IACJ,IAAI,aAAa,KAAK,SAAS,IAAI,QAAQ,KAAK,OAAO;QACrD,MAAM,IAAI,kBAAkB,CAC1B,qDAAqD,CACtD,CAAC;IACJ,IAAI,mBAAmB,KAAK,SAAS,IAAI,QAAQ,KAAK,WAAW;QAC/D,MAAM,IAAI,kBAAkB,CAC1B,2DAA2D,CAC5D,CAAC;IACJ,OAAO;QACL,UAAU;QACV,QAAQ;QACR,SAAS;QACT,mBAAmB;QACnB,aAAa;QACb,mBAAmB,EAAE,mBAAmB,IAAI,IAAI,GAAG,CAAC,mBAAmB,CAAC;KACzE,CAAC;AACJ,CAAC","sourcesContent":["import { isNativeError, isNumberObject } from \"node:util/types\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { LocalExternalImportOptions } from \"./external-findings-import.js\";\nimport {\n checkEmittedJsonNumber,\n checkReportNumber,\n requireCloudEvidenceDepth,\n requireJsonNumber,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport type { ExternalFindingEvidence } from \"./external-import-models.js\";\n\n/** A provider occurrence and its evidence, independent of a Codex assessment. */\nexport interface ExternalFinding {\n source_finding_id: string;\n evidence: ExternalFindingEvidence;\n}\n\n/** Repository provenance retained by a reader outside the published evidence. */\nexport interface ExternalSourceRepository {\n url: string;\n platform?: \"github\" | \"gitlab\";\n}\n\nexport function snapshotSourceRepositories(\n references: readonly ExternalSourceRepository[] = [],\n): ExternalSourceRepository[] {\n return references.map(({ url, platform }) => ({ url, platform }));\n}\n\nexport interface ExternalFindings {\n read: number;\n /** Reader-retained run metadata, including diagnostics for empty reports. */\n report?: Record<string, unknown>;\n findings: ExternalFinding[];\n excluded: {\n position: number;\n source_finding_id: string | null;\n reason: string;\n }[];\n}\n\nexport function hasNoExternalRecords(input: ExternalFindings): boolean {\n return input.read === 0 && !input.findings.length && !input.excluded.length;\n}\n\n/** Classify a reader selection before deciding whether to store, publish, or report it. */\nexport function externalImportDisposition(\n input: ExternalFindings,\n): \"ready\" | \"empty\" | \"excluded\" | \"failed\" {\n if (input.findings.length) return \"ready\";\n const errors = input.report?.[\"errors\"];\n if (Array.isArray(errors) && errors.length) return \"failed\";\n if (hasNoExternalRecords(input)) return \"empty\";\n return input.read === input.excluded.length ? \"excluded\" : \"failed\";\n}\n\n/** No findings can be imported. The selection retains every reader exclusion and diagnostic. */\nexport class NoPublishableFindingsError extends CodexSecurityError {\n readonly summary: string;\n\n constructor(public readonly selection: ExternalFindings) {\n const diagnostics = reportForJson(selection.report)?.[\"errors\"];\n const summary =\n externalImportDisposition(selection) === \"empty\"\n ? \"No supported findings are ready to publish: the report is empty.\"\n : `No supported findings are ready to publish (${selection.read} read, ${selection.excluded.length} excluded).${Array.isArray(diagnostics) && diagnostics.length ? ` Scanner diagnostics: ${JSON.stringify(diagnostics)}` : \"\"}`;\n const reasons = selection.excluded.map(\n (item) => `Item ${item.position}: ${item.reason}`,\n );\n super([summary, ...reasons].join(\" \"));\n this.summary = summary;\n }\n}\n\nexport function reportForJson(report: ExternalFindings[\"report\"]) {\n const errors = report?.[\"errors\"];\n if (!Array.isArray(errors)) return report;\n const json = JSON.stringify(errors, (_key, entry: unknown) =>\n entry instanceof Error ? { ...entry, message: entry.message } : entry,\n );\n return { ...report, errors: JSON.parse(json) as unknown[] };\n}\n\nconst isScannerError = Error.isError ?? isNativeError;\nexport const nativeErrorStackGetter = Object.getOwnPropertyDescriptor(\n new Error(),\n \"stack\",\n)?.get;\n\nfunction cloneScannerDiagnostic(source: Error): Error {\n const message = Object.getOwnPropertyDescriptor(source, \"message\");\n const stack = Object.getOwnPropertyDescriptor(source, \"stack\");\n try {\n if (\n (!message || Object.hasOwn(message, \"value\")) &&\n (!stack?.get || stack.get === nativeErrorStackGetter)\n )\n return structuredClone(source);\n // Keep the native error type and data-valued cause without running a\n // caller-supplied message or stack getter while restoring diagnostics.\n const cause = Object.getOwnPropertyDescriptor(source, \"cause\");\n const clean = new Error(message?.value, { cause: cause?.value });\n const name = Object.getOwnPropertyDescriptor(\n Object.getPrototypeOf(source),\n \"name\",\n )?.value;\n if (typeof name === \"string\") clean.name = name;\n if (!message?.get && nativeErrorStackGetter) {\n const nativeStack: unknown = nativeErrorStackGetter.call(source);\n if (typeof nativeStack === \"string\") clean.stack = nativeStack;\n }\n return structuredClone(clean);\n } catch {\n // A noncloneable cause does not prevent JSON export.\n return new Error(message?.value);\n }\n}\n\n/** @internal Capture fresh input once, so preview, limits and storage use the same JSON. */\nexport function snapshotNormalizedFindings<T extends Partial<ExternalFindings>>(\n input: T,\n checkEvidenceNumber = (value: number) => requireJsonNumber(value, \"Evidence\"),\n target: ExternalImportTarget = \"local\",\n provider?: string,\n): T {\n const fields = new Map<string, unknown>();\n const errors: { path: string[]; error: Error }[] = [];\n let root: unknown;\n\n function captureField(field: string, observed: unknown): string | undefined {\n const parents: { key: string; value: object }[] = [];\n // The outer traversal already called this field's toJSON with its real key.\n // Returning that value from the wrapper keeps JSON from calling it twice.\n return JSON.stringify(\n { toJSON: () => observed },\n function (this: object, key, value: unknown) {\n while (parents.length && parents.at(-1)!.value !== this) parents.pop();\n const evidence = field === \"findings\" && parents[2]?.key === \"evidence\";\n if (evidence && target === \"cloud\")\n requireCloudEvidenceDepth(parents.length - 2, this, value);\n if (isNumberObject(value)) value = +value;\n if (field === \"report\") checkReportNumber(value);\n if (evidence) checkEmittedJsonNumber(value, checkEvidenceNumber);\n if (value !== null && typeof value === \"object\") {\n if (value === root) {\n const path = [field, ...parents.slice(1).map((p) => p.key)];\n if (parents.length) path.push(key);\n throw new TypeError(\n `Converting circular structure to JSON at ${JSON.stringify(path)}`,\n );\n }\n if (\n field === \"report\" &&\n parents[1]?.key === \"errors\" &&\n Array.isArray(parents[1].value) &&\n isScannerError(value)\n ) {\n errors.push({\n path: [field, ...parents.slice(1).map((p) => p.key), key],\n error: value,\n });\n }\n parents.push({ key, value });\n }\n return value;\n },\n );\n }\n\n // Capture each member in native property order. A report and a findings\n // payload can each fit in a string while their combined JSON does not.\n const envelope = JSON.stringify(\n input,\n function (this: object, field, value: unknown) {\n if (this !== root) {\n root = value;\n return value;\n }\n const json = captureField(field, value);\n if (json === undefined) return undefined;\n fields.set(field, JSON.parse(json));\n return null;\n },\n );\n const result = JSON.parse(envelope);\n for (const [key, value] of fields) result[key] = value;\n for (const { path, error: source } of errors) {\n const key = path.pop()!;\n let parent = result as unknown as Record<string, unknown>;\n for (const field of path) parent = parent[field] as Record<string, unknown>;\n const error = cloneScannerDiagnostic(source);\n Object.defineProperties(\n error,\n Object.getOwnPropertyDescriptors(parent[key] as object),\n );\n parent[key] = error;\n }\n // Reader scope can live on a getter. Do not evaluate enumerable getters twice.\n if (provider !== undefined) {\n const keys = [\"sourceFormat\", \"semgrepPlatformScope\", \"snykRestContext\"];\n if (provider === \"semgrep\" || provider === \"snyk\")\n keys.push(\"sourceRepositoryUrl\", \"sourceRepositoryPlatform\");\n for (const key of keys)\n if (\n !(key in result) &&\n key in input &&\n !Object.prototype.propertyIsEnumerable.call(input, key)\n )\n result[key] = structuredClone(Reflect.get(input, key));\n }\n return result;\n}\n\n/** @internal Clone owned values without serializing the evidence again in every preview view. */\nexport function cloneImportPreview<T extends ExternalFindings>(input: T): T {\n if (input.report === undefined) return structuredClone(input);\n return {\n ...structuredClone({ ...input, report: undefined }),\n ...snapshotNormalizedFindings({ report: input.report }),\n };\n}\n\n/** Capture the caller's import settings before reading an export or resolving its destination. */\nexport function snapshotImportOptions<P extends string>({\n repository,\n provider,\n sourceKey,\n sourceRepositoryUrl,\n trivyScanRoot,\n inspectorProjectMap,\n}: Omit<LocalExternalImportOptions, \"provider\"> & { provider: P }) {\n if (provider === \"trivy\" && sourceRepositoryUrl !== undefined)\n throw new CodexSecurityError(\n \"Trivy reads repository provenance from the report; do not supply --source-repository-url.\",\n );\n if (trivyScanRoot !== undefined && provider !== \"trivy\")\n throw new CodexSecurityError(\n \"--trivy-scan-root applies only to --provider trivy.\",\n );\n if (inspectorProjectMap !== undefined && provider !== \"inspector\")\n throw new CodexSecurityError(\n \"An Inspector project map requires the inspector provider.\",\n );\n return {\n repository,\n provider,\n sourceKey,\n sourceRepositoryUrl,\n trivyScanRoot,\n inspectorProjectMap: inspectorProjectMap && new Map(inspectorProjectMap),\n };\n}\n"]}