@openai/codex-security 0.9.1 → 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 (387) hide show
  1. package/README.md +37 -788
  2. package/_bundled_plugin/.codex-plugin/plugin.json +2 -0
  3. package/_bundled_plugin/.mcp.json +2 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br +0 -0
  5. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  6. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  7. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  12. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  13. package/_bundled_plugin/mcp/server.mjs.br +0 -0
  14. package/_bundled_plugin/references/artifact-storage.md +1 -1
  15. package/_bundled_plugin/references/baseline-auditor.md +18 -0
  16. package/_bundled_plugin/references/core-scan.md +5 -42
  17. package/_bundled_plugin/references/final-report.md +1 -1
  18. package/_bundled_plugin/references/focused-investigator.md +13 -0
  19. package/_bundled_plugin/references/scan-prologue.md +2 -2
  20. package/_bundled_plugin/references/scan-runtime.md +4 -2
  21. package/_bundled_plugin/references/security-guidance.md +14 -1
  22. package/_bundled_plugin/references/validate-scan-findings.md +3 -0
  23. package/_bundled_plugin/scripts/deep_scan_workbench.py +29 -12
  24. package/_bundled_plugin/scripts/dispatch_inventory_tool +7 -0
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +29 -3
  26. package/_bundled_plugin/scripts/launch_codex_security_mcp +54 -16
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +26 -1
  28. package/_bundled_plugin/scripts/snapshot_sqlite.py +8 -2
  29. package/_bundled_plugin/scripts/windows_scan_local_files.py +216 -25
  30. package/_bundled_plugin/scripts/workbench/handoff.py +55 -25
  31. package/_bundled_plugin/scripts/workbench/storage.py +25 -5
  32. package/_bundled_plugin/scripts/workbench_cli.py +24 -2
  33. package/_bundled_plugin/scripts/workbench_constants.py +2 -0
  34. package/_bundled_plugin/scripts/workbench_db.py +244 -217
  35. package/_bundled_plugin/scripts/workbench_feedback.py +49 -4
  36. package/_bundled_plugin/scripts/workbench_native_indexes.py +226 -29
  37. package/_bundled_plugin/scripts/workbench_progress.py +159 -3
  38. package/_bundled_plugin/scripts/workbench_publication.py +2 -3
  39. package/_bundled_plugin/scripts/workbench_remediation.py +142 -2
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +48 -8
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +281 -119
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +143 -9
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +36 -10
  44. package/_bundled_plugin/scripts/workbench_schema.py +220 -14
  45. package/_bundled_plugin/scripts/workbench_setup.py +1 -1
  46. package/_bundled_plugin/scripts/workbench_target.py +471 -84
  47. package/_bundled_plugin/scripts/workbench_target_state.py +1108 -22
  48. package/_bundled_plugin/shared/workbench-history-repairs.json +60 -14
  49. package/_bundled_plugin/shared/workbench-migrations.json +66 -0
  50. package/_bundled_plugin/skills/fix-finding/SKILL.md +1 -0
  51. package/_bundled_plugin/skills/publish-findings/SKILL.md +24 -160
  52. package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +2 -2
  53. package/_bundled_plugin/skills/publish-findings/references/checkmarx-import.md +2 -2
  54. package/_bundled_plugin/skills/publish-findings/scripts/collect_checkmarx.py +3 -58
  55. package/_bundled_plugin/skills/publish-findings/scripts/collect_continuum.py +224 -0
  56. package/_bundled_plugin/skills/publish-findings/scripts/collector_paths.py +63 -0
  57. package/_bundled_plugin/skills/security-scan/SKILL.md +9 -46
  58. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +2 -2
  59. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +3 -21
  60. package/_bundled_plugin/skills/security-scan/references/managed-scan.md +11 -0
  61. package/_bundled_plugin/skills/security-scan/references/scan-results.md +15 -0
  62. package/_bundled_plugin/skills/security-scan/references/scoped-paths.md +23 -0
  63. package/_bundled_plugin/skills/security-scan/references/sdk-files.md +24 -0
  64. package/bin/codex-security.mjs +2 -2
  65. package/dist/api.d.ts +6 -1
  66. package/dist/api.d.ts.map +1 -1
  67. package/dist/api.js +437 -154
  68. package/dist/api.js.map +1 -1
  69. package/dist/armorcode-findings.d.ts +9 -0
  70. package/dist/armorcode-findings.d.ts.map +1 -0
  71. package/dist/armorcode-findings.js +145 -0
  72. package/dist/armorcode-findings.js.map +1 -0
  73. package/dist/artifact-export.d.ts +2 -0
  74. package/dist/artifact-export.d.ts.map +1 -1
  75. package/dist/artifact-export.js +29 -13
  76. package/dist/artifact-export.js.map +1 -1
  77. package/dist/auth.d.ts +6 -2
  78. package/dist/auth.d.ts.map +1 -1
  79. package/dist/auth.js +33 -12
  80. package/dist/auth.js.map +1 -1
  81. package/dist/batch-cost.d.ts +18 -0
  82. package/dist/batch-cost.d.ts.map +1 -0
  83. package/dist/batch-cost.js +41 -0
  84. package/dist/batch-cost.js.map +1 -0
  85. package/dist/blackduck-findings.d.ts +1 -1
  86. package/dist/blackduck-findings.d.ts.map +1 -1
  87. package/dist/blackduck-findings.js +5 -18
  88. package/dist/blackduck-findings.js.map +1 -1
  89. package/dist/bundled-plugin.d.ts +4 -0
  90. package/dist/bundled-plugin.d.ts.map +1 -0
  91. package/dist/bundled-plugin.js +23 -0
  92. package/dist/bundled-plugin.js.map +1 -0
  93. package/dist/classify-scan-severity.d.ts +1 -1
  94. package/dist/classify-scan-severity.d.ts.map +1 -1
  95. package/dist/classify-scan-severity.js +11 -3
  96. package/dist/classify-scan-severity.js.map +1 -1
  97. package/dist/classify-severity.d.ts.map +1 -1
  98. package/dist/classify-severity.js +9 -6
  99. package/dist/classify-severity.js.map +1 -1
  100. package/dist/cli-argument.d.ts +4 -0
  101. package/dist/cli-argument.d.ts.map +1 -0
  102. package/dist/cli-argument.js +17 -0
  103. package/dist/cli-argument.js.map +1 -0
  104. package/dist/cli-help.d.ts +1 -1
  105. package/dist/cli-help.d.ts.map +1 -1
  106. package/dist/cli-help.js +71 -29
  107. package/dist/cli-help.js.map +1 -1
  108. package/dist/cli-hook.d.ts +3 -0
  109. package/dist/cli-hook.d.ts.map +1 -0
  110. package/dist/cli-hook.js +87 -0
  111. package/dist/cli-hook.js.map +1 -0
  112. package/dist/cli-integrations.d.ts +13 -0
  113. package/dist/cli-integrations.d.ts.map +1 -0
  114. package/dist/cli-integrations.js +333 -0
  115. package/dist/cli-integrations.js.map +1 -0
  116. package/dist/cli-mcp.d.ts +15 -0
  117. package/dist/cli-mcp.d.ts.map +1 -0
  118. package/dist/cli-mcp.js +178 -0
  119. package/dist/cli-mcp.js.map +1 -0
  120. package/dist/cli-token-view.d.ts +10 -0
  121. package/dist/cli-token-view.d.ts.map +1 -0
  122. package/dist/cli-token-view.js +41 -0
  123. package/dist/cli-token-view.js.map +1 -0
  124. package/dist/cli.d.ts +5 -3
  125. package/dist/cli.d.ts.map +1 -1
  126. package/dist/cli.js +1763 -894
  127. package/dist/cli.js.map +1 -1
  128. package/dist/cloud-publish.d.ts.map +1 -1
  129. package/dist/cloud-publish.js +33 -31
  130. package/dist/cloud-publish.js.map +1 -1
  131. package/dist/codex-sdk-environment.d.ts +6 -0
  132. package/dist/codex-sdk-environment.d.ts.map +1 -1
  133. package/dist/codex-sdk-environment.js +19 -0
  134. package/dist/codex-sdk-environment.js.map +1 -1
  135. package/dist/command-words.d.ts +3 -0
  136. package/dist/command-words.d.ts.map +1 -0
  137. package/dist/command-words.js +46 -0
  138. package/dist/command-words.js.map +1 -0
  139. package/dist/component-scan.d.ts +3 -1
  140. package/dist/component-scan.d.ts.map +1 -1
  141. package/dist/component-scan.js +40 -7
  142. package/dist/component-scan.js.map +1 -1
  143. package/dist/config.d.ts +1 -1
  144. package/dist/config.d.ts.map +1 -1
  145. package/dist/config.js +30 -1
  146. package/dist/config.js.map +1 -1
  147. package/dist/continuum-findings.d.ts +1 -1
  148. package/dist/continuum-findings.d.ts.map +1 -1
  149. package/dist/continuum-findings.js +93 -31
  150. package/dist/continuum-findings.js.map +1 -1
  151. package/dist/cost.d.ts.map +1 -1
  152. package/dist/cost.js +1 -45
  153. package/dist/cost.js.map +1 -1
  154. package/dist/custom-validation-prompt.d.ts +1 -1
  155. package/dist/custom-validation-prompt.d.ts.map +1 -1
  156. package/dist/custom-validation-prompt.js +29 -19
  157. package/dist/custom-validation-prompt.js.map +1 -1
  158. package/dist/deduplication/local.d.ts +3 -1
  159. package/dist/deduplication/local.d.ts.map +1 -1
  160. package/dist/deduplication/local.js +8 -1
  161. package/dist/deduplication/local.js.map +1 -1
  162. package/dist/deduplication/refusal.d.ts.map +1 -1
  163. package/dist/deduplication/refusal.js +2 -1
  164. package/dist/deduplication/refusal.js.map +1 -1
  165. package/dist/deduplication/scan.d.ts +2 -0
  166. package/dist/deduplication/scan.d.ts.map +1 -1
  167. package/dist/deduplication/scan.js +24 -7
  168. package/dist/deduplication/scan.js.map +1 -1
  169. package/dist/deep-scan.d.ts.map +1 -1
  170. package/dist/deep-scan.js +16 -15
  171. package/dist/deep-scan.js.map +1 -1
  172. package/dist/endor-findings.d.ts +2 -2
  173. package/dist/endor-findings.d.ts.map +1 -1
  174. package/dist/endor-findings.js +6 -23
  175. package/dist/endor-findings.js.map +1 -1
  176. package/dist/errors.d.ts +3 -1
  177. package/dist/errors.d.ts.map +1 -1
  178. package/dist/errors.js +7 -3
  179. package/dist/errors.js.map +1 -1
  180. package/dist/executable-path.d.ts +3 -0
  181. package/dist/executable-path.d.ts.map +1 -1
  182. package/dist/executable-path.js +26 -0
  183. package/dist/executable-path.js.map +1 -1
  184. package/dist/external-findings-import.d.ts.map +1 -1
  185. package/dist/external-findings-import.js +12 -1
  186. package/dist/external-findings-import.js.map +1 -1
  187. package/dist/external-findings-local.d.ts +66 -4
  188. package/dist/external-findings-local.d.ts.map +1 -1
  189. package/dist/external-findings-local.js +234 -53
  190. package/dist/external-findings-local.js.map +1 -1
  191. package/dist/external-findings-publish.d.ts +6 -1
  192. package/dist/external-findings-publish.d.ts.map +1 -1
  193. package/dist/external-findings-publish.js +326 -1633
  194. package/dist/external-findings-publish.js.map +1 -1
  195. package/dist/external-findings-read.d.ts +1 -0
  196. package/dist/external-findings-read.d.ts.map +1 -1
  197. package/dist/external-findings-read.js +31 -51
  198. package/dist/external-findings-read.js.map +1 -1
  199. package/dist/external-findings.d.ts +1 -1
  200. package/dist/external-findings.d.ts.map +1 -1
  201. package/dist/external-findings.js +12 -1
  202. package/dist/external-findings.js.map +1 -1
  203. package/dist/external-import-contract.d.ts +3 -11
  204. package/dist/external-import-contract.d.ts.map +1 -1
  205. package/dist/external-import-contract.js +29 -176
  206. package/dist/external-import-contract.js.map +1 -1
  207. package/dist/external-import-models.d.ts +1 -1
  208. package/dist/external-import-models.d.ts.map +1 -1
  209. package/dist/external-import-models.js.map +1 -1
  210. package/dist/finding-prompt.d.ts.map +1 -1
  211. package/dist/finding-prompt.js +2 -2
  212. package/dist/finding-prompt.js.map +1 -1
  213. package/dist/github-dependabot-findings.d.ts.map +1 -1
  214. package/dist/github-dependabot-findings.js +3 -4
  215. package/dist/github-dependabot-findings.js.map +1 -1
  216. package/dist/github-findings.d.ts.map +1 -1
  217. package/dist/github-findings.js +19 -287
  218. package/dist/github-findings.js.map +1 -1
  219. package/dist/hosted-remediation.d.ts +1 -0
  220. package/dist/hosted-remediation.d.ts.map +1 -1
  221. package/dist/hosted-remediation.js +23 -3
  222. package/dist/hosted-remediation.js.map +1 -1
  223. package/dist/index.d.ts +3 -2
  224. package/dist/index.d.ts.map +1 -1
  225. package/dist/index.js +2 -1
  226. package/dist/index.js.map +1 -1
  227. package/dist/inspector-findings.d.ts.map +1 -1
  228. package/dist/inspector-findings.js +19 -35
  229. package/dist/inspector-findings.js.map +1 -1
  230. package/dist/knowledge-base.d.ts +1 -1
  231. package/dist/knowledge-base.d.ts.map +1 -1
  232. package/dist/knowledge-base.js +34 -27
  233. package/dist/knowledge-base.js.map +1 -1
  234. package/dist/linear.d.ts +11 -0
  235. package/dist/linear.d.ts.map +1 -1
  236. package/dist/linear.js.map +1 -1
  237. package/dist/local-git-metadata.d.ts +5 -2
  238. package/dist/local-git-metadata.d.ts.map +1 -1
  239. package/dist/local-git-metadata.js +8 -4
  240. package/dist/local-git-metadata.js.map +1 -1
  241. package/dist/multiscan.d.ts +4 -0
  242. package/dist/multiscan.d.ts.map +1 -1
  243. package/dist/multiscan.js +79 -37
  244. package/dist/multiscan.js.map +1 -1
  245. package/dist/opengrep-findings.d.ts +4 -2
  246. package/dist/opengrep-findings.d.ts.map +1 -1
  247. package/dist/opengrep-findings.js +39 -22
  248. package/dist/opengrep-findings.js.map +1 -1
  249. package/dist/private-finding-import.d.ts +8 -13
  250. package/dist/private-finding-import.d.ts.map +1 -1
  251. package/dist/private-finding-import.js +69 -129
  252. package/dist/private-finding-import.js.map +1 -1
  253. package/dist/project-config.d.ts.map +1 -1
  254. package/dist/project-config.js +53 -13
  255. package/dist/project-config.js.map +1 -1
  256. package/dist/prompt-files.d.ts +7 -2
  257. package/dist/prompt-files.d.ts.map +1 -1
  258. package/dist/prompt-files.js +42 -20
  259. package/dist/prompt-files.js.map +1 -1
  260. package/dist/provider-profile.d.ts.map +1 -1
  261. package/dist/provider-profile.js +4 -9
  262. package/dist/provider-profile.js.map +1 -1
  263. package/dist/publication.d.ts +1 -1
  264. package/dist/publication.d.ts.map +1 -1
  265. package/dist/publication.js.map +1 -1
  266. package/dist/record.d.ts +1 -5
  267. package/dist/record.d.ts.map +1 -1
  268. package/dist/record.js +3 -51
  269. package/dist/record.js.map +1 -1
  270. package/dist/remediation.d.ts.map +1 -1
  271. package/dist/remediation.js +3 -1
  272. package/dist/remediation.js.map +1 -1
  273. package/dist/runtime.d.ts +35 -7
  274. package/dist/runtime.d.ts.map +1 -1
  275. package/dist/runtime.js +778 -153
  276. package/dist/runtime.js.map +1 -1
  277. package/dist/saved-scan-bootstrap.d.ts +6 -1
  278. package/dist/saved-scan-bootstrap.d.ts.map +1 -1
  279. package/dist/saved-scan-bootstrap.js +267 -115
  280. package/dist/saved-scan-bootstrap.js.map +1 -1
  281. package/dist/scan-archive-path.d.ts +2 -0
  282. package/dist/scan-archive-path.d.ts.map +1 -0
  283. package/dist/scan-archive-path.js +5 -0
  284. package/dist/scan-archive-path.js.map +1 -0
  285. package/dist/scan-comparison.d.ts.map +1 -1
  286. package/dist/scan-comparison.js +6 -2
  287. package/dist/scan-comparison.js.map +1 -1
  288. package/dist/scan-dashboard.d.ts +1 -0
  289. package/dist/scan-dashboard.d.ts.map +1 -1
  290. package/dist/scan-dashboard.js +18 -2
  291. package/dist/scan-dashboard.js.map +1 -1
  292. package/dist/scan-executor.d.ts.map +1 -1
  293. package/dist/scan-executor.js +4 -2
  294. package/dist/scan-executor.js.map +1 -1
  295. package/dist/scan-history-renderer.d.ts +1 -0
  296. package/dist/scan-history-renderer.d.ts.map +1 -1
  297. package/dist/scan-history-renderer.js +25 -9
  298. package/dist/scan-history-renderer.js.map +1 -1
  299. package/dist/scan-logs.d.ts.map +1 -1
  300. package/dist/scan-logs.js +28 -4
  301. package/dist/scan-logs.js.map +1 -1
  302. package/dist/scanner-import.d.ts +5 -11
  303. package/dist/scanner-import.d.ts.map +1 -1
  304. package/dist/scanner-import.js +16 -89
  305. package/dist/scanner-import.js.map +1 -1
  306. package/dist/security-policy.d.ts.map +1 -1
  307. package/dist/security-policy.js +26 -6
  308. package/dist/security-policy.js.map +1 -1
  309. package/dist/semgrep-findings.d.ts.map +1 -1
  310. package/dist/semgrep-findings.js +14 -48
  311. package/dist/semgrep-findings.js.map +1 -1
  312. package/dist/semgrep-platform-findings.d.ts +20 -70
  313. package/dist/semgrep-platform-findings.d.ts.map +1 -1
  314. package/dist/semgrep-platform-findings.js +116 -333
  315. package/dist/semgrep-platform-findings.js.map +1 -1
  316. package/dist/snyk-findings.d.ts +2 -0
  317. package/dist/snyk-findings.d.ts.map +1 -1
  318. package/dist/snyk-findings.js +5 -8
  319. package/dist/snyk-findings.js.map +1 -1
  320. package/dist/snyk-rest-findings.d.ts +3 -20
  321. package/dist/snyk-rest-findings.d.ts.map +1 -1
  322. package/dist/snyk-rest-findings.js +45 -217
  323. package/dist/snyk-rest-findings.js.map +1 -1
  324. package/dist/sonar-findings.d.ts +1 -1
  325. package/dist/sonar-findings.d.ts.map +1 -1
  326. package/dist/sonar-findings.js +2 -4
  327. package/dist/sonar-findings.js.map +1 -1
  328. package/dist/sonar-import.d.ts +3 -0
  329. package/dist/sonar-import.d.ts.map +1 -1
  330. package/dist/sonar-import.js +28 -30
  331. package/dist/sonar-import.js.map +1 -1
  332. package/dist/stored-finding-projection.d.ts +6 -0
  333. package/dist/stored-finding-projection.d.ts.map +1 -0
  334. package/dist/stored-finding-projection.js +104 -0
  335. package/dist/stored-finding-projection.js.map +1 -0
  336. package/dist/stored-findings-publication.d.ts +23 -0
  337. package/dist/stored-findings-publication.d.ts.map +1 -0
  338. package/dist/stored-findings-publication.js +169 -0
  339. package/dist/stored-findings-publication.js.map +1 -0
  340. package/dist/targets.d.ts +6 -1
  341. package/dist/targets.d.ts.map +1 -1
  342. package/dist/targets.js +76 -23
  343. package/dist/targets.js.map +1 -1
  344. package/dist/tenable-findings.d.ts +1 -4
  345. package/dist/tenable-findings.d.ts.map +1 -1
  346. package/dist/tenable-findings.js.map +1 -1
  347. package/dist/trivy-findings.d.ts.map +1 -1
  348. package/dist/trivy-findings.js +0 -11
  349. package/dist/trivy-findings.js.map +1 -1
  350. package/dist/trusted-executable.d.ts +6 -0
  351. package/dist/trusted-executable.d.ts.map +1 -1
  352. package/dist/trusted-executable.js +140 -37
  353. package/dist/trusted-executable.js.map +1 -1
  354. package/dist/veracode-findings.d.ts +1 -3
  355. package/dist/veracode-findings.d.ts.map +1 -1
  356. package/dist/veracode-findings.js +13 -38
  357. package/dist/veracode-findings.js.map +1 -1
  358. package/dist/version.d.ts +3 -1
  359. package/dist/version.d.ts.map +1 -1
  360. package/dist/version.js +184 -32
  361. package/dist/version.js.map +1 -1
  362. package/dist/wiz-findings.d.ts +2 -2
  363. package/dist/wiz-findings.d.ts.map +1 -1
  364. package/dist/wiz-findings.js +14 -92
  365. package/dist/wiz-findings.js.map +1 -1
  366. package/docs/cli.md +373 -106
  367. package/docs/findings-service.md +22 -9
  368. package/docs/hosted-remediation.md +13 -4
  369. package/docs/sdk.md +903 -0
  370. package/package.json +10 -6
  371. package/schemas/external-findings.schema.json +2 -1
  372. package/dist/hosted-scanner-v1.d.ts +0 -6
  373. package/dist/hosted-scanner-v1.d.ts.map +0 -1
  374. package/dist/hosted-scanner-v1.js +0 -60
  375. package/dist/hosted-scanner-v1.js.map +0 -1
  376. package/dist/reader-selection.d.ts +0 -15
  377. package/dist/reader-selection.d.ts.map +0 -1
  378. package/dist/reader-selection.js +0 -89
  379. package/dist/reader-selection.js.map +0 -1
  380. package/dist/semgrep-platform-v1.d.ts +0 -6
  381. package/dist/semgrep-platform-v1.d.ts.map +0 -1
  382. package/dist/semgrep-platform-v1.js +0 -83
  383. package/dist/semgrep-platform-v1.js.map +0 -1
  384. package/dist/snyk-rest-v1.d.ts +0 -28
  385. package/dist/snyk-rest-v1.d.ts.map +0 -1
  386. package/dist/snyk-rest-v1.js +0 -132
  387. package/dist/snyk-rest-v1.js.map +0 -1
