@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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// What a `run:` script fetches and runs (commands.js), graded (README.md).
|
|
2
|
+
import { HOST_TAGS, npmExfiltration, npmHostTags } from '../../files/hosts.js'
|
|
3
|
+
import { lineOf } from '../../files/script.js'
|
|
4
|
+
import { installsOf, scriptFinds } from './commands.js'
|
|
5
|
+
|
|
6
|
+
// The events a workflow runs on with its secrets for anyone's pull request.
|
|
7
|
+
const PRIVILEGED_TRIGGERS = new Set(['pull_request_target', 'workflow_run', 'issue_comment', 'issues', 'discussion', 'discussion_comment',
|
|
8
|
+
'pull_request_review', 'pull_request_review_comment', 'fork', 'watch'])
|
|
9
|
+
|
|
10
|
+
// The expressions anyone can write: a title, a body, a branch's name, a
|
|
11
|
+
// commit's message, a fork's description.
|
|
12
|
+
const INDEX = String.raw`(?:\s*\[[^\]]*\]|\.\*)`
|
|
13
|
+
const AUTHOR = String.raw`(?:author|committer)\.(?:email|name)`
|
|
14
|
+
const UNTRUSTED = new RegExp(String.raw`\bgithub\s*\.\s*(?:head_ref|event\s*\.\s*(?:`
|
|
15
|
+
+ [String.raw`issue\.(?:title|body)`,
|
|
16
|
+
String.raw`pull_request\.(?:title|body|head\.(?:ref|label|repo\.(?:default_branch|description|homepage)))`,
|
|
17
|
+
String.raw`(?:comment|review|review_comment)\.body`,
|
|
18
|
+
String.raw`pages${INDEX}\.page_name`,
|
|
19
|
+
String.raw`commits${INDEX}\.(?:message|${AUTHOR})`,
|
|
20
|
+
String.raw`head_commit\.(?:message|${AUTHOR})`,
|
|
21
|
+
String.raw`workflow_run\.(?:head_branch|display_title|head_commit\.(?:message|${AUTHOR})|head_repository\.(?:description|homepage|default_branch)|pull_requests${INDEX}\.head\.ref)`,
|
|
22
|
+
String.raw`discussion\.(?:title|body)`].join('|')
|
|
23
|
+
+ String.raw`))(?![\w-])`, 'gu')
|
|
24
|
+
|
|
25
|
+
// An expression with its index syntax's properties (`github['event']`) as
|
|
26
|
+
// dereferences, as GitHub reads either.
|
|
27
|
+
export const dotted = text => text.replaceAll(/\[\s*'([\w-]+)'\s*\]/gu, '.$1')
|
|
28
|
+
|
|
29
|
+
// Each expression anyone can write in a script's `text`, a finding with
|
|
30
|
+
// the `index` its `${{` is at: red where the workflow runs with its secrets
|
|
31
|
+
// for anyone (`triggers`), else orange.
|
|
32
|
+
export function scriptInjections(text, triggers) {
|
|
33
|
+
if (typeof text !== 'string' || !text.includes('${{')) return []
|
|
34
|
+
const severity = triggers.some(event => PRIVILEGED_TRIGGERS.has(event)) ? 'critical' : 'high'
|
|
35
|
+
return [...text.matchAll(/\$\{\{([\s\S]*?)\}\}/gu)].flatMap(({ 1: inner, index }) =>
|
|
36
|
+
[...dotted(inner).matchAll(UNTRUSTED)].map(({ 0: expression }) => ({ id: 'script-injection', severity, expression: expression.replaceAll(/\s+/gu, ''), index })))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// A ref or a repository naming a pull request's own code, as
|
|
40
|
+
// `actions/checkout` checks it out: its head's commit or branch (a
|
|
41
|
+
// `workflow_run`'s pull requests' too), or the fork's repository, whose
|
|
42
|
+
// default branch it is then.
|
|
43
|
+
const PULL_HEAD = new RegExp(String.raw`\bgithub\.(?:head_ref|event\.(?:number|pull_request\.(?:number|merge_commit_sha|head\.(?:sha|ref|repo\.(?:full_name|owner\.login)))|workflow_run\.(?:head_sha|head_branch|head_commit\.id|pull_requests\[[^\]]*\]\.head\.(?:sha|ref)|head_repository\.(?:full_name|owner\.login))))\b`
|
|
44
|
+
.replaceAll('\\.', String.raw`\s*\.\s*`) + String.raw`|refs\/pull\/`, 'u')
|
|
45
|
+
export const namesPullHead = text => typeof text === 'string' && PULL_HEAD.test(dotted(text))
|
|
46
|
+
|
|
47
|
+
// Programs whose package is named otherwise: `npx tsc` runs typescript's.
|
|
48
|
+
const KNOWN_BINS = new Map([['tsc', 'typescript'], ['tsserver', 'typescript'], ['ng', '@angular/cli'], ['nest', '@nestjs/cli'],
|
|
49
|
+
['changeset', '@changesets/cli'], ['biome', '@biomejs/biome'], ['svelte-kit', '@sveltejs/kit'], ['api-extractor', '@microsoft/api-extractor'],
|
|
50
|
+
['commitlint', '@commitlint/cli'], ['attw', '@arethetypeswrong/cli'], ['ncu', 'npm-check-updates'], ['vue-cli-service', '@vue/cli-service'],
|
|
51
|
+
['firebase', 'firebase-tools'], ['netlify', 'netlify-cli'], ['cdk', 'aws-cdk'], ['sls', 'serverless'], ['playwright', '@playwright/test'],
|
|
52
|
+
['eas', 'eas-cli'], ['expo', 'expo'], ['vsce', '@vscode/vsce'], ['wdio', '@wdio/cli'], ['lhci', '@lhci/cli'], ['tsx', 'tsx'], ['webpack', 'webpack-cli']])
|
|
53
|
+
const PACKAGING = new Set(['pip', 'setuptools', 'wheel'])
|
|
54
|
+
|
|
55
|
+
// Whether `locked` (a Set) has what npx runs by `name`, or the package giving it.
|
|
56
|
+
export const lockedName = (locked, name) => locked.has(name) || (KNOWN_BINS.has(name) && locked.has(KNOWN_BINS.get(name)))
|
|
57
|
+
|
|
58
|
+
// How severe fetching a package is; null for none.
|
|
59
|
+
function packageSeverity(found, { locked, installed, external }) {
|
|
60
|
+
const runsOwn = found.ecosystem === 'npm' && found.localFirst && found.registry && (found.spec === null || found.exact)
|
|
61
|
+
if (runsOwn && (external ? installed : locked && installed)) return null
|
|
62
|
+
if (found.ecosystem === 'go' && found.exact) return null
|
|
63
|
+
if (found.ecosystem === 'crates' && found.exact && found.locked) return null
|
|
64
|
+
if (found.ecosystem === 'pypi' && PACKAGING.has(found.name.toLowerCase())) return 'notice'
|
|
65
|
+
// A version a variable names may be one, set elsewhere in the workflow.
|
|
66
|
+
return found.exact || found.spec?.includes('$') ? 'moderate' : 'high'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The findings of one find of a script, `locked` what a lockfile says of it.
|
|
70
|
+
function graded(found, context, locked) {
|
|
71
|
+
if (found.kind === 'package') {
|
|
72
|
+
const { tool, name, spec, localFirst } = found, installed = context.installed
|
|
73
|
+
const severity = packageSeverity(found, { locked, installed, external: context.external })
|
|
74
|
+
return severity ? [{ id: 'fetched-package', severity, tool, name, spec, ...localFirst ? { localFirst, locked, installed } : {} }] : []
|
|
75
|
+
}
|
|
76
|
+
if (found.kind === 'unlocked-install') return [{ id: 'unlocked-install', severity: /^(?:yarn|bun)\b/u.test(found.tool) ? 'low' : 'moderate', tool: found.tool }]
|
|
77
|
+
if (found.kind === 'remote-script') return [{ id: 'remote-script', severity: 'high', command: found.command }]
|
|
78
|
+
if (found.kind === 'image') return found.read?.digest ? [] : [imageFinding(found.text, found.read)]
|
|
79
|
+
return found.kind === 'clone' ? [{ id: 'clone', severity: 'low', url: found.url }] : []
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// An image run by a tag: orange with none or `latest`, else yellow.
|
|
83
|
+
export const imageFinding = (text, read) => ({ id: 'unpinned-image', severity: !read || read.tag === null || read.tag === 'latest' ? 'high' : 'moderate', image: text })
|
|
84
|
+
|
|
85
|
+
// The file's line a script's line is on: a `|` block scalar's own, else `run:`'s.
|
|
86
|
+
const fileLine = (run, line) => run.start === null ? run.line : run.start + line
|
|
87
|
+
|
|
88
|
+
// Whether `dir` is `directory` or above it, as node finds a package there;
|
|
89
|
+
// null for anywhere.
|
|
90
|
+
export const within = (dir, directory) => dir === null || dir === '' || directory === dir || directory.startsWith(`${dir}/`)
|
|
91
|
+
|
|
92
|
+
// Every finding of a `run` script (workflow.js runOf); `context`'s
|
|
93
|
+
// `locked(name, dir)` whether a lockfile there locks it (`dev` where
|
|
94
|
+
// devDependencies alone need it), `installed(dev, dir)` whether an install
|
|
95
|
+
// ran before that installs such a package there, `dir` a path from the
|
|
96
|
+
// step's directory, as a `cd` moves to.
|
|
97
|
+
export function scriptFindings(run, context) {
|
|
98
|
+
const findings = []
|
|
99
|
+
// An install earlier in the script counts as one in a step before.
|
|
100
|
+
const installs = installsOf(run.script, run.production)
|
|
101
|
+
for (const found of scriptFinds(run.script)) {
|
|
102
|
+
const dir = found.dir ?? ''
|
|
103
|
+
const locked = found.kind === 'package' && found.ecosystem === 'npm' && found.localFirst && context.locked(found.exact ? `${found.name}@${found.spec.replace(/^[v=]/u, '')}` : found.name, dir)
|
|
104
|
+
const before = context.installed(locked === 'dev', dir) || installs.some(({ order, into, prod }) => order < found.order && within(into, dir) && !(prod && locked === 'dev'))
|
|
105
|
+
for (const finding of graded(found, { ...context, installed: before }, Boolean(locked))) findings.push({ ...finding, line: fileLine(run, found.line) })
|
|
106
|
+
}
|
|
107
|
+
for (const [tag, services] of npmHostTags(npmExfiltration('run.sh', run.script, true))) {
|
|
108
|
+
findings.push({ id: 'hosts', severity: HOST_TAGS.get(tag), tag, services: [...services.keys()], line: fileLine(run, Math.min(...[...services.values()].flat()) - 1) })
|
|
109
|
+
}
|
|
110
|
+
const line = lineOf(run.script)
|
|
111
|
+
for (const { index, ...finding } of scriptInjections(run.script, context.triggers)) findings.push({ ...finding, line: fileLine(run, line(index) - 1) })
|
|
112
|
+
return findings
|
|
113
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// What a command of npm's tools fetches and runs past what a lockfile locks
|
|
2
|
+
// (commands.js), npx's and its kin's the project's own where installed
|
|
3
|
+
// (`localFirst`), and an install that resolves anew (`unlocked`).
|
|
4
|
+
import { isExactVersion } from '@preventive/upstream/semver.js'
|
|
5
|
+
|
|
6
|
+
// A package spec's name and spec, `exact` for a version, `registry: false` for
|
|
7
|
+
// a URL, a path, git or a GitHub shorthand.
|
|
8
|
+
export function npmSpec(text) {
|
|
9
|
+
if (/^(?:\.{0,2}\/|~|[a-z][\w+.-]*:|[\w.-]+\/[\w.-]+(?:#.*)?$)/iu.test(text) && !/^@[\w.-]+\//u.test(text)) {
|
|
10
|
+
return { name: text, spec: null, exact: false, registry: false }
|
|
11
|
+
}
|
|
12
|
+
const at = text.indexOf('@', text.startsWith('@') ? 1 : 0)
|
|
13
|
+
const name = at === -1 ? text : text.slice(0, at)
|
|
14
|
+
const spec = at === -1 ? null : text.slice(at + 1)
|
|
15
|
+
if (!/^(?:@[\w.-]+\/)?[\w.-]+$/u.test(name)) return null
|
|
16
|
+
return { name, spec, exact: spec !== null && isExactVersion(spec.replace(/^[v=]/u, '')), registry: true }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// A package a tool fetches, as a script's find; none for none.
|
|
20
|
+
export const fetched = (tool, spec, { ecosystem = 'npm', localFirst = false, ...more } = {}) => spec ? [{ kind: 'package', tool, ecosystem, localFirst, ...more, ...spec }] : []
|
|
21
|
+
|
|
22
|
+
// What `npm create x` runs: `create-x`, `@s/create` for `@s`, `@s/create-x`.
|
|
23
|
+
function createPackage(text) {
|
|
24
|
+
const scoped = /^(@[\w.-]+)(?:@(.+))?$/u.exec(text)
|
|
25
|
+
if (scoped) return npmSpec(`${scoped[1]}/create${scoped[2] ? `@${scoped[2]}` : ''}`)
|
|
26
|
+
const spec = npmSpec(text)
|
|
27
|
+
if (!spec?.registry) return spec
|
|
28
|
+
const [scope, name] = spec.name.startsWith('@') ? spec.name.split('/') : [null, spec.name]
|
|
29
|
+
const named = scope ? (name ? `${scope}/create-${name}` : `${scope}/create`) : `create-${name}`
|
|
30
|
+
return { ...spec, name: named }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Options of npm's tools that take a value.
|
|
34
|
+
const VALUED = /^(?:-[pcwC]|--(?:package|call|cache|userconfig|registry|workspace|prefix|filter|dir|global-dir|store-dir|loglevel|cwd|spec|location|include|omit|only))$/u
|
|
35
|
+
const GLOBAL = /^(?:-g|--global|--location=global)$/u
|
|
36
|
+
|
|
37
|
+
// A command's words past `from`: those not options (`operands`), all past
|
|
38
|
+
// `--` too, and each option's values (`values`), of `--x=v`, and `--x v` for
|
|
39
|
+
// one `valued` names.
|
|
40
|
+
export function optionsOf(argv, from, valued = VALUED) {
|
|
41
|
+
const operands = [], values = new Map()
|
|
42
|
+
for (let at = from; at < argv.length; at++) {
|
|
43
|
+
const [, name, joined] = /^(--[\w-]+)=(.*)$/u.exec(argv[at]) ?? [], word = argv[at]
|
|
44
|
+
if (word === '--') return { operands: [...operands, ...argv.slice(at + 1)], values }
|
|
45
|
+
if (name || valued.test(word)) values.set(name ?? word, [...values.get(name ?? word) ?? [], joined ?? argv[++at] ?? ''])
|
|
46
|
+
else if (!word.startsWith('-')) operands.push(word)
|
|
47
|
+
}
|
|
48
|
+
return { operands, values }
|
|
49
|
+
}
|
|
50
|
+
const positional = (argv, from) => optionsOf(argv, from).operands
|
|
51
|
+
// The values of `names`' options, in their order.
|
|
52
|
+
export const valuesOf = ({ values }, ...names) => names.flatMap(name => values.get(name) ?? [])
|
|
53
|
+
|
|
54
|
+
// What an exec (npx, `npm exec`, bunx, dlx) fetches: its `--package`s, else
|
|
55
|
+
// its command's; none with `--no`, `--offline`, or a command line (`-c`).
|
|
56
|
+
function execPackages(tool, argv, from, localFirst) {
|
|
57
|
+
if (argv.some(word => /^(?:--no|--no-install|--offline)$/u.test(word))) return []
|
|
58
|
+
const named = valuesOf(optionsOf(argv, 1), '-p', '--package').filter(Boolean)
|
|
59
|
+
if (named.length === 0 && argv.some(word => word === '-c' || word === '--call')) return []
|
|
60
|
+
return (named.length > 0 ? named : positional(argv, from).slice(0, 1)).flatMap(text => fetched(tool, npmSpec(text), { localFirst }))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The directory an install names for its project (`--prefix`, `-C`, `--dir`,
|
|
64
|
+
// `--cwd`); null for the one it runs in, `.` too.
|
|
65
|
+
export function projectOf(argv) {
|
|
66
|
+
const [dir = null] = valuesOf(optionsOf(argv, 1), '-C', '--prefix', '--dir', '--cwd')
|
|
67
|
+
return dir === null || /^\.\/?$/u.test(dir) ? null : dir
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const installs = (tool, words) => words.flatMap(text => fetched(tool, npmSpec(text)))
|
|
71
|
+
// npm's install command and its aliases (commands.js installsOf).
|
|
72
|
+
export const NPM_INSTALLS = 'i|in|ins|inst|insta|instal|install|isnt|isnta|isntal|isntall|add|it|install-test'
|
|
73
|
+
const created = (tool, text) => text ? fetched(tool, createPackage(text)) : []
|
|
74
|
+
const unlocked = tool => [{ kind: 'unlocked-install', tool }]
|
|
75
|
+
const isInstalled = word => /^(?:\.{1,2}(?:\/|$)|file:|link:|workspace:)/u.test(word)
|
|
76
|
+
|
|
77
|
+
function npm(argv) {
|
|
78
|
+
const [command = '', ...rest] = positional(argv, 1)
|
|
79
|
+
if (command === 'exec' || command === 'x') return execPackages(`npm ${command}`, argv, argv.indexOf(command) + 1, true)
|
|
80
|
+
if (/^(?:create|init|innit)$/u.test(command)) return created(`npm ${command}`, rest[0])
|
|
81
|
+
if (new RegExp(`^(?:${NPM_INSTALLS})$`, 'u').test(command)) {
|
|
82
|
+
const named = rest.filter(word => !isInstalled(word))
|
|
83
|
+
if (argv.some(word => GLOBAL.test(word))) return installs(`npm ${command} -g`, named)
|
|
84
|
+
return named.length > 0 ? installs(`npm ${command}`, named) : unlocked(`npm ${command}`)
|
|
85
|
+
}
|
|
86
|
+
return /^(?:update|up|upgrade|udpate)$/u.test(command) ? unlocked(`npm ${command}`) : []
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// pnpm's and bun's, by the word each runs a package with (`exec`), what an
|
|
90
|
+
// install resolving anew is told by (`anew`, null for none), and its updates.
|
|
91
|
+
const pnpmLike = (program, exec, localFirst, anew, updates) => argv => {
|
|
92
|
+
const [command = '', ...rest] = positional(argv, 1)
|
|
93
|
+
if (command === exec) return execPackages(`${program} ${exec}`, argv, argv.indexOf(exec) + 1, localFirst)
|
|
94
|
+
if (command === 'create') return created(`${program} create`, rest[0])
|
|
95
|
+
const global = argv.some(word => GLOBAL.test(word)), installing = command === 'install' || command === 'i'
|
|
96
|
+
if (command === 'add' || (installing && rest.length > 0)) return installs(`${program} ${command}${global ? ' -g' : ''}`, rest.filter(word => !isInstalled(word)))
|
|
97
|
+
if (installing && anew(argv) !== null) return unlocked(`${program} ${command}${anew(argv)}`)
|
|
98
|
+
return updates.test(command) ? unlocked(`${program} ${command}`) : []
|
|
99
|
+
}
|
|
100
|
+
const pnpm = pnpmLike('pnpm', 'dlx', false, argv => argv.includes('--no-frozen-lockfile') ? ' --no-frozen-lockfile' : null, /^(?:update|up|upgrade)$/u)
|
|
101
|
+
const bun = pnpmLike('bun', 'x', true, argv => argv.some(word => word === '--frozen-lockfile' || word === '--ci') ? null : '', /^update$/u)
|
|
102
|
+
|
|
103
|
+
function yarn(argv) {
|
|
104
|
+
const [command = '', ...rest] = positional(argv, 1)
|
|
105
|
+
if (command === 'dlx') return execPackages('yarn dlx', argv, argv.indexOf('dlx') + 1, false)
|
|
106
|
+
if (command === 'create') return created('yarn create', rest[0])
|
|
107
|
+
if (command === 'global' && rest[0] === 'add') return installs('yarn global add', rest.slice(1))
|
|
108
|
+
if (command === 'add') return installs('yarn add', rest.filter(word => !isInstalled(word)))
|
|
109
|
+
const frozen = argv.some(word => /^--(?:frozen-lockfile|immutable)$/u.test(word))
|
|
110
|
+
if ((command === '' || command === 'install') && !frozen) return unlocked(command ? 'yarn install' : 'yarn')
|
|
111
|
+
return /^(?:upgrade|up)$/u.test(command) ? unlocked(`yarn ${command}`) : []
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The tools that run a package (whether one installed first), and the rest.
|
|
115
|
+
const EXECS = new Map([['npx', true], ['bunx', true], ['pnpx', false]])
|
|
116
|
+
const TOOLS = new Map([['npm', npm], ['pnpm', pnpm], ['yarn', yarn], ['bun', bun]])
|
|
117
|
+
|
|
118
|
+
// What a command of npm's tools fetches, by its program's name: packages and
|
|
119
|
+
// installs resolving anew.
|
|
120
|
+
export function npmToolFinds(program, argv) {
|
|
121
|
+
if (EXECS.has(program)) return execPackages(program, argv, 1, EXECS.get(program))
|
|
122
|
+
return TOOLS.get(program)?.(argv) ?? []
|
|
123
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// A `run:` script read into the commands it runs, as a shell would split
|
|
2
|
+
// them, for commands.js. A quick read, not a shell's parse: a command built
|
|
3
|
+
// as the script runs goes unseen.
|
|
4
|
+
import { SHELLS } from '../../files/runs-code.js'
|
|
5
|
+
import { resolved } from '../../npm/files.js'
|
|
6
|
+
|
|
7
|
+
// A shell, by its program, wherever it is, Windows' `.exe` too (risk's
|
|
8
|
+
// runs-code.js SHELLS).
|
|
9
|
+
const SHELL = new RegExp(String.raw`^(?:.*[\/\\])?${SHELLS}(?:\.exe)?$`, 'iu')
|
|
10
|
+
|
|
11
|
+
// A line of a script, its continuations joined (an escaped line's end, or a
|
|
12
|
+
// pipe, `&&` or `||` the next line goes on from), and the line it starts
|
|
13
|
+
// on, counting from 0.
|
|
14
|
+
export function scriptLines(script) {
|
|
15
|
+
// An expression (`${{ … }}`), which GitHub writes in before the shell reads
|
|
16
|
+
// the script, read as a variable is: a value unknown here, each line it
|
|
17
|
+
// spans past its first continuing the one it is on; a `}}` in one of its
|
|
18
|
+
// strings (`format('{{0}}')`) not its end.
|
|
19
|
+
const lines = script.replaceAll(/\$\{\{(?:'[^']*'|[^'])*?\}\}/gu, expression => `$EXPRESSION${' \\\n'.repeat(expression.split('\n').length - 1)}`).split('\n')
|
|
20
|
+
const joined = []
|
|
21
|
+
for (let at = 0; at < lines.length; at++) {
|
|
22
|
+
const start = at
|
|
23
|
+
let text = lines[at].replace(/\r$/u, '')
|
|
24
|
+
for (;;) {
|
|
25
|
+
const escaped = /(?:^|[^\\])(?:\\\\)*[\\`^]$/u.test(text), piped = /(?:\||&&)\s*$/u.test(text) && !/(?:^|\s)#/u.test(text)
|
|
26
|
+
if (!(escaped || piped) || at + 1 === lines.length) break
|
|
27
|
+
text = `${escaped ? text.slice(0, -1) : text} ${lines[++at].replace(/\r$/u, '')}`
|
|
28
|
+
}
|
|
29
|
+
joined.push({ text, line: start })
|
|
30
|
+
}
|
|
31
|
+
return joined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const WRAPPERS = new Set(['sudo', 'env', 'time', 'nohup', 'exec', 'command', 'nice', 'stdbuf', 'xvfb-run', 'timeout', 'corepack'])
|
|
35
|
+
// A wrapper's options taking a value, as `sudo -u user`, `timeout 10m` do.
|
|
36
|
+
const WRAPPER_VALUES = new Map([['sudo', /^-[ugCDhpRrTU]$/u], ['env', /^-[uC]$/u], ['nice', /^-n$/u], ['timeout', /^-[sk]$/u]])
|
|
37
|
+
|
|
38
|
+
// What a command runs (`argv`): its words past settings, kept (`env`), and
|
|
39
|
+
// wrappers, a wrapper's options and their values, and `timeout`'s duration.
|
|
40
|
+
function argvOf(words) {
|
|
41
|
+
const env = {}
|
|
42
|
+
let at = 0
|
|
43
|
+
for (;;) {
|
|
44
|
+
for (; at < words.length && /^[A-Za-z_]\w*=/u.test(words[at]); at++) env[words[at].slice(0, words[at].indexOf('='))] = words[at].slice(words[at].indexOf('=') + 1)
|
|
45
|
+
const wrapper = words[at]?.replace(/^.*\//u, '')
|
|
46
|
+
if (!WRAPPERS.has(wrapper)) return { argv: words.slice(at), env }
|
|
47
|
+
at++
|
|
48
|
+
while (at < words.length && words[at].startsWith('-')) at += WRAPPER_VALUES.get(wrapper)?.test(words[at]) ? 2 : 1
|
|
49
|
+
if (wrapper === 'timeout' && /^\d/u.test(words[at] ?? '')) at++
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// A command's words, quotes taken off, redirections dropped, and the file
|
|
54
|
+
// its output is written to (`> file`, `>> file`), or null.
|
|
55
|
+
function wordsOf(text) {
|
|
56
|
+
const words = []
|
|
57
|
+
let quote = null, word = null
|
|
58
|
+
for (let at = 0; at <= text.length; at++) {
|
|
59
|
+
const char = text[at]
|
|
60
|
+
if (quote) {
|
|
61
|
+
if (char === quote) quote = null
|
|
62
|
+
else if (char === undefined) break
|
|
63
|
+
else word += quote === '"' && char === '\\' && /["\\$`]/u.test(text[at + 1] ?? '') ? text[++at] : char
|
|
64
|
+
} else if (char === undefined || /\s/u.test(char)) {
|
|
65
|
+
if (word !== null) words.push(word)
|
|
66
|
+
word = null
|
|
67
|
+
} else if (char === '"' || char === "'") { quote = char; word ??= '' }
|
|
68
|
+
// A redirection joined to a word before it (`url>file`) starts its own.
|
|
69
|
+
else if ((char === '>' || char === '<') && word !== null && !/^\d*&?$|[<>]$/u.test(word)) { words.push(word); word = char }
|
|
70
|
+
else word = (word ?? '') + (char === '\\' && at + 1 < text.length ? text[++at] : char)
|
|
71
|
+
}
|
|
72
|
+
const kept = []
|
|
73
|
+
let out = null
|
|
74
|
+
for (let at = 0; at < words.length; at++) {
|
|
75
|
+
const redirect = /^(\d*)(>>?|<<?|&>>?)(.*)$/u.exec(words[at])
|
|
76
|
+
if (!redirect) { kept.push(words[at]); continue }
|
|
77
|
+
const target = redirect[3] === '' ? words[++at] : redirect[3]
|
|
78
|
+
if (redirect[2].includes('>') && (redirect[1] === '' || redirect[1] === '1') && target && !target.startsWith('&')) out = target
|
|
79
|
+
}
|
|
80
|
+
return { words: kept, out }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Where a `$(…)` starting at `from` (its `(`) closes, or the line's end.
|
|
84
|
+
function closing(text, from) {
|
|
85
|
+
let depth = 0, quote = null
|
|
86
|
+
for (let at = from; at < text.length; at++) {
|
|
87
|
+
const char = text[at]
|
|
88
|
+
if (quote) { if (char === quote) quote = null; else if (char === '\\') at++ }
|
|
89
|
+
else if (char === "'" || char === '"') quote = char
|
|
90
|
+
else if (char === '(') depth++
|
|
91
|
+
else if (char === ')' && --depth === 0) return at
|
|
92
|
+
}
|
|
93
|
+
return text.length
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// A line's commands, each `{ argv, env, piped, out, nested }`, `env` the
|
|
97
|
+
// settings it runs with, `piped` where a pipe feeds it, `out` the file it writes its output to and `nested` its
|
|
98
|
+
// command substitutions' text, to read as lines of their own; and those of
|
|
99
|
+
// none of them (`nested`).
|
|
100
|
+
function commandsOf(text) {
|
|
101
|
+
const commands = []
|
|
102
|
+
let nested = [], piped = false, quote = null, start = 0
|
|
103
|
+
const end = (at, next) => {
|
|
104
|
+
const { words, out } = wordsOf(text.slice(start, at))
|
|
105
|
+
const { argv, env } = argvOf(words)
|
|
106
|
+
if (argv.length > 0) { commands.push({ argv, env, piped, out, nested }); nested = [] }
|
|
107
|
+
piped = next
|
|
108
|
+
}
|
|
109
|
+
for (let at = 0; at < text.length; at++) {
|
|
110
|
+
const char = text[at]
|
|
111
|
+
if (quote === "'") { if (char === "'") quote = null; continue }
|
|
112
|
+
if (char === '\\') { at++; continue }
|
|
113
|
+
if (char === '$' && text[at + 1] === '(') {
|
|
114
|
+
const close = closing(text, at + 1)
|
|
115
|
+
nested.push(text.slice(at + 2, close))
|
|
116
|
+
at = close
|
|
117
|
+
} else if (quote === '"') { if (char === '"') quote = null }
|
|
118
|
+
else if (char === '"' || char === "'") quote = char
|
|
119
|
+
else if (char === '#' && (at === 0 || /\s/u.test(text[at - 1]))) { end(at, false); start = text.length; break }
|
|
120
|
+
else if ((char === '&' || char === '|') && text[at + 1] === char) { end(at, false); start = ++at + 1 }
|
|
121
|
+
else if (char === ';' || (char === '&' && !/[<>]/u.test(text[at - 1] ?? '') && text[at + 1] !== '>')) { end(at, false); start = at + 1 }
|
|
122
|
+
else if (char === '|') { end(at, true); start = at + (text[at + 1] === '&' ? 2 : 1); if (text[at + 1] === '&') at++ }
|
|
123
|
+
}
|
|
124
|
+
if (start < text.length) end(text.length, false)
|
|
125
|
+
return { commands, nested }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// The command line a shell is given to run (`bash -euc '…'`, `pwsh
|
|
129
|
+
// -Command '…'`), else null.
|
|
130
|
+
function shellLine([program, ...words]) {
|
|
131
|
+
if (!SHELL.test(program)) return null
|
|
132
|
+
const option = /(?:pwsh|powershell)(?:\.exe)?$/iu.test(program) ? /^-(?:c|command)$/iu : /^-[a-z]*c[a-z]*$/u
|
|
133
|
+
const at = words.findIndex(word => option.test(word))
|
|
134
|
+
return at === -1 ? null : words[at + 1] ?? null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// A path `to` from `dir`, both from the step's directory ('' for it); as
|
|
138
|
+
// written where a variable, `~`, `-` or an absolute path names it.
|
|
139
|
+
export const pathFrom = (dir, to) => /^[$~/-]/u.test(to) ? to : resolved(dir ? dir.split('/') : [], to)?.join('/') ?? [dir, to].filter(Boolean).join('/')
|
|
140
|
+
|
|
141
|
+
// Each command of a script, in the order they run (`order`): its `line` from
|
|
142
|
+
// 0, the directory the `cd`s before it moved to (`dir`, by pathFrom), and
|
|
143
|
+
// `pipedTo`, the commands its output is piped through; a command
|
|
144
|
+
// substitution's before its command's, a shell's command line's (`sh -c`)
|
|
145
|
+
// after it.
|
|
146
|
+
export function scriptCommands(script) {
|
|
147
|
+
const found = []
|
|
148
|
+
let dir = '', read = 0
|
|
149
|
+
// A substitution's or a shell's command line (`apart`) moves no `cd` of its caller's.
|
|
150
|
+
const readLine = (text, line, apart = false) => {
|
|
151
|
+
if (read++ >= 64) return
|
|
152
|
+
const outer = dir, { commands, nested } = commandsOf(text)
|
|
153
|
+
commands.forEach(({ nested: substituted, ...command }, at) => {
|
|
154
|
+
for (const each of substituted) readLine(each, line, true)
|
|
155
|
+
const end = commands.findIndex((each, after) => after > at && !each.piped)
|
|
156
|
+
found.push({ ...command, line, dir, order: found.length, pipedTo: commands.slice(at + 1, end === -1 ? undefined : end) })
|
|
157
|
+
if (command.argv[0] === 'cd') dir = pathFrom(dir, command.argv.slice(1).find(word => !/^-[LPe@]+$/u.test(word)) ?? '~')
|
|
158
|
+
const shell = shellLine(command.argv)
|
|
159
|
+
if (shell) readLine(shell, line, true)
|
|
160
|
+
})
|
|
161
|
+
for (const each of nested) readLine(each, line, true)
|
|
162
|
+
if (apart) dir = outer
|
|
163
|
+
}
|
|
164
|
+
for (const { text, line } of scriptLines(script)) {
|
|
165
|
+
read = 0
|
|
166
|
+
readLine(text, line)
|
|
167
|
+
}
|
|
168
|
+
return found
|
|
169
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// What a `uses:` names, as GitHub reads it (`owner/repo[/path]@ref`, `./path`,
|
|
2
|
+
// `$/path`, `docker://image`), and an image a job runs in.
|
|
3
|
+
|
|
4
|
+
const GITHUB_OWNERS = new Set(['actions', 'github'])
|
|
5
|
+
|
|
6
|
+
const OWNER = /^[\da-z](?:[\da-z]|-(?=[\da-z])){0,38}$/iu
|
|
7
|
+
const NAME = /^(?!\.{1,2}$)[\w.-]{1,100}$/u
|
|
8
|
+
const SHA = /^[\da-f]{40}$/u
|
|
9
|
+
const SHORT_SHA = /^[\da-f]{7,39}$/u
|
|
10
|
+
// A version a comment beside a pin names, as Dependabot, Renovate, pinact
|
|
11
|
+
// and ratchet write one (`# v4.1.1`, `# tag=v4.1.1`, `# ratchet:x@v4`).
|
|
12
|
+
const VERSION = String.raw`v?\d+(?:\.\d+){0,3}(?:[-+][\w.-]+)?`
|
|
13
|
+
const VERSION_COMMENT = new RegExp(String.raw`^#\s*(?:tag\s*[=:]\s*|pin@|ratchet:[^\s@]+@)?(${VERSION})(?![\w.])`, 'iu')
|
|
14
|
+
// Whether what a comment names is a version, not a ref named alone.
|
|
15
|
+
const VERSION_ALONE = new RegExp(`^${VERSION}$`, 'iu')
|
|
16
|
+
export const isVersion = text => VERSION_ALONE.test(text)
|
|
17
|
+
// Else a branch or a tag a comment names alone (`# main`, `# ratchet:x@main`),
|
|
18
|
+
// one git can name so.
|
|
19
|
+
const REF_COMMENT = /^#\s*(?:ratchet:[^\s@]+@)?([\w./-]{1,255})$/u
|
|
20
|
+
const BAD_REF = /\.\.|\/\/|^-|(?:^|\/)\.|\.lock(?:\/|$)|[./]$|^\//u
|
|
21
|
+
|
|
22
|
+
// `sha`, `short-sha`, `ref` (a tag or a branch), or `expression`, which GitHub refuses.
|
|
23
|
+
function pinOf(ref) {
|
|
24
|
+
if (/\$\{\{/u.test(ref)) return 'expression'
|
|
25
|
+
if (SHA.test(ref)) return 'sha'
|
|
26
|
+
return SHORT_SHA.test(ref) ? 'short-sha' : 'ref'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// An image's name, tag and digest (`[host[:port]/]path[:tag][@digest]`), null
|
|
30
|
+
// for none; null where it isn't one.
|
|
31
|
+
export function readImage(text) {
|
|
32
|
+
if (typeof text !== 'string' || text === '' || /\$\{\{|\s/u.test(text)) return null
|
|
33
|
+
const at = text.indexOf('@')
|
|
34
|
+
const digest = at === -1 ? null : text.slice(at + 1)
|
|
35
|
+
const named = at === -1 ? text : text.slice(0, at)
|
|
36
|
+
const colon = named.lastIndexOf(':')
|
|
37
|
+
const tagged = colon > named.lastIndexOf('/')
|
|
38
|
+
if (digest !== null && !/^sha256:[\da-f]{64}$/u.test(digest)) return null
|
|
39
|
+
return { image: tagged ? named.slice(0, colon) : named, tag: tagged ? named.slice(colon + 1) : null, digest }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The ref a comment names alone, whole (`# v1/maintenance`), else the
|
|
43
|
+
// version it begins with (`# v4 is fine`); null for neither.
|
|
44
|
+
function commentNamed(comment) {
|
|
45
|
+
const text = typeof comment === 'string' ? comment.trim() : ''
|
|
46
|
+
const ref = REF_COMMENT.exec(text)?.[1]
|
|
47
|
+
return ref && !BAD_REF.test(ref) ? ref : VERSION_COMMENT.exec(text)?.[1] ?? null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const isWorkflowPath = path => /^\.github\/workflows\/[^/]+\.ya?ml$/u.test(path)
|
|
51
|
+
|
|
52
|
+
// `{ kind, uses, … }`: `action`, or `workflow` at a job's level (`job`), with
|
|
53
|
+
// its `repo`, `path`, `ref`, `pin` and the version or ref its `comment`
|
|
54
|
+
// names; `local`, `self` at the commit running, `job` a reusable workflow's,
|
|
55
|
+
// at the calling workflow's commit; `docker`; or `invalid`, which GitHub
|
|
56
|
+
// won't run.
|
|
57
|
+
export function readUses(text, { job = false, comment = null } = {}) {
|
|
58
|
+
const uses = typeof text === 'string' ? text.trim() : ''
|
|
59
|
+
if (uses.startsWith('./') || uses.startsWith('$/')) {
|
|
60
|
+
return { kind: 'local', uses, path: uses.slice(2).replace(/\/+$/u, ''), ...uses.startsWith('$/') ? { self: true } : {}, ...job ? { job: true } : {} }
|
|
61
|
+
}
|
|
62
|
+
if (uses.startsWith('docker://')) {
|
|
63
|
+
const image = job ? null : readImage(uses.slice('docker://'.length))
|
|
64
|
+
return image ? { kind: 'docker', uses, ...image } : { kind: 'invalid', uses }
|
|
65
|
+
}
|
|
66
|
+
const at = uses.indexOf('@')
|
|
67
|
+
const [owner = '', name = '', ...path] = (at === -1 ? uses : uses.slice(0, at)).split('/')
|
|
68
|
+
const ref = at === -1 ? '' : uses.slice(at + 1)
|
|
69
|
+
if (!OWNER.test(owner) || !NAME.test(name) || ref === '' || path.some(part => !NAME.test(part)) || (job && !isWorkflowPath(path.join('/')))) {
|
|
70
|
+
return { kind: 'invalid', uses }
|
|
71
|
+
}
|
|
72
|
+
return { kind: job ? 'workflow' : 'action', uses, repo: `${owner}/${name}`, path: path.join('/'), ref, pin: pinOf(ref), comment: commentNamed(comment) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The key a reference is resolved once by, a commit's with what its comment
|
|
76
|
+
// names, and one a checkout resolves a branch first by (`checkout`) so.
|
|
77
|
+
export const usesKey = ({ repo, path, ref, pin, comment, checkout }) => `${repo.toLowerCase()}${path ? `/${path}` : ''}@${ref}${
|
|
78
|
+
pin === 'sha' ? comment ? ` # ${comment}` : '' : checkout ? ' # checkout' : ''}`
|
|
79
|
+
|
|
80
|
+
// A reference from its key, a reusable workflow's by its path's.
|
|
81
|
+
export function usesOfKey(key) {
|
|
82
|
+
const m = typeof key === 'string' ? /^([^@\s]+@\S+)(?: # (\S+))?$/u.exec(key) : null
|
|
83
|
+
const job = Boolean(m && /^[^/]+\/[^/]+\/\.github\/workflows\/[^/@]+\.ya?ml@/u.test(m[1]))
|
|
84
|
+
const read = m ? readUses(m[1], { job, comment: m[2] ? `# ${m[2]}` : null }) : null
|
|
85
|
+
const each = read?.kind === 'action' && read.pin !== 'sha' && m[2] === 'checkout' ? { ...read, comment: null, checkout: true } : read
|
|
86
|
+
return each && (each.kind === 'action' || each.kind === 'workflow') && usesKey(each) === key ? each : null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// GitHub's own, the workflow's owner's, or another's.
|
|
90
|
+
export function ownerKind(repo, owner) {
|
|
91
|
+
const of = repo.split('/')[0].toLowerCase()
|
|
92
|
+
if (GITHUB_OWNERS.has(of)) return 'github'
|
|
93
|
+
return typeof owner === 'string' && of === owner.toLowerCase() ? 'own' : 'third-party'
|
|
94
|
+
}
|