@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80

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 (442) hide show
  1. package/LICENSE-APACHE +202 -0
  2. package/README.md +16 -0
  3. package/api/reap.ts +16 -78
  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 +6 -0
  13. package/common/bundle-compare-diff.js +377 -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-imports.js +20 -0
  20. package/common/bundle-metadata.d.ts +15 -0
  21. package/common/bundle-metadata.js +226 -0
  22. package/common/bundle-pkg-of.d.ts +1 -0
  23. package/common/bundle-pkg-of.js +90 -0
  24. package/common/bundle-reasons.d.ts +6 -0
  25. package/common/bundle-reasons.js +58 -0
  26. package/common/bundle-source-links.d.ts +6 -0
  27. package/common/bundle-source-links.js +216 -0
  28. package/common/bundle-sourcemap.d.ts +10 -0
  29. package/common/bundle-sourcemap.js +100 -0
  30. package/common/bundle-sources.d.ts +10 -0
  31. package/common/bundle-sources.js +374 -0
  32. package/common/bundle-stats.js +41 -0
  33. package/common/bundle-tabs.js +1 -0
  34. package/common/code-language.js +66 -0
  35. package/common/default-scan-models.ts +36 -0
  36. package/common/dependency-reviews.d.ts +18 -0
  37. package/common/dependency-reviews.js +64 -0
  38. package/common/finding-duplicates.js +63 -0
  39. package/common/finding-filters.js +313 -0
  40. package/common/finding-id.js +47 -0
  41. package/common/finding-repo.d.ts +5 -0
  42. package/common/finding-repo.js +67 -0
  43. package/common/github-issue-labels.d.ts +1 -0
  44. package/common/github-issue-labels.js +11 -0
  45. package/common/github-pr.ts +56 -0
  46. package/common/gzip.js +59 -0
  47. package/common/line-diff.d.ts +14 -0
  48. package/common/line-diff.js +181 -0
  49. package/common/linked-workspace-groups.js +63 -0
  50. package/common/managed/agent-tasks.ts +292 -0
  51. package/common/managed/comments.ts +43 -0
  52. package/common/managed/dependency-routes.js +25 -0
  53. package/common/managed/directory-packages.ts +28 -0
  54. package/common/managed/finding-detail.d.ts +5 -0
  55. package/common/managed/finding-detail.js +75 -0
  56. package/common/managed/finding-values.d.ts +2 -0
  57. package/common/managed/finding-values.js +138 -0
  58. package/common/managed/github-agents.ts +114 -0
  59. package/common/managed/github-logins.ts +49 -0
  60. package/common/managed/lite-name.d.ts +2 -0
  61. package/common/managed/lite-name.js +20 -0
  62. package/common/managed/npm-packages.d.ts +9 -0
  63. package/common/managed/npm-packages.js +63 -0
  64. package/common/managed/permissions.ts +31 -0
  65. package/common/managed/report-content.ts +72 -0
  66. package/common/managed/report-filter.ts +120 -0
  67. package/common/managed/repository-alias.ts +65 -0
  68. package/common/managed/review-view-routes.js +23 -0
  69. package/common/managed/risk-routes.js +30 -0
  70. package/common/managed/roles.ts +41 -0
  71. package/common/managed/routes.d.ts +2 -0
  72. package/common/managed/routes.js +385 -0
  73. package/common/managed/scan-models.ts +6 -0
  74. package/common/managed/stasis-config.ts +7 -0
  75. package/common/managed/team-app.d.ts +19 -0
  76. package/common/managed/team-app.js +129 -0
  77. package/common/managed/team-filters.js +26 -0
  78. package/common/managed/triage.ts +83 -0
  79. package/common/managed/upload-seal.ts +126 -0
  80. package/common/pretty-json.js +98 -0
  81. package/common/pretty-kinds.js +20 -0
  82. package/common/pretty-print.d.ts +6 -0
  83. package/common/pretty-print.js +36 -0
  84. package/common/pretty-sourcemap.js +70 -0
  85. package/common/repo-commit.d.ts +4 -0
  86. package/common/repo-commit.js +30 -0
  87. package/common/revalidation-conflicts.js +48 -0
  88. package/common/revalidation-input-groups.js +56 -0
  89. package/common/save-error-reason.ts +20 -7
  90. package/common/scan-server.ts +13 -0
  91. package/common/security-links.d.ts +5 -0
  92. package/common/security-links.js +33 -0
  93. package/common/server-info.ts +46 -0
  94. package/common/sourcemap-listing.js +78 -0
  95. package/common/sourcemap-mappings.js +136 -0
  96. package/common/sourcemap-unlist.js +85 -0
  97. package/common/stasis-files.d.ts +5 -0
  98. package/common/stasis-files.js +20 -0
  99. package/common/stasis-tgz.d.ts +6 -0
  100. package/common/stasis-tgz.js +27 -0
  101. package/common/utf8.d.ts +3 -0
  102. package/common/utf8.js +45 -0
  103. package/common/whitespace-insensitive.js +19 -0
  104. package/common/workspace-app.js +91 -0
  105. package/common/workspace-groups.js +176 -0
  106. package/out/activity.js +2 -0
  107. package/out/brotli-fallback.js +3 -3
  108. package/out/chunk-2XUEZHIP.js +28 -0
  109. package/out/chunk-55YIWY3H.js +5 -0
  110. package/out/chunk-5AVGKFMR.js +1 -0
  111. package/out/chunk-5CJKUV53.js +1 -0
  112. package/out/chunk-5EAVJAD2.js +3 -0
  113. package/out/chunk-5M2X3QPK.js +6 -0
  114. package/out/chunk-5QWPKTCE.js +40 -0
  115. package/out/chunk-6CCSTJWB.js +1 -0
  116. package/out/chunk-6VOB5WXX.js +2 -0
  117. package/out/chunk-6Y6PZ2BU.js +9 -0
  118. package/out/chunk-74JZTGTO.js +11 -0
  119. package/out/chunk-7BKKYVWR.js +7 -0
  120. package/out/chunk-7C7DWL7I.js +1 -0
  121. package/out/chunk-7HP2VYIC.js +2 -0
  122. package/out/chunk-7YFJUT2P.js +1 -0
  123. package/out/chunk-7YO4QV5P.js +1 -0
  124. package/out/chunk-A4BBBHQU.js +1 -0
  125. package/out/chunk-B64CTMVU.js +4 -0
  126. package/out/chunk-BEKYZCPX.js +14 -0
  127. package/out/chunk-C4Z6ZBXV.js +10 -0
  128. package/out/chunk-CU3FPB3P.js +1 -0
  129. package/out/chunk-DEVAORP2.js +1 -0
  130. package/out/chunk-DUASGS2O.js +8 -0
  131. package/out/chunk-DUS5ARE2.js +53 -0
  132. package/out/chunk-EEJA7JBI.js +13 -0
  133. package/out/chunk-FSU2PLJL.js +1 -0
  134. package/out/chunk-GBMAXAYK.js +3 -0
  135. package/out/chunk-GO7FT4OD.js +1 -0
  136. package/out/chunk-GX5UXWT4.js +1 -0
  137. package/out/chunk-ITUKKCCK.js +10 -0
  138. package/out/chunk-IYPY47MC.js +1 -0
  139. package/out/chunk-JXBRWLMA.js +4 -0
  140. package/out/chunk-K4XJHM2T.js +1 -0
  141. package/out/chunk-LBD3M3J6.js +1 -0
  142. package/out/chunk-LVSLM7HB.js +1 -0
  143. package/out/chunk-LVW7WWV4.js +1 -0
  144. package/out/chunk-MV66NL3G.js +3 -0
  145. package/out/chunk-N57OWFKY.js +15 -0
  146. package/out/chunk-NRPC74AM.js +1 -0
  147. package/out/chunk-OOJM4CTU.js +1 -0
  148. package/out/chunk-OWSEQOL5.js +1 -0
  149. package/out/chunk-PKLVXUEI.js +11 -0
  150. package/out/chunk-PLGH63UC.js +2 -0
  151. package/out/chunk-PNHBZGDD.js +1 -0
  152. package/out/chunk-PTFYDJUP.js +1 -0
  153. package/out/chunk-PWFUOLZK.js +17 -0
  154. package/out/chunk-PXK7EU4V.js +1 -0
  155. package/out/chunk-QD3IBSF4.js +7 -0
  156. package/out/chunk-QI66YA4F.js +1 -0
  157. package/out/chunk-QRKFPLA4.js +80 -0
  158. package/out/chunk-R3NZFXVR.js +1 -0
  159. package/out/chunk-R5O6FAW4.js +2 -0
  160. package/out/chunk-RPNO56H2.js +1 -0
  161. package/out/chunk-SSPDMA6D.js +1 -0
  162. package/out/chunk-SZWPYLPC.js +1 -0
  163. package/out/chunk-TUII34K2.js +1 -0
  164. package/out/chunk-UJP4PQJA.js +1 -0
  165. package/out/chunk-UJSJMXEG.js +1 -0
  166. package/out/chunk-UR4WYMIP.js +1 -0
  167. package/out/chunk-VHEXSGGP.js +1 -0
  168. package/out/chunk-VYYUMYVW.js +9 -0
  169. package/out/chunk-VZPPX6MV.js +1 -0
  170. package/out/chunk-WCDYSIKG.js +1 -0
  171. package/out/chunk-XM4RLC4A.js +2 -0
  172. package/out/chunk-YKCRCNYZ.js +266 -0
  173. package/out/chunk-ZQHLECTI.js +1 -0
  174. package/out/client-managed-import.js +4 -0
  175. package/out/client-managed.js +37 -0
  176. package/out/client-sync.js +11 -17
  177. package/out/compare.js +26 -0
  178. package/out/dialogs.js +40 -0
  179. package/out/github-issue-authorized.html +3 -0
  180. package/out/github-issue-authorized.js +1 -0
  181. package/out/graph.js +19 -4
  182. package/out/index.html +104 -24
  183. package/out/prism.js +14 -10
  184. package/out/scan.js +2 -0
  185. package/out/stasis.svg +20 -0
  186. package/out/terminal.js +367 -39
  187. package/out/view.css +1 -1
  188. package/out/view.js +19 -147
  189. package/package.json +409 -64
  190. package/risk/actions/findings.js +161 -0
  191. package/risk/actions/resolve.js +287 -0
  192. package/risk/actions/scripts/commands.js +182 -0
  193. package/risk/actions/scripts/grade.js +113 -0
  194. package/risk/actions/scripts/packages.js +123 -0
  195. package/risk/actions/scripts/shell.js +169 -0
  196. package/risk/actions/uses.js +94 -0
  197. package/risk/actions/workflow.js +183 -0
  198. package/risk/files/characters.js +341 -0
  199. package/risk/files/hosts.js +206 -0
  200. package/risk/files/readability.js +185 -0
  201. package/risk/files/runs-code.js +563 -0
  202. package/risk/files/script.js +402 -0
  203. package/risk/files/source-map-link.js +43 -0
  204. package/risk/files/stamps.js +47 -0
  205. package/risk/index.d.ts +294 -0
  206. package/risk/index.js +12 -0
  207. package/risk/npm/assess.js +285 -0
  208. package/risk/npm/combined.js +68 -0
  209. package/risk/npm/compare.js +236 -0
  210. package/risk/npm/dependencies.js +172 -0
  211. package/risk/npm/diff.js +79 -0
  212. package/risk/npm/downloads.js +84 -0
  213. package/risk/npm/files.js +445 -0
  214. package/risk/npm/held.js +67 -0
  215. package/risk/npm/install-scripts.js +34 -0
  216. package/risk/npm/malware.js +38 -0
  217. package/risk/npm/manifest.js +65 -0
  218. package/risk/npm/new-dependency.js +60 -0
  219. package/risk/npm/old-version.js +108 -0
  220. package/risk/npm/registry.js +393 -0
  221. package/risk/npm/release.js +85 -0
  222. package/risk/npm/score.js +59 -0
  223. package/risk/npm/specs.js +124 -0
  224. package/risk/npm/tarball.js +169 -0
  225. package/server-common/database-config.ts +16 -0
  226. package/server-common/initialize.ts +18 -0
  227. package/server-common/npm-advisories.ts +101 -0
  228. package/{server → server-common}/origin.ts +5 -5
  229. package/server-common/reap.ts +48 -0
  230. package/server-common/scan-config.ts +19 -0
  231. package/server-common/standalone.ts +29 -0
  232. package/server-common/storage-crypto.ts +182 -0
  233. package/server-common/storage-log.ts +38 -0
  234. package/server-common/vercel-blob.ts +103 -0
  235. package/server-e2e/app.ts +487 -0
  236. package/{server → server-e2e}/bus-receiver.ts +2 -1
  237. package/{server → server-e2e}/cli.js +9 -4
  238. package/{server → server-e2e}/config.ts +50 -42
  239. package/{server → server-e2e}/db-neon.ts +2 -2
  240. package/{server → server-e2e}/db-revision-sql.ts +1 -1
  241. package/{server → server-e2e}/db-stmt.ts +2 -2
  242. package/{server → server-e2e}/db.ts +7 -7
  243. package/{server → server-e2e}/http.ts +44 -13
  244. package/{server → server-e2e}/hub.ts +40 -9
  245. package/server-e2e/index.ts +17 -0
  246. package/server-e2e/lifecycle.ts +95 -0
  247. package/{server → server-e2e}/neon-driver.ts +2 -2
  248. package/{server → server-e2e}/npm-proxy.ts +12 -145
  249. package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
  250. package/{server → server-e2e}/objstore/blob.ts +1 -1
  251. package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
  252. package/{server → server-e2e}/objstore/handlers.ts +9 -8
  253. package/{server → server-e2e}/objstore/init.ts +19 -27
  254. package/{server → server-e2e}/objstore/reaper.ts +1 -1
  255. package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
  256. package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
  257. package/{server → server-e2e}/objstore/rest.ts +3 -3
  258. package/{server → server-e2e}/objstore/store-neon.ts +6 -10
  259. package/{server → server-e2e}/objstore/store.ts +7 -7
  260. package/{server → server-e2e}/objstore/tokens.ts +2 -2
  261. package/{server → server-e2e}/pubsub.ts +12 -9
  262. package/{server → server-e2e}/sign.ts +4 -4
  263. package/{server → server-e2e}/sse-server.ts +60 -33
  264. package/{server → server-e2e}/static.ts +18 -17
  265. package/{server → server-e2e}/sync-handlers.ts +64 -30
  266. package/{server → server-e2e}/ws-server.ts +20 -9
  267. package/server-managed/activity.ts +247 -0
  268. package/server-managed/agent-merges.ts +109 -0
  269. package/server-managed/app-agents.ts +23 -0
  270. package/server-managed/avatar-store.ts +13 -0
  271. package/server-managed/blob-store.ts +26 -0
  272. package/server-managed/brotli.ts +10 -0
  273. package/server-managed/bundle-advisories.ts +79 -0
  274. package/server-managed/bundle-advisory-inventory.ts +85 -0
  275. package/server-managed/bundle-build-diagnostics.d.ts +10 -0
  276. package/server-managed/bundle-build-diagnostics.js +23 -0
  277. package/server-managed/bundle-build-leases.ts +41 -0
  278. package/server-managed/bundle-build-worker.js +380 -0
  279. package/server-managed/bundle-build.ts +326 -0
  280. package/server-managed/bundle-cache.ts +261 -0
  281. package/server-managed/bundle-catalog.ts +29 -0
  282. package/server-managed/bundle-commits.ts +133 -0
  283. package/server-managed/bundle-dependency-reviews.ts +91 -0
  284. package/server-managed/bundle-store.ts +24 -0
  285. package/server-managed/bundle-summary-cache.ts +139 -0
  286. package/server-managed/bundle-validation.ts +33 -0
  287. package/server-managed/bundle.ts +151 -0
  288. package/server-managed/cache-storage.ts +20 -0
  289. package/server-managed/cli.js +21 -0
  290. package/server-managed/combined.ts +43 -0
  291. package/server-managed/comments.ts +138 -0
  292. package/server-managed/commit-coauthors.ts +105 -0
  293. package/server-managed/commit-lockfiles.ts +78 -0
  294. package/server-managed/comparison.ts +51 -0
  295. package/server-managed/config.ts +163 -0
  296. package/server-managed/content-access.ts +15 -0
  297. package/server-managed/crypto.ts +25 -0
  298. package/server-managed/db-methods.ts +1914 -0
  299. package/server-managed/db-neon.ts +398 -0
  300. package/server-managed/db-schema.ts +263 -0
  301. package/server-managed/db-table-names.ts +22 -0
  302. package/server-managed/db.ts +149 -0
  303. package/server-managed/dependabot-access.ts +61 -0
  304. package/server-managed/dependabot-alerts.ts +180 -0
  305. package/server-managed/dependency-review-comments.ts +143 -0
  306. package/server-managed/dependency-reviews.ts +369 -0
  307. package/server-managed/github-accounts.ts +59 -0
  308. package/server-managed/github-actions.ts +71 -0
  309. package/server-managed/github-app.ts +347 -0
  310. package/server-managed/github-errors.ts +92 -0
  311. package/server-managed/github-graphql.ts +42 -0
  312. package/server-managed/github-issue-links.ts +264 -0
  313. package/server-managed/github-issue-oauth.ts +30 -0
  314. package/server-managed/github-issues.ts +157 -0
  315. package/server-managed/github-link-oauth.ts +56 -0
  316. package/server-managed/github-links.ts +204 -0
  317. package/server-managed/github-metadata.ts +213 -0
  318. package/server-managed/github-oauth.ts +264 -0
  319. package/server-managed/github-pulls.ts +257 -0
  320. package/server-managed/github-requests.ts +181 -0
  321. package/server-managed/github-users.ts +30 -0
  322. package/server-managed/github-values.ts +26 -0
  323. package/server-managed/history-windows.ts +172 -0
  324. package/server-managed/http-response.ts +76 -0
  325. package/server-managed/http.ts +6324 -0
  326. package/server-managed/import-triage.ts +51 -0
  327. package/server-managed/index.ts +204 -0
  328. package/server-managed/kept-briefly.ts +37 -0
  329. package/server-managed/kept.ts +28 -0
  330. package/server-managed/link-reports.ts +149 -0
  331. package/server-managed/listed-activity.ts +39 -0
  332. package/server-managed/locked-packages.ts +234 -0
  333. package/server-managed/lockfile-scope.ts +58 -0
  334. package/server-managed/lru.ts +30 -0
  335. package/server-managed/managed-issues.ts +92 -0
  336. package/server-managed/management-catalog.ts +45 -0
  337. package/server-managed/management.ts +116 -0
  338. package/server-managed/npm-delta-worker.js +142 -0
  339. package/server-managed/npm-delta.ts +277 -0
  340. package/server-managed/npm-insights.ts +455 -0
  341. package/server-managed/npm-kept.ts +265 -0
  342. package/server-managed/npm-loads.ts +259 -0
  343. package/server-managed/npm-manifest.ts +117 -0
  344. package/server-managed/npm-packages.ts +469 -0
  345. package/server-managed/npm-patch-paths.ts +86 -0
  346. package/server-managed/npm-patch.ts +455 -0
  347. package/server-managed/npm-provenance.ts +127 -0
  348. package/server-managed/npm-risk.ts +287 -0
  349. package/server-managed/object-storage-disk.ts +147 -0
  350. package/server-managed/object-storage-vercel.ts +71 -0
  351. package/server-managed/object-storage.ts +82 -0
  352. package/server-managed/package-entry-points.ts +127 -0
  353. package/server-managed/pretty-copies.ts +22 -0
  354. package/server-managed/pretty-format.d.ts +3 -0
  355. package/server-managed/pretty-format.js +13 -0
  356. package/server-managed/pretty-print.ts +442 -0
  357. package/server-managed/public-workspace.ts +243 -0
  358. package/server-managed/pull-comment-reviews.ts +161 -0
  359. package/server-managed/pull-dependencies.ts +370 -0
  360. package/server-managed/pull-dependency-reviews.ts +407 -0
  361. package/server-managed/pull-reviews.ts +202 -0
  362. package/server-managed/queue.ts +54 -0
  363. package/server-managed/release-commits.ts +85 -0
  364. package/server-managed/rename-diff-worker.js +30 -0
  365. package/server-managed/rename-diff.ts +237 -0
  366. package/server-managed/repo-path.ts +21 -0
  367. package/server-managed/report-migration.ts +32 -0
  368. package/server-managed/report-opening.ts +77 -0
  369. package/server-managed/report-query.ts +10 -0
  370. package/server-managed/report-response.ts +16 -0
  371. package/server-managed/report-sources.ts +185 -0
  372. package/server-managed/report-store.ts +77 -0
  373. package/server-managed/repository-actions.ts +220 -0
  374. package/server-managed/repository-agents.ts +422 -0
  375. package/server-managed/repository-aliases.ts +119 -0
  376. package/server-managed/repository-browser.ts +361 -0
  377. package/server-managed/repository-changes.ts +280 -0
  378. package/server-managed/repository-code.ts +222 -0
  379. package/server-managed/repository-dependency-reviews.ts +182 -0
  380. package/server-managed/repository-discovery.ts +83 -0
  381. package/server-managed/repository-history.ts +428 -0
  382. package/server-managed/repository-issues.ts +293 -0
  383. package/server-managed/repository-policy.ts +27 -0
  384. package/server-managed/repository-pulls.ts +207 -0
  385. package/server-managed/repository-pulse.ts +477 -0
  386. package/server-managed/repository-risk-assess.ts +108 -0
  387. package/server-managed/repository-risk-audit.ts +78 -0
  388. package/server-managed/repository-risk-caches.ts +37 -0
  389. package/server-managed/repository-risk-read.ts +260 -0
  390. package/server-managed/repository-risk-stasis.ts +61 -0
  391. package/server-managed/repository-risk-turn.ts +97 -0
  392. package/server-managed/repository-risk.ts +516 -0
  393. package/server-managed/repository-squashes.ts +160 -0
  394. package/server-managed/repository-stamp.ts +41 -0
  395. package/server-managed/request-timing.ts +63 -0
  396. package/server-managed/reviewed-dependencies.ts +170 -0
  397. package/server-managed/revisions.ts +35 -0
  398. package/server-managed/scan-downloads.ts +121 -0
  399. package/server-managed/session.ts +132 -0
  400. package/server-managed/slugs.ts +38 -0
  401. package/server-managed/solidity-entry-points.ts +71 -0
  402. package/server-managed/sql-postgres.ts +34 -0
  403. package/server-managed/sql.ts +107 -0
  404. package/server-managed/stasis-config.ts +147 -0
  405. package/server-managed/stasis-dependencies.ts +221 -0
  406. package/server-managed/static.ts +28 -0
  407. package/server-managed/storage-command.ts +16 -0
  408. package/server-managed/storage-db.ts +183 -0
  409. package/server-managed/storage-encryption.ts +288 -0
  410. package/server-managed/storage-maintenance.ts +259 -0
  411. package/server-managed/storage-payload.ts +121 -0
  412. package/server-managed/storage-stores.ts +91 -0
  413. package/server-managed/storage.ts +82 -0
  414. package/server-managed/team-app-summaries.ts +56 -0
  415. package/server-managed/team-app.ts +156 -0
  416. package/server-managed/team-catalog.ts +7 -0
  417. package/server-managed/team-feed.ts +180 -0
  418. package/server-managed/team-npm-scopes.ts +103 -0
  419. package/server-managed/team-reports.ts +368 -0
  420. package/server-managed/triage-response.ts +16 -0
  421. package/server-managed/type-only-proof.js +161 -0
  422. package/server-managed/type-only-worker.js +31 -0
  423. package/server-managed/type-only.ts +135 -0
  424. package/server-managed/uploads.ts +106 -0
  425. package/server-managed/upstream-cache.ts +256 -0
  426. package/server-managed/view-as.ts +58 -0
  427. package/server-managed/worker-turns.ts +76 -0
  428. package/server-managed/workspace-shares.ts +170 -0
  429. package/server.ts +70 -0
  430. package/strip-types-loader.js +13 -10
  431. package/server/index.ts +0 -480
  432. package/server/lifecycle.ts +0 -208
  433. /package/{LICENSE → LICENSE-MIT} +0 -0
  434. /package/{server → server-e2e}/auth.ts +0 -0
  435. /package/{server → server-e2e}/config.example.json +0 -0
  436. /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
  437. /package/{server → server-e2e}/objstore/fs.ts +0 -0
  438. /package/{server → server-e2e}/objstore/sign.ts +0 -0
  439. /package/{server → server-e2e}/peer.ts +0 -0
  440. /package/{server → server-e2e}/sse-session.ts +0 -0
  441. /package/{server → server-e2e}/util.ts +0 -0
  442. /package/{server → server-e2e}/validation.ts +0 -0
