@openai/codex-security 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/README.md +45 -57
  2. package/_bundled_plugin/.app.json +4 -0
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
  7. package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
  8. package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
  9. package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
  10. package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
  11. package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
  12. package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
  13. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  14. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  15. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +46 -12
  16. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  17. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  18. package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
  19. package/_bundled_plugin/references/artifact-storage.md +1 -1
  20. package/_bundled_plugin/references/core-scan.md +14 -5
  21. package/_bundled_plugin/references/default-severity-rubric.md +28 -0
  22. package/_bundled_plugin/references/finding-detail-fields.md +1 -0
  23. package/_bundled_plugin/references/threat-model.md +1 -0
  24. package/_bundled_plugin/scripts/deep_scan_workbench.py +23 -112
  25. package/_bundled_plugin/scripts/finalize_scan_contract.py +167 -153
  26. package/_bundled_plugin/scripts/finding_preview.py +5 -29
  27. package/_bundled_plugin/scripts/posix_scan_local_files.py +187 -0
  28. package/_bundled_plugin/scripts/report_projection.py +87 -136
  29. package/_bundled_plugin/scripts/validate_scan_contract.py +2 -6
  30. package/_bundled_plugin/scripts/windows_scan_local_files.py +212 -55
  31. package/_bundled_plugin/scripts/workbench/retained_coverage.py +8 -24
  32. package/_bundled_plugin/scripts/workbench/saved_coverage.py +143 -231
  33. package/_bundled_plugin/scripts/workbench_cli.py +102 -13
  34. package/_bundled_plugin/scripts/workbench_constants.py +9 -0
  35. package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
  36. package/_bundled_plugin/scripts/workbench_db.py +187 -363
  37. package/_bundled_plugin/scripts/workbench_finding_workflows.py +86 -4
  38. package/_bundled_plugin/scripts/workbench_native_indexes.py +17 -21
  39. package/_bundled_plugin/scripts/workbench_remediation.py +495 -11
  40. package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
  41. package/_bundled_plugin/scripts/workbench_scan_history.py +22 -25
  42. package/_bundled_plugin/scripts/workbench_scan_start.py +1 -1
  43. package/_bundled_plugin/scripts/workbench_scan_usage.py +25 -52
  44. package/_bundled_plugin/scripts/workbench_schema.py +1 -1
  45. package/_bundled_plugin/scripts/workbench_setup.py +239 -0
  46. package/_bundled_plugin/scripts/workbench_source_scopes.py +15 -23
  47. package/_bundled_plugin/scripts/workbench_target.py +120 -35
  48. package/_bundled_plugin/scripts/workbench_validation.py +1 -9
  49. package/_bundled_plugin/shared/workbench-history-repairs.json +7 -0
  50. package/_bundled_plugin/shared/workbench-migrations.json +19 -0
  51. package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +1 -1
  52. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +4 -68
  53. package/_bundled_plugin/skills/check-skills/SKILL.md +43 -0
  54. package/_bundled_plugin/skills/check-skills/agents/openai.yaml +4 -0
  55. package/_bundled_plugin/skills/cloud-findings/SKILL.md +2 -0
  56. package/_bundled_plugin/skills/fix-finding/SKILL.md +18 -1
  57. package/_bundled_plugin/skills/publish-findings/SKILL.md +68 -35
  58. package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +2 -21
  59. package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
  60. package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
  61. package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
  62. package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
  63. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
  64. package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
  65. package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
  66. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
  67. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
  68. package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
  69. package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
  70. package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
  71. package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
  72. package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
  73. package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
  74. package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +569 -0
  75. package/_bundled_plugin/skills/track-findings/SKILL.md +5 -3
  76. package/_bundled_plugin/skills/triage-finding/references/github-rest-intake.md +22 -68
  77. package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -4
  78. package/dist/api.d.ts +6 -1
  79. package/dist/api.d.ts.map +1 -1
  80. package/dist/api.js +414 -163
  81. package/dist/api.js.map +1 -1
  82. package/dist/auth.js +7 -2
  83. package/dist/auth.js.map +1 -1
  84. package/dist/blackduck-findings.d.ts +8 -0
  85. package/dist/blackduck-findings.d.ts.map +1 -0
  86. package/dist/blackduck-findings.js +305 -0
  87. package/dist/blackduck-findings.js.map +1 -0
  88. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  89. package/dist/bulk-scan-discovery.js +51 -36
  90. package/dist/bulk-scan-discovery.js.map +1 -1
  91. package/dist/classify-severity-records.d.ts +5 -0
  92. package/dist/classify-severity-records.d.ts.map +1 -1
  93. package/dist/classify-severity-records.js +6 -8
  94. package/dist/classify-severity-records.js.map +1 -1
  95. package/dist/classify-severity.d.ts +4 -1
  96. package/dist/classify-severity.d.ts.map +1 -1
  97. package/dist/classify-severity.js +28 -9
  98. package/dist/classify-severity.js.map +1 -1
  99. package/dist/cli.d.ts +3 -0
  100. package/dist/cli.d.ts.map +1 -1
  101. package/dist/cli.js +635 -266
  102. package/dist/cli.js.map +1 -1
  103. package/dist/codex-prompt.d.ts +2 -0
  104. package/dist/codex-prompt.d.ts.map +1 -1
  105. package/dist/codex-prompt.js +6 -0
  106. package/dist/codex-prompt.js.map +1 -1
  107. package/dist/component-scan.d.ts.map +1 -1
  108. package/dist/component-scan.js +6 -5
  109. package/dist/component-scan.js.map +1 -1
  110. package/dist/config.d.ts +2 -1
  111. package/dist/config.d.ts.map +1 -1
  112. package/dist/config.js +162 -40
  113. package/dist/config.js.map +1 -1
  114. package/dist/continuum-findings.d.ts +7 -0
  115. package/dist/continuum-findings.d.ts.map +1 -0
  116. package/dist/continuum-findings.js +157 -0
  117. package/dist/continuum-findings.js.map +1 -0
  118. package/dist/contract-values.d.ts +28 -0
  119. package/dist/contract-values.d.ts.map +1 -0
  120. package/dist/contract-values.js +75 -0
  121. package/dist/contract-values.js.map +1 -0
  122. package/dist/contract.d.ts +2 -20
  123. package/dist/contract.d.ts.map +1 -1
  124. package/dist/contract.js +58 -669
  125. package/dist/contract.js.map +1 -1
  126. package/dist/cost-model.d.ts.map +1 -1
  127. package/dist/cost-model.js +1 -4
  128. package/dist/cost-model.js.map +1 -1
  129. package/dist/cost.d.ts +19 -1
  130. package/dist/cost.d.ts.map +1 -1
  131. package/dist/cost.js +2120 -39
  132. package/dist/cost.js.map +1 -1
  133. package/dist/custom-validation-prompt.d.ts +1 -1
  134. package/dist/custom-validation-prompt.d.ts.map +1 -1
  135. package/dist/custom-validation-prompt.js +5 -0
  136. package/dist/custom-validation-prompt.js.map +1 -1
  137. package/dist/custom-validation.d.ts +2 -0
  138. package/dist/custom-validation.d.ts.map +1 -1
  139. package/dist/custom-validation.js +6 -2
  140. package/dist/custom-validation.js.map +1 -1
  141. package/dist/deduplication/deduplication-prompts.d.ts +4 -4
  142. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
  143. package/dist/deduplication/deduplication-prompts.js +2 -2
  144. package/dist/deduplication/deduplication-prompts.js.map +1 -1
  145. package/dist/deduplication/deduplication-reviewer.d.ts +14 -11
  146. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  147. package/dist/deduplication/deduplication-reviewer.js +12 -5
  148. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  149. package/dist/deduplication/deduplication.js.map +1 -1
  150. package/dist/deduplication/finding-schema.d.ts +19 -1
  151. package/dist/deduplication/finding-schema.d.ts.map +1 -1
  152. package/dist/deduplication/finding-schema.js +25 -0
  153. package/dist/deduplication/finding-schema.js.map +1 -1
  154. package/dist/deduplication/local.d.ts.map +1 -1
  155. package/dist/deduplication/local.js +3 -8
  156. package/dist/deduplication/local.js.map +1 -1
  157. package/dist/deduplication/records.d.ts +11 -3
  158. package/dist/deduplication/records.d.ts.map +1 -1
  159. package/dist/deduplication/records.js +48 -16
  160. package/dist/deduplication/records.js.map +1 -1
  161. package/dist/deep-scan.d.ts +11 -0
  162. package/dist/deep-scan.d.ts.map +1 -1
  163. package/dist/deep-scan.js +235 -4
  164. package/dist/deep-scan.js.map +1 -1
  165. package/dist/default-severity-rubric.d.ts +1 -2
  166. package/dist/default-severity-rubric.d.ts.map +1 -1
  167. package/dist/default-severity-rubric.js +2 -66
  168. package/dist/default-severity-rubric.js.map +1 -1
  169. package/dist/endor-findings.d.ts.map +1 -1
  170. package/dist/endor-findings.js +44 -89
  171. package/dist/endor-findings.js.map +1 -1
  172. package/dist/errors.js +1 -1
  173. package/dist/errors.js.map +1 -1
  174. package/dist/external-findings-import.d.ts.map +1 -1
  175. package/dist/external-findings-import.js +11 -15
  176. package/dist/external-findings-import.js.map +1 -1
  177. package/dist/external-findings-local.d.ts +12 -1
  178. package/dist/external-findings-local.d.ts.map +1 -1
  179. package/dist/external-findings-local.js +411 -184
  180. package/dist/external-findings-local.js.map +1 -1
  181. package/dist/external-findings-publish.d.ts +15 -1
  182. package/dist/external-findings-publish.d.ts.map +1 -1
  183. package/dist/external-findings-publish.js +1238 -226
  184. package/dist/external-findings-publish.js.map +1 -1
  185. package/dist/external-findings-read.d.ts +10 -0
  186. package/dist/external-findings-read.d.ts.map +1 -1
  187. package/dist/external-findings-read.js +71 -51
  188. package/dist/external-findings-read.js.map +1 -1
  189. package/dist/external-findings.d.ts +13 -0
  190. package/dist/external-findings.d.ts.map +1 -1
  191. package/dist/external-findings.js +124 -1
  192. package/dist/external-findings.js.map +1 -1
  193. package/dist/external-import-contract.d.ts +29 -1
  194. package/dist/external-import-contract.d.ts.map +1 -1
  195. package/dist/external-import-contract.js +314 -44
  196. package/dist/external-import-contract.js.map +1 -1
  197. package/dist/external-import-models.d.ts +1 -1
  198. package/dist/external-import-models.d.ts.map +1 -1
  199. package/dist/external-import-models.js.map +1 -1
  200. package/dist/finding-normalization.d.ts +1 -1
  201. package/dist/finding-normalization.d.ts.map +1 -1
  202. package/dist/finding-normalization.js +46 -11
  203. package/dist/finding-normalization.js.map +1 -1
  204. package/dist/finding-retrieval.d.ts +3 -3
  205. package/dist/finding-retrieval.d.ts.map +1 -1
  206. package/dist/finding-retrieval.js.map +1 -1
  207. package/dist/finding-workflow.d.ts +6 -1
  208. package/dist/finding-workflow.d.ts.map +1 -1
  209. package/dist/finding-workflow.js +2 -2
  210. package/dist/finding-workflow.js.map +1 -1
  211. package/dist/git-remote.d.ts +4 -0
  212. package/dist/git-remote.d.ts.map +1 -1
  213. package/dist/git-remote.js +20 -0
  214. package/dist/git-remote.js.map +1 -1
  215. package/dist/github-advisories.d.ts +3 -12
  216. package/dist/github-advisories.d.ts.map +1 -1
  217. package/dist/github-advisories.js +9 -29
  218. package/dist/github-advisories.js.map +1 -1
  219. package/dist/github-dependabot-findings.d.ts.map +1 -1
  220. package/dist/github-dependabot-findings.js +7 -16
  221. package/dist/github-dependabot-findings.js.map +1 -1
  222. package/dist/github-findings.d.ts.map +1 -1
  223. package/dist/github-findings.js +344 -56
  224. package/dist/github-findings.js.map +1 -1
  225. package/dist/github.d.ts +17 -7
  226. package/dist/github.d.ts.map +1 -1
  227. package/dist/github.js +43 -30
  228. package/dist/github.js.map +1 -1
  229. package/dist/host-protocol.d.ts +7 -2
  230. package/dist/host-protocol.d.ts.map +1 -1
  231. package/dist/host-protocol.js +27 -3
  232. package/dist/host-protocol.js.map +1 -1
  233. package/dist/host-records-protocol.d.ts +10 -11
  234. package/dist/host-records-protocol.d.ts.map +1 -1
  235. package/dist/host-records-protocol.js +69 -9
  236. package/dist/host-records-protocol.js.map +1 -1
  237. package/dist/hosted-scan.d.ts +15 -0
  238. package/dist/hosted-scan.d.ts.map +1 -1
  239. package/dist/hosted-scan.js +55 -33
  240. package/dist/hosted-scan.js.map +1 -1
  241. package/dist/index.d.ts +8 -0
  242. package/dist/index.d.ts.map +1 -1
  243. package/dist/index.js +7 -0
  244. package/dist/index.js.map +1 -1
  245. package/dist/inspector-findings.d.ts +9 -0
  246. package/dist/inspector-findings.d.ts.map +1 -0
  247. package/dist/inspector-findings.js +512 -0
  248. package/dist/inspector-findings.js.map +1 -0
  249. package/dist/knowledge-base.js +18 -5
  250. package/dist/knowledge-base.js.map +1 -1
  251. package/dist/local-git-metadata.d.ts +5 -0
  252. package/dist/local-git-metadata.d.ts.map +1 -0
  253. package/dist/local-git-metadata.js +131 -0
  254. package/dist/local-git-metadata.js.map +1 -0
  255. package/dist/multiscan.d.ts.map +1 -1
  256. package/dist/multiscan.js +22 -12
  257. package/dist/multiscan.js.map +1 -1
  258. package/dist/opengrep-findings.d.ts.map +1 -1
  259. package/dist/opengrep-findings.js +34 -20
  260. package/dist/opengrep-findings.js.map +1 -1
  261. package/dist/patch-tui.d.ts +1 -1
  262. package/dist/patch-tui.d.ts.map +1 -1
  263. package/dist/patch-tui.js +94 -36
  264. package/dist/patch-tui.js.map +1 -1
  265. package/dist/private-finding-import.d.ts +246 -0
  266. package/dist/private-finding-import.d.ts.map +1 -0
  267. package/dist/private-finding-import.js +387 -0
  268. package/dist/private-finding-import.js.map +1 -0
  269. package/dist/project-config.d.ts.map +1 -1
  270. package/dist/project-config.js +2 -2
  271. package/dist/project-config.js.map +1 -1
  272. package/dist/provider-profile.d.ts +10 -2
  273. package/dist/provider-profile.d.ts.map +1 -1
  274. package/dist/provider-profile.js +72 -10
  275. package/dist/provider-profile.js.map +1 -1
  276. package/dist/publication.js +7 -1
  277. package/dist/publication.js.map +1 -1
  278. package/dist/reader-selection.d.ts +13 -0
  279. package/dist/reader-selection.d.ts.map +1 -0
  280. package/dist/reader-selection.js +81 -0
  281. package/dist/reader-selection.js.map +1 -0
  282. package/dist/record.d.ts +6 -1
  283. package/dist/record.d.ts.map +1 -1
  284. package/dist/record.js +53 -2
  285. package/dist/record.js.map +1 -1
  286. package/dist/remediation.d.ts +5 -0
  287. package/dist/remediation.d.ts.map +1 -1
  288. package/dist/remediation.js +30 -0
  289. package/dist/remediation.js.map +1 -1
  290. package/dist/result.d.ts +2 -0
  291. package/dist/result.d.ts.map +1 -1
  292. package/dist/result.js +3 -1
  293. package/dist/result.js.map +1 -1
  294. package/dist/runtime.d.ts +5 -3
  295. package/dist/runtime.d.ts.map +1 -1
  296. package/dist/runtime.js +110 -57
  297. package/dist/runtime.js.map +1 -1
  298. package/dist/scan-activity.js +40 -17
  299. package/dist/scan-activity.js.map +1 -1
  300. package/dist/scan-comparison.d.ts +1 -1
  301. package/dist/scan-comparison.d.ts.map +1 -1
  302. package/dist/scan-comparison.js +11 -13
  303. package/dist/scan-comparison.js.map +1 -1
  304. package/dist/scan-dashboard.d.ts +1 -0
  305. package/dist/scan-dashboard.d.ts.map +1 -1
  306. package/dist/scan-dashboard.js +37 -48
  307. package/dist/scan-dashboard.js.map +1 -1
  308. package/dist/scan-executor.d.ts +2 -0
  309. package/dist/scan-executor.d.ts.map +1 -1
  310. package/dist/scan-executor.js.map +1 -1
  311. package/dist/scan-history-renderer.d.ts.map +1 -1
  312. package/dist/scan-history-renderer.js +22 -9
  313. package/dist/scan-history-renderer.js.map +1 -1
  314. package/dist/scan-logs.d.ts.map +1 -1
  315. package/dist/scan-logs.js +5 -5
  316. package/dist/scan-logs.js.map +1 -1
  317. package/dist/scanner-import.d.ts +48 -3
  318. package/dist/scanner-import.d.ts.map +1 -1
  319. package/dist/scanner-import.js +214 -39
  320. package/dist/scanner-import.js.map +1 -1
  321. package/dist/scanner-repository-url.d.ts +14 -0
  322. package/dist/scanner-repository-url.d.ts.map +1 -0
  323. package/dist/scanner-repository-url.js +67 -0
  324. package/dist/scanner-repository-url.js.map +1 -0
  325. package/dist/semgrep-findings.d.ts.map +1 -1
  326. package/dist/semgrep-findings.js +50 -88
  327. package/dist/semgrep-findings.js.map +1 -1
  328. package/dist/semgrep-platform-findings.d.ts +12 -0
  329. package/dist/semgrep-platform-findings.d.ts.map +1 -0
  330. package/dist/semgrep-platform-findings.js +198 -0
  331. package/dist/semgrep-platform-findings.js.map +1 -0
  332. package/dist/severity-rubric.d.ts +20 -0
  333. package/dist/severity-rubric.d.ts.map +1 -0
  334. package/dist/severity-rubric.js +73 -0
  335. package/dist/severity-rubric.js.map +1 -0
  336. package/dist/severity-store.js +15 -5
  337. package/dist/severity-store.js.map +1 -1
  338. package/dist/snyk-findings.d.ts.map +1 -1
  339. package/dist/snyk-findings.js +97 -106
  340. package/dist/snyk-findings.js.map +1 -1
  341. package/dist/sonar-collector.d.ts +16 -0
  342. package/dist/sonar-collector.d.ts.map +1 -0
  343. package/dist/sonar-collector.js +383 -0
  344. package/dist/sonar-collector.js.map +1 -0
  345. package/dist/sonar-findings.d.ts +49 -0
  346. package/dist/sonar-findings.d.ts.map +1 -0
  347. package/dist/sonar-findings.js +288 -0
  348. package/dist/sonar-findings.js.map +1 -0
  349. package/dist/sonar-import.d.ts +111 -0
  350. package/dist/sonar-import.d.ts.map +1 -0
  351. package/dist/sonar-import.js +279 -0
  352. package/dist/sonar-import.js.map +1 -0
  353. package/dist/suggest-owners.d.ts.map +1 -1
  354. package/dist/suggest-owners.js +2 -1
  355. package/dist/suggest-owners.js.map +1 -1
  356. package/dist/targets.d.ts +3 -0
  357. package/dist/targets.d.ts.map +1 -1
  358. package/dist/targets.js +18 -12
  359. package/dist/targets.js.map +1 -1
  360. package/dist/terminal-columns.d.ts +4 -0
  361. package/dist/terminal-columns.d.ts.map +1 -0
  362. package/dist/terminal-columns.js +19 -0
  363. package/dist/terminal-columns.js.map +1 -0
  364. package/dist/validation-records.d.ts +0 -3
  365. package/dist/validation-records.d.ts.map +1 -1
  366. package/dist/validation-records.js +0 -16
  367. package/dist/validation-records.js.map +1 -1
  368. package/dist/veracode-findings.d.ts +7 -0
  369. package/dist/veracode-findings.d.ts.map +1 -0
  370. package/dist/veracode-findings.js +371 -0
  371. package/dist/veracode-findings.js.map +1 -0
  372. package/dist/windows-path.d.ts.map +1 -1
  373. package/dist/windows-path.js +1 -0
  374. package/dist/windows-path.js.map +1 -1
  375. package/dist/wiz-csv.d.ts +2 -2
  376. package/dist/wiz-csv.d.ts.map +1 -1
  377. package/dist/wiz-csv.js +1 -3
  378. package/dist/wiz-csv.js.map +1 -1
  379. package/dist/wiz-findings.d.ts +10 -2
  380. package/dist/wiz-findings.d.ts.map +1 -1
  381. package/dist/wiz-findings.js +88 -49
  382. package/dist/wiz-findings.js.map +1 -1
  383. package/docs/classify-severity-records.md +1 -1
  384. package/docs/cli.md +320 -481
  385. package/docs/dedupe-records.md +27 -4
  386. package/docs/findings-service.md +21 -8
  387. package/docs/hosted-scans.md +16 -1
  388. package/package.json +9 -10
  389. package/schemas/external-findings.schema.json +12 -1
  390. package/schemas/hosted-scan-v2.fixture.json +16 -1
  391. package/_bundled_plugin/scripts/validate_tracking_source.py +0 -82
  392. package/_bundled_plugin/scripts/workbench_local_dedupe.py +0 -136
  393. package/dist/deduplication/records-protocol.d.ts +0 -4
  394. package/dist/deduplication/records-protocol.d.ts.map +0 -1
  395. package/dist/deduplication/records-protocol.js +0 -35
  396. package/dist/deduplication/records-protocol.js.map +0 -1
