@preventive/triage 1.0.0-alpha.9 → 1.0.0-alpha.90
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.
- package/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +378 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +80 -0
- package/common/default-scan-models.ts +37 -0
- package/common/dependency-reviews.d.ts +19 -0
- package/common/dependency-reviews.js +67 -0
- package/common/finding-duplicates.js +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +3 -0
- package/common/github-issue-labels.js +42 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +15 -0
- package/common/line-diff.js +188 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +48 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +386 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/npm-token.d.ts +2 -0
- package/common/npm-token.js +14 -0
- package/common/pretty-json.js +123 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +7 -0
- package/common/pretty-print.js +41 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-3DOSBILK.js +4 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5PWEAEA5.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-BZJU5EEV.js +1 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CJVMNJDZ.js +3 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-ESXA7KID.js +1 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-HGWFRZNC.js +267 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JZAROLQT.js +40 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-KP2XM324.js +6 -0
- package/out/chunk-LRWB6QVO.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RAM3GDAD.js +1 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SMNFBOLO.js +10 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZTCJVZJ.js +55 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TKPNRQNN.js +3 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-UTYWTUTC.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-WBK5ZN4K.js +3 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-XRAAYXPR.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +35 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -5
- package/out/index.html +105 -25
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -148
- package/package.json +416 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +354 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +568 -0
- package/risk/files/script.js +420 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +309 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +303 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +401 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +52 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +3 -3
- package/{server → server-e2e}/static.ts +18 -17
- package/{server → server-e2e}/sync-handlers.ts +56 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +269 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +21 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +176 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +387 -0
- package/server-managed/bundle-build.ts +328 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1950 -0
- package/server-managed/db-neon.ts +401 -0
- package/server-managed/db-schema.ts +271 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +150 -0
- package/server-managed/dependabot-access.ts +85 -0
- package/server-managed/dependabot-alerts.ts +197 -0
- package/server-managed/dependency-review-comments.ts +158 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +169 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +218 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +290 -0
- package/server-managed/github-requests.ts +181 -0
- package/server-managed/github-users.ts +53 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +6722 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/known-listings.ts +112 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +203 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +274 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +477 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +457 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +310 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +4 -0
- package/server-managed/pretty-format.js +27 -0
- package/server-managed/pretty-print.ts +444 -0
- package/server-managed/public-workspace.ts +242 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +458 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/pulse-walk.ts +164 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +362 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +220 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +444 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +409 -0
- package/server-managed/repository-risk-assess.ts +179 -0
- package/server-managed/repository-risk-audit.ts +145 -0
- package/server-managed/repository-risk-caches.ts +56 -0
- package/server-managed/repository-risk-kept.ts +86 -0
- package/server-managed/repository-risk-read.ts +296 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +528 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +280 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +57 -0
- package/server-managed/team-app.ts +162 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-icons.ts +50 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-progress.ts +77 -0
- package/server-managed/team-reports.ts +369 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +181 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +275 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
package/risk/index.d.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// Hand-written against index.js; a change to either belongs with the other.
|
|
2
|
+
import type { CacheStore } from '@preventive/upstream/npm.js'
|
|
3
|
+
import type { Client } from '@preventive/upstream/github.js'
|
|
4
|
+
import type { Entry } from '@preventive/archive/tar.js'
|
|
5
|
+
|
|
6
|
+
// How severe a stamp or a finding is, the most first: `critical` red, `high`
|
|
7
|
+
// a warning's orange, `moderate` yellow, `low`, and a `notice`.
|
|
8
|
+
export type Severity = 'critical' | 'high' | 'moderate' | 'low' | 'notice'
|
|
9
|
+
|
|
10
|
+
// The severities, the most severe first.
|
|
11
|
+
export const SEVERITIES: readonly Severity[]
|
|
12
|
+
|
|
13
|
+
// How old a version must be to be trusted unless said: two weeks, in ms.
|
|
14
|
+
export const DEFAULT_MINIMUM_RELEASE_AGE: number
|
|
15
|
+
|
|
16
|
+
// npm has no such package or version (`package-not-found`,
|
|
17
|
+
// `version-not-found`), a tarball unpacks past risk's bounds
|
|
18
|
+
// (`package-too-large`) or would install other than one set of files
|
|
19
|
+
// (`tarball-conflict`, npmTarLayout), npm asked to be asked later
|
|
20
|
+
// (`upstream-busy`, a 429, for a caller to wait on and ask again), or npm
|
|
21
|
+
// couldn't be asked (`upstream-unavailable`), answered past them
|
|
22
|
+
// (`upstream-too-large`) or answered what can't be read (`upstream-invalid`).
|
|
23
|
+
// `message` tells which request and why.
|
|
24
|
+
export class NpmRiskError extends Error {
|
|
25
|
+
code: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface AssessNpmOptions {
|
|
29
|
+
// The version to compare with; true for the one of the package's versions
|
|
30
|
+
// most likely free of what an attack injects, as risk picks it by npm's
|
|
31
|
+
// document (risk/npm/old-version.js), none where none is below it; without
|
|
32
|
+
// one, everything of the version is new.
|
|
33
|
+
oldVersion?: string | true | null
|
|
34
|
+
// Compare all files with an empty package, for an initial dependency review.
|
|
35
|
+
fromEmpty?: boolean
|
|
36
|
+
// Younger than this, in ms, a version is `too-new`; 0 for none, as a
|
|
37
|
+
// caller's own scopes take. Two weeks unless given.
|
|
38
|
+
minimumReleaseAge?: number
|
|
39
|
+
// Whether the package is flagged as few download it (`popularity`); false
|
|
40
|
+
// for none, as a caller's own scopes take, its downloads then not asked.
|
|
41
|
+
// True unless given.
|
|
42
|
+
popularity?: boolean
|
|
43
|
+
// Where what is read is kept, by type (risk/npm/registry.js and assess.js
|
|
44
|
+
// name each): `npm/tarballs`, `risk/npm/versions`, `risk/npm/packages`,
|
|
45
|
+
// `risk/npm/old-versions`, `risk/npm/public`, `risk/npm/downloads`,
|
|
46
|
+
// `risk/npm/advisories` and `risk/npm/assessments`. One that reads records
|
|
47
|
+
// of any types at once (`readEach`, each null where none is kept) is read
|
|
48
|
+
// so where risk reads several together.
|
|
49
|
+
cache?: (CacheStore & { readEach?(entries: [type: string, key: string][]): Promise<unknown[]> }) | false
|
|
50
|
+
// Asks for a package's whole document in risk's stead, as the managed
|
|
51
|
+
// server does within its bounds: null where npm has none for this asker.
|
|
52
|
+
// `authorized` whether it may be asked with the caller's npm token: the
|
|
53
|
+
// package assessed, not its dependencies.
|
|
54
|
+
packument?: (name: string, options: { authorized: boolean; signal: AbortSignal | undefined }) => Promise<Record<string, unknown> | null>
|
|
55
|
+
// Reads a version's tarball, gzipped, in place of upstream's getTarball, as
|
|
56
|
+
// the managed server does within its bounds: `version` the one assessed or
|
|
57
|
+
// `oldVersion`, that one only where its files could change what is found.
|
|
58
|
+
// What it throws is thrown as it is.
|
|
59
|
+
tarball?: (name: string, version: string, options: { signal: AbortSignal | undefined }) => Promise<Uint8Array>
|
|
60
|
+
now?: number
|
|
61
|
+
signal?: AbortSignal
|
|
62
|
+
// Whether npm's downloads are asked for: the package's popularity, and its
|
|
63
|
+
// new dependencies' tiers and ages. True unless given.
|
|
64
|
+
downloads?: boolean
|
|
65
|
+
// Whether its new dependencies' tiers and ages are asked for, a request or
|
|
66
|
+
// two of npm each, where `downloads` is. True unless given.
|
|
67
|
+
dependencies?: boolean
|
|
68
|
+
// Whether npm's advisories of the version are asked for, an advisory of
|
|
69
|
+
// malware naming it a `malware` finding, as its package taken down by npm
|
|
70
|
+
// is. True unless given.
|
|
71
|
+
advisories?: boolean
|
|
72
|
+
// Whether OSV's records of malware in the version are asked for too, where
|
|
73
|
+
// `advisories` are: false for a private package, whose name OSV is never
|
|
74
|
+
// to be sent, as upstream sends it none npm's registry doesn't serve
|
|
75
|
+
// anyone. True unless given.
|
|
76
|
+
osv?: boolean
|
|
77
|
+
// A client of upstream's (its github.js createClient): with `advisories`,
|
|
78
|
+
// those the version's GitHub repository publishes count too, its listing
|
|
79
|
+
// kept in `cache` (`github/advisories`, and `npm/public`, upstream's own).
|
|
80
|
+
// Where GitHub fails to give it, npm's alone. None unless given.
|
|
81
|
+
github?: Client | null
|
|
82
|
+
// Whether a package is the caller's own, as its own scopes take: a new
|
|
83
|
+
// dependency on one is told no tier nor age, nor is npm asked of it. None
|
|
84
|
+
// unless given.
|
|
85
|
+
owned?: (name: string) => boolean | Promise<boolean>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// What calls for a look, by `id`, with what it found beside.
|
|
89
|
+
export interface Finding {
|
|
90
|
+
id: string
|
|
91
|
+
severity: Severity
|
|
92
|
+
[found: string]: unknown
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A stamp on a file, as a list of files tags it.
|
|
96
|
+
export interface Stamp {
|
|
97
|
+
name: string
|
|
98
|
+
severity: Severity
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface FileRisk {
|
|
102
|
+
stamps: Stamp[]
|
|
103
|
+
readability: Record<string, unknown>
|
|
104
|
+
runsCode: Record<string, number[]> | null
|
|
105
|
+
exfiltration: Record<string, number[]> | null
|
|
106
|
+
hosts: Record<string, number> | null
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface DependencyRisk {
|
|
110
|
+
key: string
|
|
111
|
+
name: string
|
|
112
|
+
kind: 'peer' | 'optional' | null
|
|
113
|
+
range?: string
|
|
114
|
+
from?: string
|
|
115
|
+
to?: string
|
|
116
|
+
opens: string | null
|
|
117
|
+
flags: { check: string; label: string; tooltip: string }[]
|
|
118
|
+
tier?: number | null
|
|
119
|
+
level?: string
|
|
120
|
+
// Its last whole month's downloads, by what its tier goes by: none where
|
|
121
|
+
// npm counts none of them.
|
|
122
|
+
month?: { total: number; from: string }
|
|
123
|
+
// Whether npm counts none of its downloads, as of a package published
|
|
124
|
+
// the day before; unpopular all the same.
|
|
125
|
+
uncounted?: true
|
|
126
|
+
created?: string
|
|
127
|
+
gap?: number
|
|
128
|
+
// For one nothing imports, the version its spec installs (registry.js
|
|
129
|
+
// npmPublicFacts): its package's latest beside it, when it was published,
|
|
130
|
+
// whether it has install scripts, and whether that was since the version
|
|
131
|
+
// compared with (`new`).
|
|
132
|
+
installs?: { version: string; latest: string | null; published: string | null; scripts: boolean; new: boolean }
|
|
133
|
+
// Where its package was looked up and npm has none of it for anyone.
|
|
134
|
+
missing?: true
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// A version's risk as one number (risk/npm/score.js): what its findings call
|
|
138
|
+
// for (`raised`, each it counts), each by its severity, malware all of it,
|
|
139
|
+
// lowered by its exposure (`lowered`): how long it has been out (`days`)
|
|
140
|
+
// among how many download its package (`tier`, its rank, null past the last
|
|
141
|
+
// or where unknown), `by` the share taken off. Its `level` is named as the
|
|
142
|
+
// findings' severities are: from 75 critical, 50 high, 25 moderate, else low.
|
|
143
|
+
export interface RiskScore {
|
|
144
|
+
score: number
|
|
145
|
+
level: 'critical' | 'high' | 'moderate' | 'low'
|
|
146
|
+
raised: { id: string; severity: Severity }[]
|
|
147
|
+
lowered?: { days: number; tier: number | null; by: number }
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface NpmAssessment {
|
|
151
|
+
name: string
|
|
152
|
+
version: string
|
|
153
|
+
// The version compared with, as given or as risk picked it; null for none.
|
|
154
|
+
oldVersion: string | null
|
|
155
|
+
published: string | null
|
|
156
|
+
// A version npm removed, as it removes every one it finds malware in, told
|
|
157
|
+
// of by its `malware` finding alone, with no files nor dependencies.
|
|
158
|
+
removed?: true
|
|
159
|
+
findings: Finding[]
|
|
160
|
+
files: Record<string, FileRisk>
|
|
161
|
+
// Against `oldVersion`, each it holds too, flagged against none (`held`).
|
|
162
|
+
dependencies: { added: DependencyRisk[]; changed: DependencyRisk[]; held?: DependencyRisk[] }
|
|
163
|
+
score: RiskScore
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function assessNpm(name: string, version: string, options?: AssessNpmOptions): Promise<NpmAssessment>
|
|
167
|
+
|
|
168
|
+
// The `malware` finding of a version alone, as assessNpm finds it: its
|
|
169
|
+
// package taken down by npm, and npm's advisories of malware naming it,
|
|
170
|
+
// OSV's too where `osv` is (true unless given false), and with `github` its
|
|
171
|
+
// repository's, read and kept as assessNpm reads and keeps them, none of its
|
|
172
|
+
// files nor its dependencies read; null where neither tells of any. Throws
|
|
173
|
+
// an NpmRiskError as assessNpm does where npm has no such package or version
|
|
174
|
+
// (nor malware explaining one removed), or can't be asked.
|
|
175
|
+
export function npmMalware(name: string, version: string, options?: Pick<AssessNpmOptions, 'cache' | 'packument' | 'now' | 'signal' | 'osv' | 'github'>): Promise<Finding | null>
|
|
176
|
+
|
|
177
|
+
// Readies, at once, the downloads assessNpm asks of each of these packages
|
|
178
|
+
// that can be, kept in `cache` as it keeps them, so that their assessments
|
|
179
|
+
// ask npm none: those kept within a week, and unscoped ones, asked of npm 128
|
|
180
|
+
// at a time. `ready` is told each once its downloads are kept; the rest (scoped
|
|
181
|
+
// ones, which npm answers only one by one) are left for npmReadyDownload.
|
|
182
|
+
// npm asking to be asked later is thrown as an NpmRiskError
|
|
183
|
+
// (`upstream-busy`), those readied by then told.
|
|
184
|
+
// A cache that reads and writes many at once too (`readMany`, `writeMany`)
|
|
185
|
+
// is read once and written once a lookup.
|
|
186
|
+
export function npmReadyDownloads(names: string[], ready: (name: string) => void, options: { cache: CacheStore & {
|
|
187
|
+
readMany?(type: string, keys: string[]): Promise<Map<string, unknown>>
|
|
188
|
+
writeMany?(type: string, entries: [key: string, value: unknown][]): Promise<void>
|
|
189
|
+
}; signal?: AbortSignal; now?: number }): Promise<void>
|
|
190
|
+
|
|
191
|
+
// Readies the downloads assessNpm asks of a package, asked of npm on their
|
|
192
|
+
// own where they aren't kept; npm asking to be asked later thrown as an
|
|
193
|
+
// NpmRiskError (`upstream-busy`).
|
|
194
|
+
export function npmReadyDownload(name: string, options: { cache: CacheStore; signal?: AbortSignal; now?: number }): Promise<void>
|
|
195
|
+
|
|
196
|
+
// Whether an advisory is of malware rather than a vulnerability: OSV's of a
|
|
197
|
+
// malicious package (`MAL-…`), or one such a record names (its `aliases`),
|
|
198
|
+
// CWE-506, embedded malicious code, whatever its title, or a title naming
|
|
199
|
+
// malware. The rule @preventive/upstream's advisories tell `malware` by, for
|
|
200
|
+
// those it doesn't tell, as Dependabot's alerts.
|
|
201
|
+
export function npmMalwareAdvisory(advisory: { id?: string | undefined; aliases?: readonly string[] | undefined; cwe?: readonly string[] | undefined; title?: string | undefined }): boolean
|
|
202
|
+
|
|
203
|
+
export function npmFileRisk(path: string, text: string | null, bytes?: number, script?: boolean): unknown
|
|
204
|
+
|
|
205
|
+
// How many levels up a package's symlinks may point: any (npm/tarball.js).
|
|
206
|
+
export const NPM_SYMLINKS_ABOVE: number
|
|
207
|
+
|
|
208
|
+
// The folds macOS or Windows may take two paths as one under (npm/tarball.js).
|
|
209
|
+
export const NPM_PATH_FOLDS: readonly ((path: string) => string)[]
|
|
210
|
+
|
|
211
|
+
// Every file a tar archive's entries hold, by package path, as npm and pnpm
|
|
212
|
+
// lay them out (npm/tarball.js): each entry's name as stored past its first
|
|
213
|
+
// component, whatever that is, and a file under no directory at its name, as
|
|
214
|
+
// pnpm installs it; a hard link is the file it names again, a symlink its
|
|
215
|
+
// target as stored (`link`), a file with an execute bit `executable`. `refuse` is called, and throws, with
|
|
216
|
+
// `tarball-conflict` where the files conflict (two at one path that differ,
|
|
217
|
+
// or at two paths one on macOS or Windows unless `foldPaths` is false, a
|
|
218
|
+
// file within another), and with `package-too-large` past `maxFiles` files or
|
|
219
|
+
// `maxBytes` bytes.
|
|
220
|
+
export function npmTarLayout(entries: Iterable<Pick<Entry, 'name' | 'storedName' | 'type' | 'data' | 'linkname' | 'mode'>>,
|
|
221
|
+
reading: { maxFiles: number; maxBytes: number; foldPaths?: boolean },
|
|
222
|
+
refuse: (code: 'tarball-conflict' | 'package-too-large') => never): Map<string, { bytes: Uint8Array; link?: string; executable?: true }>
|
|
223
|
+
|
|
224
|
+
// GitHub Actions (actions/), a workflow GitHub can't run thrown as
|
|
225
|
+
// @preventive/lockfile's YamlError. A finding of a workflow's, its `line` from 1; of a reference's own code,
|
|
226
|
+
// with the `file` it is in.
|
|
227
|
+
export interface ActionsFinding extends Finding {
|
|
228
|
+
line?: number | null
|
|
229
|
+
file?: string
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// What a `uses:` names: an action's or a reusable workflow's, by its `key`,
|
|
233
|
+
// or the repository's own. `checkout`, a ref a checkout put a `./` action
|
|
234
|
+
// at, looked for as a branch before a tag.
|
|
235
|
+
export type ActionUses = { kind: 'action' | 'workflow'; uses: string; repo: string; path: string; ref: string; pin: 'sha' | 'short-sha' | 'ref' | 'expression'; comment: string | null; checkout?: true; key?: string; line?: number | null }
|
|
236
|
+
export type Uses = ActionUses | { kind: 'local'; uses: string; path: string; self?: true; job?: true; line?: number | null }
|
|
237
|
+
|
|
238
|
+
export interface ScanOptions {
|
|
239
|
+
// Whose repository it is, as an unpinned `uses:` of its owner's is yellow.
|
|
240
|
+
owner?: string | null
|
|
241
|
+
// Its lockfiles' paths, the packages each locks, as npx runs those, by
|
|
242
|
+
// name and by `name@version`, and those only devDependencies need.
|
|
243
|
+
lockfiles?: { path: string; names: ReadonlySet<string>; dev?: ReadonlySet<string> }[]
|
|
244
|
+
// Its own actions' metadata by their directories, and its workflows by
|
|
245
|
+
// their paths: for where its actions install its packages, else each
|
|
246
|
+
// counts as installing them anywhere; and for the inputs its actions and
|
|
247
|
+
// reusable workflows write into their scripts, else each of a reusable
|
|
248
|
+
// workflow's counts as one.
|
|
249
|
+
actions?: ReadonlyMap<string, string> | null
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export type WorkflowScan = { uses: Uses[]; findings: ActionsFinding[] } | { error: 'workflow-unreadable'; detail: string }
|
|
253
|
+
|
|
254
|
+
export function scanWorkflow(kind: 'workflow' | 'action', text: string, options?: ScanOptions): WorkflowScan
|
|
255
|
+
// The actions of the repository's own a workflow or an action uses, by
|
|
256
|
+
// their directories, and a Docker action's Dockerfile, from its own.
|
|
257
|
+
export function ownFilesOf(kind: 'workflow' | 'action', text: string): { actions: string[]; dockerfile: string | null }
|
|
258
|
+
// A Dockerfile's findings, each on its line.
|
|
259
|
+
export function dockerfileFindings(text: string): ActionsFinding[]
|
|
260
|
+
// A reference by its key, as a scan names it; null for none.
|
|
261
|
+
export function usesOfKey(key: string): ActionUses | null
|
|
262
|
+
|
|
263
|
+
// GitHub as the asker can read it; null for none.
|
|
264
|
+
export interface ActionsSource {
|
|
265
|
+
// Its name now, where it moved, and the repository it forks.
|
|
266
|
+
repo(name: string): Promise<{ fullName: string; defaultBranch: string; fork?: string | null; archived?: boolean; private?: boolean } | null>
|
|
267
|
+
// Every tag's commit; null where it has too many to list.
|
|
268
|
+
tags(name: string): Promise<{ tag: string; oid: string }[] | null>
|
|
269
|
+
tag(name: string, tag: string): Promise<string | null>
|
|
270
|
+
branch(name: string, branch: string): Promise<string | null>
|
|
271
|
+
// Its branches, and whether those are all.
|
|
272
|
+
branches(name: string): Promise<{ branches: { branch: string; oid: string }[]; complete: boolean }>
|
|
273
|
+
// Whether `sha` is `base` or in its history; null for no such commit. Of two
|
|
274
|
+
// commits, it holds for good.
|
|
275
|
+
contains(name: string, base: string, sha: string): Promise<boolean | null>
|
|
276
|
+
file(name: string, path: string, commit: string): Promise<string | null>
|
|
277
|
+
// A repository's advisories at `versions`, as upstream's `advisories`
|
|
278
|
+
// tells those of a `github` package: its own published ones, and but for
|
|
279
|
+
// one `internal` (not known public), OSV's of it as an Action. Without it,
|
|
280
|
+
// none are asked.
|
|
281
|
+
advisories?(name: string, versions: string[], internal: boolean): Promise<ActionAdvisory[]>
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// An advisory of a repository, as upstream's `advisories` tells one.
|
|
285
|
+
export interface ActionAdvisory {
|
|
286
|
+
id: string
|
|
287
|
+
url?: string | undefined
|
|
288
|
+
title?: string | undefined
|
|
289
|
+
severity?: string | undefined
|
|
290
|
+
malware?: boolean | undefined
|
|
291
|
+
// The versions asked that it affects.
|
|
292
|
+
versions: string[]
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// A reference resolved: its repository as GitHub has it now, its ref's
|
|
296
|
+
// commit, what the ref is, the tags on the commit, and the keys of the
|
|
297
|
+
// references its code makes; null for none.
|
|
298
|
+
export interface ResolvedAction extends Pick<ActionUses, 'kind' | 'repo' | 'path' | 'ref'> {
|
|
299
|
+
key: string
|
|
300
|
+
repository: { fullName: string; private: boolean } | null
|
|
301
|
+
commit: string | null
|
|
302
|
+
at: 'sha' | 'tag' | 'branch' | null
|
|
303
|
+
tags: string[]
|
|
304
|
+
findings: ActionsFinding[]
|
|
305
|
+
uses: string[]
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export function resolveAction(uses: ActionUses, source: ActionsSource, options?: { owner?: string | null }): Promise<ResolvedAction>
|
|
309
|
+
export function keptSource(source: ActionsSource): ActionsSource
|
package/risk/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// What calls for a look at a package version, or a repository's GitHub
|
|
2
|
+
// Actions, for a reviewer: risk's heuristics, apart from any view of them.
|
|
3
|
+
// See README.md.
|
|
4
|
+
export { assessNpm, npmMalware } from './npm/assess.js'
|
|
5
|
+
export { npmMalwareAdvisory } from './npm/malware.js'
|
|
6
|
+
export { DEFAULT_MINIMUM_RELEASE_AGE } from './npm/release.js'
|
|
7
|
+
export { NpmRiskError, npmReadyDownload, npmReadyDownloads } from './npm/registry.js'
|
|
8
|
+
export { NPM_PATH_FOLDS, NPM_SYMLINKS_ABOVE, npmTarLayout } from './npm/tarball.js'
|
|
9
|
+
export { SEVERITIES, npmFileRisk } from './files/stamps.js'
|
|
10
|
+
export { ownFilesOf, scanWorkflow } from './actions/findings.js'
|
|
11
|
+
export { dockerfileFindings, keptSource, resolveAction } from './actions/resolve.js'
|
|
12
|
+
export { usesOfKey } from './actions/uses.js'
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// A package version's risk, as the managed server asks it: what calls for a
|
|
2
|
+
// look at it, against the version before it where one is given or risk picks
|
|
3
|
+
// one (old-version.js), each file's stamps, and its dependencies', from npm's
|
|
4
|
+
// registry, kept in the caller's cache (registry.js) as it goes.
|
|
5
|
+
import { npmBaseFilesTell, npmCompareFindings } from './compare.js'
|
|
6
|
+
import { npmCombinedFindings, npmHeldDependencyFindings } from './combined.js'
|
|
7
|
+
import { npmHeldFindings, npmVersionFindings } from './held.js'
|
|
8
|
+
import { npmVersionFileRisk } from './files.js'
|
|
9
|
+
import { npmDependencyChanges, npmFlagDependencyChanges, npmUnusedDependencyCounted } from './dependencies.js'
|
|
10
|
+
import { npmDownloadMonths, npmDownloadTier, npmSettledDownloads, npmTierLevel } from './downloads.js'
|
|
11
|
+
import { NpmRiskError, npmDownloads, npmPackageFacts, npmPackageReleases, npmPublicFacts, npmVersionAdvisories, npmVersionFiles } from './registry.js'
|
|
12
|
+
import { npmMalwareFinding } from './malware.js'
|
|
13
|
+
import { npmKnownScope } from './manifest.js'
|
|
14
|
+
import { DEFAULT_MINIMUM_RELEASE_AGE, npmAccountStanding } from './release.js'
|
|
15
|
+
import { npmAddedDependency, npmUnusedDependencySeverity } from './new-dependency.js'
|
|
16
|
+
import { SEVERITIES } from '../files/stamps.js'
|
|
17
|
+
import { npmRiskScore } from './score.js'
|
|
18
|
+
|
|
19
|
+
// Which reading of a version an assessment kept (`risk/npm/assessments`) is:
|
|
20
|
+
// one more whenever a heuristic changes what it finds, so one kept by an
|
|
21
|
+
// older reading is read anew.
|
|
22
|
+
const RISK_VERSION = 23
|
|
23
|
+
|
|
24
|
+
// How long an assessment kept may be as JSON, and what risk reads of either
|
|
25
|
+
// version's files: a package past it, whose files name thousands of hosts or
|
|
26
|
+
// do what they run on thousands of lines each, is refused as too large as its
|
|
27
|
+
// files are read, before more of them is held (filesRisk), and the assessment
|
|
28
|
+
// once told, rather than kept and answered. A package's files tell a few
|
|
29
|
+
// hundred characters each, a few MiB for the most files npm's viewer reads.
|
|
30
|
+
const MAX_ASSESSMENT_LENGTH = 16 * 1024 * 1024
|
|
31
|
+
const tooLarge = what => new NpmRiskError('package-too-large', `what risk tells of ${what} is past ${MAX_ASSESSMENT_LENGTH} characters`)
|
|
32
|
+
|
|
33
|
+
// A value as JSON holds it: a Map as an object, its keys as strings.
|
|
34
|
+
const plain = value => value instanceof Map ? Object.fromEntries([...value].map(([key, item]) => [key, plain(item)]))
|
|
35
|
+
: Array.isArray(value) ? value.map(plain)
|
|
36
|
+
: value && typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, plain(item)])) : value
|
|
37
|
+
|
|
38
|
+
// A tier among npm's packages as an assessment says it: `{ tier, level }`, the
|
|
39
|
+
// rank a package is among (null past the last, unpopular) and its tint
|
|
40
|
+
// (downloads.js npmTierLevel).
|
|
41
|
+
const tierOf = tier => ({ tier: Number.isFinite(tier) ? tier : null, level: npmTierLevel(tier) })
|
|
42
|
+
|
|
43
|
+
// Each of a version's files' stamps and what risk read of it (stamps.js
|
|
44
|
+
// npmFileRisk), by path, as JSON holds them: read a file at a time and given
|
|
45
|
+
// up on, as too large, once they are past MAX_ASSESSMENT_LENGTH as JSON
|
|
46
|
+
// altogether, so that no more of them is held than that.
|
|
47
|
+
function filesRisk(version, what) {
|
|
48
|
+
let length = 0
|
|
49
|
+
return Object.fromEntries(version.json.sources.map(path => {
|
|
50
|
+
const { readability, runsCode, exfiltration, hosts, stamps } = npmVersionFileRisk(version, path)
|
|
51
|
+
const risk = plain({ stamps, readability, runsCode, exfiltration, hosts })
|
|
52
|
+
length += path.length + JSON.stringify(risk).length
|
|
53
|
+
if (length > MAX_ASSESSMENT_LENGTH) throw tooLarge(what)
|
|
54
|
+
return [path, risk]
|
|
55
|
+
}))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// What of an assessment holds whatever the time, of the open version
|
|
59
|
+
// (`other`) against the one compared with (`base`), or alone without one,
|
|
60
|
+
// each as compare.js takes a version, as JSON holds it: what it holds,
|
|
61
|
+
// always (held.js npmHeldFindings, and its dependencies against none,
|
|
62
|
+
// combined.js npmHeldDependencyFindings), and against `base` what its files,
|
|
63
|
+
// dependencies, install scripts, publisher and provenance call for anew
|
|
64
|
+
// (compare.js npmCompareFindings), folded into what it holds, never lowering
|
|
65
|
+
// it (combined.js npmCombinedFindings); each file's stamps and what risk read
|
|
66
|
+
// of it (filesRisk); and its dependencies added and changed, each with its
|
|
67
|
+
// flags (dependencies.js), against `base` each it holds too (`held`). Its own findings are told fresh
|
|
68
|
+
// (npmAssessmentOf). The managed server's assessments keep it (`lasting`),
|
|
69
|
+
// and a test can tell what one says of versions it holds. Each publisher's
|
|
70
|
+
// standing on the package is told where `standing` is given (release.js
|
|
71
|
+
// npmAccountStanding, of the open version).
|
|
72
|
+
export const npmLastingRisk = (other, base = null, standing = null) => lastingOf(other, base, filesRisk(other, `${other.npm.name}@${other.npm.version}`), standing)
|
|
73
|
+
|
|
74
|
+
// npmLastingRisk's, the open version's files read within bounds (`files`,
|
|
75
|
+
// filesRisk's), as the one compared with's are where `base` has them, before
|
|
76
|
+
// the findings read them all.
|
|
77
|
+
function lastingOf(other, base, files, standing) {
|
|
78
|
+
if (base?.json) filesRisk(base, `${base.npm.name}@${base.npm.version}`)
|
|
79
|
+
const all = npmFlagDependencyChanges(npmDependencyChanges(undefined, other.npm.manifest), null, other)
|
|
80
|
+
const held = [...npmHeldFindings(other), ...npmHeldDependencyFindings(all)]
|
|
81
|
+
const { added, changed } = base ? npmFlagDependencyChanges(npmDependencyChanges(base.npm.manifest, other.npm.manifest), base, other) : all
|
|
82
|
+
const findings = base ? npmCombinedFindings(held, npmCompareFindings(base, other, { added, changed }, standing)) : held
|
|
83
|
+
const kept = { findings: plain(findings), files, dependencies: plain({ added, changed, ...base ? { held: all.added } : {} }) }
|
|
84
|
+
if (JSON.stringify(kept).length > MAX_ASSESSMENT_LENGTH) throw tooLarge(`${other.npm.name}@${other.npm.version}`)
|
|
85
|
+
return kept
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// What of an assessment holds whatever the time (npmLastingRisk), kept once a
|
|
89
|
+
// reading and pair, its versions' files read from npm only where it isn't:
|
|
90
|
+
// the open version's first, then the one compared with's only where they
|
|
91
|
+
// could change what is found (compare.js npmBaseFilesTell), that one else
|
|
92
|
+
// told by what npm's document of it says alone; and where another account
|
|
93
|
+
// published it, each one's standing on the package (release.js
|
|
94
|
+
// npmAccountStanding), by its versions as `facts` read them, or as its
|
|
95
|
+
// document is read again where they were kept. A standing changes as npm
|
|
96
|
+
// removes a version, its publisher then unknown, and never else, so such a
|
|
97
|
+
// pair is kept by how many npm has removed (`~<removals>`), read anew as it
|
|
98
|
+
// removes another.
|
|
99
|
+
async function lasting(name, version, oldVersion, facts, context, fromEmpty) {
|
|
100
|
+
const old = oldVersion === null ? null : facts.versions.get(oldVersion)
|
|
101
|
+
const publishers = [old, facts.versions.get(version)].map(fact => fact?.manifest.publisher)
|
|
102
|
+
const changed = publishers.every(Boolean) && publishers[0] !== publishers[1]
|
|
103
|
+
const key = `${RISK_VERSION}/${name}@${version}${fromEmpty ? '..(empty)' : oldVersion === null ? '' : `..${oldVersion}`}${changed ? `~${facts.removals}` : ''}`
|
|
104
|
+
const hit = context.cache ? await context.cache.read('risk/npm/assessments', key) : null
|
|
105
|
+
if (hit) return hit
|
|
106
|
+
const other = await npmVersionFiles(name, version, facts.versions.get(version), context)
|
|
107
|
+
const files = filesRisk(other, `${name}@${version}`)
|
|
108
|
+
const base = fromEmpty ? { npm: { name, version: '', manifest: {} }, json: { sources: [], sourcesContent: [] } } : old === null ? null : npmBaseFilesTell(other, old.manifest) ? await npmVersionFiles(name, oldVersion, old, context)
|
|
109
|
+
: { npm: { name, version: oldVersion, manifest: old.manifest, published: old.published }, json: null }
|
|
110
|
+
const standing = changed ? npmAccountStanding(facts.releases ?? await npmPackageReleases(name, context), other.npm.published) : null
|
|
111
|
+
const kept = lastingOf(other, base, files, standing)
|
|
112
|
+
if (context.cache) await context.cache.write('risk/npm/assessments', key, kept)
|
|
113
|
+
return kept
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// How many dependencies added are told of at most, however many a version
|
|
117
|
+
// adds, as each costs npm a request or two: the rest are left as they are,
|
|
118
|
+
// their packages unknown.
|
|
119
|
+
const MAX_TOLD_DEPENDENCIES = 100
|
|
120
|
+
|
|
121
|
+
// Each dependency `added` that npm installs from its registry, up to
|
|
122
|
+
// MAX_TOLD_DEPENDENCIES of them, but for the caller's own packages (`owned`,
|
|
123
|
+
// as its own scopes take, few downloading them, as new as its releases),
|
|
124
|
+
// with what risk tells of its package
|
|
125
|
+
// (new-dependency.js npmAddedDependency): its tier, its last whole month's
|
|
126
|
+
// downloads by what its tier goes by where it has one (`month`, `{ total,
|
|
127
|
+
// from }`), `uncounted` where npm counts none of them, `created` and `gap`
|
|
128
|
+
// where it is new since the version compared with (`published`, when that
|
|
129
|
+
// and the open version were), and for one nothing imports (flagged so, or
|
|
130
|
+
// among `unusedKeys`) that risk counts (dependencies.js
|
|
131
|
+
// npmUnusedDependencyCounted), the version its spec installs (`installs`,
|
|
132
|
+
// registry.js npmPublicFacts); `missing` where
|
|
133
|
+
// its package was looked up and npm has none of it for anyone, as once
|
|
134
|
+
// unpublished or taken down; four asked at a time, whether each is the
|
|
135
|
+
// caller's own among them, none more once one fails or MAX_TOLD_DEPENDENCIES
|
|
136
|
+
// not the caller's own were taken, however many a version adds.
|
|
137
|
+
async function addedDependencies(added, published, context, owned, unusedKeys = new Set()) {
|
|
138
|
+
const told = [...added]
|
|
139
|
+
const asked = told.flatMap((row, at) => row.opens ? [at] : [])
|
|
140
|
+
let next = 0, taken = 0
|
|
141
|
+
const tell = async row => {
|
|
142
|
+
const downloads = await npmDownloads(row.opens, context)
|
|
143
|
+
const unused = (row.flags.some(flag => flag.check === 'unimported') || unusedKeys.has(keyOf(row))) && npmUnusedDependencyCounted(row)
|
|
144
|
+
let facts = npmAddedDependency({ downloads, published, unused }, context.now), missing = false
|
|
145
|
+
if (facts.wanted) {
|
|
146
|
+
const listed = await npmPublicFacts(row.opens, context, unused ? row.range : null)
|
|
147
|
+
missing = listed === null
|
|
148
|
+
facts = npmAddedDependency({ downloads, listed: listed && { ...listed, private: false }, published, unused }, context.now)
|
|
149
|
+
}
|
|
150
|
+
const settled = npmSettledDownloads(downloads, context.now)
|
|
151
|
+
const month = npmDownloadMonths(settled).at(-1)
|
|
152
|
+
return { ...row, ...facts.tier === null ? {} : { ...tierOf(facts.tier), ...settled ? month && { month: { total: month.total, from: month.from.toISOString().slice(0, 10) } } : { uncounted: true } },
|
|
153
|
+
...facts.created ? { created: facts.created, gap: facts.gap } : {}, ...facts.installs ? { installs: facts.installs } : {}, ...missing ? { missing } : {} }
|
|
154
|
+
}
|
|
155
|
+
await Promise.all(Array.from({ length: 4 }, async () => {
|
|
156
|
+
while (next < asked.length && taken < MAX_TOLD_DEPENDENCIES) {
|
|
157
|
+
const at = asked[next++]
|
|
158
|
+
try {
|
|
159
|
+
if (await owned(told[at].opens)) continue
|
|
160
|
+
if (taken >= MAX_TOLD_DEPENDENCIES) break
|
|
161
|
+
taken++
|
|
162
|
+
told[at] = await tell(told[at])
|
|
163
|
+
} catch (error) { next = asked.length; throw error }
|
|
164
|
+
}
|
|
165
|
+
}))
|
|
166
|
+
return told
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// The malware finding of `version` of package `name` alone, as assessNpm
|
|
170
|
+
// finds it (npmMalwareFinding): its package taken down by npm, and npm's
|
|
171
|
+
// advisories of malware naming it, OSV's too where `osv` is (true unless
|
|
172
|
+
// given false), and with `github` its repository's, read and kept as
|
|
173
|
+
// assessNpm reads and keeps them (`cache`, `packument`, `now`, `signal`),
|
|
174
|
+
// none of its files nor its dependencies read; null where neither tells of
|
|
175
|
+
// any. Throws as assessNpm does where npm has no such package or version
|
|
176
|
+
// (nor malware explaining one removed), or can't be asked.
|
|
177
|
+
export async function npmMalware(name, version, { cache, packument, now = Date.now(), signal, osv = true, github = null } = {}) {
|
|
178
|
+
const context = { cache, packument, now, signal }
|
|
179
|
+
const facts = await npmPackageFacts(name, version, null, context)
|
|
180
|
+
const advised = await npmVersionAdvisories(name, version, osv, context, facts.versions.get(version)?.repo ?? null, github)
|
|
181
|
+
const malware = npmMalwareFinding({ takenDown: facts.takenDown, advisories: advised })
|
|
182
|
+
if (!malware && !facts.versions.has(version)) throw new NpmRiskError('version-not-found', `npm has no ${name}@${version}`)
|
|
183
|
+
return malware
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// What calls for a look at `version` of package `name`, as JSON holds it:
|
|
187
|
+
// malware first (malware.js npmMalwareFinding: its package taken down by
|
|
188
|
+
// npm, and npm's advisories of malware naming it where `advisories`, true
|
|
189
|
+
// unless given false, has them asked, OSV's too where `osv` is, true unless
|
|
190
|
+
// given false, as a private package's name is never sent it, and with
|
|
191
|
+
// `github`, its repository's, registry.js npmVersionAdvisories); against `oldVersion` where given,
|
|
192
|
+
// true for the one of its versions most likely free of what an attack
|
|
193
|
+
// injects, as risk picks it by npm's document (old-version.js npmOldVersion;
|
|
194
|
+
// none where none is below it), the one it picked said as `oldVersion`
|
|
195
|
+
// (compare.js npmCompareFindings's order), else what it holds (held.js
|
|
196
|
+
// npmHeldFindings), a deprecation first, and last
|
|
197
|
+
// one younger than `minimumReleaseAge` (two weeks unless given; 0 for none, as
|
|
198
|
+
// a caller's own scopes take), and the package's tier past the top 20,000
|
|
199
|
+
// (`popularity`, held.js npmVersionFindings, unless `popularity` is given
|
|
200
|
+
// false, as a caller's own scopes take); `files`, each file's stamps and what risk read of it; and
|
|
201
|
+
// `dependencies`, those added and changed against it, each with its flags,
|
|
202
|
+
// an added one with its package's tier and age where `downloads` (true unless
|
|
203
|
+
// given false) has them asked, and `dependencies` (true unless given false)
|
|
204
|
+
// too, but where `owned` says its package is the caller's own, as its own scopes
|
|
205
|
+
// take (none unless given). `cache` keeps what is read (registry.js),
|
|
206
|
+
// `packument` asks for a package's whole document and `tarball` for a
|
|
207
|
+
// version's tarball in risk's stead (registry.js), `now` is when it is asked, `signal` gives up on what is
|
|
208
|
+
// still asked of npm. A version npm removed, as it removes every one it finds
|
|
209
|
+
// malware in, is told of by its malware alone (`removed`), nothing of it left
|
|
210
|
+
// to read. Throws an NpmRiskError (registry.js), its `code` saying why, where
|
|
211
|
+
// npm has no such package or version (nor malware explaining one removed),
|
|
212
|
+
// answers past risk's bounds, or can't be asked.
|
|
213
|
+
export async function assessNpm(name, version, { oldVersion = null, fromEmpty = false, minimumReleaseAge = DEFAULT_MINIMUM_RELEASE_AGE, popularity = true, cache, packument, tarball, now = Date.now(), signal, downloads = true, dependencies = true, advisories = true, osv = true, github = null, owned = () => false } = {}) {
|
|
214
|
+
const context = { cache, packument, tarball, now, signal }
|
|
215
|
+
const facts = await npmPackageFacts(name, version, oldVersion, context)
|
|
216
|
+
const old = facts.oldVersion
|
|
217
|
+
if (old !== null && !facts.versions.has(old)) throw new NpmRiskError('version-not-found', `npm has no ${name}@${old}`)
|
|
218
|
+
// Its advisories, its lasting risk and its downloads need none of each
|
|
219
|
+
// other, so all are asked at once, and waited on in this order, so that a
|
|
220
|
+
// failure fails it as the first of them failing would.
|
|
221
|
+
const listed = facts.versions.has(version)
|
|
222
|
+
const advised = settledLater(advisories ? npmVersionAdvisories(name, version, osv, context, facts.versions.get(version)?.repo ?? null, github) : Promise.resolve([]))
|
|
223
|
+
const keeping = listed ? settledLater(lasting(name, version, old, facts, context, fromEmpty)) : null
|
|
224
|
+
const counting = listed && downloads && popularity ? settledLater(npmDownloads(name, context)) : null
|
|
225
|
+
const malware = npmMalwareFinding({ takenDown: facts.takenDown, advisories: await advised })
|
|
226
|
+
if (!listed) {
|
|
227
|
+
if (!malware) throw new NpmRiskError('version-not-found', `npm has no ${name}@${version}`)
|
|
228
|
+
return { name, version, oldVersion: null, published: facts.removed.get(version), removed: true, findings: [malware], files: {}, dependencies: { added: [], changed: [] },
|
|
229
|
+
score: npmRiskScore([malware]) }
|
|
230
|
+
}
|
|
231
|
+
const { published, manifest } = facts.versions.get(version)
|
|
232
|
+
const kept = await keeping
|
|
233
|
+
const counted = await counting
|
|
234
|
+
const own = npmVersionFindings({ deprecated: facts.deprecated[version], published, minimumReleaseAge, now, known: Boolean(manifest.knownAccounts), scope: npmKnownScope(name),
|
|
235
|
+
provenance: Boolean(manifest.provenance), downloads: counted })
|
|
236
|
+
const was = old === null ? null : facts.versions.get(old).published
|
|
237
|
+
// Those it holds that nothing imports by another spec than the version
|
|
238
|
+
// compared with's, told by their new spec as an added one nothing imports
|
|
239
|
+
// is (`respecified`), and an added one nothing imports however it was
|
|
240
|
+
// flagged, as one moved from another kind of dependency is.
|
|
241
|
+
const unusedKeys = unusedKeysOf(kept)
|
|
242
|
+
const respecified = kept.dependencies.changed.filter(row => unusedKeys.has(keyOf(row))).map(row => ({ ...row, range: row.to }))
|
|
243
|
+
const told = downloads && dependencies ? await addedDependencies([...kept.dependencies.added, ...respecified], [was, published], context, owned, unusedKeys)
|
|
244
|
+
: [...kept.dependencies.added, ...respecified]
|
|
245
|
+
const added = told.slice(0, kept.dependencies.added.length)
|
|
246
|
+
const assessment = npmAssessmentOf(kept, malware ? [malware, ...own] : own, added, told.slice(added.length))
|
|
247
|
+
return { name, version, oldVersion: old, published, ...assessment, score: npmRiskScore(assessment.findings, { published, now, tier: counted ? npmDownloadTier(counted) : null }) }
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// A dependency's key among a version's, by its kind and name.
|
|
251
|
+
const keyOf = row => `${row.kind ?? ''}\0${row.name}`
|
|
252
|
+
|
|
253
|
+
// `promise`, waited on later: its failure, if it fails before then, not
|
|
254
|
+
// thrown as unhandled meanwhile.
|
|
255
|
+
const settledLater = promise => { promise.catch(() => {}); return promise }
|
|
256
|
+
|
|
257
|
+
// The keys of the dependencies a version holds that nothing of it imports
|
|
258
|
+
// (`kept`, npmLastingRisk's: its `held-unused-deps`), those risk counts
|
|
259
|
+
// (dependencies.js npmUnusedDependencyCounted).
|
|
260
|
+
const unusedKeysOf = kept => new Set((kept.findings.find(({ id }) => id === 'held-unused-deps')?.dependencies ?? []).filter(npmUnusedDependencyCounted).map(keyOf))
|
|
261
|
+
|
|
262
|
+
// The dependencies nothing of a version imports (`held-unused-deps`), each
|
|
263
|
+
// graded by what risk tells of its package fresh (`told`, as
|
|
264
|
+
// addedDependencies tells it; new-dependency.js
|
|
265
|
+
// npmUnusedDependencySeverity), with its tier, when its package was first
|
|
266
|
+
// published and the version its spec installs where told: kept from the
|
|
267
|
+
// version compared with where there was one (`compared`) and it named it as
|
|
268
|
+
// the same kind of dependency by the same spec: not one marked new, nor
|
|
269
|
+
// `added` (its kind and name new, as one moved from another kind is), nor
|
|
270
|
+
// `changed` (each said with the spec it had, `was`); one risk doesn't count
|
|
271
|
+
// (dependencies.js npmUnusedDependencyCounted) a notice, told all the same.
|
|
272
|
+
// The finding as its most severe.
|
|
273
|
+
function unusedGraded(finding, told, compared, { added, changed }) {
|
|
274
|
+
const facts = new Map(told.map(row => [keyOf(row), row])), was = new Map(changed.map(row => [keyOf(row), row.from]))
|
|
275
|
+
const anew = new Set(added.map(keyOf))
|
|
276
|
+
const dependencies = finding.dependencies.map(row => {
|
|
277
|
+
const of = facts.get(keyOf(row))
|
|
278
|
+
return { ...row, ...was.has(keyOf(row)) ? { was: was.get(keyOf(row)) } : {}, severity: npmUnusedDependencyCounted(row)
|
|
279
|
+
? npmUnusedDependencySeverity(of, compared && !row.added && !anew.has(keyOf(row)) && !was.has(keyOf(row))) : 'notice',
|
|
280
|
+
...of?.level ? { tier: of.tier, level: of.level } : {}, ...of?.created ? { created: of.created, gap: of.gap } : {}, ...of?.installs ? { installs: of.installs } : {},
|
|
281
|
+
...of?.missing ? { missing: true } : {} }
|
|
282
|
+
})
|
|
283
|
+
return { ...finding, severity: SEVERITIES[Math.min(...dependencies.map(row => SEVERITIES.indexOf(row.severity)))], dependencies }
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// An assessment of what of it holds whatever the time (`kept`,
|
|
287
|
+
// npmLastingRisk's) and what is told fresh: the open version's own findings
|
|
288
|
+
// (`own`, held.js npmVersionFindings, and its malware), its malware and
|
|
289
|
+
// deprecation first and the rest last, its tier as JSON holds it (tierOf),
|
|
290
|
+
// and its dependencies `added`, as addedDependencies tells them, those it
|
|
291
|
+
// holds by another spec that nothing imports beside them (`respecified`),
|
|
292
|
+
// for its unused dependencies' grades. The managed
|
|
293
|
+
// server's (assessNpm), and a test's of versions it holds.
|
|
294
|
+
const FIRST = new Set(['malware', 'deprecated'])
|
|
295
|
+
export function npmAssessmentOf(kept, own, added = kept.dependencies.added, respecified = []) {
|
|
296
|
+
return {
|
|
297
|
+
findings: [...own.filter(({ id }) => FIRST.has(id)), ...kept.findings.map(finding => finding.id === 'held-unused-deps'
|
|
298
|
+
? unusedGraded(finding, [...added, ...respecified], Boolean(kept.dependencies.held), kept.dependencies) : finding),
|
|
299
|
+
...own.filter(({ id }) => !FIRST.has(id)).map(finding => finding.id === 'popularity' ? { ...finding, ...tierOf(finding.tier) } : finding)],
|
|
300
|
+
files: kept.files,
|
|
301
|
+
dependencies: { ...kept.dependencies, added },
|
|
302
|
+
}
|
|
303
|
+
}
|