@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.60

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 (406) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +17 -0
  4. package/cli.js +6 -0
  5. package/client/dependency-paths.d.ts +3 -0
  6. package/client/dependency-paths.js +36 -0
  7. package/client/finding-link.js +305 -0
  8. package/client/linked-findings.d.ts +1 -0
  9. package/client/linked-findings.js +115 -0
  10. package/common/bundle-commit.d.ts +1 -0
  11. package/common/bundle-commit.js +4 -0
  12. package/common/bundle-compare-diff.d.ts +3 -0
  13. package/common/bundle-compare-diff.js +376 -0
  14. package/common/bundle-compare-inputs.d.ts +3 -0
  15. package/common/bundle-compare-inputs.js +141 -0
  16. package/common/bundle-compare-versions.js +172 -0
  17. package/common/bundle-comparison.d.ts +8 -0
  18. package/common/bundle-comparison.js +69 -0
  19. package/common/bundle-metadata.d.ts +15 -0
  20. package/common/bundle-metadata.js +226 -0
  21. package/common/bundle-pkg-of.d.ts +1 -0
  22. package/common/bundle-pkg-of.js +90 -0
  23. package/common/bundle-reasons.d.ts +2 -0
  24. package/common/bundle-reasons.js +21 -0
  25. package/common/bundle-source-links.d.ts +6 -0
  26. package/common/bundle-source-links.js +216 -0
  27. package/common/bundle-sourcemap.d.ts +10 -0
  28. package/common/bundle-sourcemap.js +100 -0
  29. package/common/bundle-sources.d.ts +7 -0
  30. package/common/bundle-sources.js +333 -0
  31. package/common/bundle-stats.js +41 -0
  32. package/common/bundle-tabs.js +1 -0
  33. package/common/code-language.js +65 -0
  34. package/common/default-scan-models.ts +35 -0
  35. package/common/dependency-reviews.d.ts +18 -0
  36. package/common/dependency-reviews.js +64 -0
  37. package/common/finding-duplicates.js +58 -0
  38. package/common/finding-filters.js +274 -0
  39. package/common/finding-id.js +47 -0
  40. package/common/finding-repo.d.ts +5 -0
  41. package/common/finding-repo.js +67 -0
  42. package/common/github-issue-labels.d.ts +1 -0
  43. package/common/github-issue-labels.js +11 -0
  44. package/common/github-pr.ts +56 -0
  45. package/common/gzip.js +59 -0
  46. package/common/line-diff.d.ts +8 -0
  47. package/common/line-diff.js +57 -0
  48. package/common/linked-workspace-groups.js +63 -0
  49. package/common/managed/agent-tasks.ts +292 -0
  50. package/common/managed/comments.ts +34 -0
  51. package/common/managed/finding-detail.d.ts +5 -0
  52. package/common/managed/finding-detail.js +75 -0
  53. package/common/managed/finding-values.d.ts +2 -0
  54. package/common/managed/finding-values.js +44 -0
  55. package/common/managed/github-agents.ts +114 -0
  56. package/common/managed/github-logins.ts +49 -0
  57. package/common/managed/lite-name.d.ts +2 -0
  58. package/common/managed/lite-name.js +20 -0
  59. package/common/managed/npm-packages.d.ts +7 -0
  60. package/common/managed/npm-packages.js +51 -0
  61. package/common/managed/permissions.ts +31 -0
  62. package/common/managed/report-content.ts +72 -0
  63. package/common/managed/report-filter.ts +120 -0
  64. package/common/managed/repository-alias.ts +65 -0
  65. package/common/managed/roles.ts +35 -0
  66. package/common/managed/routes.d.ts +2 -0
  67. package/common/managed/routes.js +363 -0
  68. package/common/managed/scan-models.ts +6 -0
  69. package/common/managed/team-app.d.ts +15 -0
  70. package/common/managed/team-app.js +100 -0
  71. package/common/managed/team-filters.js +26 -0
  72. package/common/managed/triage.ts +83 -0
  73. package/common/managed/upload-seal.ts +126 -0
  74. package/common/pretty-print.d.ts +5 -0
  75. package/common/pretty-print.js +24 -0
  76. package/common/repo-commit.d.ts +4 -0
  77. package/common/repo-commit.js +30 -0
  78. package/common/revalidation-conflicts.js +48 -0
  79. package/common/revalidation-input-groups.js +56 -0
  80. package/common/save-error-reason.ts +20 -7
  81. package/common/scan-server.ts +13 -0
  82. package/common/security-links.d.ts +5 -0
  83. package/common/security-links.js +33 -0
  84. package/common/server-info.ts +46 -0
  85. package/common/utf8.d.ts +3 -0
  86. package/common/utf8.js +45 -0
  87. package/common/workspace-app.js +71 -0
  88. package/common/workspace-groups.js +176 -0
  89. package/out/activity.js +4 -0
  90. package/out/brotli-fallback.js +3 -3
  91. package/out/chunk-2SY4PYUQ.js +4 -0
  92. package/out/chunk-2XUEZHIP.js +28 -0
  93. package/out/chunk-4EMM6UCD.js +1 -0
  94. package/out/chunk-4HI2MSAV.js +17 -0
  95. package/out/chunk-4ISO5F7Y.js +7 -0
  96. package/out/chunk-4TQKM3JC.js +42 -0
  97. package/out/chunk-4XIH7YTX.js +1 -0
  98. package/out/chunk-6VDDCFHT.js +3 -0
  99. package/out/chunk-74AEKRES.js +10 -0
  100. package/out/chunk-7BKKYVWR.js +7 -0
  101. package/out/chunk-7C7DWL7I.js +1 -0
  102. package/out/chunk-C4Z6ZBXV.js +10 -0
  103. package/out/chunk-DEVAORP2.js +1 -0
  104. package/out/chunk-E3LFSUDJ.js +9 -0
  105. package/out/chunk-EEQHVKR3.js +1 -0
  106. package/out/chunk-G3LY2FV4.js +1 -0
  107. package/out/chunk-GO7FT4OD.js +1 -0
  108. package/out/chunk-HAZKDK4M.js +4 -0
  109. package/out/chunk-HNQNDNIE.js +12 -0
  110. package/out/chunk-HOB3YPS5.js +1 -0
  111. package/out/chunk-IYPY47MC.js +1 -0
  112. package/out/chunk-IZ6MYRYB.js +3 -0
  113. package/out/chunk-J2FWBXFV.js +1 -0
  114. package/out/chunk-JCIIBLKR.js +1 -0
  115. package/out/chunk-JFL7WLRV.js +1 -0
  116. package/out/chunk-JMG5DXII.js +2 -0
  117. package/out/chunk-JOXLZXMI.js +1 -0
  118. package/out/chunk-M37X4LCF.js +14 -0
  119. package/out/chunk-M3Y6SLC4.js +1 -0
  120. package/out/chunk-NRPC74AM.js +1 -0
  121. package/out/chunk-NXATZJQ2.js +1 -0
  122. package/out/chunk-OFPDMZJF.js +244 -0
  123. package/out/chunk-OOJM4CTU.js +1 -0
  124. package/out/chunk-OQRSIBSC.js +1 -0
  125. package/out/chunk-PAD2JHZT.js +1 -0
  126. package/out/chunk-PNHBZGDD.js +1 -0
  127. package/out/chunk-PTFQKLKO.js +1 -0
  128. package/out/chunk-PWFUOLZK.js +17 -0
  129. package/out/chunk-PXK7EU4V.js +1 -0
  130. package/out/chunk-QMVOEBWC.js +13 -0
  131. package/out/chunk-QRKFPLA4.js +80 -0
  132. package/out/chunk-R3NZFXVR.js +1 -0
  133. package/out/chunk-R5O6FAW4.js +2 -0
  134. package/out/chunk-RRBIJL2B.js +1 -0
  135. package/out/chunk-SYXT3SFP.js +2 -0
  136. package/out/chunk-TOXMUOIW.js +5 -0
  137. package/out/chunk-TUII34K2.js +1 -0
  138. package/out/chunk-TZS7KERJ.js +52 -0
  139. package/out/chunk-UCP3JRE2.js +1 -0
  140. package/out/chunk-VFWMQ3LG.js +2 -0
  141. package/out/chunk-VRX2APNA.js +9 -0
  142. package/out/chunk-VZJIHHTQ.js +1 -0
  143. package/out/chunk-WCPJDAYA.js +10 -0
  144. package/out/chunk-WMFDQS2L.js +11 -0
  145. package/out/chunk-WREU7JAG.js +1 -0
  146. package/out/chunk-Y5ZHFNBD.js +2 -0
  147. package/out/chunk-YF4M5OCI.js +1 -0
  148. package/out/chunk-YGRRXC2L.js +1 -0
  149. package/out/chunk-YTO6AQZM.js +2 -0
  150. package/out/chunk-Z667U2UJ.js +1 -0
  151. package/out/chunk-ZQHLECTI.js +1 -0
  152. package/out/client-managed-import.js +4 -0
  153. package/out/client-managed.js +34 -0
  154. package/out/client-sync.js +11 -17
  155. package/out/compare.js +35 -0
  156. package/out/dialogs.js +40 -0
  157. package/out/github-issue-authorized.html +3 -0
  158. package/out/github-issue-authorized.js +1 -0
  159. package/out/graph.js +19 -4
  160. package/out/index.html +106 -8
  161. package/out/prism.js +14 -10
  162. package/out/scan.js +2 -0
  163. package/out/stasis.svg +20 -0
  164. package/out/terminal.js +366 -39
  165. package/out/view.css +1 -1
  166. package/out/view.js +19 -144
  167. package/package.json +379 -62
  168. package/risk/actions/findings.js +161 -0
  169. package/risk/actions/resolve.js +250 -0
  170. package/risk/actions/scripts/commands.js +182 -0
  171. package/risk/actions/scripts/grade.js +113 -0
  172. package/risk/actions/scripts/packages.js +123 -0
  173. package/risk/actions/scripts/shell.js +169 -0
  174. package/risk/actions/uses.js +76 -0
  175. package/risk/actions/workflow.js +110 -0
  176. package/risk/files/characters.js +196 -0
  177. package/risk/files/hosts.js +205 -0
  178. package/risk/files/readability.js +177 -0
  179. package/risk/files/runs-code.js +615 -0
  180. package/risk/files/script.js +118 -0
  181. package/risk/files/stamps.js +47 -0
  182. package/risk/index.d.ts +272 -0
  183. package/risk/index.js +11 -0
  184. package/risk/npm/assess.js +285 -0
  185. package/risk/npm/combined.js +68 -0
  186. package/risk/npm/compare.js +257 -0
  187. package/risk/npm/dependencies.js +172 -0
  188. package/risk/npm/diff.js +79 -0
  189. package/risk/npm/downloads.js +84 -0
  190. package/risk/npm/files.js +445 -0
  191. package/risk/npm/held.js +63 -0
  192. package/risk/npm/install-scripts.js +34 -0
  193. package/risk/npm/malware.js +38 -0
  194. package/risk/npm/manifest.js +65 -0
  195. package/risk/npm/new-dependency.js +60 -0
  196. package/risk/npm/old-version.js +108 -0
  197. package/risk/npm/registry.js +390 -0
  198. package/risk/npm/release.js +85 -0
  199. package/risk/npm/score.js +59 -0
  200. package/risk/npm/specs.js +124 -0
  201. package/risk/npm/tarball.js +96 -0
  202. package/server-common/database-config.ts +16 -0
  203. package/server-common/initialize.ts +18 -0
  204. package/server-common/npm-advisories.ts +101 -0
  205. package/{server → server-common}/origin.ts +5 -5
  206. package/server-common/reap.ts +48 -0
  207. package/server-common/scan-config.ts +19 -0
  208. package/server-common/standalone.ts +29 -0
  209. package/server-common/storage-crypto.ts +182 -0
  210. package/server-common/storage-log.ts +38 -0
  211. package/server-common/vercel-blob.ts +103 -0
  212. package/server-e2e/app.ts +487 -0
  213. package/{server → server-e2e}/bus-receiver.ts +2 -1
  214. package/{server → server-e2e}/cli.js +9 -4
  215. package/{server → server-e2e}/config.ts +50 -42
  216. package/{server → server-e2e}/db-neon.ts +2 -2
  217. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  218. package/{server → server-e2e}/db-stmt.ts +2 -2
  219. package/{server → server-e2e}/db.ts +7 -7
  220. package/{server → server-e2e}/http.ts +44 -13
  221. package/{server → server-e2e}/hub.ts +40 -9
  222. package/server-e2e/index.ts +17 -0
  223. package/server-e2e/lifecycle.ts +95 -0
  224. package/{server → server-e2e}/neon-driver.ts +2 -2
  225. package/{server → server-e2e}/npm-proxy.ts +12 -145
  226. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  227. package/{server → server-e2e}/objstore/blob.ts +1 -1
  228. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  229. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  230. package/{server → server-e2e}/objstore/init.ts +19 -27
  231. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  232. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  233. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  234. package/{server → server-e2e}/objstore/rest.ts +3 -3
  235. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  236. package/{server → server-e2e}/objstore/store.ts +7 -7
  237. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  238. package/{server → server-e2e}/pubsub.ts +12 -9
  239. package/{server → server-e2e}/sign.ts +4 -4
  240. package/{server → server-e2e}/sse-server.ts +60 -33
  241. package/{server → server-e2e}/static.ts +31 -21
  242. package/{server → server-e2e}/sync-handlers.ts +64 -30
  243. package/{server → server-e2e}/ws-server.ts +20 -9
  244. package/server-managed/activity.ts +258 -0
  245. package/server-managed/agent-merges.ts +109 -0
  246. package/server-managed/app-agents.ts +23 -0
  247. package/server-managed/avatar-store.ts +13 -0
  248. package/server-managed/blob-store.ts +17 -0
  249. package/server-managed/brotli.ts +10 -0
  250. package/server-managed/bundle-advisories.ts +102 -0
  251. package/server-managed/bundle-advisory-inventory.ts +77 -0
  252. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  253. package/server-managed/bundle-build-diagnostics.js +23 -0
  254. package/server-managed/bundle-build-leases.ts +41 -0
  255. package/server-managed/bundle-build-worker.js +203 -0
  256. package/server-managed/bundle-build.ts +232 -0
  257. package/server-managed/bundle-cache.ts +211 -0
  258. package/server-managed/bundle-catalog.ts +29 -0
  259. package/server-managed/bundle-commits.ts +140 -0
  260. package/server-managed/bundle-dependency-reviews.ts +74 -0
  261. package/server-managed/bundle-store.ts +24 -0
  262. package/server-managed/bundle-summary-cache.ts +130 -0
  263. package/server-managed/bundle-validation.ts +32 -0
  264. package/server-managed/bundle.ts +119 -0
  265. package/server-managed/cache-storage.ts +20 -0
  266. package/server-managed/cli.js +21 -0
  267. package/server-managed/combined.ts +47 -0
  268. package/server-managed/comments.ts +151 -0
  269. package/server-managed/commit-coauthors.ts +106 -0
  270. package/server-managed/commit-lockfiles.ts +76 -0
  271. package/server-managed/comparison.ts +52 -0
  272. package/server-managed/config.ts +164 -0
  273. package/server-managed/content-access.ts +15 -0
  274. package/server-managed/crypto.ts +25 -0
  275. package/server-managed/db-methods.ts +1958 -0
  276. package/server-managed/db-neon.ts +484 -0
  277. package/server-managed/db-schema.ts +238 -0
  278. package/server-managed/db-table-names.ts +22 -0
  279. package/server-managed/db.ts +152 -0
  280. package/server-managed/dependabot-access.ts +60 -0
  281. package/server-managed/dependabot-alerts.ts +185 -0
  282. package/server-managed/dependency-review-comments.ts +98 -0
  283. package/server-managed/dependency-reviews.ts +364 -0
  284. package/server-managed/github-accounts.ts +60 -0
  285. package/server-managed/github-actions.ts +71 -0
  286. package/server-managed/github-app.ts +376 -0
  287. package/server-managed/github-errors.ts +70 -0
  288. package/server-managed/github-graphql.ts +39 -0
  289. package/server-managed/github-issue-links.ts +244 -0
  290. package/server-managed/github-issue-oauth.ts +47 -0
  291. package/server-managed/github-issues.ts +155 -0
  292. package/server-managed/github-link-oauth.ts +69 -0
  293. package/server-managed/github-links.ts +204 -0
  294. package/server-managed/github-metadata.ts +213 -0
  295. package/server-managed/github-oauth.ts +238 -0
  296. package/server-managed/github-pulls.ts +246 -0
  297. package/server-managed/github-requests.ts +166 -0
  298. package/server-managed/github-users.ts +30 -0
  299. package/server-managed/history-windows.ts +172 -0
  300. package/server-managed/http-response.ts +76 -0
  301. package/server-managed/http.ts +5855 -0
  302. package/server-managed/import-triage.ts +51 -0
  303. package/server-managed/index.ts +204 -0
  304. package/server-managed/kept-briefly.ts +37 -0
  305. package/server-managed/kept.ts +28 -0
  306. package/server-managed/link-reports.ts +162 -0
  307. package/server-managed/listed-activity.ts +39 -0
  308. package/server-managed/locked-packages.ts +152 -0
  309. package/server-managed/lockfile-scope.ts +49 -0
  310. package/server-managed/lru.ts +30 -0
  311. package/server-managed/managed-issues.ts +92 -0
  312. package/server-managed/management-catalog.ts +45 -0
  313. package/server-managed/management.ts +99 -0
  314. package/server-managed/npm-delta-worker.js +23 -0
  315. package/server-managed/npm-delta.ts +194 -0
  316. package/server-managed/npm-insights.ts +450 -0
  317. package/server-managed/npm-kept.ts +233 -0
  318. package/server-managed/npm-loads.ts +264 -0
  319. package/server-managed/npm-manifest.ts +115 -0
  320. package/server-managed/npm-packages.ts +454 -0
  321. package/server-managed/npm-patch.ts +325 -0
  322. package/server-managed/npm-provenance.ts +123 -0
  323. package/server-managed/npm-risk.ts +285 -0
  324. package/server-managed/object-storage-disk.ts +148 -0
  325. package/server-managed/object-storage-vercel.ts +67 -0
  326. package/server-managed/object-storage.ts +75 -0
  327. package/server-managed/package-entry-points.ts +79 -0
  328. package/server-managed/pretty-print.ts +436 -0
  329. package/server-managed/public-workspace.ts +238 -0
  330. package/server-managed/pull-comment-reviews.ts +161 -0
  331. package/server-managed/pull-dependencies.ts +351 -0
  332. package/server-managed/pull-dependency-reviews.ts +334 -0
  333. package/server-managed/pull-reviews.ts +205 -0
  334. package/server-managed/queue.ts +39 -0
  335. package/server-managed/release-commits.ts +84 -0
  336. package/server-managed/rename-diff-worker.js +26 -0
  337. package/server-managed/rename-diff.ts +279 -0
  338. package/server-managed/repo-path.ts +21 -0
  339. package/server-managed/report-migration.ts +35 -0
  340. package/server-managed/report-query.ts +10 -0
  341. package/server-managed/report-response.ts +16 -0
  342. package/server-managed/report-sources.ts +185 -0
  343. package/server-managed/report-store.ts +85 -0
  344. package/server-managed/repository-actions.ts +221 -0
  345. package/server-managed/repository-agents.ts +448 -0
  346. package/server-managed/repository-aliases.ts +91 -0
  347. package/server-managed/repository-browser.ts +301 -0
  348. package/server-managed/repository-changes.ts +284 -0
  349. package/server-managed/repository-code.ts +215 -0
  350. package/server-managed/repository-dependency-reviews.ts +166 -0
  351. package/server-managed/repository-discovery.ts +82 -0
  352. package/server-managed/repository-history.ts +432 -0
  353. package/server-managed/repository-issues.ts +195 -0
  354. package/server-managed/repository-policy.ts +27 -0
  355. package/server-managed/repository-pulls.ts +212 -0
  356. package/server-managed/repository-pulse.ts +471 -0
  357. package/server-managed/repository-risk-assess.ts +105 -0
  358. package/server-managed/repository-risk-audit.ts +78 -0
  359. package/server-managed/repository-risk-read.ts +170 -0
  360. package/server-managed/repository-risk.ts +491 -0
  361. package/server-managed/repository-squashes.ts +168 -0
  362. package/server-managed/repository-stamp.ts +41 -0
  363. package/server-managed/request-timing.ts +63 -0
  364. package/server-managed/reviewed-dependencies.ts +149 -0
  365. package/server-managed/revisions.ts +35 -0
  366. package/server-managed/scan-downloads.ts +87 -0
  367. package/server-managed/session.ts +132 -0
  368. package/server-managed/slugs.ts +38 -0
  369. package/server-managed/solidity-entry-points.ts +71 -0
  370. package/server-managed/sql-postgres.ts +34 -0
  371. package/server-managed/sql.ts +89 -0
  372. package/server-managed/stasis-config.ts +55 -0
  373. package/server-managed/static.ts +28 -0
  374. package/server-managed/storage-command.ts +16 -0
  375. package/server-managed/storage-db.ts +183 -0
  376. package/server-managed/storage-encryption.ts +290 -0
  377. package/server-managed/storage-maintenance.ts +259 -0
  378. package/server-managed/storage-payload.ts +121 -0
  379. package/server-managed/storage-stores.ts +91 -0
  380. package/server-managed/storage.ts +82 -0
  381. package/server-managed/team-app-summaries.ts +54 -0
  382. package/server-managed/team-app.ts +157 -0
  383. package/server-managed/team-catalog.ts +7 -0
  384. package/server-managed/team-feed.ts +180 -0
  385. package/server-managed/team-npm-scopes.ts +106 -0
  386. package/server-managed/team-reports.ts +351 -0
  387. package/server-managed/triage-response.ts +16 -0
  388. package/server-managed/type-only-worker.js +19 -0
  389. package/server-managed/type-only.ts +105 -0
  390. package/server-managed/uploads.ts +106 -0
  391. package/server-managed/upstream-cache.ts +252 -0
  392. package/server-managed/view-as.ts +58 -0
  393. package/server-managed/workspace-shares.ts +171 -0
  394. package/server.ts +70 -0
  395. package/server/index.ts +0 -480
  396. package/server/lifecycle.ts +0 -208
  397. /package/{LICENSE → LICENSE-MIT} +0 -0
  398. /package/{server → server-e2e}/auth.ts +0 -0
  399. /package/{server → server-e2e}/config.example.json +0 -0
  400. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  401. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  402. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  403. /package/{server → server-e2e}/peer.ts +0 -0
  404. /package/{server → server-e2e}/sse-session.ts +0 -0
  405. /package/{server → server-e2e}/util.ts +0 -0
  406. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,185 @@