@@ -1,186 +1,263 @@
1
- import { lstat, readFile, realpath, stat } from "node:fs/promises";
2
- import { dirname, isAbsolute, join, resolve, sep } from "node:path";
3
- import { isNumberObject } from "node:util/types";
4
- import { environmentEntry } from "./auth.js";
5
1
  import { CodexSecurityError } from "./errors.js";
6
2
  import { forwardExternalImportSetting, requireExternalImports, } from "./external-imports-feature.js";
7
- import { cloudRepositoryUrlKey, repositoryUrlKey, validateExternalReport, } from "./external-import-contract.js";
8
- import { parseGitRemote } from "./git-remote.js";
3
+ import { cloneImportPreview, snapshotImportOptions, snapshotNormalizedFindings, snapshotSourceRepositories, } from "./external-findings.js";
4
+ import { cloudRepositoryUrlKey, requireSafeJsonInteger, repositoryUrlKey, } from "./external-import-contract.js";
5
+ import { localFindingRepositories } from "./external-findings-read.js";
6
+ import { hasGitMetadata, localGitProtectionRoots, importGitProtectionRoots, } from "./local-git-metadata.js";
7
+ import { blackDuckReportRepositories, projectedBlackDuckRepositoryUrl, } from "./blackduck-findings.js";
8
+ import { azureReposHttpsUrl, isGitHubCloudHost, isGitHubSshOverHttps, isGitSsh, parseGitRemote, } from "./git-remote.js";
9
+ import { continuumReportRepositories } from "./continuum-findings.js";
10
+ import { veracodeReportRepositories } from "./veracode-findings.js";
11
+ import { inspectorReportRepository } from "./inspector-findings.js";
12
+ import { declaredScannerRepositoryUrl } from "./scanner-repository-url.js";
13
+ import { sonarRepositoryUrls } from "./sonar-findings.js";
9
14
  import { isRecord } from "./record.js";