@@ -0,0 +1,161 @@
1
+ // What a workflow, or an action's metadata, calls for by its own text (README.md).
2
+ import { YamlError } from '@preventive/lockfile/yaml.js'
3
+ import { readWorkflow } from './workflow.js'
4
+ import { installsOf } from './scripts/commands.js'
5
+ import { dotted, imageFinding, lockedName, namesPullHead, scriptFindings, scriptInjections, within } from './scripts/grade.js'
6
+ import { ownerKind, usesKey } from './uses.js'
7
+ import { resolved } from '../npm/files.js'
8
+
9
+ // What a `uses:` calls for by its pin, a reference's with its `key`.
10
+ function usesFinding(uses, owner) {
11
+ if (uses.kind === 'invalid') return { id: 'invalid-uses', severity: 'low', uses: uses.uses }
12
+ if (uses.kind === 'docker') return uses.digest ? null : imageFinding(uses.uses, uses)
13
+ if ((uses.kind !== 'action' && uses.kind !== 'workflow') || uses.pin === 'sha') return null
14
+ const at = { uses: uses.uses, key: usesKey(uses) }
15
+ return uses.pin === 'short-sha' ? { id: 'short-sha', severity: 'high', ...at } : { id: 'unpinned', severity: ownerKind(uses.repo, owner) === 'third-party' ? 'high' : 'moderate', ...at, ref: uses.ref }
16
+ }
17
+
18
+ // An action that installs a project's npm packages, by its name: npm's,
19
+ // Yarn's, pnpm's or Bun's install of dependencies (`bahmutov/npm-install`),
20
+ // not another tool's (`cachix/install-nix-action`).
21
+ const INSTALLER = /(?:npm|yarn|pnpm|bun|node[-_]?modules)[-_]?(?:ci|install)|install[-_]?(?:npm|yarn|pnpm|bun|node[-_]?modules|dep(?:endencie)?s|packages)/iu
22
+
23
+ // Where a step installs a project's packages, each `{ at, prod }`: a
24
+ // script's install's directory or the one it names, and whether it leaves
25
+ // devDependencies out; an action of its own's, by its metadata (ScanOptions
26
+ // `actions`), anywhere (null) where none is told; and anywhere for an action
27
+ // that installs them (cypress-io/github-action's unless `install: false`,
28
+ // pnpm/action-setup's with `run_install`).
29
+ const ANYWHERE = [{ at: null, prod: false }]
30
+ function installs(step, actions, seen = new Set()) {
31
+ if (step.uses?.kind === 'local') return actions ? ownInstalls(actions, step.uses.path, seen) : ANYWHERE
32
+ const repo = step.uses?.repo?.toLowerCase()
33
+ if (repo && (INSTALLER.test(repo) || (repo === 'cypress-io/github-action' && String(step.with?.install) !== 'false'))) return ANYWHERE
34
+ if (repo === 'pnpm/action-setup' && /^(?:true|\[|\{|-)/u.test(String(step.with?.run_install ?? '').trim())) return ANYWHERE
35
+ return step.run ? installsOf(step.run.script, step.run.production).map(({ into, prod }) => ({ at: directoryOf(step.run.workingDirectory, into), prod })) : []
36
+ }
37
+
38
+ // Where the repository's own action at `dir` installs, by its steps, each
39
+ // action of its own once.
40
+ function ownInstalls(actions, dir, seen) {
41
+ const read = actions.has(dir) && !seen.has(dir) && seen.add(dir) ? readWorkflow('action', actions.get(dir)) : null
42
+ return read && !(read instanceof YamlError) ? read.jobs.flatMap(job => job.steps.flatMap(step => installs(step, actions, seen))) : []
43
+ }
44
+
45
+ // A step's directory, and a path from it (`into`), from the repository's
46
+ // root, '' for it; as written where an expression or a variable names it, or
47
+ // it is out of the repository, so that it is within the same alone.
48
+ function directoryOf(workingDirectory, into = null) {
49
+ const path = into?.startsWith('/') ? into : [workingDirectory, into].filter(Boolean).join('/')
50
+ return /\$|^\//u.test(path) ? path : resolved([], path)?.join('/') ?? path
51
+ }
52
+
53
+ // Whether the nearest lockfiles at or above `directory`, its project's, lock
54
+ // what npx runs by `name`: `dev` where only devDependencies need it in each
55
+ // that does.
56
+ const lockDir = path => path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''
57
+ function lockedIn(lockfiles, directory, name) {
58
+ const above = lockfiles.filter(({ path }) => within(lockDir(path), directory))
59
+ const nearest = Math.max(...above.map(({ path }) => lockDir(path).length))
60
+ const locking = above.filter(({ path, names }) => lockDir(path).length === nearest && lockedName(names, name))
61
+ return locking.length > 0 && (locking.every(({ dev }) => dev && lockedName(dev, name)) ? 'dev' : true)
62
+ }
63
+
64
+ // The inputs a text names (`${{ inputs.title }}`).
65
+ const inputsIn = text => typeof text === 'string' ? [...dotted(text).matchAll(/\$\{\{[^}]*?\binputs\s*\.\s*([\w-]+)/gu)].map(match => match[1]) : []
66
+
67
+ // The inputs a step's action, or a job's reusable workflow, writes into a
68
+ // script: github-script's `script`; those one of the repository's own
69
+ // (ScanOptions `actions`) names in its `run:`s or its jobs' images, or hands
70
+ // to such an input of a step's or a job's; and each of another reusable
71
+ // workflow's, or one whose text isn't told, as it may.
72
+ function scriptInputs(step, actions, seen = new Set()) {
73
+ if (step.uses?.repo?.toLowerCase() === 'actions/github-script') return ['script']
74
+ if (step.uses?.kind === 'workflow' || (step.uses?.job && !actions?.has(step.uses.path))) return Object.keys(step.with ?? {})
75
+ const path = step.uses?.kind === 'local' && actions?.has(step.uses.path) && !seen.has(step.uses.path) ? step.uses.path : null
76
+ const read = path === null ? null : readWorkflow(step.uses.job ? 'workflow' : 'action', actions.get(path))
77
+ if (!read || read instanceof YamlError) return []
78
+ const inner = new Set(seen).add(path)
79
+ const handed = each => scriptInputs(each, actions, inner).flatMap(input => inputsIn(each.with?.[input]))
80
+ return [...new Set(read.jobs.flatMap(job => [...job.uses ? handed(job) : [], ...job.images.flatMap(image => inputsIn(image.text)),
81
+ ...job.steps.flatMap(each => [...inputsIn(each.run?.script), ...handed(each)])]))]
82
+ }
83
+
84
+ // Injections through the inputs an action writes into its scripts, and a
85
+ // fork's code or artifacts taken where the workflow runs with its secrets.
86
+ function stepFindings(step, triggers, actions) {
87
+ const repo = step.uses?.repo?.toLowerCase()
88
+ const found = scriptInputs(step, actions).flatMap(input => scriptInjections(step.with?.[input], triggers).map(({ index: _index, ...finding }) => ({ ...finding, line: step.withLines[input] })))
89
+ const forks = ['pull_request_target', 'workflow_run', 'issue_comment'].some(event => triggers.includes(event))
90
+ if (forks && repo === 'actions/checkout' && (namesPullHead(step.with?.ref) || namesPullHead(step.with?.repository))) {
91
+ found.push({ id: 'pwn-request', severity: 'critical', ref: String(step.with.ref ?? step.with.repository), line: step.withLines.ref ?? step.withLines.repository ?? step.line })
92
+ }
93
+ if (forks && step.run && /\bgh\s+pr\s+checkout\b/u.test(step.run.script)) found.push({ id: 'pwn-request', severity: 'critical', ref: 'gh pr checkout', line: step.run.line })
94
+ if (triggers.includes('workflow_run') && ((repo === 'actions/download-artifact' && (step.with?.['run-id'] !== undefined || step.with?.['github-token'] !== undefined))
95
+ || repo === 'dawidd6/action-download-artifact' || /\bgh\s+run\s+download\b/u.test(step.run?.script ?? ''))) found.push({ id: 'untrusted-artifact', severity: 'high', line: step.uses?.line ?? step.run.line })
96
+ return found
97
+ }
98
+
99
+ // A job's findings, each script graded by the installs before it and its lockfiles.
100
+ function jobFindings(job, triggers, { owner, lockfiles, external, actions }) {
101
+ const found = []
102
+ if (job.uses) {
103
+ const finding = usesFinding(job.uses, owner)
104
+ if (finding) found.push({ ...finding, line: job.uses.line })
105
+ if (job.secrets === 'inherit' && job.uses.repo && ownerKind(job.uses.repo, owner) === 'third-party') found.push({ id: 'secrets-inherited', severity: 'high', uses: job.uses.uses, key: usesKey(job.uses), line: job.uses.line })
106
+ // An input a reusable workflow writes into its scripts.
107
+ for (const input of scriptInputs(job, actions)) for (const { index: _index, ...injected } of scriptInjections(job.with?.[input], triggers)) found.push({ ...injected, line: job.withLines[input] })
108
+ }
109
+ for (const image of job.images) {
110
+ if (!image.read?.digest && !image.text.includes('${{')) found.push({ ...imageFinding(image.text, image.read), line: image.line })
111
+ for (const { index: _index, ...injected } of scriptInjections(image.text, triggers)) found.push({ ...injected, line: image.line })
112
+ }
113
+ const installed = []
114
+ for (const step of job.steps) {
115
+ const finding = step.uses && usesFinding(step.uses, owner)
116
+ if (finding) found.push({ ...finding, line: step.uses.line })
117
+ if (step.run) {
118
+ const directory = dir => directoryOf(step.run.workingDirectory, dir)
119
+ const locked = (name, dir) => !external && lockedIn(lockfiles, directory(dir), name)
120
+ const before = (dev, dir) => installed.some(({ at, prod }) => within(at, directory(dir)) && !(prod && dev))
121
+ found.push(...scriptFindings(step.run, { locked, installed: before, external, triggers }))
122
+ }
123
+ found.push(...stepFindings(step, triggers, actions))
124
+ installed.push(...installs(step, actions))
125
+ }
126
+ return found
127
+ }
128
+
129
+ // Every finding of a workflow read (readWorkflow), in its lines' order, by
130
+ // index.d.ts ScanOptions.
131
+ export function workflowFindings(read, { owner = null, lockfiles = [], external = false, actions = null } = {}) {
132
+ const found = read.jobs.flatMap(job => jobFindings(job, read.triggers, { owner, lockfiles, external, actions }))
133
+ if (/^node(?:12|16)$/u.test(read.using ?? '')) found.push({ id: 'deprecated-runtime', severity: 'low', using: read.using, line: read.usingLine })
134
+ return found.toSorted((a, b) => (a.line ?? 0) - (b.line ?? 0))
135
+ }
136
+
137
+ // The references a workflow read makes: of GitHub's, each with its `key`, and
138
+ // of its own (`local`).
139
+ export function workflowUses(read) {
140
+ return read.jobs.flatMap(job => [job.uses, ...job.steps.map(step => step.uses)]).flatMap(uses => {
141
+ if (uses?.kind === 'local') return [uses]
142
+ return uses?.kind === 'action' || uses?.kind === 'workflow' ? [{ ...uses, key: usesKey(uses) }] : []
143
+ })
144
+ }
145
+
146
+ // The actions of the repository's own a workflow or an action uses, by
147
+ // their directories, and a Docker action's Dockerfile; none for one GitHub
148
+ // can't run.
149
+ export function ownFilesOf(kind, text) {
150
+ const read = readWorkflow(kind, text)
151
+ if (read instanceof YamlError) return { actions: [], dockerfile: null }
152
+ return { actions: workflowUses(read).flatMap(uses => uses.kind === 'local' && !uses.job ? [uses.path] : []), dockerfile: read.dockerfile?.path ?? null }
153
+ }
154
+
155
+ // A workflow's or an action's metadata's (`kind`) references and findings;
156
+ // why not (`workflow-unreadable`) for one GitHub can't run.
157
+ export function scanWorkflow(kind, text, options = {}) {
158
+ const read = readWorkflow(kind, text)
159
+ if (read instanceof YamlError) return { error: 'workflow-unreadable', detail: read.message.slice(0, 500) }
160
+ return { uses: workflowUses(read), findings: workflowFindings(read, options) }
161
+ }
@@ -0,0 +1,287 @@
1
+ // A reference resolved on GitHub (`source`, index.d.ts ActionsSource): its
2
+ // repository, its ref's commit, its advisories and its own code's findings
3
+ // (README.md).
4
+ import { YamlError } from '@preventive/lockfile/yaml.js'
5
+ import { readWorkflow } from './workflow.js'
6
+ import { workflowFindings, workflowUses } from './findings.js'
7
+ import { imageFinding, scriptFindings } from './scripts/grade.js'
8
+ import { isVersion, isWorkflowPath, ownerKind, readImage, readUses, usesKey } from './uses.js'
9
+
10
+ // An action's tags as versions: a release's (`v4.2.1`), and a major (`v4`) or
11
+ // minor one (`v4.2`) moved to its line's latest. `[major, minor, patch]`,
12
+ // null for a part a tag hasn't; null for no version.
13
+ export function tagVersion(tag) {
14
+ const m = typeof tag === 'string' ? /^v?(\d{1,9})(?:\.(\d{1,9}))?(?:\.(\d{1,9}))?$/u.exec(tag) : null
15
+ return m && [Number(m[1]), m[2] === undefined ? null : Number(m[2]), m[3] === undefined ? null : Number(m[3])]
16
+ }
17
+
18
+ const isRelease = version => version !== null && version[2] !== null
19
+
20
+ const byVersion = (a, b) => (b[0] - a[0]) || ((b[1] ?? -1) - (a[1] ?? -1)) || ((b[2] ?? -1) - (a[2] ?? -1))
21
+
22
+ // Whether a release is of a major or minor tag's line: `v4`'s `4.x.y`.
23
+ const ofLine = (version, other) => isRelease(other) && other[0] === version[0] && (version[1] === null || other[1] === version[1])
24
+
25
+ // The versions of `tags` (`{ tag, oid }` each), the highest first.
26
+ const versionsOf = tags => tags.flatMap(({ tag, oid }) => { const version = tagVersion(tag); return version ? [{ tag, oid, version }] : [] })
27
+ .toSorted((a, b) => byVersion(a.version, b.version))
28
+
29
+ // The latest release's tag of `tags`, else the highest version's; null where
30
+ // none is one.
31
+ export function latestOf(tags) {
32
+ const versions = versionsOf(tags)
33
+ return (versions.find(({ version }) => isRelease(version)) ?? versions[0])?.tag ?? null
34
+ }
35
+
36
+ // The highest release of each major line, the latest line first: where a
37
+ // commit is most likely in a release's history.
38
+ export function newestOfLines(tags) {
39
+ const seen = new Set()
40
+ return versionsOf(tags).filter(({ version }) => isRelease(version) && !seen.has(version[0]) && seen.add(version[0]))
41
+ }
42
+
43
+ // An instruction's lines, its continuations (`\` at a line's end) joined,
44
+ // and each heredoc's (`<<EOF`) through its delimiter, as BuildKit reads one.
45
+ function instructions(text) {
46
+ const lines = text.split('\n').map(line => line.replace(/\r$/u, ''))
47
+ const found = []
48
+ for (let at = 0; at < lines.length; at++) {
49
+ const start = at
50
+ while (lines[at].endsWith('\\') && at + 1 < lines.length) at++
51
+ for (const { 2: quoted, 3: bare } of lines.slice(start, at + 1).join('\n').matchAll(/(?<!<)<<-?\s*(?:(["'])(.+?)\1|([^\s"'<>|&;()]+))/gu)) {
52
+ do at++
53
+ while (at < lines.length - 1 && lines[at].trim() !== (quoted ?? bare))
54
+ }
55
+ found.push({ start, lines: lines.slice(start, Math.min(at, lines.length - 1) + 1) })
56
+ at = Math.min(at, lines.length - 1)
57
+ }
58
+ return found
59
+ }
60
+
61
+ // A `RUN`'s command, its exec form (`RUN ["sh", "-c", "…"]`) as words.
62
+ function runCommand(text) {
63
+ if (!text.trimStart().startsWith('[')) return text
64
+ try {
65
+ const words = JSON.parse(text)
66
+ return Array.isArray(words) ? words.map(word => /[\s'"]/u.test(String(word)) ? `'${String(word).replaceAll("'", "'\\''")}'` : String(word)).join(' ') : text
67
+ } catch { return text }
68
+ }
69
+
70
+ // A Docker action's Dockerfile: each `FROM` by a tag, a build argument's
71
+ // yellow, and each `RUN` read as a script's (scripts/grade.js).
72
+ export function dockerfileFindings(text) {
73
+ const findings = [], script = [], stages = new Set()
74
+ for (const { start, lines } of instructions(text)) {
75
+ const first = /^\s*(FROM|RUN)\s+(.*)$/iu.exec(lines[0])
76
+ // A RUN's options (`--mount=…`, `--network=…`) aren't its command.
77
+ if (first?.[1].toUpperCase() === 'RUN') { script.push(runCommand(first[2].replace(/^(?:--[a-z-]+(?:=\S*)?\s+)*/iu, '')), ...lines.slice(1)); continue }
78
+ script.push(...lines.map(() => ''))
79
+ if (!first) continue
80
+ const words = lines.join(' ').replaceAll('\\', ' ').trim().split(/\s+/u).slice(1).filter(word => !word.startsWith('--'))
81
+ const [image, as, stage] = words
82
+ const built = image && stages.has(image.toLowerCase())
83
+ if (as?.toLowerCase() === 'as' && stage) stages.add(stage.toLowerCase())
84
+ if (!image || image === 'scratch' || built) continue
85
+ const read = readImage(image)
86
+ if (image.includes('$')) findings.push({ id: 'unpinned-image', severity: 'moderate', image, line: start + 1 })
87
+ else if (!read?.digest) findings.push({ ...imageFinding(image, read), line: start + 1 })
88
+ }
89
+ const run = { script: script.join('\n'), line: 1, start: 1 }
90
+ findings.push(...scriptFindings(run, { locked: () => false, installed: () => false, external: true, triggers: [] }))
91
+ return findings.toSorted((a, b) => a.line - b.line)
92
+ }
93
+
94
+ // How many major lines' releases a commit is looked for in.
95
+ const MAX_LINES = 10
96
+
97
+ async function repositoryOf(uses, source, owner) {
98
+ const info = await source.repo(uses.repo)
99
+ if (!info) return { info: null, findings: [{ id: 'repo-missing', severity: ownerKind(uses.repo, owner) === 'own' ? 'moderate' : 'critical' }] }
100
+ const findings = []
101
+ if (info.fullName.toLowerCase() !== uses.repo.toLowerCase()) findings.push({ id: 'repo-moved', severity: 'high', to: info.fullName })
102
+ if (info.fork) findings.push({ id: 'repo-fork', severity: 'low', parent: info.fork })
103
+ if (info.archived) findings.push({ id: 'repo-archived', severity: 'low' })
104
+ return { info, findings }
105
+ }
106
+
107
+ // Where `sha` is in the history (`default`, `release`, `branch`), `none`,
108
+ // `unknown` where not all could be looked in, or `missing`: each branch and
109
+ // release looked in once, from its commit.
110
+ async function reachable(source, info, sha, tags) {
111
+ const name = info.fullName, releases = newestOfLines(tags ?? []).slice(0, MAX_LINES)
112
+ if (releases.some(({ oid }) => oid === sha)) return 'release'
113
+ const head = await source.branch(name, info.defaultBranch)
114
+ const onDefault = await source.contains(name, head ?? info.defaultBranch, sha)
115
+ if (onDefault === null) return 'missing'
116
+ if (onDefault) return 'default'
117
+ const looked = new Set([head])
118
+ const contains = oid => !looked.has(oid) && looked.add(oid) && source.contains(name, oid, sha)
119
+ for (const { oid } of releases) if (await contains(oid)) return 'release'
120
+ const { branches, complete } = await source.branches(name)
121
+ for (const { oid } of branches) if (oid === sha || await contains(oid)) return 'branch'
122
+ return complete && tags !== null ? 'none' : 'unknown'
123
+ }
124
+
125
+ const tagsOn = (tags, commit) => tags?.filter(({ oid }) => oid === commit).map(({ tag }) => tag) ?? []
126
+
127
+ function tagFindings(ref, commit, tags) {
128
+ const version = tagVersion(ref)
129
+ if (!version) return [{ id: 'not-version', severity: 'moderate' }]
130
+ if (!tags) return []
131
+ const findings = []
132
+ const releases = versionsOf(tags).filter(other => ofLine(version, other.version))
133
+ if (version[2] === null && releases.length > 0 && !releases.some(({ oid }) => oid === commit)) findings.push({ id: 'tag-off-release', severity: 'high', release: releases[0].tag })
134
+ const latest = latestOf(tags)
135
+ if (latest && tagVersion(latest)[0] > version[0]) findings.push({ id: 'outdated', severity: 'low', latest })
136
+ return findings
137
+ }
138
+
139
+ // The ref a reference names, and whether a branch or a tag alone (`only`):
140
+ // HEAD, as a checkout with no ref names one, its default branch; a
141
+ // checkout's `refs/heads/…` and `refs/tags/…`.
142
+ function refNamed(uses, info) {
143
+ if (uses.ref === 'HEAD') return { ref: info.defaultBranch, only: 'branch' }
144
+ const qualified = /^refs\/(heads|tags)\/(.+)$/u.exec(uses.ref)
145
+ return qualified ? { ref: qualified[2], only: qualified[1] === 'heads' ? 'branch' : 'tag' } : { ref: uses.ref, only: null }
146
+ }
147
+
148
+ // A ref not a commit, resolved as GitHub resolves it, a tag before a branch,
149
+ // or as a checkout does (`checkout`), a branch before a tag; one named a
150
+ // branch or a tag alone as that alone.
151
+ async function refOf(uses, info, source, tags) {
152
+ const name = info.fullName, { ref, only } = refNamed(uses, info)
153
+ const [tagged, branched] = await Promise.all([only === 'branch' ? null : tags ? tags.find(each => each.tag === ref)?.oid ?? null : source.tag(name, ref),
154
+ only === 'tag' ? null : source.branch(name, ref)])
155
+ if (!tagged && !branched) return { commit: null, at: null, findings: [{ id: 'ref-missing', severity: 'moderate' }] }
156
+ const ambiguous = tagged && branched ? [{ id: 'ambiguous-ref', severity: 'high', branch: branched }] : []
157
+ if (!tagged || (branched && uses.checkout)) return { commit: branched, at: 'branch', findings: [...ambiguous, { id: 'branch-ref', severity: 'high' }] }
158
+ const findings = [...ambiguous, ...tagFindings(ref, tagged, tags)]
159
+ const where = await reachable(source, info, tagged, tags)
160
+ if (where === 'none') findings.push({ id: 'tag-off-branch', severity: 'low' })
161
+ return { commit: tagged, at: 'tag', findings }
162
+ }
163
+
164
+ // Whether the version or ref a comment names is a tag on the commit, a
165
+ // version with or without its `v`, or a major or minor tag's line.
166
+ function commentHolds(comment, named) {
167
+ const unprefixed = text => text.replace(/^v/u, ''), version = tagVersion(comment)
168
+ return named.some(tag => tag === comment || (isVersion(comment) && isVersion(tag) && unprefixed(tag) === unprefixed(comment))
169
+ || (version && version[2] === null && ofLine(version, tagVersion(tag))))
170
+ }
171
+
172
+ // Whether the branch a comment names has the commit in its history; null
173
+ // where it has no such branch, or GitHub no such commit.
174
+ async function onBranch(source, name, branch, commit) {
175
+ const head = await source.branch(name, branch)
176
+ return head === null ? null : head === commit || await source.contains(name, head, commit)
177
+ }
178
+
179
+ // A commit, looked for in the history where no tag names it, held to its
180
+ // comment: by a tag on it of the version or ref the comment names, else by
181
+ // a branch so named with it in its history (`# main`, or a `# v4` that is
182
+ // a branch). A ref named alone that no tag nor branch is named is a note,
183
+ // held to nothing.
184
+ async function pinnedOf(uses, info, source, tags) {
185
+ const commit = uses.ref, { comment } = uses
186
+ const commented = !tags && comment ? await source.tag(info.fullName, comment) : null
187
+ const named = commented === commit ? [comment] : tagsOn(tags, commit)
188
+ const findings = []
189
+ if (named.length === 0) {
190
+ const where = await reachable(source, info, commit, tags)
191
+ if (where === 'missing') findings.push({ id: 'commit-missing', severity: 'high' })
192
+ else if (where === 'none') findings.push({ id: 'imposter-commit', severity: 'critical' })
193
+ else if (where === 'unknown') findings.push({ id: 'unverified-commit', severity: 'high' })
194
+ else if (tags) findings.push({ id: 'untagged-commit', severity: 'moderate', on: where })
195
+ }
196
+ if (comment && !commentHolds(comment, named)) {
197
+ const branch = await onBranch(source, info.fullName, comment, commit)
198
+ const tagged = commented !== null || Boolean(tags?.some(({ tag }) => tag === comment))
199
+ if (branch === false || (branch === null && (isVersion(comment) || tagged))) {
200
+ findings.push({ id: 'comment-mismatch', severity: 'high', comment, tags: named, ...branch === false && { branch: comment } })
201
+ }
202
+ }
203
+ return { commit, at: 'sha', named, findings }
204
+ }
205
+
206
+ // The versions a reference's advisories are asked of, as upstream's `github`
207
+ // packages take them: the releases on the commit it runs (`v4.2.1`, not the
208
+ // `v4` moving with it), else a commit by its tags, or as any release where
209
+ // none names it, and a tag or a branch as named (a moving tag its whole line).
210
+ function advisedVersions(at, ref, commit, named) {
211
+ const releases = named.filter(tag => isRelease(tagVersion(tag)))
212
+ if (releases.length > 0) return releases
213
+ if (at === 'sha') return named.length > 0 ? named : [commit]
214
+ return [ref]
215
+ }
216
+
217
+ const RATED = new Set(['critical', 'high', 'moderate', 'low'])
218
+
219
+ // A repository's advisories at `versions` (`source.advisories`), each a
220
+ // finding: malware red, else as its source rates it, one unrated yellow. One
221
+ // not known public is `internal`, asked of its own advisories alone, its name
222
+ // sent to no other source; why not (`advisories-unavailable`) where they
223
+ // couldn't be had, the rest resolved all the same. Each with what tells it
224
+ // apart, as its row's tooltip shows it: its source, other ids, CVSS score,
225
+ // CWEs, the range it affects, whether its source rates it (`unrated`) and,
226
+ // where it is no vulnerability as such, what it is (`informational`); not
227
+ // its text, which its link has.
228
+ async function advisoryFindings(source, info, versions) {
229
+ if (source.advisories === undefined) return []
230
+ try {
231
+ return (await source.advisories(info.fullName, versions, info.private ?? true)).map(({ id, title, url, severity, malware, versions: affected, source: from,
232
+ aliases, cvss, cwe, range, informational }) => ({
233
+ id: 'advisory', severity: malware ? 'critical' : RATED.has(severity) ? severity : 'moderate', advisory: id, ...title && { title }, ...url && { url },
234
+ ...malware && { malware: true }, ...!malware && !RATED.has(severity) && { unrated: true }, versions: affected, ...from && { source: from }, ...aliases?.length && { aliases }, ...Number.isFinite(cvss) && { cvss },
235
+ ...cwe?.length && { cwe }, ...range && { range }, ...informational && { informational } }))
236
+ } catch { return [{ id: 'advisories-unavailable', severity: 'notice' }] }
237
+ }
238
+
239
+ // A `$/path` (the repository's own at the commit running) as a reference.
240
+ const selfRef = (uses, info, commit) => readUses(`${info.fullName}/${uses.path}@${commit}`, { job: isWorkflowPath(uses.path) })
241
+
242
+ // What a reference runs at `commit` (action.yml, a reusable workflow, a
243
+ // Dockerfile): its findings, each with its file, and the references it makes.
244
+ async function codeOf(uses, info, commit, source) {
245
+ const dir = uses.path ? `${uses.path}/` : '', name = info.fullName
246
+ const candidates = uses.kind === 'workflow' ? [uses.path] : [`${dir}action.yml`, `${dir}action.yaml`]
247
+ let file = null, text = null
248
+ for (const path of candidates) {
249
+ text = await source.file(name, path, commit)
250
+ if (text !== null) { file = path; break }
251
+ }
252
+ if (text === null) return { findings: [{ id: 'action-missing', severity: 'moderate' }], uses: [] }
253
+ const read = readWorkflow(uses.kind === 'workflow' ? 'workflow' : 'action', text)
254
+ if (read instanceof YamlError) return { findings: [{ id: 'unreadable', severity: 'moderate', file, detail: read.message }], uses: [] }
255
+ const findings = workflowFindings(read, { owner: name.split('/')[0], external: true }).map(finding => ({ ...finding, file }))
256
+ const dockerfile = read.dockerfile && `${dir}${read.dockerfile.path}`
257
+ const docker = dockerfile && !dockerfile.split('/').includes('..') ? await source.file(name, dockerfile, commit) : null
258
+ if (docker !== null) findings.push(...dockerfileFindings(docker).map(finding => ({ ...finding, file: dockerfile })))
259
+ const nested = workflowUses(read).map(each => each.kind === 'local' ? (each.self || each.job) && selfRef(each, info, commit) : each)
260
+ return { findings, uses: nested.filter(each => each?.kind === 'action' || each?.kind === 'workflow').map(usesKey) }
261
+ }
262
+
263
+ // A reference resolved (index.d.ts ResolvedAction); `owner`, whose workflow names it.
264
+ export async function resolveAction(uses, source, { owner = null } = {}) {
265
+ const at = { key: usesKey(uses), kind: uses.kind, repo: uses.repo, path: uses.path, ref: uses.ref }
266
+ const { info, findings } = await repositoryOf(uses, source, owner)
267
+ if (!info) return { ...at, repository: null, commit: null, at: null, tags: [], findings, uses: [] }
268
+ const tags = await source.tags(info.fullName)
269
+ const ref = uses.pin === 'sha' ? await pinnedOf(uses, info, source, tags) : await refOf(uses, info, source, tags)
270
+ const runs = ref.commit && !ref.findings.some(({ id }) => id === 'commit-missing')
271
+ // What it runs, and its advisories at the versions that is.
272
+ const [code, advised] = runs ? await Promise.all([codeOf(uses, info, ref.commit, source),
273
+ advisoryFindings(source, info, advisedVersions(ref.at, refNamed(uses, info).ref, ref.commit, ref.named ?? tagsOn(tags, ref.commit)))]) : [null, []]
274
+ return { ...at, repository: { fullName: info.fullName, private: Boolean(info.private) }, commit: ref.commit, at: ref.at, tags: tagsOn(tags, ref.commit),
275
+ findings: [...findings, ...ref.findings, ...advised, ...code?.findings ?? []], uses: code?.uses ?? [] }
276
+ }
277
+
278
+ // `source` with its answers kept, by what was asked, while held: a scan's.
279
+ export function keptSource(source) {
280
+ const kept = new Map()
281
+ const keep = method => (...args) => {
282
+ const key = `${method}\0${JSON.stringify(args)}`
283
+ if (!kept.has(key)) kept.set(key, source[method](...args).catch(error => { kept.delete(key); throw error }))
284
+ return kept.get(key)
285
+ }
286
+ return Object.fromEntries(['repo', 'tags', 'tag', 'branch', 'branches', 'contains', 'file', 'advisories'].filter(method => source[method]).map(method => [method, keep(method)]))
287
+ }
@@ -0,0 +1,182 @@
1
+ // What a `run:` script fetches and runs past what a lockfile or a digest pins,
2
+ // command by command (shell.js), each with its line in the script from 0.
3
+ import { NPM_INSTALLS, fetched, npmToolFinds, optionsOf, projectOf, valuesOf } from './packages.js'
4
+ import { pathFrom, scriptCommands, scriptLines } from './shell.js'
5
+ import { SHELLS as SHELL_NAMES } from '../../files/runs-code.js'
6
+ import { readImage } from '../uses.js'
7
+
8
+ // A program's file name, lowercase, past its directory and a Windows extension.
9
+ const programOf = word => (word ?? '').split(/[/\\]/u).at(-1).toLowerCase().replace(/\.(?:cmd|exe|bat|ps1)$|@[\w.-]*$/u, '')
10
+
11
+ const SHELLS = new RegExp(String.raw`^(?:${SHELL_NAMES}|python[\d.]*|node|perl|ruby|php|iex|invoke-expression)$`, 'u')
12
+ const FETCHERS = /^(?:curl|wget|irm|iwr|invoke-restmethod|invoke-webrequest)$/u
13
+ // A script fetched and run on one line: `<(curl …)`, `-c "$(curl …)"`, `iex (irm …)`.
14
+ const FETCHED_AND_RUN = [
15
+ /\b(?:(?:ba|z|da|k)?sh|source|\.)\s+(?:-\S+\s+)*<\(\s*(?:curl|wget)\b/iu,
16
+ /\b(?:(?:ba|z|da|k)?sh|python[\d.]*|node|perl|ruby)\s+(?:-\S+\s+)*-c\s+["']?\$\(\s*(?:curl|wget)\b/iu,
17
+ /\b(?:iex|invoke-expression)\b[^|;]*\b(?:irm|iwr|invoke-restmethod|invoke-webrequest|downloadstring)\b/iu,
18
+ ]
19
+
20
+ // The file curl or wget saves to (`-o f`, `-of`, `--output f`, curl's `-O`,
21
+ // wget's by its URL), or PowerShell's (`-OutFile f`); else null.
22
+ function savedTo(program, argv) {
23
+ for (let at = 1; at < argv.length; at++) {
24
+ const outFile = /^-outfile(?::(.+))?$/iu.exec(argv[at]), word = argv[at]
25
+ if (outFile && !/^(?:curl|wget)$/u.test(program)) return outFile[1] ?? argv[at + 1] ?? null
26
+ const attached = { curl: /^-[a-zA-Z]*o(.+)$/u, wget: /^-[a-zA-Z]*O(.+)$/u }[program]?.exec(word)
27
+ if (attached) return attached[1] === '-' ? null : attached[1]
28
+ if (program === 'curl' && (/^-[a-zA-Z]*o$/u.test(word) || word === '--output')) return argv[at + 1] ?? null
29
+ if (program === 'wget' && (/^-[a-zA-Z]*O$/u.test(word) || word === '--output-document')) return argv[at + 1] === '-' ? null : argv[at + 1] ?? null
30
+ const joined = /^(?:--output|--output-document)=(.+)$/u.exec(word)
31
+ if (joined) return joined[1]
32
+ }
33
+ const url = program === 'wget' || (program === 'curl' && argv.some(word => /^-[a-zA-Z]*O[a-zA-Z]*$/u.test(word) || word === '--remote-name')) ? argv.find(word => /^https?:\/\//u.test(word)) : null
34
+ return url ? URL.parse(url)?.pathname.split('/').at(-1) || null : null
35
+ }
36
+
37
+ // A path from the current directory, its `./` (PowerShell's `.\`, its `\`
38
+ // read as an escape) taken off.
39
+ const local = path => path.replace(/^\.\/?/u, '')
40
+
41
+ // Whether a command runs `file`, as a program or a shell's script.
42
+ function runsFile({ argv }, file) {
43
+ if (local(argv[0]) === local(file) || argv[0] === file) return true
44
+ return (SHELLS.test(programOf(argv[0])) || argv[0] === 'source' || argv[0] === '.') && argv.slice(1).some(word => local(word) === local(file))
45
+ }
46
+
47
+ const pythonPackage = text => {
48
+ if (/^(?:git\+|https?:|file:|\.{0,2}\/)/iu.test(text)) return { name: text, spec: null, exact: /@[\da-f]{40}(?:#|$)/u.test(text), registry: false }
49
+ const m = /^([\w.-]+)(?:\[[^\]]*\])?\s*(.*)$/u.exec(text)
50
+ return m && { name: m[1], spec: m[2] || null, exact: /^===?\s*[\w.!+-]+$/u.test(m[2]), registry: true }
51
+ }
52
+
53
+ // The packages pip installs by name, not a requirements file's or a path.
54
+ const PIP_VALUED = /^(?:-r|--requirement|-c|--constraint|-e|--editable|-i|--index-url|--extra-index-url|-t|--target|--prefix|--root|-f|--find-links)$/u
55
+ const pip = (tool, argv, from) => optionsOf(argv, from, PIP_VALUED).operands.filter(word => !/^\.{1,2}(?:\/|$)/u.test(word))
56
+ .flatMap(text => fetched(tool, pythonPackage(text), { ecosystem: 'pypi' }))
57
+ // A package named `name@version`, as Go's, crates' and Deno's are.
58
+ const atVersion = (text, exact) => {
59
+ const at = text.lastIndexOf('@')
60
+ const spec = at > 0 ? text.slice(at + 1) : null
61
+ return { name: at > 0 ? text.slice(0, at) : text, spec, exact: spec !== null && exact(spec), registry: true }
62
+ }
63
+
64
+ function python(program, argv) {
65
+ if (program === 'pip' || /^pip\d/u.test(program)) return argv[1] === 'install' ? pip(program, argv, 2) : []
66
+ if (/^python[\d.]*$/u.test(program) && argv[1] === '-m' && /^pip\d?$/u.test(argv[2] ?? '') && argv[3] === 'install') return pip(`${program} -m pip`, argv, 4)
67
+ if (program === 'uv' && argv[1] === 'pip' && argv[2] === 'install') return pip('uv pip', argv, 3)
68
+ if (program === 'uvx' || (program === 'uv' && argv[1] === 'tool' && /^(?:run|install)$/u.test(argv[2] ?? ''))) {
69
+ const options = optionsOf(argv, program === 'uvx' ? 1 : 3, /^--(?:from|python|with)$/u), [spec] = [...valuesOf(options, '--from'), ...options.operands]
70
+ return fetched(program === 'uvx' ? 'uvx' : `uv tool ${argv[2]}`, spec && pythonPackage(spec), { ecosystem: 'pypi' })
71
+ }
72
+ if (program === 'pipx' && /^(?:run|install)$/u.test(argv[1] ?? '')) {
73
+ const options = optionsOf(argv, 2, /^--(?:spec|python)$/u), [spec] = [...valuesOf(options, '--spec'), ...options.operands]
74
+ return fetched(`pipx ${argv[1]}`, spec && pythonPackage(spec), { ecosystem: 'pypi' })
75
+ }
76
+ return []
77
+ }
78
+
79
+
80
+ const EXACT_SEMVER = text => /^=?\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/u.test(text)
81
+
82
+ // `go install x@v y@v`, `go run x@v`, a version held to Go's checksum database.
83
+ function go(argv) {
84
+ const { operands } = optionsOf(argv, 2, /^-(?:o|modfile|tags|ldflags|gcflags|C|exec)$/u)
85
+ return (argv[1] === 'run' ? operands.slice(0, 1) : operands).filter(target => target.includes('@'))
86
+ .flatMap(target => fetched(`go ${argv[1]}`, atVersion(target, spec => /^v\d+\.\d+\.\d+/u.test(spec)), { ecosystem: 'go' }))
87
+ }
88
+
89
+ // `cargo install`: each crate by its version, or a repository by its commit;
90
+ // `locked` with `--locked`.
91
+ function cargo(argv) {
92
+ if (argv.includes('--path')) return []
93
+ const options = optionsOf(argv, 2, /^--(?:version|git|branch|rev|tag|root|features|registry|index|bin|example|target|profile|jobs)$|^-[jF]$/u)
94
+ const [git = null] = valuesOf(options, '--git'), [version = null] = valuesOf(options, '--version'), [ref = null] = valuesOf(options, '--rev', '--tag', '--branch')
95
+ const specs = git ? [{ name: git, spec: ref, exact: /^[\da-f]{40}$/u.test(valuesOf(options, '--rev')[0] ?? ''), registry: false }] : options.operands.map(crate => atVersion(crate, EXACT_SEMVER))
96
+ return specs.flatMap(spec => fetched(`cargo ${argv[1]}`, { ...spec, spec: spec.spec ?? version, exact: spec.exact || (!git && EXACT_SEMVER(version ?? '')), locked: argv.includes('--locked') }, { ecosystem: 'crates' }))
97
+ }
98
+
99
+ // `gem install x [-v 1.2.3]`.
100
+ function gem(argv) {
101
+ const options = optionsOf(argv, 2, /^(?:-v|--version|-i|--install-dir|-s|--source|-n|--bindir)$/u), [version = null] = valuesOf(options, '-v', '--version')
102
+ return options.operands.flatMap(name => fetched('gem install', { name, spec: version, exact: /^=?\s*\d+(?:\.\d+)+$/u.test(version ?? ''), registry: true }, { ecosystem: 'rubygems' }))
103
+ }
104
+
105
+ // `deno run|install|x` of a URL or a registry's package.
106
+ function deno(argv) {
107
+ const target = argv.slice(2).find(word => /^(?:https?:\/\/|npm:|jsr:)/u.test(word))
108
+ if (!target) return []
109
+ return fetched(`deno ${argv[1]}`, /^(?:npm|jsr):/u.test(target) ? atVersion(target.replace(/^(?:npm|jsr):/u, ''), EXACT_SEMVER)
110
+ : { name: target, spec: null, exact: /@v?\d+\.\d+\.\d+/u.test(target), registry: false }, { ecosystem: 'deno' })
111
+ }
112
+
113
+ function others(program, argv) {
114
+ if (program === 'go' && /^(?:install|run)$/u.test(argv[1] ?? '')) return go(argv)
115
+ if (program === 'cargo' && /^(?:install|binstall)$/u.test(argv[1] ?? '')) return cargo(argv)
116
+ if (program === 'gem' && argv[1] === 'install') return gem(argv)
117
+ return program === 'deno' && /^(?:run|install|x|compile)$/u.test(argv[1] ?? '') ? deno(argv) : []
118
+ }
119
+
120
+ // What a command fetches or runs unpinned, but a script fetched and run.
121
+ function commandFinds(command) {
122
+ const { argv } = command
123
+ const program = programOf(argv[0])
124
+ if (/^(?:docker|podman)$/u.test(program) && /^(?:run|pull|create)$/u.test(argv[1] ?? '')) {
125
+ const image = argv.slice(2).find((word, at, words) => !word.startsWith('-') && !/^(?:-[evpwulhm]|--(?:env|volume|publish|workdir|user|label|hostname|memory|name|network|entrypoint|platform|mount|env-file|cpus|add-host|cap-add|device|dns|gpus|ipc|pid|restart|runtime|pull|security-opt|shm-size|tmpfs|ulimit|volumes-from|log-driver))$/u.test(words[at - 1] ?? ''))
126
+ return image ? [{ kind: 'image', text: image, read: readImage(image) }] : []
127
+ }
128
+ if (program === 'git' && argv[1] === 'clone') return [{ kind: 'clone', url: argv.slice(2).find(word => /^(?:https?:|git@|git:|ssh:)/u.test(word)) ?? null }]
129
+ return [...npmToolFinds(program, argv), ...python(program, argv), ...others(program, argv)]
130
+ }
131
+
132
+ const INSTALLS = { npm: new RegExp(`^(?:ci|clean-install|ic|install-clean|${NPM_INSTALLS})$`, 'u'), pnpm: /^(?:i|install|add)$/u, bun: /^(?:i|install|add)$/u }
133
+ // An install's options that leave the project's node_modules as they are.
134
+ const NOT_LOCAL = /^(?:-g|--location=global|--(?:global|package-lock-only|lockfile-only|dry-run)(?:=true)?)$/u
135
+
136
+ // A script's installs of a project's packages: each one's `order`, the
137
+ // directory it installs into, by its `cd`s and the one it names (`into`, a
138
+ // path from the step's, '' for it), and whether it leaves devDependencies out
139
+ // (`prod`), by an option or NODE_ENV production (the step's `production`).
140
+ export function installsOf(script, production = false) {
141
+ const found = []
142
+ let exported = production
143
+ for (const { argv, dir, env, order } of scriptCommands(script)) {
144
+ const program = programOf(argv[0])
145
+ if (program === 'export') for (const word of argv) if (word.startsWith('NODE_ENV=')) exported = word === 'NODE_ENV=production'
146
+ const options = optionsOf(argv, 1), [command] = options.operands
147
+ if (argv.some(word => NOT_LOCAL.test(word)) || !(program === 'yarn' ? command === undefined || command === 'install' : INSTALLS[program]?.test(command ?? ''))) continue
148
+ // npm installs what `--include` names whatever leaves it out.
149
+ const prod = !valuesOf(options, '--include').includes('dev') && (valuesOf(options, '--omit').includes('dev') || /^prod(?:uction)?$/u.test(valuesOf(options, '--only')[0] ?? '')
150
+ || argv.some(word => /^--prod(?:uction)?$/u.test(word)) || (env.NODE_ENV ?? (exported ? 'production' : '')) === 'production')
151
+ const project = projectOf(argv)
152
+ found.push({ order, into: project === null ? dir : pathFrom(dir, project), prod })
153
+ }
154
+ return found
155
+ }
156
+
157
+ // A script's line, as a finding names what it runs, cut short.
158
+ const excerpt = text => { const trimmed = text.trim().replaceAll(/\s+/gu, ' '); return trimmed.length > 120 ? `${trimmed.slice(0, 119)}…` : trimmed }
159
+
160
+ // Everything a script fetches and runs past a pin, in its order.
161
+ export function scriptFinds(script) {
162
+ const found = []
163
+ const lines = new Map(scriptLines(script).map(({ text, line }) => [line, text]))
164
+ for (const [line, text] of lines) {
165
+ if (FETCHED_AND_RUN.some(pattern => pattern.test(text))) found.push({ kind: 'remote-script', line, command: excerpt(text) })
166
+ }
167
+ const saved = new Map()
168
+ for (const command of scriptCommands(script)) {
169
+ const program = programOf(command.argv[0])
170
+ if (FETCHERS.test(program) && command.pipedTo.some(each => SHELLS.test(programOf(each.argv[0])))) found.push({ kind: 'remote-script', line: command.line, command: excerpt(lines.get(command.line) ?? '') })
171
+ const file = FETCHERS.test(program) ? savedTo(program, command.argv) ?? command.out : null
172
+ if (file) saved.set(file, command.line)
173
+ for (const [name, at] of saved) {
174
+ if (FETCHERS.test(program) || !runsFile(command, name)) continue
175
+ found.push({ kind: 'remote-script', line: command.line, command: excerpt(lines.get(at) ?? '') })
176
+ saved.delete(name)
177
+ }
178
+ for (const each of commandFinds(command)) found.push({ ...each, line: command.line, order: command.order, dir: command.dir })
179
+ }
180
+ const told = new Set()
181
+ return found.filter(({ order: _order, ...each }) => { const key = JSON.stringify(each); return !told.has(key) && told.add(key) }).toSorted((a, b) => a.line - b.line)
182
+ }