1
+ // A repository's Dependabot alerts of npm's ecosystem, open or dismissed, as a
2
+ // repository risk scan blends them into npm's advisories (repository-risk.ts),
3
+ // a dismissed one with who dismissed it, when and why: GitHub's
4
+ // `GET /repos/:repo/dependabot/alerts`, a page of 100 at a time, each found by
5
+ // the cursor the one before's Link header names, MAX_PAGES at most. Asked with
6
+ // the App's installation token, once the admin's own access to the repository
7
+ // is found to let them see the alerts on GitHub (dependabot-access.ts): where
8
+ // the installation hasn't Dependabot alerts: read, or the repository has them
9
+ // off, that is thrown as its code, never GitHub's text, for the scan to tell
10
+ // and go on.
11
+ import { isExactVersion, satisfies, validRange } from '@preventive/upstream/semver.js'
12
+ import { isNpmPackageName } from '../common/managed/npm-packages.js'
13
+ import { GithubApiError, githubUnreachable, throwGithubResponseError } from './github-errors.ts'
14
+ import type { LockedPackage } from './locked-packages.ts'
15
+
16
+ // An alert, as GitHub has it: its `number` in its repository and its page
17
+ // there (`url`, built, never fetched), the manifest or lockfile it is of
18
+ // (`manifest`, from the repository's root), its package and advisory, the
19
+ // versions it affects as GitHub writes them (`range`, `>= 1.0.0, < 1.2.6`)
20
+ // and the first that isn't (`patched`), `dev` where GitHub tells the
21
+ // dependency is only for development, and `dismissed` where it is: by whom,
22
+ // when, why and what they said, or by one of the repository's rules (`auto`).
23
+ export interface DependabotAlert {
24
+ number: number
25
+ url: string
26
+ manifest: string
27
+ name: string
28
+ ghsa: string
29
+ // The advisory's other ids, as its CVE.
30
+ aliases: string[]
31
+ title?: string
32
+ // `critical`, `high`, `moderate`, `low`: GitHub's `medium` reads `moderate`.
33
+ severity?: string
34
+ range?: string
35
+ patched?: string
36
+ cwe: string[]
37
+ dev?: true
38
+ dismissed?: AlertDismissal
39
+ }
40
+
41
+ // GitHub's `dismissed_reason`: `fix_started`, `inaccurate`, `no_bandwidth`,
42
+ // `not_used` or `tolerable_risk`; `at` as GitHub writes it (ISO 8601).
43
+ export interface AlertDismissal { auto?: true; reason?: string; at?: string; by?: string; comment?: string }
44
+
45
+ const API = 'https://api.github.com'
46
+ const API_VERSION = '2022-11-28'
47
+ const USER_AGENT = 'deepview-triage'
48
+ const PER_PAGE = 100
49
+ // Up to how many pages a listing asks: 2,000 alerts of npm's in a repository,
50
+ // past which the rest are left out; where open and dismissed ones are more,
51
+ // the open ones are listed again on their own (dependabotAlerts).
52
+ const MAX_PAGES = 20
53
+ // A page holds each advisory's whole text: given longer than githubJson's.
54
+ const PAGE_TIMEOUT_MS = 20_000
55
+ const GHSA = /^GHSA(?:-[23456789cfghjmpqrvwx]{4}){3}$/u
56
+ const SEVERITIES = new Map([['critical', 'critical'], ['high', 'high'], ['medium', 'moderate'], ['moderate', 'moderate'], ['low', 'low']])
57
+ // A path from a repository's root, as git takes one: no empty, `.` or `..`
58
+ // component, nor a control character.
59
+ const isRepoPath = (path: unknown): path is string => typeof path === 'string' && path.length <= 1024 && !/\p{Cc}/u.test(path)
60
+ && path.split('/').every(part => part !== '' && part !== '.' && part !== '..')
61
+
62
+ // The states asked: a fixed alert's dependency is no longer what it was.
63
+ const STATES = ['open', 'dismissed', 'auto_dismissed']
64
+ const REASONS = new Set(['fix_started', 'inaccurate', 'no_bandwidth', 'not_used', 'tolerable_risk'])
65
+ const LOGIN = /^[\dA-Za-z](?:[\dA-Za-z-]{0,38})(?:\[bot\])?$/u
66
+
67
+ const text = (value: unknown, most = 500) => typeof value === 'string' && value.trim() ? value.trim().slice(0, most) : undefined
68
+
69
+ // How a dismissed alert was dismissed, as far as GitHub tells it soundly.
70
+ function dismissalOf(state: string, raw: Record<string, any>): AlertDismissal {
71
+ const at = state === 'auto_dismissed' ? raw['auto_dismissed_at'] : raw['dismissed_at']
72
+ const when = typeof at === 'string' && at.length <= 40 && !Number.isNaN(Date.parse(at)) ? { at } : {}
73
+ if (state === 'auto_dismissed') return { auto: true, ...when }
74
+ const by = raw['dismissed_by']?.login, comment = text(raw['dismissed_comment'], 280), reason = raw['dismissed_reason']
75
+ return { ...REASONS.has(reason) ? { reason } : {}, ...when, ...typeof by === 'string' && LOGIN.test(by) ? { by } : {}, ...comment === undefined ? {} : { comment } }
76
+ }
77
+
78
+ // An alert as GitHub answers it, or null for one that isn't an open or
79
+ // dismissed one of npm's, of a package and GHSA npm and GitHub would name.
80
+ function alertOf(fullName: string, raw: unknown): DependabotAlert | null {
81
+ if (raw == null || typeof raw !== 'object') return null
82
+ const { number, state, dependency, security_advisory: advisory, security_vulnerability: vulnerability } = raw as Record<string, any>
83
+ if (!Number.isSafeInteger(number) || number <= 0 || !STATES.includes(state)) return null
84
+ const ghsa = advisory?.ghsa_id, manifest = dependency?.manifest_path, name = dependency?.package?.name
85
+ if (dependency?.package?.ecosystem !== 'npm' || !isNpmPackageName(name) || !isRepoPath(manifest) || typeof ghsa !== 'string' || !GHSA.test(ghsa)) return null
86
+ const severity = SEVERITIES.get(vulnerability?.severity ?? advisory?.severity)
87
+ const patched = text(vulnerability?.first_patched_version?.identifier, 100), range = text(vulnerability?.vulnerable_version_range, 200), title = text(advisory?.summary)
88
+ const ids = Array.isArray(advisory?.identifiers) ? advisory.identifiers as { value?: unknown }[] : []
89
+ const cwes = Array.isArray(advisory?.cwes) ? advisory.cwes as { cwe_id?: unknown }[] : []
90
+ return {
91
+ number, url: `https://github.com/${fullName.split('/').map(encodeURIComponent).join('/')}/security/dependabot/${number}`, manifest, name, ghsa,
92
+ aliases: [...new Set(ids.flatMap(id => typeof id?.value === 'string' && /^[\w.:-]{1,64}$/u.test(id.value) && id.value !== ghsa ? [id.value] : []))],
93
+ ...title === undefined ? {} : { title }, ...severity === undefined ? {} : { severity },
94
+ ...range === undefined ? {} : { range }, ...patched === undefined ? {} : { patched },
95
+ cwe: [...new Set(cwes.flatMap(cwe => typeof cwe?.cwe_id === 'string' && /^CWE-\d{1,6}$/u.test(cwe.cwe_id) ? [cwe.cwe_id] : []))],
96
+ ...dependency.scope === 'development' ? { dev: true as const } : {},
97
+ ...state === 'open' ? {} : { dismissed: dismissalOf(state, raw as Record<string, any>) },
98
+ }
99
+ }
100
+
101
+ // The next page's cursor, as the Link header's `next` names it: its `after`,
102
+ // or its `page`, all that is taken of it, the rest of its URL left as asked.
103
+ function nextPage(link: string | null): [string, string] | null {
104
+ const next = link?.split(',').map(part => /^\s*<([^>]*)>\s*;\s*rel="next"\s*$/u.exec(part)?.[1]).find(Boolean)
105
+ if (!next) return null
106
+ let url
107
+ try { url = new URL(next) } catch { return null }
108
+ if (url.origin !== API) return null
109
+ const after = url.searchParams.get('after'), page = url.searchParams.get('page')
110
+ return after ? ['after', after] : page && /^\d{1,4}$/u.test(page) ? ['page', page] : null
111
+ }
112
+
113
+ // A page asked of GitHub: its alerts and the headers they came with. A 403
114
+ // that isn't a rate limit is told as the alerts being off
115
+ // (`dependabot-disabled`) or not to be read by the App's installation
116
+ // (`dependabot-app-permission`), as a 404 is, the repository found just
117
+ // before; the rest as githubJson tells them.
118
+ async function askPage(url: string, token: string, fetchImpl: typeof fetch): Promise<{ alerts: unknown[]; link: string | null }> {
119
+ const started = Date.now()
120
+ let res: Response
121
+ try {
122
+ res = await fetchImpl(url, {
123
+ signal: AbortSignal.timeout(PAGE_TIMEOUT_MS), redirect: 'error',
124
+ headers: { authorization: `Bearer ${token}`, accept: 'application/vnd.github+json', 'user-agent': USER_AGENT, 'x-github-api-version': API_VERSION },
125
+ })
126
+ } catch (error) { throw githubUnreachable(error, started) }
127
+ if (res.status === 403) {
128
+ const message = (await res.clone().json().catch(() => null) as { message?: unknown } | null)?.message
129
+ const limited = res.headers.get('x-ratelimit-remaining') === '0' || res.headers.has('retry-after')
130
+ || (typeof message === 'string' && /rate limit|abuse detection/iu.test(message))
131
+ if (!limited) throw new GithubApiError(403, typeof message === 'string' && /disabled/iu.test(message) ? 'dependabot-disabled' : 'dependabot-app-permission')
132
+ }
133
+ if (res.status === 404) throw new GithubApiError(403, 'dependabot-app-permission')
134
+ if (!res.ok) await throwGithubResponseError(res)
135
+ let body
136
+ try { body = await res.json() } catch (error) {
137
+ throw error instanceof SyntaxError ? new GithubApiError(502, 'github-malformed') : githubUnreachable(error, started)
138
+ }
139
+ if (!Array.isArray(body)) throw new GithubApiError(502, 'github-malformed')
140
+ return { alerts: body, link: res.headers.get('link') }
141
+ }
142
+
143
+ // `fullName`'s alerts in `states`, MAX_PAGES at most, in GitHub's order (the
144
+ // newest first), and whether that is all of them.
145
+ async function listAlerts(fullName: string, states: readonly string[], token: string, fetchImpl: typeof fetch) {
146
+ const base = `${API}/repos/${fullName.split('/').map(encodeURIComponent).join('/')}/dependabot/alerts`
147
+ const alerts: DependabotAlert[] = []
148
+ const seen = new Set<number>()
149
+ let cursor: [string, string] | null = null
150
+ for (let pages = 0; pages < MAX_PAGES; pages++) {
151
+ const query = new URLSearchParams({ state: states.join(','), ecosystem: 'npm', per_page: String(PER_PAGE), ...cursor ? { [cursor[0]]: cursor[1] } : {} })
152
+ const answer = await askPage(`${base}?${query}`, token, fetchImpl)
153
+ for (const raw of answer.alerts) {
154
+ const alert = alertOf(fullName, raw)
155
+ if (alert && !seen.has(alert.number)) { seen.add(alert.number); alerts.push(alert) }
156
+ }
157
+ cursor = answer.alerts.length === 0 ? null : nextPage(answer.link)
158
+ if (!cursor) return { alerts, whole: true }
159
+ }
160
+ return { alerts, whole: false }
161
+ }
162
+
163
+ // `fullName`'s Dependabot alerts of npm's ecosystem, open or dismissed, as
164
+ // `token`, the App's installation's (dependabot-access.ts), may see them, in
165
+ // GitHub's order. Asked at once, but where they are more than a listing holds,
166
+ // as newer dismissed ones would leave older open ones out, the open ones are
167
+ // listed again on their own, and the dismissed ones had kept after them.
168
+ export async function dependabotAlerts(fullName: string, token: string, fetchImpl: typeof fetch = globalThis.fetch): Promise<DependabotAlert[]> {
169
+ const all = await listAlerts(fullName, STATES, token, fetchImpl)
170
+ if (all.whole) return all.alerts
171
+ const open = await listAlerts(fullName, ['open'], token, fetchImpl)
172
+ const told = new Set(open.alerts.map(alert => alert.number))
173
+ return [...open.alerts, ...all.alerts.filter(alert => alert.dismissed && !told.has(alert.number))]
174
+ }
175
+
176
+ // The versions of an alert's package that a lockfile it is of locks
177
+ // (`packages`) and its range covers, GitHub's read as npm's semver reads its
178
+ // own (`>= 1.0.0, < 1.2.6` as `>= 1.0.0 < 1.2.6`); none where it is of no
179
+ // lockfile read, or its range is none semver reads.
180
+ export function alertVersions(alert: Pick<DependabotAlert, 'name' | 'range'>, packages: readonly LockedPackage[] | undefined): string[] {
181
+ const range = alert.range === undefined ? null : validRange(alert.range.replaceAll(',', ' '))
182
+ if (!packages || range === null) return []
183
+ return [...new Set(packages.flatMap(({ name, version, source }) => name === alert.name && (source === 'registry' || source === 'mirror')
184
+ && isExactVersion(version) && satisfies(version, range) ? [version] : []))]
185
+ }
@@ -0,0 +1,98 @@
1
+ // The comment a host formats of one's own dependency reviews, for a copy
2
+ // button to give (reviewed-dependencies.ts `formatDependencyReviews`): of each
3
+ // of one's reviews, as their lists and the review page show them
4
+ // (`withFormatted`), and of those of the versions an open pull request adds
5
+ // (`formattedPull`). It is given one's own published reviews alone, never
6
+ // another's, a draft or a revoked one, however it is asked (`formatOwn`, the
7
+ // only caller of the hook); and is told of none where it answers nothing, or
8
+ // fails, which is logged.
9
+ import type { DependencyReview, DependencyReviewStore } from './dependency-reviews.ts'
10
+ import { type PullDependencies, eachOf } from './pull-dependencies.ts'
11
+ import type { PublishedReview, RepoReviewState } from './repository-dependency-reviews.ts'
12
+ import type { DependencyReviewEntry, ReviewedDependencies } from './reviewed-dependencies.ts'
13
+
14
+ const FORMAT_AT_ONCE = 8
15
+ // The longest comment told, past which none is.
16
+ const MAX_FORMATTED = 1_000_000
17
+ // The reviews of a pull request's versions read at once, those past them
18
+ // read after, every one formatted.
19
+ const REVIEWS_AT_ONCE = 200
20
+
21
+ // `review` as the hook is given it: each version with the integrity and
22
+ // shasum the review keeps of the tarball it read, and the version it is of
23
+ // with the patch it is of, where it is a patched one's.
24
+ function entryOf(review: DependencyReview): DependencyReviewEntry {
25
+ return { ecosystem: 'npm', old: review.basePackage === null ? null : { name: review.basePackage, version: review.baseVersion ?? '', integrity: review.baseIntegrity ?? '',
26
+ ...review.baseShasum ? { shasum: review.baseShasum } : {} },
27
+ new: { name: review.package, version: review.version, integrity: review.integrity, ...review.shasum ? { shasum: review.shasum } : {},
28
+ ...review.patchHash ? { patchHash: review.patchHash } : {} },
29
+ status: review.status!, coverage: review.coverage === 'full' ? 'full' : 'partial', comment: review.comment,
30
+ files: review.entries.filter(entry => entry.status !== null || entry.comment.trim() !== '').map(entry => ({ path: entry.file, status: entry.status, comment: entry.comment })),
31
+ reviewer: review.userLogin, publishedAt: review.publishedAt! }
32
+ }
33
+
34
+ // Whether `review` is `user`'s own, published, not revoked, with its verdict.
35
+ const ownPublished = (review: DependencyReview, user: string) => review.user === user && review.publishedAt !== null && review.revokedAt === null && review.status !== null
36
+
37
+ // What the host formats of `reviews`, of them `user`'s own published ones
38
+ // alone, and the pull request they are of the versions of, where it is
39
+ // one's; none where it formats none of them.
40
+ async function formatOwn(reviewed: ReviewedDependencies | null, user: string, reviews: DependencyReview[],
41
+ pullRequest?: { repository: string; number: number }): Promise<string | null> {
42
+ const format = reviewed?.formatDependencyReviews
43
+ const own = reviews.filter(review => ownPublished(review, user))
44
+ if (!format || own.length === 0) return null
45
+ try {
46
+ const text = await format({ reviews: own.map(entryOf), ...pullRequest ? { pullRequest } : {} })
47
+ return typeof text === 'string' && text.trim() !== '' && text.length <= MAX_FORMATTED ? text : null
48
+ } catch (error) {
49
+ console.warn('reviewed dependencies: failed to format dependency reviews', error instanceof Error ? error.message : error)
50
+ return null
51
+ }
52
+ }
53
+
54
+ // `reviews`, each of `user`'s own with the comment the host formats of it
55
+ // (`formatted`), where it formats one; another's never asked of.
56
+ export function withFormatted<T extends DependencyReview>(reviewed: ReviewedDependencies | null, user: string, reviews: T[]): Promise<(T & { formatted?: string })[]> {
57
+ if (!reviewed?.formatDependencyReviews) return Promise.resolve(reviews)
58
+ return eachOf(reviews, FORMAT_AT_ONCE, async review => {
59
+ const formatted = ownPublished(review, user) ? await formatOwn(reviewed, user, [review]) : null
60
+ return formatted ? { ...review, formatted } : review
61
+ })
62
+ }
63
+
64
+ // The ids of those of `reviews` `user` published of the versions `told`
65
+ // adds, as its lockfiles lock each: of its version, of an integrity it is
66
+ // locked with and of its patch, whole or compared with a version it was.
67
+ function ownOfPull(told: PullDependencies, reviews: PublishedReview[], user: string): Set<string> {
68
+ // Theirs by the version they are of, each version probed once.
69
+ const theirs = new Map<string, PublishedReview[]>()
70
+ for (const review of reviews) {
71
+ if (review.id === undefined || review.reviewer !== user) continue
72
+ const key = `${review.package}@${review.version}`
73
+ theirs.set(key, [...theirs.get(key) ?? [], review])
74
+ }
75
+ const mine = new Set<string>()
76
+ if (theirs.size === 0) return mine
77
+ for (const pkg of told.lockfiles.flatMap(dir => 'added' in dir ? dir.added : [])) {
78
+ const hashes = new Set((pkg.integrity ?? '').split(/\s+/u).filter(Boolean))
79
+ for (const review of theirs.get(`${pkg.name}@${pkg.version}`) ?? []) {
80
+ if (!hashes.has(review.integrity) || (review.patchHash ?? '') !== (pkg.patchHash ?? '')) continue
81
+ if (review.basePackage === null || (review.basePackage === pkg.name && (pkg.was ?? []).includes(review.baseVersion ?? ''))) mine.add(review.id!)
82
+ }
83
+ }
84
+ return mine
85
+ }
86
+
87
+ // The comment the host formats of `user`'s reviews of the versions pull
88
+ // request `number` of `repository` adds (`told`), those its review's state
89
+ // tells of, published to a team counting for it; none where it has none.
90
+ export async function formattedPull(reviewed: ReviewedDependencies | null, db: Pick<DependencyReviewStore, 'listOwnDependencyReviewsById'>, user: string,
91
+ told: PullDependencies, state: RepoReviewState | null, pullRequest: { repository: string; number: number }): Promise<string | null> {
92
+ if (!reviewed?.formatDependencyReviews || !state) return null
93
+ const mine = ownOfPull(told, state.reviews, user)
94
+ if (mine.size === 0) return null
95
+ const ids = [...mine], reviews: DependencyReview[] = []
96
+ for (let at = 0; at < ids.length; at += REVIEWS_AT_ONCE) reviews.push(...await db.listOwnDependencyReviewsById(user, ids.slice(at, at + REVIEWS_AT_ONCE)))
97
+ return formatOwn(reviewed, user, reviews, pullRequest)
98
+ }