@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +17 -0
- 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 +3 -0
- package/common/bundle-compare-diff.js +376 -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-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 +2 -0
- package/common/bundle-reasons.js +21 -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 +7 -0
- package/common/bundle-sources.js +333 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +65 -0
- package/common/default-scan-models.ts +35 -0
- package/common/dependency-reviews.d.ts +18 -0
- package/common/dependency-reviews.js +64 -0
- package/common/finding-duplicates.js +58 -0
- package/common/finding-filters.js +274 -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 +1 -0
- package/common/github-issue-labels.js +11 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +8 -0
- package/common/line-diff.js +57 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +34 -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 +44 -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 +7 -0
- package/common/managed/npm-packages.js +51 -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/roles.ts +35 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +363 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/team-app.d.ts +15 -0
- package/common/managed/team-app.js +100 -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/pretty-print.d.ts +5 -0
- package/common/pretty-print.js +24 -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/save-error-reason.ts +20 -7
- 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/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/workspace-app.js +71 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +4 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2SY4PYUQ.js +4 -0
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-4EMM6UCD.js +1 -0
- package/out/chunk-4HI2MSAV.js +17 -0
- package/out/chunk-4ISO5F7Y.js +7 -0
- package/out/chunk-4TQKM3JC.js +42 -0
- package/out/chunk-4XIH7YTX.js +1 -0
- package/out/chunk-6VDDCFHT.js +3 -0
- package/out/chunk-74AEKRES.js +10 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-E3LFSUDJ.js +9 -0
- package/out/chunk-EEQHVKR3.js +1 -0
- package/out/chunk-G3LY2FV4.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-HAZKDK4M.js +4 -0
- package/out/chunk-HNQNDNIE.js +12 -0
- package/out/chunk-HOB3YPS5.js +1 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-IZ6MYRYB.js +3 -0
- package/out/chunk-J2FWBXFV.js +1 -0
- package/out/chunk-JCIIBLKR.js +1 -0
- package/out/chunk-JFL7WLRV.js +1 -0
- package/out/chunk-JMG5DXII.js +2 -0
- package/out/chunk-JOXLZXMI.js +1 -0
- package/out/chunk-M37X4LCF.js +14 -0
- package/out/chunk-M3Y6SLC4.js +1 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-NXATZJQ2.js +1 -0
- package/out/chunk-OFPDMZJF.js +244 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-OQRSIBSC.js +1 -0
- package/out/chunk-PAD2JHZT.js +1 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PTFQKLKO.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QMVOEBWC.js +13 -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-RRBIJL2B.js +1 -0
- package/out/chunk-SYXT3SFP.js +2 -0
- package/out/chunk-TOXMUOIW.js +5 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-TZS7KERJ.js +52 -0
- package/out/chunk-UCP3JRE2.js +1 -0
- package/out/chunk-VFWMQ3LG.js +2 -0
- package/out/chunk-VRX2APNA.js +9 -0
- package/out/chunk-VZJIHHTQ.js +1 -0
- package/out/chunk-WCPJDAYA.js +10 -0
- package/out/chunk-WMFDQS2L.js +11 -0
- package/out/chunk-WREU7JAG.js +1 -0
- package/out/chunk-Y5ZHFNBD.js +2 -0
- package/out/chunk-YF4M5OCI.js +1 -0
- package/out/chunk-YGRRXC2L.js +1 -0
- package/out/chunk-YTO6AQZM.js +2 -0
- package/out/chunk-Z667U2UJ.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +34 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +35 -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 -4
- package/out/index.html +106 -8
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +366 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -144
- package/package.json +379 -62
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +250 -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 +76 -0
- package/risk/actions/workflow.js +110 -0
- package/risk/files/characters.js +196 -0
- package/risk/files/hosts.js +205 -0
- package/risk/files/readability.js +177 -0
- package/risk/files/runs-code.js +615 -0
- package/risk/files/script.js +118 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +272 -0
- package/risk/index.js +11 -0
- package/risk/npm/assess.js +285 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +257 -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 +63 -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 +390 -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 +96 -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 +50 -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 +60 -33
- package/{server → server-e2e}/static.ts +31 -21
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +258 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +13 -0
- package/server-managed/blob-store.ts +17 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +102 -0
- package/server-managed/bundle-advisory-inventory.ts +77 -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 +203 -0
- package/server-managed/bundle-build.ts +232 -0
- package/server-managed/bundle-cache.ts +211 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +140 -0
- package/server-managed/bundle-dependency-reviews.ts +74 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +130 -0
- package/server-managed/bundle-validation.ts +32 -0
- package/server-managed/bundle.ts +119 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +47 -0
- package/server-managed/comments.ts +151 -0
- package/server-managed/commit-coauthors.ts +106 -0
- package/server-managed/commit-lockfiles.ts +76 -0
- package/server-managed/comparison.ts +52 -0
- package/server-managed/config.ts +164 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1958 -0
- package/server-managed/db-neon.ts +484 -0
- package/server-managed/db-schema.ts +238 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +152 -0
- package/server-managed/dependabot-access.ts +60 -0
- package/server-managed/dependabot-alerts.ts +185 -0
- package/server-managed/dependency-review-comments.ts +98 -0
- package/server-managed/dependency-reviews.ts +364 -0
- package/server-managed/github-accounts.ts +60 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +376 -0
- package/server-managed/github-errors.ts +70 -0
- package/server-managed/github-graphql.ts +39 -0
- package/server-managed/github-issue-links.ts +244 -0
- package/server-managed/github-issue-oauth.ts +47 -0
- package/server-managed/github-issues.ts +155 -0
- package/server-managed/github-link-oauth.ts +69 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +238 -0
- package/server-managed/github-pulls.ts +246 -0
- package/server-managed/github-requests.ts +166 -0
- package/server-managed/github-users.ts +30 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +5855 -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/link-reports.ts +162 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +152 -0
- package/server-managed/lockfile-scope.ts +49 -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 +99 -0
- package/server-managed/npm-delta-worker.js +23 -0
- package/server-managed/npm-delta.ts +194 -0
- package/server-managed/npm-insights.ts +450 -0
- package/server-managed/npm-kept.ts +233 -0
- package/server-managed/npm-loads.ts +264 -0
- package/server-managed/npm-manifest.ts +115 -0
- package/server-managed/npm-packages.ts +454 -0
- package/server-managed/npm-patch.ts +325 -0
- package/server-managed/npm-provenance.ts +123 -0
- package/server-managed/npm-risk.ts +285 -0
- package/server-managed/object-storage-disk.ts +148 -0
- package/server-managed/object-storage-vercel.ts +67 -0
- package/server-managed/object-storage.ts +75 -0
- package/server-managed/package-entry-points.ts +79 -0
- package/server-managed/pretty-print.ts +436 -0
- package/server-managed/public-workspace.ts +238 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +351 -0
- package/server-managed/pull-dependency-reviews.ts +334 -0
- package/server-managed/pull-reviews.ts +205 -0
- package/server-managed/queue.ts +39 -0
- package/server-managed/release-commits.ts +84 -0
- package/server-managed/rename-diff-worker.js +26 -0
- package/server-managed/rename-diff.ts +279 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +35 -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 +85 -0
- package/server-managed/repository-actions.ts +221 -0
- package/server-managed/repository-agents.ts +448 -0
- package/server-managed/repository-aliases.ts +91 -0
- package/server-managed/repository-browser.ts +301 -0
- package/server-managed/repository-changes.ts +284 -0
- package/server-managed/repository-code.ts +215 -0
- package/server-managed/repository-dependency-reviews.ts +166 -0
- package/server-managed/repository-discovery.ts +82 -0
- package/server-managed/repository-history.ts +432 -0
- package/server-managed/repository-issues.ts +195 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +212 -0
- package/server-managed/repository-pulse.ts +471 -0
- package/server-managed/repository-risk-assess.ts +105 -0
- package/server-managed/repository-risk-audit.ts +78 -0
- package/server-managed/repository-risk-read.ts +170 -0
- package/server-managed/repository-risk.ts +491 -0
- package/server-managed/repository-squashes.ts +168 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +149 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +87 -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 +89 -0
- package/server-managed/stasis-config.ts +55 -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 +290 -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 +54 -0
- package/server-managed/team-app.ts +157 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +106 -0
- package/server-managed/team-reports.ts +351 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-worker.js +19 -0
- package/server-managed/type-only.ts +105 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +252 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/workspace-shares.ts +171 -0
- package/server.ts +70 -0
- 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,161 @@
|
|
|
1
|
+
// What a workflow, or an action's metadata, calls for by its own text (README.md).
|
|
2
|
+
import { YamlError } from '@preventive/lockfile/yaml.js'
|
|
3
|
+
import { readWorkflow } from './workflow.js'
|
|
4
|
+
import { installsOf } from './scripts/commands.js'
|
|
5
|
+
import { dotted, imageFinding, lockedName, namesPullHead, scriptFindings, scriptInjections, within } from './scripts/grade.js'
|
|
6
|
+
import { ownerKind, usesKey } from './uses.js'
|
|
7
|
+
import { resolved } from '../npm/files.js'
|
|
8
|
+
|
|
9
|
+
// What a `uses:` calls for by its pin, a reference's with its `key`.
|
|
10
|
+
function usesFinding(uses, owner) {
|
|
11
|
+
if (uses.kind === 'invalid') return { id: 'invalid-uses', severity: 'low', uses: uses.uses }
|
|
12
|
+
if (uses.kind === 'docker') return uses.digest ? null : imageFinding(uses.uses, uses)
|
|
13
|
+
if ((uses.kind !== 'action' && uses.kind !== 'workflow') || uses.pin === 'sha') return null
|
|
14
|
+
const at = { uses: uses.uses, key: usesKey(uses) }
|
|
15
|
+
return uses.pin === 'short-sha' ? { id: 'short-sha', severity: 'high', ...at } : { id: 'unpinned', severity: ownerKind(uses.repo, owner) === 'third-party' ? 'high' : 'moderate', ...at, ref: uses.ref }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// An action that installs a project's npm packages, by its name: npm's,
|
|
19
|
+
// Yarn's, pnpm's or Bun's install of dependencies (`bahmutov/npm-install`),
|
|
20
|
+
// not another tool's (`cachix/install-nix-action`).
|
|
21
|
+
const INSTALLER = /(?:npm|yarn|pnpm|bun|node[-_]?modules)[-_]?(?:ci|install)|install[-_]?(?:npm|yarn|pnpm|bun|node[-_]?modules|dep(?:endencie)?s|packages)/iu
|
|
22
|
+
|
|
23
|
+
// Where a step installs a project's packages, each `{ at, prod }`: a
|
|
24
|
+
// script's install's directory or the one it names, and whether it leaves
|
|
25
|
+
// devDependencies out; an action of its own's, by its metadata (ScanOptions
|
|
26
|
+
// `actions`), anywhere (null) where none is told; and anywhere for an action
|
|
27
|
+
// that installs them (cypress-io/github-action's unless `install: false`,
|
|
28
|
+
// pnpm/action-setup's with `run_install`).
|
|
29
|
+
const ANYWHERE = [{ at: null, prod: false }]
|
|
30
|
+
function installs(step, actions, seen = new Set()) {
|
|
31
|
+
if (step.uses?.kind === 'local') return actions ? ownInstalls(actions, step.uses.path, seen) : ANYWHERE
|
|
32
|
+
const repo = step.uses?.repo?.toLowerCase()
|
|
33
|
+
if (repo && (INSTALLER.test(repo) || (repo === 'cypress-io/github-action' && String(step.with?.install) !== 'false'))) return ANYWHERE
|
|
34
|
+
if (repo === 'pnpm/action-setup' && /^(?:true|\[|\{|-)/u.test(String(step.with?.run_install ?? '').trim())) return ANYWHERE
|
|
35
|
+
return step.run ? installsOf(step.run.script, step.run.production).map(({ into, prod }) => ({ at: directoryOf(step.run.workingDirectory, into), prod })) : []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Where the repository's own action at `dir` installs, by its steps, each
|
|
39
|
+
// action of its own once.
|
|
40
|
+
function ownInstalls(actions, dir, seen) {
|
|
41
|
+
const read = actions.has(dir) && !seen.has(dir) && seen.add(dir) ? readWorkflow('action', actions.get(dir)) : null
|
|
42
|
+
return read && !(read instanceof YamlError) ? read.jobs.flatMap(job => job.steps.flatMap(step => installs(step, actions, seen))) : []
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// A step's directory, and a path from it (`into`), from the repository's
|
|
46
|
+
// root, '' for it; as written where an expression or a variable names it, or
|
|
47
|
+
// it is out of the repository, so that it is within the same alone.
|
|
48
|
+
function directoryOf(workingDirectory, into = null) {
|
|
49
|
+
const path = into?.startsWith('/') ? into : [workingDirectory, into].filter(Boolean).join('/')
|
|
50
|
+
return /\$|^\//u.test(path) ? path : resolved([], path)?.join('/') ?? path
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Whether the nearest lockfiles at or above `directory`, its project's, lock
|
|
54
|
+
// what npx runs by `name`: `dev` where only devDependencies need it in each
|
|
55
|
+
// that does.
|
|
56
|
+
const lockDir = path => path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''
|
|
57
|
+
function lockedIn(lockfiles, directory, name) {
|
|
58
|
+
const above = lockfiles.filter(({ path }) => within(lockDir(path), directory))
|
|
59
|
+
const nearest = Math.max(...above.map(({ path }) => lockDir(path).length))
|
|
60
|
+
const locking = above.filter(({ path, names }) => lockDir(path).length === nearest && lockedName(names, name))
|
|
61
|
+
return locking.length > 0 && (locking.every(({ dev }) => dev && lockedName(dev, name)) ? 'dev' : true)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The inputs a text names (`${{ inputs.title }}`).
|
|
65
|
+
const inputsIn = text => typeof text === 'string' ? [...dotted(text).matchAll(/\$\{\{[^}]*?\binputs\s*\.\s*([\w-]+)/gu)].map(match => match[1]) : []
|
|
66
|
+
|
|
67
|
+
// The inputs a step's action, or a job's reusable workflow, writes into a
|
|
68
|
+
// script: github-script's `script`; those one of the repository's own
|
|
69
|
+
// (ScanOptions `actions`) names in its `run:`s or its jobs' images, or hands
|
|
70
|
+
// to such an input of a step's or a job's; and each of another reusable
|
|
71
|
+
// workflow's, or one whose text isn't told, as it may.
|
|
72
|
+
function scriptInputs(step, actions, seen = new Set()) {
|
|
73
|
+
if (step.uses?.repo?.toLowerCase() === 'actions/github-script') return ['script']
|
|
74
|
+
if (step.uses?.kind === 'workflow' || (step.uses?.job && !actions?.has(step.uses.path))) return Object.keys(step.with ?? {})
|
|
75
|
+
const path = step.uses?.kind === 'local' && actions?.has(step.uses.path) && !seen.has(step.uses.path) ? step.uses.path : null
|
|
76
|
+
const read = path === null ? null : readWorkflow(step.uses.job ? 'workflow' : 'action', actions.get(path))
|
|
77
|
+
if (!read || read instanceof YamlError) return []
|
|
78
|
+
const inner = new Set(seen).add(path)
|
|
79
|
+
const handed = each => scriptInputs(each, actions, inner).flatMap(input => inputsIn(each.with?.[input]))
|
|
80
|
+
return [...new Set(read.jobs.flatMap(job => [...job.uses ? handed(job) : [], ...job.images.flatMap(image => inputsIn(image.text)),
|
|
81
|
+
...job.steps.flatMap(each => [...inputsIn(each.run?.script), ...handed(each)])]))]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Injections through the inputs an action writes into its scripts, and a
|
|
85
|
+
// fork's code or artifacts taken where the workflow runs with its secrets.
|
|
86
|
+
function stepFindings(step, triggers, actions) {
|
|
87
|
+
const repo = step.uses?.repo?.toLowerCase()
|
|
88
|
+
const found = scriptInputs(step, actions).flatMap(input => scriptInjections(step.with?.[input], triggers).map(({ index: _index, ...finding }) => ({ ...finding, line: step.withLines[input] })))
|
|
89
|
+
const forks = ['pull_request_target', 'workflow_run', 'issue_comment'].some(event => triggers.includes(event))
|
|
90
|
+
if (forks && repo === 'actions/checkout' && (namesPullHead(step.with?.ref) || namesPullHead(step.with?.repository))) {
|
|
91
|
+
found.push({ id: 'pwn-request', severity: 'critical', ref: String(step.with.ref ?? step.with.repository), line: step.withLines.ref ?? step.withLines.repository ?? step.line })
|
|
92
|
+
}
|
|
93
|
+
if (forks && step.run && /\bgh\s+pr\s+checkout\b/u.test(step.run.script)) found.push({ id: 'pwn-request', severity: 'critical', ref: 'gh pr checkout', line: step.run.line })
|
|
94
|
+
if (triggers.includes('workflow_run') && ((repo === 'actions/download-artifact' && (step.with?.['run-id'] !== undefined || step.with?.['github-token'] !== undefined))
|
|
95
|
+
|| repo === 'dawidd6/action-download-artifact' || /\bgh\s+run\s+download\b/u.test(step.run?.script ?? ''))) found.push({ id: 'untrusted-artifact', severity: 'high', line: step.uses?.line ?? step.run.line })
|
|
96
|
+
return found
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// A job's findings, each script graded by the installs before it and its lockfiles.
|
|
100
|
+
function jobFindings(job, triggers, { owner, lockfiles, external, actions }) {
|
|
101
|
+
const found = []
|
|
102
|
+
if (job.uses) {
|
|
103
|
+
const finding = usesFinding(job.uses, owner)
|
|
104
|
+
if (finding) found.push({ ...finding, line: job.uses.line })
|
|
105
|
+
if (job.secrets === 'inherit' && job.uses.repo && ownerKind(job.uses.repo, owner) === 'third-party') found.push({ id: 'secrets-inherited', severity: 'high', uses: job.uses.uses, key: usesKey(job.uses), line: job.uses.line })
|
|
106
|
+
// An input a reusable workflow writes into its scripts.
|
|
107
|
+
for (const input of scriptInputs(job, actions)) for (const { index: _index, ...injected } of scriptInjections(job.with?.[input], triggers)) found.push({ ...injected, line: job.withLines[input] })
|
|
108
|
+
}
|
|
109
|
+
for (const image of job.images) {
|
|
110
|
+
if (!image.read?.digest && !image.text.includes('${{')) found.push({ ...imageFinding(image.text, image.read), line: image.line })
|
|
111
|
+
for (const { index: _index, ...injected } of scriptInjections(image.text, triggers)) found.push({ ...injected, line: image.line })
|
|
112
|
+
}
|
|
113
|
+
const installed = []
|
|
114
|
+
for (const step of job.steps) {
|
|
115
|
+
const finding = step.uses && usesFinding(step.uses, owner)
|
|
116
|
+
if (finding) found.push({ ...finding, line: step.uses.line })
|
|
117
|
+
if (step.run) {
|
|
118
|
+
const directory = dir => directoryOf(step.run.workingDirectory, dir)
|
|
119
|
+
const locked = (name, dir) => !external && lockedIn(lockfiles, directory(dir), name)
|
|
120
|
+
const before = (dev, dir) => installed.some(({ at, prod }) => within(at, directory(dir)) && !(prod && dev))
|
|
121
|
+
found.push(...scriptFindings(step.run, { locked, installed: before, external, triggers }))
|
|
122
|
+
}
|
|
123
|
+
found.push(...stepFindings(step, triggers, actions))
|
|
124
|
+
installed.push(...installs(step, actions))
|
|
125
|
+
}
|
|
126
|
+
return found
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Every finding of a workflow read (readWorkflow), in its lines' order, by
|
|
130
|
+
// index.d.ts ScanOptions.
|
|
131
|
+
export function workflowFindings(read, { owner = null, lockfiles = [], external = false, actions = null } = {}) {
|
|
132
|
+
const found = read.jobs.flatMap(job => jobFindings(job, read.triggers, { owner, lockfiles, external, actions }))
|
|
133
|
+
if (/^node(?:12|16)$/u.test(read.using ?? '')) found.push({ id: 'deprecated-runtime', severity: 'low', using: read.using, line: read.usingLine })
|
|
134
|
+
return found.toSorted((a, b) => (a.line ?? 0) - (b.line ?? 0))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The references a workflow read makes: of GitHub's, each with its `key`, and
|
|
138
|
+
// of its own (`local`).
|
|
139
|
+
export function workflowUses(read) {
|
|
140
|
+
return read.jobs.flatMap(job => [job.uses, ...job.steps.map(step => step.uses)]).flatMap(uses => {
|
|
141
|
+
if (uses?.kind === 'local') return [uses]
|
|
142
|
+
return uses?.kind === 'action' || uses?.kind === 'workflow' ? [{ ...uses, key: usesKey(uses) }] : []
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// The actions of the repository's own a workflow or an action uses, by
|
|
147
|
+
// their directories, and a Docker action's Dockerfile; none for one GitHub
|
|
148
|
+
// can't run.
|
|
149
|
+
export function ownFilesOf(kind, text) {
|
|
150
|
+
const read = readWorkflow(kind, text)
|
|
151
|
+
if (read instanceof YamlError) return { actions: [], dockerfile: null }
|
|
152
|
+
return { actions: workflowUses(read).flatMap(uses => uses.kind === 'local' && !uses.job ? [uses.path] : []), dockerfile: read.dockerfile?.path ?? null }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// A workflow's or an action's metadata's (`kind`) references and findings;
|
|
156
|
+
// why not (`workflow-unreadable`) for one GitHub can't run.
|
|
157
|
+
export function scanWorkflow(kind, text, options = {}) {
|
|
158
|
+
const read = readWorkflow(kind, text)
|
|
159
|
+
if (read instanceof YamlError) return { error: 'workflow-unreadable', detail: read.message.slice(0, 500) }
|
|
160
|
+
return { uses: workflowUses(read), findings: workflowFindings(read, options) }
|
|
161
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// A reference resolved on GitHub (`source`, index.d.ts ActionsSource): its
|
|
2
|
+
// repository, its ref's commit, its advisories and its own code's findings
|
|
3
|
+
// (README.md).
|
|
4
|
+
import { YamlError } from '@preventive/lockfile/yaml.js'
|
|
5
|
+
import { readWorkflow } from './workflow.js'
|
|
6
|
+
import { workflowFindings, workflowUses } from './findings.js'
|
|
7
|
+
import { imageFinding, scriptFindings } from './scripts/grade.js'
|
|
8
|
+
import { isWorkflowPath, ownerKind, readImage, readUses, usesKey } from './uses.js'
|
|
9
|
+
|
|
10
|
+
// An action's tags as versions: a release's (`v4.2.1`), and a major (`v4`) or
|
|
11
|
+
// minor one (`v4.2`) moved to its line's latest. `[major, minor, patch]`,
|
|
12
|
+
// null for a part a tag hasn't; null for no version.
|
|
13
|
+
export function tagVersion(tag) {
|
|
14
|
+
const m = typeof tag === 'string' ? /^v?(\d{1,9})(?:\.(\d{1,9}))?(?:\.(\d{1,9}))?$/u.exec(tag) : null
|
|
15
|
+
return m && [Number(m[1]), m[2] === undefined ? null : Number(m[2]), m[3] === undefined ? null : Number(m[3])]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const isRelease = version => version !== null && version[2] !== null
|
|
19
|
+
|
|
20
|
+
const byVersion = (a, b) => (b[0] - a[0]) || ((b[1] ?? -1) - (a[1] ?? -1)) || ((b[2] ?? -1) - (a[2] ?? -1))
|
|
21
|
+
|
|
22
|
+
// Whether a release is of a major or minor tag's line: `v4`'s `4.x.y`.
|
|
23
|
+
const ofLine = (version, other) => isRelease(other) && other[0] === version[0] && (version[1] === null || other[1] === version[1])
|
|
24
|
+
|
|
25
|
+
// The versions of `tags` (`{ tag, oid }` each), the highest first.
|
|
26
|
+
const versionsOf = tags => tags.flatMap(({ tag, oid }) => { const version = tagVersion(tag); return version ? [{ tag, oid, version }] : [] })
|
|
27
|
+
.toSorted((a, b) => byVersion(a.version, b.version))
|
|
28
|
+
|
|
29
|
+
// The latest release's tag of `tags`, else the highest version's; null where
|
|
30
|
+
// none is one.
|
|
31
|
+
export function latestOf(tags) {
|
|
32
|
+
const versions = versionsOf(tags)
|
|
33
|
+
return (versions.find(({ version }) => isRelease(version)) ?? versions[0])?.tag ?? null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The highest release of each major line, the latest line first: where a
|
|
37
|
+
// commit is most likely in a release's history.
|
|
38
|
+
export function newestOfLines(tags) {
|
|
39
|
+
const seen = new Set()
|
|
40
|
+
return versionsOf(tags).filter(({ version }) => isRelease(version) && !seen.has(version[0]) && seen.add(version[0]))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// An instruction's lines, its continuations (`\` at a line's end) joined,
|
|
44
|
+
// and each heredoc's (`<<EOF`) through its delimiter, as BuildKit reads one.
|
|
45
|
+
function instructions(text) {
|
|
46
|
+
const lines = text.split('\n').map(line => line.replace(/\r$/u, ''))
|
|
47
|
+
const found = []
|
|
48
|
+
for (let at = 0; at < lines.length; at++) {
|
|
49
|
+
const start = at
|
|
50
|
+
while (lines[at].endsWith('\\') && at + 1 < lines.length) at++
|
|
51
|
+
for (const { 2: quoted, 3: bare } of lines.slice(start, at + 1).join('\n').matchAll(/(?<!<)<<-?\s*(?:(["'])(.+?)\1|([^\s"'<>|&;()]+))/gu)) {
|
|
52
|
+
do at++
|
|
53
|
+
while (at < lines.length - 1 && lines[at].trim() !== (quoted ?? bare))
|
|
54
|
+
}
|
|
55
|
+
found.push({ start, lines: lines.slice(start, Math.min(at, lines.length - 1) + 1) })
|
|
56
|
+
at = Math.min(at, lines.length - 1)
|
|
57
|
+
}
|
|
58
|
+
return found
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A `RUN`'s command, its exec form (`RUN ["sh", "-c", "…"]`) as words.
|
|
62
|
+
function runCommand(text) {
|
|
63
|
+
if (!text.trimStart().startsWith('[')) return text
|
|
64
|
+
try {
|
|
65
|
+
const words = JSON.parse(text)
|
|
66
|
+
return Array.isArray(words) ? words.map(word => /[\s'"]/u.test(String(word)) ? `'${String(word).replaceAll("'", "'\\''")}'` : String(word)).join(' ') : text
|
|
67
|
+
} catch { return text }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A Docker action's Dockerfile: each `FROM` by a tag, a build argument's
|
|
71
|
+
// yellow, and each `RUN` read as a script's (scripts/grade.js).
|
|
72
|
+
export function dockerfileFindings(text) {
|
|
73
|
+
const findings = [], script = [], stages = new Set()
|
|
74
|
+
for (const { start, lines } of instructions(text)) {
|
|
75
|
+
const first = /^\s*(FROM|RUN)\s+(.*)$/iu.exec(lines[0])
|
|
76
|
+
// A RUN's options (`--mount=…`, `--network=…`) aren't its command.
|
|
77
|
+
if (first?.[1].toUpperCase() === 'RUN') { script.push(runCommand(first[2].replace(/^(?:--[a-z-]+(?:=\S*)?\s+)*/iu, '')), ...lines.slice(1)); continue }
|
|
78
|
+
script.push(...lines.map(() => ''))
|
|
79
|
+
if (!first) continue
|
|
80
|
+
const words = lines.join(' ').replaceAll('\\', ' ').trim().split(/\s+/u).slice(1).filter(word => !word.startsWith('--'))
|
|
81
|
+
const [image, as, stage] = words
|
|
82
|
+
const built = image && stages.has(image.toLowerCase())
|
|
83
|
+
if (as?.toLowerCase() === 'as' && stage) stages.add(stage.toLowerCase())
|
|
84
|
+
if (!image || image === 'scratch' || built) continue
|
|
85
|
+
const read = readImage(image)
|
|
86
|
+
if (image.includes('$')) findings.push({ id: 'unpinned-image', severity: 'moderate', image, line: start + 1 })
|
|
87
|
+
else if (!read?.digest) findings.push({ ...imageFinding(image, read), line: start + 1 })
|
|
88
|
+
}
|
|
89
|
+
const run = { script: script.join('\n'), line: 1, start: 1 }
|
|
90
|
+
findings.push(...scriptFindings(run, { locked: () => false, installed: () => false, external: true, triggers: [] }))
|
|
91
|
+
return findings.toSorted((a, b) => a.line - b.line)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// How many major lines' releases a commit is looked for in.
|
|
95
|
+
const MAX_LINES = 10
|
|
96
|
+
|
|
97
|
+
async function repositoryOf(uses, source, owner) {
|
|
98
|
+
const info = await source.repo(uses.repo)
|
|
99
|
+
if (!info) return { info: null, findings: [{ id: 'repo-missing', severity: ownerKind(uses.repo, owner) === 'own' ? 'moderate' : 'critical' }] }
|
|
100
|
+
const findings = []
|
|
101
|
+
if (info.fullName.toLowerCase() !== uses.repo.toLowerCase()) findings.push({ id: 'repo-moved', severity: 'high', to: info.fullName })
|
|
102
|
+
if (info.fork) findings.push({ id: 'repo-fork', severity: 'low', parent: info.fork })
|
|
103
|
+
if (info.archived) findings.push({ id: 'repo-archived', severity: 'low' })
|
|
104
|
+
return { info, findings }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Where `sha` is in the history (`default`, `release`, `branch`), `none`,
|
|
108
|
+
// `unknown` where not all could be looked in, or `missing`: each branch and
|
|
109
|
+
// release looked in once, from its commit.
|
|
110
|
+
async function reachable(source, info, sha, tags) {
|
|
111
|
+
const name = info.fullName, releases = newestOfLines(tags ?? []).slice(0, MAX_LINES)
|
|
112
|
+
if (releases.some(({ oid }) => oid === sha)) return 'release'
|
|
113
|
+
const head = await source.branch(name, info.defaultBranch)
|
|
114
|
+
const onDefault = await source.contains(name, head ?? info.defaultBranch, sha)
|
|
115
|
+
if (onDefault === null) return 'missing'
|
|
116
|
+
if (onDefault) return 'default'
|
|
117
|
+
const looked = new Set([head])
|
|
118
|
+
const contains = oid => !looked.has(oid) && looked.add(oid) && source.contains(name, oid, sha)
|
|
119
|
+
for (const { oid } of releases) if (await contains(oid)) return 'release'
|
|
120
|
+
const { branches, complete } = await source.branches(name)
|
|
121
|
+
for (const { oid } of branches) if (oid === sha || await contains(oid)) return 'branch'
|
|
122
|
+
return complete && tags !== null ? 'none' : 'unknown'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const tagsOn = (tags, commit) => tags?.filter(({ oid }) => oid === commit).map(({ tag }) => tag) ?? []
|
|
126
|
+
|
|
127
|
+
function tagFindings(ref, commit, tags) {
|
|
128
|
+
const version = tagVersion(ref)
|
|
129
|
+
if (!version) return [{ id: 'not-version', severity: 'moderate' }]
|
|
130
|
+
if (!tags) return []
|
|
131
|
+
const findings = []
|
|
132
|
+
const releases = versionsOf(tags).filter(other => ofLine(version, other.version))
|
|
133
|
+
if (version[2] === null && releases.length > 0 && !releases.some(({ oid }) => oid === commit)) findings.push({ id: 'tag-off-release', severity: 'high', release: releases[0].tag })
|
|
134
|
+
const latest = latestOf(tags)
|
|
135
|
+
if (latest && tagVersion(latest)[0] > version[0]) findings.push({ id: 'outdated', severity: 'low', latest })
|
|
136
|
+
return findings
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// A ref not a commit, resolved as GitHub resolves it, a tag before a branch.
|
|
140
|
+
async function refOf(uses, info, source, tags) {
|
|
141
|
+
const name = info.fullName
|
|
142
|
+
const [tagged, branched] = await Promise.all([tags ? tags.find(({ tag }) => tag === uses.ref)?.oid ?? null : source.tag(name, uses.ref), source.branch(name, uses.ref)])
|
|
143
|
+
if (!tagged && !branched) return { commit: null, at: null, findings: [{ id: 'ref-missing', severity: 'moderate' }] }
|
|
144
|
+
if (!tagged) return { commit: branched, at: 'branch', findings: [{ id: 'branch-ref', severity: 'high' }] }
|
|
145
|
+
const findings = branched ? [{ id: 'ambiguous-ref', severity: 'high', branch: branched }] : []
|
|
146
|
+
findings.push(...tagFindings(uses.ref, tagged, tags))
|
|
147
|
+
const where = await reachable(source, info, tagged, tags)
|
|
148
|
+
if (where === 'none') findings.push({ id: 'tag-off-branch', severity: 'low' })
|
|
149
|
+
return { commit: tagged, at: 'tag', findings }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Whether a version a comment names is a tag on the commit, or one's line.
|
|
153
|
+
function commentHolds(comment, named) {
|
|
154
|
+
const version = tagVersion(comment)
|
|
155
|
+
return named.some(tag => tag === comment || tag.replace(/^v/u, '') === comment.replace(/^v/u, '') || (version && version[2] === null && ofLine(version, tagVersion(tag))))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A commit, looked for in the history where no tag names it, held to its comment.
|
|
159
|
+
async function pinnedOf(uses, info, source, tags) {
|
|
160
|
+
const commit = uses.ref
|
|
161
|
+
let named = tagsOn(tags, commit)
|
|
162
|
+
if (!tags && uses.comment && await source.tag(info.fullName, uses.comment) === commit) named = [uses.comment]
|
|
163
|
+
const findings = []
|
|
164
|
+
if (named.length === 0) {
|
|
165
|
+
const where = await reachable(source, info, commit, tags)
|
|
166
|
+
if (where === 'missing') findings.push({ id: 'commit-missing', severity: 'high' })
|
|
167
|
+
else if (where === 'none') findings.push({ id: 'imposter-commit', severity: 'critical' })
|
|
168
|
+
else if (where === 'unknown') findings.push({ id: 'unverified-commit', severity: 'high' })
|
|
169
|
+
else if (tags) findings.push({ id: 'untagged-commit', severity: 'moderate', on: where })
|
|
170
|
+
}
|
|
171
|
+
if (uses.comment && !commentHolds(uses.comment, named)) findings.push({ id: 'comment-mismatch', severity: 'high', comment: uses.comment, tags: named })
|
|
172
|
+
return { commit, at: 'sha', named, findings }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// The versions a reference's advisories are asked of, as upstream's `github`
|
|
176
|
+
// packages take them: the releases on the commit it runs (`v4.2.1`, not the
|
|
177
|
+
// `v4` moving with it), else a commit by its tags, or as any release where
|
|
178
|
+
// none names it, and a tag or a branch as named (a moving tag its whole line).
|
|
179
|
+
function advisedVersions(at, ref, commit, named) {
|
|
180
|
+
const releases = named.filter(tag => isRelease(tagVersion(tag)))
|
|
181
|
+
if (releases.length > 0) return releases
|
|
182
|
+
if (at === 'sha') return named.length > 0 ? named : [commit]
|
|
183
|
+
return [ref]
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const RATED = new Set(['critical', 'high', 'moderate', 'low'])
|
|
187
|
+
|
|
188
|
+
// A repository's advisories at `versions` (`source.advisories`), each a
|
|
189
|
+
// finding: malware red, else as its source rates it, one unrated yellow. One
|
|
190
|
+
// not known public is `internal`, asked of its own advisories alone, its name
|
|
191
|
+
// sent to no other source; why not (`advisories-unavailable`) where they
|
|
192
|
+
// couldn't be had, the rest resolved all the same.
|
|
193
|
+
async function advisoryFindings(source, info, versions) {
|
|
194
|
+
if (source.advisories === undefined) return []
|
|
195
|
+
try {
|
|
196
|
+
return (await source.advisories(info.fullName, versions, info.private ?? true)).map(({ id, title, url, severity, malware, versions: affected }) => ({
|
|
197
|
+
id: 'advisory', severity: malware ? 'critical' : RATED.has(severity) ? severity : 'moderate', advisory: id, ...title && { title }, ...url && { url },
|
|
198
|
+
...malware && { malware: true }, versions: affected }))
|
|
199
|
+
} catch { return [{ id: 'advisories-unavailable', severity: 'notice' }] }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// A `$/path` (the repository's own at the commit running) as a reference.
|
|
203
|
+
const selfRef = (uses, info, commit) => readUses(`${info.fullName}/${uses.path}@${commit}`, { job: isWorkflowPath(uses.path) })
|
|
204
|
+
|
|
205
|
+
// What a reference runs at `commit` (action.yml, a reusable workflow, a
|
|
206
|
+
// Dockerfile): its findings, each with its file, and the references it makes.
|
|
207
|
+
async function codeOf(uses, info, commit, source) {
|
|
208
|
+
const dir = uses.path ? `${uses.path}/` : '', name = info.fullName
|
|
209
|
+
const candidates = uses.kind === 'workflow' ? [uses.path] : [`${dir}action.yml`, `${dir}action.yaml`]
|
|
210
|
+
let file = null, text = null
|
|
211
|
+
for (const path of candidates) {
|
|
212
|
+
text = await source.file(name, path, commit)
|
|
213
|
+
if (text !== null) { file = path; break }
|
|
214
|
+
}
|
|
215
|
+
if (text === null) return { findings: [{ id: 'action-missing', severity: 'moderate' }], uses: [] }
|
|
216
|
+
const read = readWorkflow(uses.kind === 'workflow' ? 'workflow' : 'action', text)
|
|
217
|
+
if (read instanceof YamlError) return { findings: [{ id: 'unreadable', severity: 'moderate', file, detail: read.message }], uses: [] }
|
|
218
|
+
const findings = workflowFindings(read, { owner: name.split('/')[0], external: true }).map(finding => ({ ...finding, file }))
|
|
219
|
+
const dockerfile = read.dockerfile && `${dir}${read.dockerfile.path}`
|
|
220
|
+
const docker = dockerfile && !dockerfile.split('/').includes('..') ? await source.file(name, dockerfile, commit) : null
|
|
221
|
+
if (docker !== null) findings.push(...dockerfileFindings(docker).map(finding => ({ ...finding, file: dockerfile })))
|
|
222
|
+
const nested = workflowUses(read).map(each => each.kind === 'local' ? (each.self || each.job) && selfRef(each, info, commit) : each)
|
|
223
|
+
return { findings, uses: nested.filter(each => each?.kind === 'action' || each?.kind === 'workflow').map(usesKey) }
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// A reference resolved (index.d.ts ResolvedAction); `owner`, whose workflow names it.
|
|
227
|
+
export async function resolveAction(uses, source, { owner = null } = {}) {
|
|
228
|
+
const at = { key: usesKey(uses), kind: uses.kind, repo: uses.repo, path: uses.path, ref: uses.ref }
|
|
229
|
+
const { info, findings } = await repositoryOf(uses, source, owner)
|
|
230
|
+
if (!info) return { ...at, repository: null, commit: null, at: null, tags: [], findings, uses: [] }
|
|
231
|
+
const tags = await source.tags(info.fullName)
|
|
232
|
+
const ref = uses.pin === 'sha' ? await pinnedOf(uses, info, source, tags) : await refOf(uses, info, source, tags)
|
|
233
|
+
const runs = ref.commit && !ref.findings.some(({ id }) => id === 'commit-missing')
|
|
234
|
+
// What it runs, and its advisories at the versions that is.
|
|
235
|
+
const [code, advised] = runs ? await Promise.all([codeOf(uses, info, ref.commit, source),
|
|
236
|
+
advisoryFindings(source, info, advisedVersions(ref.at, uses.ref, ref.commit, ref.named ?? tagsOn(tags, ref.commit)))]) : [null, []]
|
|
237
|
+
return { ...at, repository: { fullName: info.fullName, private: Boolean(info.private) }, commit: ref.commit, at: ref.at, tags: tagsOn(tags, ref.commit),
|
|
238
|
+
findings: [...findings, ...ref.findings, ...advised, ...code?.findings ?? []], uses: code?.uses ?? [] }
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// `source` with its answers kept, by what was asked, while held: a scan's.
|
|
242
|
+
export function keptSource(source) {
|
|
243
|
+
const kept = new Map()
|
|
244
|
+
const keep = method => (...args) => {
|
|
245
|
+
const key = `${method}\0${JSON.stringify(args)}`
|
|
246
|
+
if (!kept.has(key)) kept.set(key, source[method](...args).catch(error => { kept.delete(key); throw error }))
|
|
247
|
+
return kept.get(key)
|
|
248
|
+
}
|
|
249
|
+
return Object.fromEntries(['repo', 'tags', 'tag', 'branch', 'branches', 'contains', 'file', 'advisories'].filter(method => source[method]).map(method => [method, keep(method)]))
|
|
250
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// What a `run:` script fetches and runs past what a lockfile or a digest pins,
|
|
2
|
+
// command by command (shell.js), each with its line in the script from 0.
|
|
3
|
+
import { NPM_INSTALLS, fetched, npmToolFinds, optionsOf, projectOf, valuesOf } from './packages.js'
|
|
4
|
+
import { pathFrom, scriptCommands, scriptLines } from './shell.js'
|
|
5
|
+
import { SHELLS as SHELL_NAMES } from '../../files/runs-code.js'
|
|
6
|
+
import { readImage } from '../uses.js'
|
|
7
|
+
|
|
8
|
+
// A program's file name, lowercase, past its directory and a Windows extension.
|
|
9
|
+
const programOf = word => (word ?? '').split(/[/\\]/u).at(-1).toLowerCase().replace(/\.(?:cmd|exe|bat|ps1)$|@[\w.-]*$/u, '')
|
|
10
|
+
|
|
11
|
+
const SHELLS = new RegExp(String.raw`^(?:${SHELL_NAMES}|python[\d.]*|node|perl|ruby|php|iex|invoke-expression)$`, 'u')
|
|
12
|
+
const FETCHERS = /^(?:curl|wget|irm|iwr|invoke-restmethod|invoke-webrequest)$/u
|
|
13
|
+
// A script fetched and run on one line: `<(curl …)`, `-c "$(curl …)"`, `iex (irm …)`.
|
|
14
|
+
const FETCHED_AND_RUN = [
|
|
15
|
+
/\b(?:(?:ba|z|da|k)?sh|source|\.)\s+(?:-\S+\s+)*<\(\s*(?:curl|wget)\b/iu,
|
|
16
|
+
/\b(?:(?:ba|z|da|k)?sh|python[\d.]*|node|perl|ruby)\s+(?:-\S+\s+)*-c\s+["']?\$\(\s*(?:curl|wget)\b/iu,
|
|
17
|
+
/\b(?:iex|invoke-expression)\b[^|;]*\b(?:irm|iwr|invoke-restmethod|invoke-webrequest|downloadstring)\b/iu,
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
// The file curl or wget saves to (`-o f`, `-of`, `--output f`, curl's `-O`,
|
|
21
|
+
// wget's by its URL), or PowerShell's (`-OutFile f`); else null.
|
|
22
|
+
function savedTo(program, argv) {
|
|
23
|
+
for (let at = 1; at < argv.length; at++) {
|
|
24
|
+
const outFile = /^-outfile(?::(.+))?$/iu.exec(argv[at]), word = argv[at]
|
|
25
|
+
if (outFile && !/^(?:curl|wget)$/u.test(program)) return outFile[1] ?? argv[at + 1] ?? null
|
|
26
|
+
const attached = { curl: /^-[a-zA-Z]*o(.+)$/u, wget: /^-[a-zA-Z]*O(.+)$/u }[program]?.exec(word)
|
|
27
|
+
if (attached) return attached[1] === '-' ? null : attached[1]
|
|
28
|
+
if (program === 'curl' && (/^-[a-zA-Z]*o$/u.test(word) || word === '--output')) return argv[at + 1] ?? null
|
|
29
|
+
if (program === 'wget' && (/^-[a-zA-Z]*O$/u.test(word) || word === '--output-document')) return argv[at + 1] === '-' ? null : argv[at + 1] ?? null
|
|
30
|
+
const joined = /^(?:--output|--output-document)=(.+)$/u.exec(word)
|
|
31
|
+
if (joined) return joined[1]
|
|
32
|
+
}
|
|
33
|
+
const url = program === 'wget' || (program === 'curl' && argv.some(word => /^-[a-zA-Z]*O[a-zA-Z]*$/u.test(word) || word === '--remote-name')) ? argv.find(word => /^https?:\/\//u.test(word)) : null
|
|
34
|
+
return url ? URL.parse(url)?.pathname.split('/').at(-1) || null : null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A path from the current directory, its `./` (PowerShell's `.\`, its `\`
|
|
38
|
+
// read as an escape) taken off.
|
|
39
|
+
const local = path => path.replace(/^\.\/?/u, '')
|
|
40
|
+
|
|
41
|
+
// Whether a command runs `file`, as a program or a shell's script.
|
|
42
|
+
function runsFile({ argv }, file) {
|
|
43
|
+
if (local(argv[0]) === local(file) || argv[0] === file) return true
|
|
44
|
+
return (SHELLS.test(programOf(argv[0])) || argv[0] === 'source' || argv[0] === '.') && argv.slice(1).some(word => local(word) === local(file))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const pythonPackage = text => {
|
|
48
|
+
if (/^(?:git\+|https?:|file:|\.{0,2}\/)/iu.test(text)) return { name: text, spec: null, exact: /@[\da-f]{40}(?:#|$)/u.test(text), registry: false }
|
|
49
|
+
const m = /^([\w.-]+)(?:\[[^\]]*\])?\s*(.*)$/u.exec(text)
|
|
50
|
+
return m && { name: m[1], spec: m[2] || null, exact: /^===?\s*[\w.!+-]+$/u.test(m[2]), registry: true }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// The packages pip installs by name, not a requirements file's or a path.
|
|
54
|
+
const PIP_VALUED = /^(?:-r|--requirement|-c|--constraint|-e|--editable|-i|--index-url|--extra-index-url|-t|--target|--prefix|--root|-f|--find-links)$/u
|
|
55
|
+
const pip = (tool, argv, from) => optionsOf(argv, from, PIP_VALUED).operands.filter(word => !/^\.{1,2}(?:\/|$)/u.test(word))
|
|
56
|
+
.flatMap(text => fetched(tool, pythonPackage(text), { ecosystem: 'pypi' }))
|
|
57
|
+
// A package named `name@version`, as Go's, crates' and Deno's are.
|
|
58
|
+
const atVersion = (text, exact) => {
|
|
59
|
+
const at = text.lastIndexOf('@')
|
|
60
|
+
const spec = at > 0 ? text.slice(at + 1) : null
|
|
61
|
+
return { name: at > 0 ? text.slice(0, at) : text, spec, exact: spec !== null && exact(spec), registry: true }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function python(program, argv) {
|
|
65
|
+
if (program === 'pip' || /^pip\d/u.test(program)) return argv[1] === 'install' ? pip(program, argv, 2) : []
|
|
66
|
+
if (/^python[\d.]*$/u.test(program) && argv[1] === '-m' && /^pip\d?$/u.test(argv[2] ?? '') && argv[3] === 'install') return pip(`${program} -m pip`, argv, 4)
|
|
67
|
+
if (program === 'uv' && argv[1] === 'pip' && argv[2] === 'install') return pip('uv pip', argv, 3)
|
|
68
|
+
if (program === 'uvx' || (program === 'uv' && argv[1] === 'tool' && /^(?:run|install)$/u.test(argv[2] ?? ''))) {
|
|
69
|
+
const options = optionsOf(argv, program === 'uvx' ? 1 : 3, /^--(?:from|python|with)$/u), [spec] = [...valuesOf(options, '--from'), ...options.operands]
|
|
70
|
+
return fetched(program === 'uvx' ? 'uvx' : `uv tool ${argv[2]}`, spec && pythonPackage(spec), { ecosystem: 'pypi' })
|
|
71
|
+
}
|
|
72
|
+
if (program === 'pipx' && /^(?:run|install)$/u.test(argv[1] ?? '')) {
|
|
73
|
+
const options = optionsOf(argv, 2, /^--(?:spec|python)$/u), [spec] = [...valuesOf(options, '--spec'), ...options.operands]
|
|
74
|
+
return fetched(`pipx ${argv[1]}`, spec && pythonPackage(spec), { ecosystem: 'pypi' })
|
|
75
|
+
}
|
|
76
|
+
return []
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
const EXACT_SEMVER = text => /^=?\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/u.test(text)
|
|
81
|
+
|
|
82
|
+
// `go install x@v y@v`, `go run x@v`, a version held to Go's checksum database.
|
|
83
|
+
function go(argv) {
|
|
84
|
+
const { operands } = optionsOf(argv, 2, /^-(?:o|modfile|tags|ldflags|gcflags|C|exec)$/u)
|
|
85
|
+
return (argv[1] === 'run' ? operands.slice(0, 1) : operands).filter(target => target.includes('@'))
|
|
86
|
+
.flatMap(target => fetched(`go ${argv[1]}`, atVersion(target, spec => /^v\d+\.\d+\.\d+/u.test(spec)), { ecosystem: 'go' }))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// `cargo install`: each crate by its version, or a repository by its commit;
|
|
90
|
+
// `locked` with `--locked`.
|
|
91
|
+
function cargo(argv) {
|
|
92
|
+
if (argv.includes('--path')) return []
|
|
93
|
+
const options = optionsOf(argv, 2, /^--(?:version|git|branch|rev|tag|root|features|registry|index|bin|example|target|profile|jobs)$|^-[jF]$/u)
|
|
94
|
+
const [git = null] = valuesOf(options, '--git'), [version = null] = valuesOf(options, '--version'), [ref = null] = valuesOf(options, '--rev', '--tag', '--branch')
|
|
95
|
+
const specs = git ? [{ name: git, spec: ref, exact: /^[\da-f]{40}$/u.test(valuesOf(options, '--rev')[0] ?? ''), registry: false }] : options.operands.map(crate => atVersion(crate, EXACT_SEMVER))
|
|
96
|
+
return specs.flatMap(spec => fetched(`cargo ${argv[1]}`, { ...spec, spec: spec.spec ?? version, exact: spec.exact || (!git && EXACT_SEMVER(version ?? '')), locked: argv.includes('--locked') }, { ecosystem: 'crates' }))
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// `gem install x [-v 1.2.3]`.
|
|
100
|
+
function gem(argv) {
|
|
101
|
+
const options = optionsOf(argv, 2, /^(?:-v|--version|-i|--install-dir|-s|--source|-n|--bindir)$/u), [version = null] = valuesOf(options, '-v', '--version')
|
|
102
|
+
return options.operands.flatMap(name => fetched('gem install', { name, spec: version, exact: /^=?\s*\d+(?:\.\d+)+$/u.test(version ?? ''), registry: true }, { ecosystem: 'rubygems' }))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// `deno run|install|x` of a URL or a registry's package.
|
|
106
|
+
function deno(argv) {
|
|
107
|
+
const target = argv.slice(2).find(word => /^(?:https?:\/\/|npm:|jsr:)/u.test(word))
|
|
108
|
+
if (!target) return []
|
|
109
|
+
return fetched(`deno ${argv[1]}`, /^(?:npm|jsr):/u.test(target) ? atVersion(target.replace(/^(?:npm|jsr):/u, ''), EXACT_SEMVER)
|
|
110
|
+
: { name: target, spec: null, exact: /@v?\d+\.\d+\.\d+/u.test(target), registry: false }, { ecosystem: 'deno' })
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function others(program, argv) {
|
|
114
|
+
if (program === 'go' && /^(?:install|run)$/u.test(argv[1] ?? '')) return go(argv)
|
|
115
|
+
if (program === 'cargo' && /^(?:install|binstall)$/u.test(argv[1] ?? '')) return cargo(argv)
|
|
116
|
+
if (program === 'gem' && argv[1] === 'install') return gem(argv)
|
|
117
|
+
return program === 'deno' && /^(?:run|install|x|compile)$/u.test(argv[1] ?? '') ? deno(argv) : []
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// What a command fetches or runs unpinned, but a script fetched and run.
|
|
121
|
+
function commandFinds(command) {
|
|
122
|
+
const { argv } = command
|
|
123
|
+
const program = programOf(argv[0])
|
|
124
|
+
if (/^(?:docker|podman)$/u.test(program) && /^(?:run|pull|create)$/u.test(argv[1] ?? '')) {
|
|
125
|
+
const image = argv.slice(2).find((word, at, words) => !word.startsWith('-') && !/^(?:-[evpwulhm]|--(?:env|volume|publish|workdir|user|label|hostname|memory|name|network|entrypoint|platform|mount|env-file|cpus|add-host|cap-add|device|dns|gpus|ipc|pid|restart|runtime|pull|security-opt|shm-size|tmpfs|ulimit|volumes-from|log-driver))$/u.test(words[at - 1] ?? ''))
|
|
126
|
+
return image ? [{ kind: 'image', text: image, read: readImage(image) }] : []
|
|
127
|
+
}
|
|
128
|
+
if (program === 'git' && argv[1] === 'clone') return [{ kind: 'clone', url: argv.slice(2).find(word => /^(?:https?:|git@|git:|ssh:)/u.test(word)) ?? null }]
|
|
129
|
+
return [...npmToolFinds(program, argv), ...python(program, argv), ...others(program, argv)]
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const INSTALLS = { npm: new RegExp(`^(?:ci|clean-install|ic|install-clean|${NPM_INSTALLS})$`, 'u'), pnpm: /^(?:i|install|add)$/u, bun: /^(?:i|install|add)$/u }
|
|
133
|
+
// An install's options that leave the project's node_modules as they are.
|
|
134
|
+
const NOT_LOCAL = /^(?:-g|--location=global|--(?:global|package-lock-only|lockfile-only|dry-run)(?:=true)?)$/u
|
|
135
|
+
|
|
136
|
+
// A script's installs of a project's packages: each one's `order`, the
|
|
137
|
+
// directory it installs into, by its `cd`s and the one it names (`into`, a
|
|
138
|
+
// path from the step's, '' for it), and whether it leaves devDependencies out
|
|
139
|
+
// (`prod`), by an option or NODE_ENV production (the step's `production`).
|
|
140
|
+
export function installsOf(script, production = false) {
|
|
141
|
+
const found = []
|
|
142
|
+
let exported = production
|
|
143
|
+
for (const { argv, dir, env, order } of scriptCommands(script)) {
|
|
144
|
+
const program = programOf(argv[0])
|
|
145
|
+
if (program === 'export') for (const word of argv) if (word.startsWith('NODE_ENV=')) exported = word === 'NODE_ENV=production'
|
|
146
|
+
const options = optionsOf(argv, 1), [command] = options.operands
|
|
147
|
+
if (argv.some(word => NOT_LOCAL.test(word)) || !(program === 'yarn' ? command === undefined || command === 'install' : INSTALLS[program]?.test(command ?? ''))) continue
|
|
148
|
+
// npm installs what `--include` names whatever leaves it out.
|
|
149
|
+
const prod = !valuesOf(options, '--include').includes('dev') && (valuesOf(options, '--omit').includes('dev') || /^prod(?:uction)?$/u.test(valuesOf(options, '--only')[0] ?? '')
|
|
150
|
+
|| argv.some(word => /^--prod(?:uction)?$/u.test(word)) || (env.NODE_ENV ?? (exported ? 'production' : '')) === 'production')
|
|
151
|
+
const project = projectOf(argv)
|
|
152
|
+
found.push({ order, into: project === null ? dir : pathFrom(dir, project), prod })
|
|
153
|
+
}
|
|
154
|
+
return found
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// A script's line, as a finding names what it runs, cut short.
|
|
158
|
+
const excerpt = text => { const trimmed = text.trim().replaceAll(/\s+/gu, ' '); return trimmed.length > 120 ? `${trimmed.slice(0, 119)}…` : trimmed }
|
|
159
|
+
|
|
160
|
+
// Everything a script fetches and runs past a pin, in its order.
|
|
161
|
+
export function scriptFinds(script) {
|
|
162
|
+
const found = []
|
|
163
|
+
const lines = new Map(scriptLines(script).map(({ text, line }) => [line, text]))
|
|
164
|
+
for (const [line, text] of lines) {
|
|
165
|
+
if (FETCHED_AND_RUN.some(pattern => pattern.test(text))) found.push({ kind: 'remote-script', line, command: excerpt(text) })
|
|
166
|
+
}
|
|
167
|
+
const saved = new Map()
|
|
168
|
+
for (const command of scriptCommands(script)) {
|
|
169
|
+
const program = programOf(command.argv[0])
|
|
170
|
+
if (FETCHERS.test(program) && command.pipedTo.some(each => SHELLS.test(programOf(each.argv[0])))) found.push({ kind: 'remote-script', line: command.line, command: excerpt(lines.get(command.line) ?? '') })
|
|
171
|
+
const file = FETCHERS.test(program) ? savedTo(program, command.argv) ?? command.out : null
|
|
172
|
+
if (file) saved.set(file, command.line)
|
|
173
|
+
for (const [name, at] of saved) {
|
|
174
|
+
if (FETCHERS.test(program) || !runsFile(command, name)) continue
|
|
175
|
+
found.push({ kind: 'remote-script', line: command.line, command: excerpt(lines.get(at) ?? '') })
|
|
176
|
+
saved.delete(name)
|
|
177
|
+
}
|
|
178
|
+
for (const each of commandFinds(command)) found.push({ ...each, line: command.line, order: command.order, dir: command.dir })
|
|
179
|
+
}
|
|
180
|
+
const told = new Set()
|
|
181
|
+
return found.filter(({ order: _order, ...each }) => { const key = JSON.stringify(each); return !told.has(key) && told.add(key) }).toSorted((a, b) => a.line - b.line)
|
|
182
|
+
}
|