10
15
  import { dependabotRepository } from "./github-dependabot-findings.js";
11
16
  import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, expandHome, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
12
- import { abortable, gitMarkerRoot, gitOutput, gitProtectionRoots, normalizeRepository, nullIfMissingPath, } from "./targets.js";
17
+ import { abortable, enclosingGitWorktreeRoot, gitOutput, normalizeRepository, } from "./targets.js";
13
18
  function requireIdentity(value, field) {
14
19
  if (typeof value !== "string" || !value.trim() || value.includes("\0"))
15
20
  throw new CodexSecurityError(`${field} must be nonempty and contain no NUL characters.`);
16
21
  }
17
- /** Compare transport forms without changing retained scanner evidence. */
18
- function remoteRepositoryKey(value, provider) {
22
+ function checkStoredNumber(value) {
23
+ if (!Number.isFinite(value))
24
+ throw new TypeError("Stored finding JSON cannot contain non-finite numbers.");
25
+ requireSafeJsonInteger(value, "Stored finding JSON");
26
+ }
27
+ const gitTransportPorts = {
28
+ "http:": "80",
29
+ "https:": "443",
30
+ "ssh:": "22",
31
+ "git+ssh:": "22",
32
+ "ssh+git:": "22",
33
+ "git:": "9418",
34
+ "ftp:": "21",
35
+ "ftps:": "990",
36
+ };
37
+ function sonarHostedGit(hostname) {
38
+ return (isGitHubCloudHost(hostname) ||
39
+ hostname === "gitlab.com" ||
40
+ hostname === "bitbucket.org");
41
+ }
42
+ function sonarHostedHostname(hostname) {
43
+ const name = hostname.toLowerCase().replace(/\.$/u, "");
44
+ return sonarHostedGit(name) ||
45
+ ["ssh.github.com", "ssh.dev.azure.com", "dev.azure.com"].includes(name)
46
+ ? name
47
+ : undefined;
48
+ }
49
+ function remoteRepository(value, provider, bound, platform = provider, possibleSshHost) {
19
50
  if (/^[A-Za-z]:[\\/]/u.test(value))
20
51
  return undefined;
52
+ const transport = bound
53
+ ? /^(?:ssh|git\+ssh|ssh\+git|git):\/\/([^/]*)(.*)$/isu.exec(value)
54
+ : null;
55
+ const authority = transport?.[1];
56
+ const http = bound && /^https?:\/\//iu.test(value.trimStart());
57
+ // Git decodes the authority before locating its path. An encoded delimiter
58
+ // cannot prove a match to another spelling through WHATWG URL's hostname.
59
+ if (authority &&
60
+ (/%2f|[?#]/iu.test(authority) ||
61
+ authority.slice(authority.lastIndexOf("@") + 1).includes("%")))
62
+ return { key: value };
21
63
  let remote;
22
64
  try {
23
65
  remote = parseGitRemote(value);
24
66
  }
25
67
  catch {
26
- return undefined;
68
+ return transport || http ? { key: "\0" + value } : undefined;
27
69
  }
28
- if (!remote ||
29
- ![
30
- "http:",
31
- "https:",
32
- "ssh:",
33
- "git:",
34
- "ftp:",
35
- "ftps:",
36
- "git+ssh:",
37
- "ssh+git:",
38
- ].includes(remote.url.protocol))
70
+ if (!remote || !Object.hasOwn(gitTransportPorts, remote.url.protocol))
39
71
  return undefined;
40
- const url = remote.url;
41
- const ssh = ["ssh:", "git+ssh:", "ssh+git:"].includes(url.protocol);
72
+ const { url, path, scpStyle } = remote;
73
+ const ssh = isGitSsh(url.protocol);
42
74
  const protocol = url.protocol === "http:" ? "http:" : "https:";
43
- const githubSshOverHttps = ssh &&
44
- url.hostname.toLowerCase() === "ssh.github.com" &&
45
- url.port === "443";
46
- const hostname = githubSshOverHttps ? "github.com" : url.hostname;
47
- const port = githubSshOverHttps ||
48
- (ssh && url.port === "22") ||
49
- (url.protocol === "git:" && url.port === "9418") ||
50
- (url.protocol === "ftp:" && url.port === "21") ||
51
- (url.protocol === "ftps:" && url.port === "990")
75
+ const hosted = sonarHostedHostname(url.hostname);
76
+ if (provider === "sonar" && hosted)
77
+ url.hostname = hosted;
78
+ const githubSshOverHttps = isGitHubSshOverHttps(url);
79
+ let hostname = githubSshOverHttps ? "github.com" : url.hostname;
80
+ // An unresolved SSH name can be a local Host alias. Only substitute the
81
+ // supplied hostname when checking the path of an unverified manual mapping.
82
+ if (possibleSshHost && ssh && (!hosted || hosted === "dev.azure.com"))
83
+ hostname = sonarHostedHostname(possibleSshHost) ?? possibleSshHost;
84
+ const port = githubSshOverHttps || url.port === gitTransportPorts[url.protocol]
52
85
  ? ""
53
86
  : url.port;
54
87
  // A GitHub source identifies a case-insensitive repository on custom Enterprise
55
88
  // hosts too; other providers can refer to VCS hosts with case-sensitive paths.
56
- const key = provider === "github" ? cloudRepositoryUrlKey : repositoryUrlKey;
57
- return key(`${protocol}//${hostname}${port ? `:${port}` : ""}/${remote.path}`);
58
- }
59
- async function bareMetadataRoots(repository, signal) {
60
- const roots = [];
61
- let directory = repository;
62
- for (;;) {
63
- signal?.throwIfAborted();
64
- const present = async (name) => (await abortable(() => lstat(join(directory, name)).catch(nullIfMissingPath), signal)) !== null;
65
- // Git also discovers bare repositories and linked metadata without .git.
66
- const head = await abortable(() => lstat(join(directory, "HEAD")).catch(nullIfMissingPath), signal);
67
- if ((head?.isFile() || head?.isSymbolicLink()) &&
68
- ((await present("commondir")) ||
69
- ((await present("objects")) && (await present("refs")))))
70
- roots.push(directory);
71
- const parent = dirname(directory);
72
- if (parent === directory)
73
- return roots;
74
- directory = parent;
75
- }
76
- }
77
- async function metadataPointer(path, prefix, context, signal) {
78
- const metadata = await abortable(() => stat(path).catch(nullIfMissingPath), signal);
79
- if (!metadata?.isFile())
80
- return undefined;
81
- const text = await abortable(() => readFile(path, "utf8"), signal);
82
- if (!text.startsWith(prefix) || (prefix === "" && text.length === 0))
83
- return undefined;
84
- const payload = text.slice(prefix.length).replace(/[\r\n]+$/u, "");
85
- if (prefix !== "" && payload.length === 0)
86
- return undefined;
87
- // Git checks emptiness before consuming the path as a NUL-terminated string.
88
- const value = payload.split("\0", 1)[0];
89
- // Preserve filesystem traversal through links before '..'.
90
- let target = isAbsolute(value) ? value : `${dirname(path)}${sep}${value}`;
91
- if (process.platform === "win32") {
92
- const drive = /^[A-Za-z]:(?![\\/])/u.exec(value)?.[0].toUpperCase();
93
- if (drive !== undefined) {
94
- const directory = context.directory.slice(0, 2).toUpperCase() === drive
95
- ? context.directory
96
- : environmentEntry(context.environment, `=${drive}`) || `${drive}\\`;
97
- target = resolve(directory, value.slice(2));
89
+ const key = platform === "github" ? cloudRepositoryUrlKey : repositoryUrlKey;
90
+ const origin = `${protocol}//${hostname}${port ? `:${port}` : ""}/`;
91
+ if (!bound)
92
+ return { key: key(origin + path) };
93
+ if (!ssh && url.protocol !== "git:") {
94
+ if (url.protocol === "http:" || url.protocol === "https:") {
95
+ // libcurl and WHATWG differ on backslashes and encoded dot segments.
96
+ const raw = /^https?:\/\/[^/\\?#\s]+(\/[^\\?#]*)?(?:[?#].*)?$/iu.exec(value);
97
+ if (!raw || /\/(?:%2e|\.%2e|%2e\.|%2e%2e)(?:\/|$)/iu.test(raw[1] ?? ""))
98
+ return { key: "\0" + value };
98
99
  }
99
- else if (isAbsolute(value))
100
- target = resolve(context.directory, value);
100
+ const suffix = /[?#].*$/su.exec(value)?.[0] ?? "";
101
+ // HTTP sends the query and omits fragment text from repository requests.
102
+ if (suffix && !["http:", "https:"].includes(url.protocol))
103
+ return { key: key(origin + path) + "\0" };
104
+ return {
105
+ key: key(origin + path) + suffix.replace(/#.*$/su, "#").replace(/\/$/u, ""),
106
+ };
101
107
  }
102
- return ((await abortable(() => realpath(target).catch(nullIfMissingPath), signal)) ?? undefined);
103
- }
104
- async function associatedMetadataRoots(directory, context, signal, configurationDirectory) {
105
- const head = await abortable(() => lstat(join(directory, "HEAD")).catch(nullIfMissingPath), signal);
106
- if (!head || (!head.isFile() && !head.isSymbolicLink()))
107
- return [];
108
- const commonMarker = join(directory, "commondir");
109
- const hasCommon = await abortable(() => lstat(commonMarker).catch(nullIfMissingPath), signal);
110
- const common = hasCommon
111
- ? await metadataPointer(commonMarker, "", context, signal)
108
+ // Git passes the original path (including dot segments, '?' and '#') to upload-pack.
109
+ const literal = (raw) => {
110
+ const bytes = Buffer.from(raw).toString("latin1");
111
+ return scpStyle
112
+ ? bytes
113
+ : bytes.replace(/%(?!00)([\da-f]{2})/giu, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
114
+ };
115
+ if (!scpStyle && !transport)
116
+ return { key: value };
117
+ const gitPath = literal(transport?.[2] ?? path);
118
+ const login = scpStyle
119
+ ? /^([^@/:\s?#]+)@/u.exec(value)?.[1]
120
+ : /^(.*)@/u.exec(authority ?? "")?.[1];
121
+ const homeRelative = /^\/?~(?:\/|$)/u.test(gitPath) || (scpStyle && !/^[~/]/u.test(gitPath));
122
+ const suffix = /[?#].*$/su.exec(gitPath);
123
+ // Express upload-pack bytes as a URL path for comparison with the HTTP source.
124
+ const name = gitPath
125
+ .slice(0, suffix?.index)
126
+ .replace(/^\//u, "")
127
+ .replace(/[%\x00-\x20\x7f-\xff]/gu, (byte) => "%" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
128
+ // Azure's generated SCP clone URL spells spaces as %20, even though Git sends SCP paths literally.
129
+ const azure = provider === "sonar" && !(scpStyle && path.startsWith("/"))
130
+ ? azureReposHttpsUrl(url, scpStyle ? name.replace(/%2520/gu, "%20") : name)
112
131
  : undefined;
113
- if (hasCommon && common === undefined)
114
- return [];
115
- const storage = common ?? directory;
116
- for (const name of ["objects", "refs"]) {
117
- const metadata = await abortable(() => stat(join(storage, name)).catch(nullIfMissingPath), signal);
118
- if (!metadata?.isDirectory())
119
- return [];
120
- }
121
- const roots = common === undefined ? [directory] : [directory, common];
122
- if (process.platform === "win32" &&
123
- configurationDirectory !== undefined &&
124
- configurationDirectory !== context.directory) {
125
- // Git rereads commondir after changing to the discovered repository root.
126
- roots.push(...(await associatedMetadataRoots(directory, {
127
- ...context,
128
- directory: await abortable(() => canonicalConfigPath(configurationDirectory), signal),
129
- }, signal)));
130
- }
131
- return roots;
132
- }
133
- async function localGitProtectionRoots(repository, environment, signal) {
134
- const roots = new Set(await abortable(() => gitProtectionRoots(repository, signal), signal));
135
- const context = {
136
- directory: await abortable(() => canonicalConfigPath(repository), signal),
137
- environment,
132
+ const repository = suffix
133
+ ? key(origin + name + "?") +
134
+ "\0" +
135
+ suffix[0].replace(/\/$/u, "").replace(/\.git$/u, "")
136
+ : key(azure ?? origin + name);
137
+ return {
138
+ key: repository,
139
+ account: ssh && login ? literal(login) : undefined,
140
+ // GitHub serves the same repository path through its SCP and SSH URLs.
141
+ homeRelative: ssh && platform !== "github" && !isGitHubCloudHost(hostname.toLowerCase())
142
+ ? homeRelative
143
+ : undefined,
138
144
  };
139
- const paths = new Set([resolve(repository), context.directory]);
140
- for (const path of paths) {
141
- for (const root of await bareMetadataRoots(path, signal)) {
142
- roots.add(root);
143
- for (const associated of await associatedMetadataRoots(root, context, signal, root))
144
- roots.add(associated);
145
+ }
146
+ function matchingRemote(left, right) {
147
+ return (left.key === right.key &&
148
+ (left.homeRelative === undefined ||
149
+ right.homeRelative === undefined ||
150
+ left.homeRelative === right.homeRelative) &&
151
+ ((left.homeRelative === false && right.homeRelative === false) ||
152
+ left.account === undefined ||
153
+ right.account === undefined ||
154
+ left.account === right.account));
155
+ }
156
+ /** A credential-free Sonar repository binding from a supported Git fetch transport. */
157
+ export function sonarRepositoryForRemote(origin) {
158
+ try {
159
+ if (/[\s\\\p{Cc}?#]/u.test(origin))
160
+ return;
161
+ const remote = parseGitRemote(origin);
162
+ if (!remote)
163
+ return;
164
+ const { url } = remote;
165
+ // Git dispatches remote helpers by the literal scheme, while URL lowercases it.
166
+ if (!remote.scpStyle && !origin.startsWith(url.protocol + "//"))
167
+ return;
168
+ // Git passes literal SSH paths to upload-pack. URL.pathname collapses dot segments.
169
+ const path = remote.scpStyle
170
+ ? remote.path
171
+ : /^[^:/]+:\/\/[^/]+\/(.+)$/u.exec(origin)?.[1];
172
+ if (!path)
173
+ return;
174
+ const hostname = url.hostname.toLowerCase();
175
+ let candidate;
176
+ if (url.protocol === "http:" || url.protocol === "https:") {
177
+ candidate = `${url.origin}/${path}`;
145
178
  }
146
- let directory = path;
147
- for (;;) {
148
- signal?.throwIfAborted();
149
- const marker = join(directory, ".git");
150
- const metadata = await abortable(() => stat(marker).catch(nullIfMissingPath), signal);
151
- if (metadata !== null) {
152
- roots.add(directory);
153
- const gitDirectory = metadata.isDirectory()
154
- ? await abortable(() => realpath(marker), signal)
155
- : await metadataPointer(marker, "gitdir: ", context, signal);
156
- if (gitDirectory !== undefined)
157
- for (const associated of await associatedMetadataRoots(gitDirectory, context, signal, directory))
158
- roots.add(associated);
159
- }
160
- const parent = dirname(directory);
161
- if (parent === directory)
162
- break;
163
- directory = parent;
179
+ else if (url.username === "git" && isGitHubSshOverHttps(url)) {
180
+ candidate = `https://github.com/${path}`;
181
+ }
182
+ else if (isGitSsh(url.protocol) &&
183
+ url.username === "git" &&
184
+ (!url.port || url.port === "22") &&
185
+ sonarHostedGit(hostname)) {
186
+ candidate = `https://${hostname}/${path}`;
164
187
  }
188
+ else {
189
+ candidate = azureReposHttpsUrl(url, path);
190
+ }
191
+ if (!candidate)
192
+ return;
193
+ const source = declaredScannerRepositoryUrl(candidate.replace(/\.git$/iu, ""), "Sonar", "local");
194
+ const candidateRemote = remoteRepository(origin, "sonar", true);
195
+ const target = remoteRepository(source, "sonar", true);
196
+ if (isGitSsh(url.protocol) && candidateRemote?.account !== "git")
197
+ return;
198
+ return candidateRemote && target && matchingRemote(candidateRemote, target)
199
+ ? source
200
+ : undefined;
201
+ }
202
+ catch {
203
+ return undefined;
165
204
  }
166
- for (const root of [...roots])
167
- roots.add(await abortable(() => canonicalConfigPath(root), signal));
168
- return [...roots];
169
205
  }
170
- async function hasGitMetadata(repository, signal) {
171
- return ((await abortable(() => gitMarkerRoot(repository, signal, "nearest"), signal)) !== null || (await bareMetadataRoots(repository, signal)).length !== 0);
206
+ /** Use the same executable and configuration boundaries for every Git query proving a binding. */
207
+ export function boundSonarWorktree(repository, protectedRoots, environment, signal) {
208
+ return enclosingGitWorktreeRoot(repository, signal, {
209
+ requireIfPresent: true,
210
+ readGit: (directory, args) => gitOutput(directory, args, signal, undefined, undefined, "utf8", protectedRoots, environment),
211
+ });
172
212
  }
173
- async function requireMatchingRepository(repository, provider, sources, protectedRoots, environment, signal) {
174
- if (sources.length === 0)
175
- return;
213
+ function localRepositoryPlatform(provider, sources, bound) {
214
+ const githubKey = (url) => remoteRepository(url, provider, bound, "github")?.key;
215
+ const githubRepositories = new Set(sources.flatMap((source) => {
216
+ if (source.platform !== "github")
217
+ return [];
218
+ const key = githubKey(source.url);
219
+ return key === undefined ? [] : [key];
220
+ }));
221
+ return (source) => {
222
+ if (source.platform === "github")
223
+ return "github";
224
+ if (githubRepositories.size === 0)
225
+ return provider;
226
+ const key = githubKey(source.url);
227
+ return key !== undefined && githubRepositories.has(key)
228
+ ? "github"
229
+ : provider;
230
+ };
231
+ }
232
+ function sameScannerRepositories(remotes) {
233
+ let known;
234
+ for (const remote of remotes) {
235
+ if (known && !matchingRemote(known, remote))
236
+ return false;
237
+ // HTTPS does not specify the login or path interpretation carried by SSH.
238
+ known = {
239
+ key: remote.key,
240
+ account: remote.account ?? known?.account,
241
+ homeRelative: remote.homeRelative ?? known?.homeRelative,
242
+ };
243
+ }
244
+ return true;
245
+ }
246
+ /** @internal Effective fetch URLs from the selected, protected checkout. */
247
+ export async function configuredFetchRemotes(repository, provider, protectedRoots, environment, signal) {
176
248
  if (!(await hasGitMetadata(repository, signal)))
177
- return;
249
+ return [];
178
250
  const gitProtectedRoots = [
179
251
  ...(typeof protectedRoots === "string"
180
252
  ? [protectedRoots]
181
253
  : (protectedRoots ?? [])),
182
- await abortable(() => canonicalConfigPath(process.cwd()), signal),
183
254
  ];
255
+ // The Sonar caller includes the discovered Git roots for both checkouts.
256
+ if (provider !== "sonar")
257
+ gitProtectedRoots.push(await abortable(() => canonicalConfigPath(process.cwd()), signal));
258
+ if (provider === "sonar" &&
259
+ !(await boundSonarWorktree(repository, gitProtectedRoots, environment, signal)))
260
+ return [];
184
261
  const readGit = (args) => abortable(() => gitOutput(repository, args, signal, { LC_ALL: "C" }, undefined, "utf8", gitProtectedRoots, environment), signal);
185
262
  let remoteNames;
186
263
  try {
@@ -197,36 +274,71 @@ async function requireMatchingRepository(repository, provider, sources, protecte
197
274
  (error.stderr.trimEnd() ===
198
275
  "fatal: not a git repository (or any of the parent directories): .git" ||
199
276
  /^fatal: not a git repository \(or any parent up to mount point [^\r\n]+\)\r?\nStopping at filesystem boundary \(GIT_DISCOVERY_ACROSS_FILESYSTEM not set\)\.$/u.test(error.stderr.trimEnd())))
200
- return;
277
+ return [];
201
278
  throw error;
202
279
  }
203
280
  const remotes = [];
204
281
  for (const name of remoteNames.split(/\r?\n/u).filter(Boolean)) {
205
- const urls = await readGit(["remote", "get-url", "--all", "--", name]);
206
- remotes.push(...urls.split(/\r?\n/u));
282
+ if (provider === "sonar") {
283
+ // Git fetches from only the first URL, after insteadOf rewrites.
284
+ const url = await readGit(["remote", "get-url", "--", name]);
285
+ if (/[\r\n]/u.test(url))
286
+ throw new CodexSecurityError("A configured Git remote URL contains a line break. Configure each fetch URL as a separate Git value.");
287
+ remotes.push({ name, url });
288
+ }
289
+ else {
290
+ const urls = await readGit(["remote", "get-url", "--all", "--", name]);
291
+ for (const url of urls.split(/\r?\n/u))
292
+ remotes.push({ name, url });
293
+ }
207
294
  }
208
- const githubRepositories = new Set(sources.flatMap((source) => {
209
- if (source.platform !== "github")
210
- return [];
211
- const key = remoteRepositoryKey(source.url, "github");
212
- return key === undefined ? [] : [key];
213
- }));
295
+ return remotes;
296
+ }
297
+ async function requireMatchingRepository(repository, provider, sources, strictSources, strictPlatformFor, protectedRoots, environment, signal, possibleSshHost, fetchRemotes) {
298
+ if (sources.length === 0)
299
+ return false;
300
+ const remotes = fetchRemotes ??
301
+ (await configuredFetchRemotes(repository, provider, protectedRoots, environment, signal));
302
+ const boundProvider = provider === "sonar" ||
303
+ provider === "continuum" ||
304
+ provider === "inspector" ||
305
+ provider === "blackduck" ||
306
+ provider === "veracode";
307
+ const loosePlatformFor = localRepositoryPlatform(provider, sources, false);
308
+ const comparable = [];
309
+ const unverified = [];
310
+ for (const { url: remote } of remotes) {
311
+ const verified = provider === "sonar" ? sonarRepositoryForRemote(remote) : remote;
312
+ if (verified)
313
+ comparable.push(verified);
314
+ else if (!/[\s\\\p{Cc}?#]/u.test(remote))
315
+ unverified.push(remote);
316
+ }
317
+ let allSourcesMatched = true;
214
318
  for (const source of sources) {
215
- const githubKey = remoteRepositoryKey(source.url, "github");
216
- const sourceProvider = source.platform === "github" ||
217
- (githubKey !== undefined && githubRepositories.has(githubKey))
218
- ? "github"
219
- : provider;
220
- const remoteKeys = new Set(remotes.flatMap((remote) => {
221
- const key = remoteRepositoryKey(remote, sourceProvider);
222
- return key === undefined ? [] : [key];
223
- }));
224
- if (remoteKeys.size === 0)
319
+ const bound = boundProvider || strictSources.has(source.url);
320
+ const platform = bound
321
+ ? (strictSources.get(source.url) ?? strictPlatformFor(source))
322
+ : loosePlatformFor(source);
323
+ const identity = (url) => remoteRepository(url, provider, bound, platform);
324
+ const targets = comparable.flatMap((remote) => identity(remote) ?? []);
325
+ const target = identity(source.url);
326
+ if (target && targets.some((remote) => matchingRemote(remote, target)))
327
+ continue;
328
+ allSourcesMatched = false;
329
+ // A custom SSH upstream can agree with a manual mapping even when a
330
+ // recognized HTTPS remote points at a fork. It cannot prove a Cloud binding.
331
+ const configured = unverified.flatMap((remote) => remoteRepository(remote, provider, bound, platform, possibleSshHost) ??
332
+ []);
333
+ if (target && configured.some((remote) => matchingRemote(remote, target)))
225
334
  continue;
226
- const key = remoteRepositoryKey(source.url, sourceProvider);
227
- if (key === undefined || !remoteKeys.has(key))
335
+ if (targets.length || configured.length)
228
336
  throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured remote of ${repository}. Select the matching local repository.`);
229
337
  }
338
+ return allSourcesMatched;
339
+ }
340
+ export function sonarCheckoutMatchesSource(repository, url, protectedRoots, environment, signal) {
341
+ return requireMatchingRepository(repository, "sonar", [{ url }], new Map(), () => "sonar", [...protectedRoots], environment, signal);
230
342
  }
231
343
  async function localContext(selectedRepository, dependencies, mode = "import") {
232
344
  dependencies.signal?.throwIfAborted();
@@ -241,8 +353,7 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
241
353
  const protectedRoot = [
242
354
  ...new Set([
243
355
  repository,
244
- ...(await abortable(() => localGitProtectionRoots(path, environment, dependencies.signal), dependencies.signal)),
245
- ...(await abortable(() => localGitProtectionRoots(process.cwd(), environment, dependencies.signal), dependencies.signal)),
356
+ ...(await abortable(() => importGitProtectionRoots(path, environment, dependencies.signal), dependencies.signal)),
246
357
  ]),
247
358
  ];
248
359
  requireOutputOutsideRepositories(protectedRoot, await abortable(() => canonicalizeModelSafePath(environment.CODEX_SECURITY_STATE_DIR), dependencies.signal), "runtime");
@@ -261,9 +372,12 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
261
372
  export async function prepareNormalizedLocalImport(input, options, dependencies = {}) {
262
373
  dependencies.signal?.throwIfAborted();
263
374
  requireExternalImports(dependencies.environment);
375
+ return prepareLocalImport(input, snapshotImportOptions(options), dependencies);
376
+ }
377
+ /** @internal Prepare evidence using settings captured by either local import entrypoint. */
378
+ export async function prepareLocalImport(input, options, dependencies, readerSources = snapshotSourceRepositories(dependencies.sourceRepositories), parsedSources = [], fetchRemotes) {
264
379
  requireIdentity(options.sourceKey, "Source key");
265
- const current = structuredClone(input);
266
- validateExternalReport(current.report);
380
+ const current = snapshotNormalizedFindings(input, checkStoredNumber);
267
381
  let dependabotSource;
268
382
  const identities = new Set();
269
383
  for (const finding of current.findings) {
@@ -288,25 +402,140 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
288
402
  }
289
403
  const { repository, options: workbenchOptions } = await localContext(options.repository, dependencies);
290
404
  const sources = new Map();
291
- for (const { evidence } of current.findings) {
405
+ const references = [...readerSources, ...parsedSources];
406
+ const inspector = inspectorReportRepository(options.provider, current.findings, "local", options.inspectorProjectMap);
407
+ const projected = options.provider === "blackduck"
408
+ ? []
409
+ : current.findings.filter((finding) => projectedBlackDuckRepositoryUrl(finding, "local"));
410
+ const mixed = projected.length > 0 && readerSources.length > 0;
411
+ const nativeSources = new Map((mixed ? current.findings : projected)
412
+ .filter(({ evidence }) => options.provider !== "endor" ||
413
+ isRecord(evidence.source_data?.["runContext"]))
414
+ .map((finding) => [
415
+ finding,
416
+ localFindingRepositories(options.provider, finding),
417
+ ]));
418
+ const platformFor = localRepositoryPlatform(options.provider, options.inspectorProjectMap
419
+ ? []
420
+ : [
421
+ ...references,
422
+ ...Array.from(nativeSources.values()).flat(),
423
+ ...(inspector ? [inspector] : []),
424
+ ], true);
425
+ const identify = (url) => remoteRepository(url, options.provider, true, platformFor({ url })) ?? {
426
+ key: url,
427
+ };
428
+ // A hint from an independent reader applies across projected rows. A native
429
+ // GitHub asset in one row only identifies the platform of that row's claims.
430
+ const operatorPlatform = localRepositoryPlatform(options.provider, readerSources, true);
431
+ const sameRepositories = (urls) => sameScannerRepositories(Array.from(urls, identify));
432
+ const bound = blackDuckReportRepositories(options.provider, current.findings, "local", sameRepositories);
433
+ for (const repositories of [
434
+ veracodeReportRepositories,
435
+ continuumReportRepositories,
436
+ ]) {
437
+ for (const source of repositories(options.provider, current.findings, "local", sameRepositories).values()) {
438
+ sources.set(source.url, source);
439
+ }
440
+ }
441
+ const strictSources = new Map();
442
+ const known = new Set(parsedSources.map(({ url }) => url));
443
+ for (const finding of current.findings) {
444
+ const { evidence, source_finding_id: id } = finding;
292
445
  const url = evidence.details?.repository?.url;
293
446
  if (url)
294
447
  sources.set(url, { url });
448
+ const retained = bound.get(id);
449
+ const native = nativeSources.get(finding) ?? [];
450
+ if (retained) {
451
+ const claims = [
452
+ retained.url,
453
+ ...(url ? [url] : []),
454
+ ...native.map((ref) => ref.url),
455
+ ];
456
+ const rowPlatform = (claim) => options.provider !== "wiz"
457
+ ? platformFor({ url: claim })
458
+ : native.some((source) => source.platform === "github")
459
+ ? "github"
460
+ : operatorPlatform({ url: claim });
461
+ if (!sameScannerRepositories(claims.map((claim) => remoteRepository(claim, options.provider, true, rowPlatform(claim)) ?? {
462
+ key: claim,
463
+ })))
464
+ throw new CodexSecurityError("The retained scanner repository does not match the original provider finding.");
465
+ for (const source of [retained, ...native])
466
+ sources.set(source.url, source);
467
+ for (const claim of claims) {
468
+ const platform = rowPlatform(claim);
469
+ if (!strictSources.has(claim) || platform !== "github")
470
+ strictSources.set(claim, platform);
471
+ }
472
+ }
473
+ for (const source of native)
474
+ known.add(source.url);
475
+ }
476
+ if (mixed) {
477
+ // A caller reference with no matching row spelling can still be a Git alias.
478
+ const rows = [...sources.keys(), ...known].map(identify);
479
+ const byKey = Map.groupBy(rows, (remote) => remote.key);
480
+ const represented = new Set(rows.map((remote) => JSON.stringify(remote)));
481
+ const aliases = readerSources
482
+ .map(({ url }) => identify(url))
483
+ .filter((remote) => !represented.has(JSON.stringify(remote)));
484
+ for (const [key, group] of Map.groupBy(aliases, (remote) => remote.key)) {
485
+ const candidates = byKey.get(key);
486
+ if (!candidates || !sameScannerRepositories([...candidates, ...group]))
487
+ throw new CodexSecurityError("Reader repository does not match a source in the normalized findings.");
488
+ }
489
+ }
490
+ if (strictSources.size && options.provider !== "blackduck") {
491
+ const keys = new Set(Array.from(strictSources.keys(), (url) => identify(url).key));
492
+ for (const source of references)
493
+ if (!strictSources.has(source.url) && keys.has(identify(source.url).key))
494
+ strictSources.set(source.url, platformFor(source));
295
495
  }
296
- for (const source of dependencies.sourceRepositories ?? []) {
297
- // A reader's explicit platform also applies to the same URL in typed evidence.
496
+ if (inspector) {
497
+ const platform = inspector.platform ?? options.provider;
498
+ const native = remoteRepository(inspector.url, options.provider, true, platform);
499
+ for (const url of sources.keys()) {
500
+ if (!native ||
501
+ remoteRepository(url, options.provider, true, platform)?.key !==
502
+ native.key)
503
+ throw new CodexSecurityError(`Imported repository ${JSON.stringify(url)} does not match the retained Inspector repository ${JSON.stringify(inspector.url)}.`);
504
+ }
505
+ }
506
+ for (const source of [...(inspector ? [inspector] : []), ...references]) {
507
+ // A reader's platform must not loosen an operator-supplied Inspector map.
298
508
  if (sources.get(source.url)?.platform !== "github")
299
- sources.set(source.url, source);
509
+ sources.set(source.url, options.inspectorProjectMap ? { url: source.url } : source);
300
510
  }
511
+ const sonarSources = sonarRepositoryUrls(options.provider, current.findings, current.report, "local");
512
+ const manualSource = options.provider === "sonar" && options.sourceRepositoryUrl
513
+ ? declaredScannerRepositoryUrl(options.sourceRepositoryUrl, "Sonar", "local")
514
+ : undefined;
515
+ if (manualSource)
516
+ sonarSources.add(manualSource);
517
+ for (const url of sonarSources)
518
+ if (!sources.has(url))
519
+ sources.set(url, { url });
520
+ if (sonarSources.size && !sameRepositories(sources.keys()))
521
+ throw new CodexSecurityError(manualSource
522
+ ? "The Sonar evidence does not match the declared source repository."
523
+ : "The retained Sonar repository does not match the other source repository claims.");
524
+ if (options.provider === "blackduck" &&
525
+ current.findings.length &&
526
+ sources.size > 1 &&
527
+ !sameScannerRepositories(Array.from(sources.keys(), identify)))
528
+ throw new CodexSecurityError("Black Duck occurrences must belong to the same project version and source repository.");
301
529
  if (dependabotSource)
302
530
  sources.set(dependabotSource, {
303
531
  url: dependabotSource,
304
532
  platform: "github",
305
533
  });
306
- await requireMatchingRepository(repository, options.provider, [...sources.values()], workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal);
534
+ const selected = manualSource ? new URL(manualSource) : undefined;
535
+ const matchesRepositoryRemote = await requireMatchingRepository(repository, options.provider, [...sources.values()], strictSources, platformFor, workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal, selected?.protocol === "https:" ? selected.hostname : undefined, fetchRemotes);
307
536
  dependencies.signal?.throwIfAborted();
308
537
  const preview = {
309
- ...structuredClone(current),
538
+ ...cloneImportPreview(current),
310
539
  repository,
311
540
  source: { provider: options.provider, source_key: options.sourceKey },
312
541
  };
@@ -314,15 +543,13 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
314
543
  repository,
315
544
  provider: options.provider,
316
545
  sourceKey: options.sourceKey,
317
- findings: current.findings,
318
- }, (_key, value) => {
319
- if (isNumberObject(value))
320
- value = +value;
321
- if (typeof value === "number" && !Number.isFinite(value))
322
- throw new TypeError("Stored finding JSON cannot contain non-finite numbers.");
323
- return value;
546
+ findings: current.findings.map(({ source_finding_id, evidence }) => ({
547
+ source_finding_id,
548
+ evidence,
549
+ })),
324
550
  });
325
551
  return {
552
+ matchesRepositoryRemote,
326
553
  preview,
327
554
  async import() {
328
555
  dependencies.signal?.throwIfAborted();
@@ -342,7 +569,7 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
342
569
  read: current.read,
343
570
  ...(current.report === undefined
344
571
  ? {}
345
- : { report: structuredClone(current.report) }),
572
+ : snapshotNormalizedFindings({ report: current.report })),
346
573
  ready: current.findings.length,
347
574
  excluded: structuredClone(current.excluded),
348
575
  findings: result["findings"],