@@ -4,6 +4,7 @@ export type LocalFindingProvider = Provider | "tenable";
4
4
  /** File reader names mapped to the provider stored with each finding. */
5
5
  export declare const EXTERNAL_FINDINGS_PROVIDERS: {
6
6
  readonly wiz: "wiz";
7
+ readonly armorcode: "armorcode";
7
8
  readonly snyk: "snyk";
8
9
  readonly semgrep: "semgrep";
9
10
  readonly trivy: "trivy";
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings-read.d.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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"}
@@ -2,25 +2,26 @@ import { readScannerJson, sarifRunRepositories } from "./scanner-import.js";
2
2
  import { CodexSecurityError } from "./errors.js";
3
3
  import { readTenableFindings } from "./tenable-findings.js";
4
4
  import { dependabotRepository } from "./github-dependabot-findings.js";
5
- import { normalizeSnykFile, readSnykReport, emptySnykReportRepositories, snykRepositoryUrls, } from "./snyk-findings.js";
5
+ import { normalizeSnykFile, emptySnykReportRepositories, snykRepositoryUrls, } from "./snyk-findings.js";
6
6
  import { isSemgrepSarifDriver, normalizeSemgrepFindings, readSemgrepReport, } from "./semgrep-findings.js";
7
7
  import { semgrepPlatformReportRepository } from "./semgrep-platform-findings.js";
8
- import { normalizeTrivyFindings, needsPreviousTrivyProjection, normalizePreviousTrivyFindings, } from "./trivy-findings.js";
8
+ import { normalizeTrivyFindings } from "./trivy-findings.js";
9
9
  import { readOpenGrepFindings } from "./opengrep-findings.js";
10
- import { normalizeEndorFindings, normalizePreviousEndorFindings, endorRepositoryUrls, } from "./endor-findings.js";
10
+ import { normalizeEndorFindings, endorRepositoryUrls, } from "./endor-findings.js";
11
11
  import { readGitHubFindings } from "./github-findings.js";
12
12
  import { readSonarFindings } from "./sonar-findings.js";
13
- import { normalizeVeracodeFindings, normalizePreviousVeracodeFindings, } from "./veracode-findings.js";
14
- import { needsPreviousBlackDuckProjection, normalizeBlackDuckFindings, normalizePreviousBlackDuckFindings, } from "./blackduck-findings.js";
15
- import { normalizeContinuumFindings, normalizePreviousContinuumFindings, } from "./continuum-findings.js";
13
+ import { normalizeVeracodeFindings } from "./veracode-findings.js";
14
+ import { normalizeBlackDuckFindings } from "./blackduck-findings.js";
15
+ import { normalizeContinuumFindings } from "./continuum-findings.js";
16
16
  import { readCheckmarxFindings } from "./checkmarx-findings.js";
17
- import { normalizeInspectorFindings, normalizePreviousInspectorFindings, } from "./inspector-findings.js";
18
- import { hasPreviousCloudProjection } from "./reader-selection.js";
17
+ import { normalizeInspectorFindings } from "./inspector-findings.js";
19
18
  import { isRecord } from "./record.js";
20
- import { readLocalWizFindings, readVendorFindingsForPublication, wizFindingRepository, } from "./wiz-findings.js";
19
+ import { readWizSelection, wizFindingRepository } from "./wiz-findings.js";
20
+ import { normalizeArmorCodeFindings } from "./armorcode-findings.js";
21
21
  /** File reader names mapped to the provider stored with each finding. */
22
22
  export const EXTERNAL_FINDINGS_PROVIDERS = {
23
23
  wiz: "wiz",
24
+ armorcode: "armorcode",
24
25
  snyk: "snyk",
25
26
  semgrep: "semgrep",
26
27
  trivy: "trivy",
@@ -108,13 +109,6 @@ export function snykFileRepositories(input) {
108
109
  export async function readExternalFindings(path, options, target = "cloud", references = []) {
109
110
  const { provider } = options;
110
111
  const url = options.sourceRepositoryUrl ?? "";
111
- // Both projections describe the same captured rows, including exclusions.
112
- function withReplay(findings, couldDiffer, previous) {
113
- return {
114
- findings,
115
- previousFindings: target === "cloud" && couldDiffer(findings) ? previous : undefined,
116
- };
117
- }
118
112
  if (provider === "tenable") {
119
113
  if (target === "cloud")
120
114
  requireCloudReader(options);
@@ -135,7 +129,7 @@ export async function readExternalFindings(path, options, target = "cloud", refe
135
129
  return { findings, sourceRepositories: [{ url }] };
136
130
  }
137
131
  if (provider === "snyk") {
138
- const input = await readSnykReport(path);
132
+ const input = await readScannerJson(path);
139
133
  const findings = await normalizeSnykFile(input, target, references);
140
134
  return { findings, sourceRepositories: snykFileRepositories(input) };
141
135
  }
@@ -152,57 +146,43 @@ export async function readExternalFindings(path, options, target = "cloud", refe
152
146
  sourceRepositories.push({ url: options.sourceRepositoryUrl });
153
147
  return { findings, sourceRepositories };
154
148
  }
149
+ if (provider === "armorcode") {
150
+ const input = await readScannerJson(path);
151
+ return {
152
+ findings: normalizeArmorCodeFindings(input, target, options.sourceRepositoryUrl),
153
+ };
154
+ }
155
155
  if (provider === "github")
156
156
  return { findings: await readGitHubFindings(path, target) };
157
157
  if (provider === "wiz") {
158
- const wiz = target === "local"
159
- ? await readLocalWizFindings(path)
160
- : await readVendorFindingsForPublication(path, target);
161
- const sourceRepositories = wiz.current.findings.flatMap((finding) => localFindingRepositories("wiz", finding));
158
+ const wiz = await readWizSelection(path, target);
159
+ const sourceRepositories = wiz.findings.findings.flatMap((finding) => localFindingRepositories("wiz", finding));
162
160
  return {
163
- findings: wiz.current,
164
- ...("legacy" in wiz && { publication: wiz }),
161
+ findings: wiz.findings,
165
162
  sourceRepositories: [...wiz.sourceRepositories, ...sourceRepositories],
166
163
  };
167
164
  }
168
165
  const input = await readScannerJson(path);
169
- if (provider === "trivy") {
170
- const args = [input, target, options.trivyScanRoot];
171
- return withReplay(normalizeTrivyFindings(...args), needsPreviousTrivyProjection, () => normalizePreviousTrivyFindings(...args));
172
- }
166
+ if (provider === "trivy")
167
+ return {
168
+ findings: normalizeTrivyFindings(input, target, options.trivyScanRoot),
169
+ };
173
170
  if (provider === "endor") {
174
171
  const findings = normalizeEndorFindings(input, target);
175
172
  return {
176
- ...withReplay(findings, hasPreviousCloudProjection, () => normalizePreviousEndorFindings(input, target)),
173
+ findings,
177
174
  sourceRepositories: sarifFileRepositories(input, "Endor") ??
178
175
  findings.findings.flatMap((row) => localFindingRepositories(provider, row)),
179
176
  };
180
177
  }
181
- const [normalize, previous, couldDiffer] = {
182
- inspector: [
183
- normalizeInspectorFindings,
184
- normalizePreviousInspectorFindings,
185
- () => true,
186
- ],
187
- continuum: [
188
- normalizeContinuumFindings,
189
- normalizePreviousContinuumFindings,
190
- () => !Array.isArray(input),
191
- ],
192
- blackduck: [
193
- normalizeBlackDuckFindings,
194
- normalizePreviousBlackDuckFindings,
195
- needsPreviousBlackDuckProjection,
196
- ],
197
- veracode: [
198
- normalizeVeracodeFindings,
199
- normalizePreviousVeracodeFindings,
200
- hasPreviousCloudProjection,
201
- ],
178
+ const normalize = {
179
+ inspector: normalizeInspectorFindings,
180
+ continuum: normalizeContinuumFindings,
181
+ blackduck: normalizeBlackDuckFindings,
182
+ veracode: normalizeVeracodeFindings,
202
183
  }[provider];
203
- const args = [input, url, target, options.inspectorProjectMap];
204
184
  return {
205
- ...withReplay(normalize(...args), couldDiffer, () => previous(...args)),
185
+ findings: normalize(input, url, target, options.inspectorProjectMap),
206
186
  sourceRepositories: [{ url }],
207
187
  };
208
188
  }
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings-read.js","sourceRoot":"","sources":["../src/external-findings-read.ts"],"names":[],"mappings":"AAMA,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,cAAc,EACd,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,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACL,sBAAsB,EACtB,8B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,GAAG,UAAU,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;QACvE,kBAAkB,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ExternalFinding,\n ExternalFindings,\n ExternalPublicationInput,\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 readSnykReport,\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 {\n normalizeTrivyFindings,\n needsPreviousTrivyProjection,\n normalizePreviousTrivyFindings,\n} from \"./trivy-findings.js\";\nimport { readOpenGrepFindings } from \"./opengrep-findings.js\";\nimport {\n normalizeEndorFindings,\n normalizePreviousEndorFindings,\n endorRepositoryUrls,\n} from \"./endor-findings.js\";\nimport { readGitHubFindings } from \"./github-findings.js\";\nimport { readSonarFindings } from \"./sonar-findings.js\";\nimport {\n normalizeVeracodeFindings,\n normalizePreviousVeracodeFindings,\n} from \"./veracode-findings.js\";\nimport {\n needsPreviousBlackDuckProjection,\n normalizeBlackDuckFindings,\n normalizePreviousBlackDuckFindings,\n} from \"./blackduck-findings.js\";\nimport {\n normalizeContinuumFindings,\n normalizePreviousContinuumFindings,\n} from \"./continuum-findings.js\";\nimport { readCheckmarxFindings } from \"./checkmarx-findings.js\";\nimport {\n normalizeInspectorFindings,\n normalizePreviousInspectorFindings,\n} from \"./inspector-findings.js\";\nimport { hasPreviousCloudProjection } from \"./reader-selection.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n readLocalWizFindings,\n readVendorFindingsForPublication,\n wizFindingRepository,\n} from \"./wiz-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 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 Shared parser output, including immutable Cloud retry projections. */\nexport interface ReadExternalFindings {\n findings: ExternalFindings;\n previousFindings?: () => 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/** 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 // Both projections describe the same captured rows, including exclusions.\n function withReplay(\n findings: ExternalFindings,\n couldDiffer: (findings: ExternalFindings) => boolean,\n previous: () => ExternalFindings,\n ): ReadExternalFindings {\n return {\n findings,\n previousFindings:\n target === \"cloud\" && couldDiffer(findings) ? previous : undefined,\n };\n }\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 readSnykReport(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 === \"github\")\n return { findings: await readGitHubFindings(path, target) };\n if (provider === \"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 const input = await readScannerJson(path);\n if (provider === \"trivy\") {\n const args = [input, target, options.trivyScanRoot] as const;\n return withReplay(\n normalizeTrivyFindings(...args),\n needsPreviousTrivyProjection,\n () => normalizePreviousTrivyFindings(...args),\n );\n }\n if (provider === \"endor\") {\n const findings = normalizeEndorFindings(input, target);\n return {\n ...withReplay(findings, hasPreviousCloudProjection, () =>\n normalizePreviousEndorFindings(input, target),\n ),\n sourceRepositories:\n sarifFileRepositories(input, \"Endor\") ??\n findings.findings.flatMap((row) =>\n localFindingRepositories(provider, row),\n ),\n };\n }\n const [normalize, previous, couldDiffer] = (\n {\n inspector: [\n normalizeInspectorFindings,\n normalizePreviousInspectorFindings,\n () => true,\n ],\n continuum: [\n normalizeContinuumFindings,\n normalizePreviousContinuumFindings,\n () => !Array.isArray(input),\n ],\n blackduck: [\n normalizeBlackDuckFindings,\n normalizePreviousBlackDuckFindings,\n needsPreviousBlackDuckProjection,\n ],\n veracode: [\n normalizeVeracodeFindings,\n normalizePreviousVeracodeFindings,\n hasPreviousCloudProjection,\n ],\n } as const\n )[provider];\n const args = [input, url, target, options.inspectorProjectMap] as const;\n return {\n ...withReplay(normalize(...args), couldDiffer, () => previous(...args)),\n sourceRepositories: [{ url }],\n };\n}\n"]}
1
+ {"version":3,"file":"external-findings-read.js","sourceRoot":"","sources":["../src/external-findings-read.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EA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CACnE,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CACzC,CAAC;QACF,OAAO;YACL,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,kBAAkB,EAAE,CAAC,GAAG,GAAG,CAAC,kBAAkB,EAAE,GAAG,kBAAkB,CAAC;SACvE,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,QAAQ,KAAK,OAAO;QACtB,OAAO;YACL,QAAQ,EAAE,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC;SACvE,CAAC;IACJ,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QACzB,MAAM,QAAQ,GAAG,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACvD,OAAO;YACL,QAAQ;YACR,kBAAkB,EAChB,qBAAqB,CAAC,KAAK,EAAE,OAAO,CAAC;gBACrC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAChC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAC,CACxC;SACJ,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG;QAChB,SAAS,EAAE,0BAA0B;QACrC,SAAS,EAAE,0BAA0B;QACrC,SAAS,EAAE,0BAA0B;QACrC,QAAQ,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"]}
@@ -35,7 +35,7 @@ export declare class NoPublishableFindingsError extends CodexSecurityError {
35
35
  export declare function reportForJson(report: ExternalFindings["report"]): Record<string, unknown> | undefined;
36
36
  export declare const nativeErrorStackGetter: (() => any) | undefined;
37
37
  /** Capture the caller's import settings before reading an export or resolving its destination. */
38
- export declare function snapshotImportOptions<P extends LocalExternalImportOptions["provider"]>({ repository, provider, sourceKey, sourceRepositoryUrl, trivyScanRoot, inspectorProjectMap, }: LocalExternalImportOptions & {
38
+ export declare function snapshotImportOptions<P extends string>({ repository, provider, sourceKey, sourceRepositoryUrl, trivyScanRoot, inspectorProjectMap, }: Omit<LocalExternalImportOptions, "provider"> & {
39
39
  provider: P;
40
40
  }): {
41
41
  repository: string;
@@ -1 +1 @@
1
- {"version":3,"file":"external-findings.d.ts","sourceRoot":"","sources":["../src/external-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAQhF,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,GAAG,QAAQ,CAAC;CAChC;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,iBAAi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
70
70
  }
71
71
  /** @internal Capture fresh input once, so preview, limits and storage use the same JSON. */
72
- export function snapshotNormalizedFindings(input, checkEvidenceNumber = (value) => requireJsonNumber(value, "Evidence"), target = "local") {
72
+ export function snapshotNormalizedFindings(input, checkEvidenceNumber = (value) => requireJsonNumber(value, "Evidence"), target = "local", provider) {
73
73
  const fields = new Map();
74
74
  const errors = [];
75
75
  let root;
@@ -135,6 +135,17 @@ export function snapshotNormalizedFindings(input, checkEvidenceNumber = (value)
135
135
  Object.defineProperties(error, Object.getOwnPropertyDescriptors(parent[key]));
136
136
  parent[key] = error;
137
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
+ }
138
149
  return result;
139
150
  }
140
151
  /** @internal Clone owned values without serializing the evidence again in every preview view. */
@@ -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,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;AACp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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): 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 LocalExternalImportOptions[\"provider\"],\n>({\n repository,\n provider,\n sourceKey,\n sourceRepositoryUrl,\n trivyScanRoot,\n inspectorProjectMap,\n}: LocalExternalImportOptions & { 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(insp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C1B,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"]}
@@ -18,7 +18,6 @@ export declare function requireJsonNumber(value: number, label: string): void;
18
18
  export declare function validateExternalReport(report: Record<string, unknown> | undefined): void;
19
19
  export declare function validateCodeLineRange(firstLine: number | null | undefined, endLine: number | null | undefined): void;
20
20
  export declare function validateExternalEvidenceFields(input: unknown, target?: ExternalImportTarget): ExternalFindingEvidence;
21
- export declare function previousAdmission(value: object): "uncertain" | import("./external-import-models.js").ImportedFindingEvidence | null | undefined;
22
21
  /** Keep a valid native record when its optional structured fields exceed the target's bounds. */
23
22
  export declare function validateEnrichedExternalEvidence(evidence: Record<string, unknown>, target: ExternalImportTarget, ...projections: (Record<string, unknown> | undefined)[]): ExternalFindingEvidence;
24
23
  export declare function validateExternalEvidence(input: unknown, target?: ExternalImportTarget): ExternalFindingEvidence;
@@ -31,21 +30,14 @@ export declare class CloudEvidenceDepthError extends Error {
31
30
  }
32
31
  /** JSON omits these object properties, but emits null for the same array elements. */
33
32
  export declare function requireCloudEvidenceDepth(depth: number, holder: object, value: unknown): void;
33
+ export declare const CLOUD_EVIDENCE_BYTES: number;
34
34
  /** Return the validated Cloud wire size, or zero for local evidence. */
35
- export declare function validateExternalEvidenceJson(input: unknown, target: ExternalImportTarget, additionalCloudBytes?: number, observe?: (previousBytes: number, currentBytes: number) => void): number;
36
- /** Reproduce the released SDK's checks on a detached native finding. */
37
- export declare function validatePreviousCloudEvidence(input: unknown): ExternalFindingEvidence;
35
+ export declare function validateExternalEvidenceJson(input: unknown, target: ExternalImportTarget, additionalCloudBytes?: number): number;
38
36
  /** Use the array index as toJSON's key, as when saving the supplied GitHub records. */
39
- export declare function exportedGitHubRecord(value: unknown, index: number, target: ExternalImportTarget, checkPreviousLocal?: boolean): {
37
+ export declare function exportedGitHubRecord(value: unknown, index: number, target: ExternalImportTarget): {
40
38
  record: unknown;
41
- bytes: number;
42
- adjustment: number;
43
- previousInvalid: unknown;
44
- skippedRawValue: boolean;
45
39
  invalid: unknown;
46
40
  };
47
- /** Combine the observed vendor bytes with the old native mapping's typed fields. */
48
- export declare function previousGitHubExclusion(evidence: ExternalFindingEvidence, sourceBytes: number, adjustment: number): string | undefined;
49
41
  export declare function validateImportRequest(input: unknown): FindingImportRequest;
50
42
  export {};
51
43
  //# sourceMappingURL=external-import-contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"external-import-contract.d.ts","sourceRoot":"","sources":["../src/external-import-contract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACb,MAAM,6BAA6B,CAAC;AAQrC,qFAAqF;AACrF,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,OAAO,CAAC;AAOrD,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAe9C;;kFAEkF;AAClF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAatD;AAID,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3D;AA4JD,eAAO,MAAM,qBAAqB,UA/BjB,OAAO,yBAiCvB,CAAC;AACF,eAAO,MAAM,oBAAoB,UAlChB,OAAO,yBAoCvB,CAAC;AACF,eAAO,MAAM,qBAAqB,UArCjB,OAAO,qBAsCyB,CAAC;AAClD,eAAO,MAAM,oBAAoB,UAvChB,OAAO,iBAuCmD,CAAC;AAG5E,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,SAAK,GAAG,MAAM,CA0BvE;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAKzE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIpE;AAED,+FAA+F;AAC/F,wBAAgB,sBAAsB,CACpC,MAAM,EA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aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,GAC9D,MAAM,CAyCR;AAED,wEAAwE;AACxE,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,OAAO,GACb,uBAAuB,CAQzB;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,oBAAoB,EAC5B,kBAAkB,UAAQ;;;;;;;EA+C3B;AAED,oFAAoF;AACpF,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,uBAAuB,EACjC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CASpB;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAgB1E"}
1
+ {"version":3,"file":"external-import-contract.d.ts","sourceRoot":"","sources":["../src/external-import-contract.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACb,MAAM,6BAA6B,CAAC;AAQrC,qFAAqF;AACrF,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,OAAO,CAAC;AAOrD,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAe9C;;kFAEkF;AAClF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAatD;AAID,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3D;AA2JD,eAAO,MAAM,qBAAqB,UA/BjB,OAAO,yBAiCvB,CAAC;AACF,eAAO,MAAM,oBAAoB,UAlChB,OAAO,yBAoCvB,CAAC;AACF,eAAO,MAAM,qBAAqB,UArCjB,OAAO,qBAsCyB,CAAC;AAClD,eAAO,MAAM,oBAAoB,UAvChB,OAAO,iBAuCmD,CAAC;AAG5E,wBAAgB,eAAe,CAAC,KAAK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