@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.61
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 +36 -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 +43 -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-2XUEZHIP.js +28 -0
- package/out/chunk-4EMM6UCD.js +1 -0
- package/out/chunk-4ISO5F7Y.js +7 -0
- package/out/chunk-4XIH7YTX.js +1 -0
- package/out/chunk-6CCSTJWB.js +1 -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-B3FNMHOE.js +1 -0
- package/out/chunk-BNH52UHC.js +2 -0
- package/out/chunk-BRO77PQY.js +42 -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-G3LY2FV4.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GRGIZOTP.js +4 -0
- package/out/chunk-HAZKDK4M.js +4 -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-JJK5OZG2.js +15 -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-OFZYEWBH.js +244 -0
- package/out/chunk-OIERSXON.js +1 -0
- package/out/chunk-OOJM4CTU.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-QCOGVL37.js +52 -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-UCP3JRE2.js +1 -0
- package/out/chunk-VFWMQ3LG.js +2 -0
- package/out/chunk-VRX2APNA.js +9 -0
- package/out/chunk-W3QFV4SP.js +3 -0
- package/out/chunk-W6VOKW2N.js +12 -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-Z667U2UJ.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/chunk-ZQNEWVGG.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 +40 -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 +383 -63
- 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 +238 -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 +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +103 -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 +238 -0
- package/server-managed/bundle-build.ts +240 -0
- package/server-managed/bundle-cache.ts +199 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +68 -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 +119 -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 +77 -0
- package/server-managed/comparison.ts +50 -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 +1877 -0
- package/server-managed/db-neon.ts +388 -0
- package/server-managed/db-schema.ts +253 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +146 -0
- package/server-managed/dependabot-access.ts +61 -0
- package/server-managed/dependabot-alerts.ts +180 -0
- package/server-managed/dependency-review-comments.ts +92 -0
- package/server-managed/dependency-reviews.ts +363 -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 +70 -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 +157 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +257 -0
- package/server-managed/github-requests.ts +179 -0
- package/server-managed/github-users.ts +30 -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 +5796 -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 +149 -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 +110 -0
- package/server-managed/npm-delta-worker.js +23 -0
- package/server-managed/npm-delta.ts +159 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +234 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +462 -0
- package/server-managed/npm-patch.ts +317 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +287 -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 +79 -0
- package/server-managed/pretty-print.ts +425 -0
- package/server-managed/public-workspace.ts +242 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +340 -0
- package/server-managed/pull-dependency-reviews.ts +327 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/queue.ts +53 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +26 -0
- package/server-managed/rename-diff.ts +236 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +181 -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 +85 -0
- package/server-managed/repository-browser.ts +303 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +215 -0
- package/server-managed/repository-dependency-reviews.ts +159 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +428 -0
- package/server-managed/repository-issues.ts +224 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +477 -0
- package/server-managed/repository-risk-assess.ts +108 -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 +483 -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 +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 +107 -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 +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 +54 -0
- package/server-managed/team-app.ts +154 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-reports.ts +351 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +108 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +115 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +250 -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/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,196 @@
|
|
|
1
|
+
// The characters a text holds that can make it read other than it runs, or
|
|
2
|
+
// hide text in it: control and bidirectional characters, and the invisible
|
|
3
|
+
// characters a payload or a name no one sees can be spelled in (variation
|
|
4
|
+
// selectors, Hangul fillers, tags). Shared with a code viewer that shows each
|
|
5
|
+
// as a labelled box (ui/view/control-chars.js), which leaves what spells an
|
|
6
|
+
// emoji, a recommended flag or a line's end as it is (passed).
|
|
7
|
+
|
|
8
|
+
// What a text holds beyond printing characters and its line breaks: the C0
|
|
9
|
+
// controls other than tab, line feed and carriage return, DEL, the C1
|
|
10
|
+
// controls, and the bidirectional controls that can make code read other than
|
|
11
|
+
// it runs ("Trojan Source"); and the invisible characters that can hide text
|
|
12
|
+
// in it (invisibleCharacters), as a payload hidden in
|
|
13
|
+
// variation selectors or a variable named by a Hangul filler.
|
|
14
|
+
export const CONTROLS = /(?![\t\n\r])\p{Cc}|[\u202A-\u202E\u2066-\u2069]/gu
|
|
15
|
+
const NON_ASCII = /\P{ASCII}/u
|
|
16
|
+
|
|
17
|
+
// A file's text: `kind` 'ascii' or 'utf8', by whether it holds anything past
|
|
18
|
+
// ASCII, else 'binary' (which the server tells by its bytes, sending no
|
|
19
|
+
// text); `controls` the control and invisible characters a text holds, how
|
|
20
|
+
// often by code point, or null for none.
|
|
21
|
+
export function npmTextEncoding(text) {
|
|
22
|
+
if (typeof text !== 'string') return { kind: 'binary', controls: null }
|
|
23
|
+
const controls = new Map()
|
|
24
|
+
for (const [char] of text.matchAll(CONTROLS)) controls.set(char.codePointAt(0), (controls.get(char.codePointAt(0)) ?? 0) + 1)
|
|
25
|
+
// The invisible characters are all past ASCII: looked for in a text that
|
|
26
|
+
// has any, from its first.
|
|
27
|
+
const past = text.search(NON_ASCII)
|
|
28
|
+
if (past !== -1) for (const [code, times] of invisibleCharacters(text, past) ?? []) controls.set(code, times)
|
|
29
|
+
return { kind: past === -1 ? 'ascii' : 'utf8', controls: controls.size > 0 ? controls : null }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// A pictograph is an assigned one (Emoji): Extended_Pictographic also takes
|
|
33
|
+
// in code points reserved for emoji to come, unassigned, each boxed itself,
|
|
34
|
+
// and a joiner or selector beside one would go unseen.
|
|
35
|
+
const EMOJI_BEFORE = /(?=\p{Emoji})\p{Extended_Pictographic}(?:\u{FE0F}|[\u{1F3FB}-\u{1F3FF}])?$/u
|
|
36
|
+
const EMOJI_AFTER = /^(?=\p{Emoji})\p{Extended_Pictographic}/u
|
|
37
|
+
const PICTOGRAPH_BEFORE = /(?=\p{Emoji})\p{Extended_Pictographic}$/u
|
|
38
|
+
const KEYCAP_BASE = /^[\d#*]$/u
|
|
39
|
+
const isTag = code => code >= 0xe0020 && code <= 0xe007f
|
|
40
|
+
// The subdivision flags Unicode recommends (RGI), their tags spelling the
|
|
41
|
+
// subdivision after a black flag: England's, Scotland's and Wales's. Others
|
|
42
|
+
// show as a black flag and their tags as nothing, as a payload in them would.
|
|
43
|
+
const FLAGS = new Set(['gbeng', 'gbsct', 'gbwls'])
|
|
44
|
+
const tagged = (text, from, to) => to - from === 10 ? String.fromCodePoint(...Array.from({ length: 5 }, (_, i) => text.codePointAt(from + 2 * i) - 0xe0000)) : ''
|
|
45
|
+
|
|
46
|
+
// Where to go on from where `code` at `at` in `text` stays text, else -1 for
|
|
47
|
+
// one to show. A CR before a newline is part of the line end, as is one that
|
|
48
|
+
// ends `text` where `lineEnd` says a newline follows it. A joiner between two
|
|
49
|
+
// emoji joins them into one, a recommended subdivision flag's tags, up to the
|
|
50
|
+
// cancel tag, name its region (FLAGS), and the text or emoji presentation
|
|
51
|
+
// selector after a pictograph, or the emoji one between a keycap's digit, #
|
|
52
|
+
// or * and its mark, draws it; after a letter or a digit alone it is another
|
|
53
|
+
// name.
|
|
54
|
+
export function passed(text, at, code, lineEnd) {
|
|
55
|
+
if (code === 0x0d && (text[at + 1] === '\n' || lineEnd && at + 1 === text.length)) return at + 1
|
|
56
|
+
if (code === 0x200d && EMOJI_BEFORE.test(text.slice(Math.max(0, at - 4), at)) && EMOJI_AFTER.test(text.slice(at + 1, at + 3))) return at + 1
|
|
57
|
+
if ((code === 0xfe0e || code === 0xfe0f) && PICTOGRAPH_BEFORE.test(text.slice(Math.max(0, at - 2), at))) return at + 1
|
|
58
|
+
if (code === 0xfe0f && KEYCAP_BASE.test(text[at - 1] ?? '') && text[at + 1] === '\u20E3') return at + 1
|
|
59
|
+
if (isTag(code) && !isTag(text.codePointAt(at - 2))) {
|
|
60
|
+
let end = at
|
|
61
|
+
while (isTag(text.codePointAt(end))) end += 2
|
|
62
|
+
if (text.codePointAt(at - 2) === 0x1f3f4 && text.codePointAt(end - 2) === 0xe007f && FLAGS.has(tagged(text, at, end - 2))) return end
|
|
63
|
+
}
|
|
64
|
+
return -1
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Those text is hidden in, as a file's Invisible chars label counts them
|
|
68
|
+
// (readability.js), where they show: variation selectors (a payload, a
|
|
69
|
+
// byte a selector), Hangul fillers (a name no one sees) and tags (ASCII no one
|
|
70
|
+
// sees). Not the format characters, a BOM or a zero-width space, which text
|
|
71
|
+
// has its uses for, nor the other marks that show as nothing (the combining
|
|
72
|
+
// grapheme joiner, the Khmer inherent vowels and the Mongolian free variation
|
|
73
|
+
// selectors), which tables of the characters a name may hold, as JavaScript
|
|
74
|
+
// parsers have, hold too; nor what of these hides nothing (benign).
|
|
75
|
+
const INVISIBLE = /[\u115F\u1160\u3164\uFFA0\u{E0001}\u{E0020}-\u{E007F}]|[\uFE00-\uFE0F]|[\u{E0100}-\u{E01EF}]/u
|
|
76
|
+
// The code units they are in, to look for them by, faster than by code point:
|
|
77
|
+
// the high surrogate starting those past the Basic Multilingual Plane (tags,
|
|
78
|
+
// the selectors' supplement) too, told apart from its others once found. No
|
|
79
|
+
// `u`, which would read a pair as the one code point it spells.
|
|
80
|
+
// eslint-disable-next-line require-unicode-regexp
|
|
81
|
+
const INVISIBLE_UNITS = /[\uFE00-\uFE0F\u115F\u1160\u3164\uFFA0\uDB40]/g
|
|
82
|
+
// A table's code points, from its ranges in hex (`30 2018-2019`).
|
|
83
|
+
const codePoints = ranges => new Set(ranges.split(' ').flatMap(range => {
|
|
84
|
+
const [from, to = from] = range.split('-').map(digits => Number.parseInt(digits, 16))
|
|
85
|
+
return Array.from({ length: to - from + 1 }, (_, i) => from + i)
|
|
86
|
+
}))
|
|
87
|
+
// The variation sequences Unicode registers, which hide nothing, though Code
|
|
88
|
+
// shows their selectors after a letter or a digit, another name there: VS1 to
|
|
89
|
+
// VS14's on other than an ideograph (StandardizedVariants.txt, Unicode
|
|
90
|
+
// 18.0.0), each selector's bases, as an HTML entity table's math symbols, and
|
|
91
|
+
// the emoji with a text and an emoji presentation, VS15 and VS16 after each
|
|
92
|
+
// (emoji-variation-sequences.txt), as a heading's anchor keeps one (`#`).
|
|
93
|
+
const STANDARDIZED = new Map([
|
|
94
|
+
[0xfe00, '30 1000 1002 1004 1010-1011 1015 1019-101a 101c-101d 1022 1031 1075'
|
|
95
|
+
+ ' 1078 107a 1080 2018-2019 201c-201d 210b 2110 2112 211b 212c 2130-2131'
|
|
96
|
+
+ ' 2133 2205 2229-222a 223d 2242-2243 2248 2268-2269 2272-2273 228a-228b'
|
|
97
|
+
+ ' 2293-2295 2297 229c 22cd 22da-22dd 29b7 2a3c-2a3d 2a6c 2a9d-2a9e'
|
|
98
|
+
+ ' 2aac-2aad 2acb-2acc 3001-3002 31c0 31c6 31c9 31cf-31d2 31d4-31d5 31d7'
|
|
99
|
+
+ ' 31db-31dd 31e5 a856 a85c a85e-a860 a868 aa60-aa66 aa6b-aa6c aa6f aa7a'
|
|
100
|
+
+ ' ff01 ff0c ff0e ff10 ff1a-ff1b ff1f 10ac5-10ac6 10ad6-10ad7 10ae1 13091'
|
|
101
|
+
+ ' 1310f 1311c 13121 13127 13139 131a0 131b1 131b8-131b9 131cb 131e0'
|
|
102
|
+
+ ' 131f9-131fa 1327b 1327f 13285 1328c 132aa 132cb 132dc 132e7 13307'
|
|
103
|
+
+ ' 1331b 13322 1333c 13377-13378 13399-1339a 133d3 133e4-133e5 133e7'
|
|
104
|
+
+ ' 133ee 133f2 133f5-133f6 13416 13419-1341a 13423 13443-13446'
|
|
105
|
+
+ ' 13be8-13bea 13f72 1d49c 1d49e-1d49f 1d4a2 1d4a5-1d4a6 1d4a9-1d4ac'
|
|
106
|
+
+ ' 1d4ae-1d4b5 1db10'],
|
|
107
|
+
[0xfe01, '2018-2019 201c-201d 210b 2110 2112 211b 212c 2130-2131 2133 3001-3002'
|
|
108
|
+
+ ' 31c6 31cf 31dd ff01 ff0c ff0e ff1a-ff1b ff1f 13093 13132 13139 13187'
|
|
109
|
+
+ ' 131b1 131ee 131f8-131fa 13257 1327f 1328b 132a4 13308 13312-13314'
|
|
110
|
+
+ ' 1331b 13321-13322 13331 133e8 13419 13f1f 14274 1d49c 1d49e-1d49f'
|
|
111
|
+
+ ' 1d4a2 1d4a5-1d4a6 1d4a9-1d4ac 1d4ae-1d4b5'],
|
|
112
|
+
[0xfe02, '2018-2019 201c-201d 13117 13139 13183 131a0 131ba 131ee 13216 1327b'
|
|
113
|
+
+ ' 132a4 132e7 132e9 132f8 132fd 13302-13303 13310-13314 1331c 13321'
|
|
114
|
+
+ ' 13331 1334a 13361 13373 1337d 13385 133af-133b0 133bf 133db 133dd'
|
|
115
|
+
+ ' 13419 1342c 1342e 14274 1d4cf'],
|
|
116
|
+
[0xfe03, '13012 130b8 130ba 1310f 1312f 13139 13184 1319c-1319d 1319f 131b1'
|
|
117
|
+
+ ' 131db 13205 13296 13338 13419'],
|
|
118
|
+
[0xfe04, '13139 1340d'],
|
|
119
|
+
[0xfe05, '13139 14274'],
|
|
120
|
+
[0xfe06, '1312f 13139 13184 131db 131ee 13205 132a4 132e9 1332b 13338'
|
|
121
|
+
+ ' 13370-13371 13419 14274'],
|
|
122
|
+
].map(([selector, bases]) => [selector, codePoints(bases)]))
|
|
123
|
+
const EMOJI = codePoints('23 2a 30-39 a9 ae 203c 2049 2122 2139 2194-2199 21a9-21aa 231a-231b 2328'
|
|
124
|
+
+ ' 23cf 23e9-23f3 23f8-23fa 24c2 25aa-25ab 25b6 25c0 25fb-25fe 2600-2604 260e'
|
|
125
|
+
+ ' 2611 2614-2615 2618 261d 2620 2622-2623 2626 262a 262e-262f 2638-263a 2640'
|
|
126
|
+
+ ' 2642 2648-2653 265f-2660 2663 2665-2666 2668 267b 267e-267f 2692-2697 2699'
|
|
127
|
+
+ ' 269b-269c 26a0-26a1 26a7 26aa-26ab 26b0-26b1 26bd-26be 26c4-26c5 26c8'
|
|
128
|
+
+ ' 26ce-26cf 26d1 26d3-26d4 26e9-26ea 26f0-26f5 26f7-26fa 26fd 2702 2705'
|
|
129
|
+
+ ' 2708-270d 270f 2712 2714 2716 271d 2721 2728 2733-2734 2744 2747 274c 274e'
|
|
130
|
+
+ ' 2753-2755 2757 2763-2764 2795-2797 27a1 27b0 27bf 2934-2935 2b05-2b07'
|
|
131
|
+
+ ' 2b1b-2b1c 2b50 2b55 3030 303d 3297 3299 1f004 1f170-1f171 1f17e-1f17f'
|
|
132
|
+
+ ' 1f202 1f21a 1f22f 1f237 1f30d-1f30f 1f315 1f31c 1f321 1f324-1f32c 1f336'
|
|
133
|
+
+ ' 1f378 1f37d 1f393 1f396-1f397 1f399-1f39b 1f39e-1f39f 1f3a7 1f3ac-1f3ae'
|
|
134
|
+
+ ' 1f3c2 1f3c4 1f3c6 1f3ca-1f3ce 1f3d4-1f3e0 1f3ed 1f3f3 1f3f5 1f3f7 1f408'
|
|
135
|
+
+ ' 1f415 1f41f 1f426 1f43f 1f441-1f442 1f446-1f449 1f44d-1f44e 1f453 1f46a'
|
|
136
|
+
+ ' 1f47d 1f4a3 1f4b0 1f4b3 1f4bb 1f4bf 1f4cb 1f4da 1f4df 1f4e4-1f4e6'
|
|
137
|
+
+ ' 1f4ea-1f4ed 1f4f7 1f4f9-1f4fb 1f4fd 1f508 1f50d 1f512-1f513 1f549-1f54a'
|
|
138
|
+
+ ' 1f550-1f567 1f56f-1f570 1f573-1f579 1f587 1f58a-1f58d 1f590 1f5a5 1f5a8'
|
|
139
|
+
+ ' 1f5b1-1f5b2 1f5bc 1f5c2-1f5c4 1f5d1-1f5d3 1f5dc-1f5de 1f5e1 1f5e3 1f5e8'
|
|
140
|
+
+ ' 1f5ef 1f5f3 1f5fa 1f610 1f687 1f68d 1f691 1f694 1f698 1f6ad 1f6b2'
|
|
141
|
+
+ ' 1f6b9-1f6ba 1f6bc 1f6cb 1f6cd-1f6cf 1f6e0-1f6e5 1f6e9 1f6f0 1f6f3')
|
|
142
|
+
// The blocks of variation selectors, as those tables write them out as ranges.
|
|
143
|
+
const BLOCKS = [[0xfe00, 0xfe0f], [0xe0100, 0xe01ef]]
|
|
144
|
+
// The compatibility jamo but their filler.
|
|
145
|
+
const JAMO = [[0x3131, 0x3163], [0x3165, 0x318e]]
|
|
146
|
+
|
|
147
|
+
// The code point before `at` in `text`, a pair of surrogates read as one.
|
|
148
|
+
function codePointBefore(text, at) {
|
|
149
|
+
if (at === 0) return undefined
|
|
150
|
+
const pair = at >= 2 ? text.codePointAt(at - 2) : 0
|
|
151
|
+
return pair > 0xffff ? pair : text.codePointAt(at - 1)
|
|
152
|
+
}
|
|
153
|
+
const within = (code, ...ranges) => code !== undefined && ranges.some(([from, to]) => code >= from && code <= to)
|
|
154
|
+
|
|
155
|
+
// Whether the one shown as `code` at `at` hides nothing: a Hangul filler
|
|
156
|
+
// composing Hangul (the initial consonant's before a vowel, a syllable with
|
|
157
|
+
// none, or the vowel's after an initial consonant, one with none), or a
|
|
158
|
+
// compatibility or halfwidth jamo's among those jamo, as a codepage's table
|
|
159
|
+
// lists them, though not one after a syllable, a name that reads as it; a
|
|
160
|
+
// variation sequence Unicode registers; a block of selectors written out as a
|
|
161
|
+
// range in a table (`VS1-VS16`); or an emoji's presentation selector doubled,
|
|
162
|
+
// as copying text leaves it.
|
|
163
|
+
function benign(text, at, code) {
|
|
164
|
+
const end = at + (code > 0xffff ? 2 : 1)
|
|
165
|
+
const after = text.codePointAt(end), before = codePointBefore(text, at)
|
|
166
|
+
switch (code) {
|
|
167
|
+
case 0x115f: return within(after, [0x1161, 0x11a7], [0xd7b0, 0xd7c6])
|
|
168
|
+
case 0x1160: return within(before, [0x1100, 0x115e], [0xa960, 0xa97c])
|
|
169
|
+
case 0x3164: return within(before, ...JAMO) || within(after, ...JAMO)
|
|
170
|
+
case 0xffa0: return within(before, [0xffa1, 0xffdc]) || within(after, [0xffa1, 0xffdc])
|
|
171
|
+
default: return (code === 0xfe0e || code === 0xfe0f ? EMOJI.has(before) : STANDARDIZED.get(code)?.has(before))
|
|
172
|
+
|| BLOCKS.some(([from, to]) => code === from && text[end] === '-' && text.codePointAt(end + 1) === to
|
|
173
|
+
|| code === to && text[at - 1] === '-' && codePointBefore(text, at - 1) === from)
|
|
174
|
+
|| (code === 0xfe0e || code === 0xfe0f) && before === code && PICTOGRAPH_BEFORE.test(text.slice(Math.max(0, at - 3), at - 1))
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// How many of each a text holds, by code point, or null for none: each one
|
|
179
|
+
// a code viewer shows (passed), visited alone, not each character it shows. `from`:
|
|
180
|
+
// where to look from, as the first character past ASCII, since all of them are.
|
|
181
|
+
export function invisibleCharacters(text, from = 0) {
|
|
182
|
+
let found = null
|
|
183
|
+
INVISIBLE_UNITS.lastIndex = from
|
|
184
|
+
for (let match = INVISIBLE_UNITS.exec(text); match; match = INVISIBLE_UNITS.exec(text)) {
|
|
185
|
+
const at = match.index, code = text.codePointAt(at)
|
|
186
|
+
if (!INVISIBLE.test(String.fromCodePoint(code))) continue
|
|
187
|
+
const next = passed(text, at, code, false)
|
|
188
|
+
if (next !== -1) INVISIBLE_UNITS.lastIndex = next
|
|
189
|
+
else if (!benign(text, at, code)) {
|
|
190
|
+
found ??= new Map()
|
|
191
|
+
found.set(code, (found.get(code) ?? 0) + 1)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return found
|
|
195
|
+
}
|
|
196
|
+
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// The hosts a version's code names, and the services malicious packages send
|
|
2
|
+
// what they take to, fetch what they run from or look the machine up with,
|
|
3
|
+
// for a reviewer: the hosts a version's scripts name that the version
|
|
4
|
+
// compared with's named in none of theirs, and the services a file names,
|
|
5
|
+
// under a tag for how much they call for (HOST_TAGS: Exfiltration, Remote,
|
|
6
|
+
// IP lookup), as a file's stamps say (stamps.js).
|
|
7
|
+
//
|
|
8
|
+
// A quick read, not a parse, as runs-code.js reads: a host is a URL's in a
|
|
9
|
+
// script's strings, regular expressions and template literals
|
|
10
|
+
// (JS_STRING_OR_COMMENT), its comments aside, where a link to docs is no host
|
|
11
|
+
// the code calls; an exfiltration host is told in any text but prose and a
|
|
12
|
+
// source map, wherever it is written. A host built as the code runs
|
|
13
|
+
// (`'https://' + name`, `${host}`) goes unseen, so a version without these
|
|
14
|
+
// labels is not one that sends nothing.
|
|
15
|
+
import { NPM_PROSE, SOURCE_MAP } from './readability.js'
|
|
16
|
+
import { JS_STRING_OR_COMMENT, NPM_MAX_FOUND, lineOf, npmIsScript } from './script.js'
|
|
17
|
+
|
|
18
|
+
// How many hosts a file is told naming at most, the first it names.
|
|
19
|
+
const NPM_MAX_HOSTS = 1000
|
|
20
|
+
|
|
21
|
+
// A URL's host: a name whose last label is letters (an internationalized
|
|
22
|
+
// one's too, as written or as punycode), or an IPv4 address, after its
|
|
23
|
+
// scheme, as a regular expression may leave its `s` optional (`https?://`),
|
|
24
|
+
// and any user, its case aside; whole, not the start of one built as the code
|
|
25
|
+
// runs (`api.service.com.${tld}`).
|
|
26
|
+
const LABEL = String.raw`[\p{L}\p{N}](?:[\p{L}\p{N}-]*[\p{L}\p{N}])?`
|
|
27
|
+
const URL_HOST = new RegExp(String.raw`\b(?:https?|wss?|ftp)\??:\/\/(?:[^\s/@'"\x60]*@)?(${LABEL}(?:\.${LABEL})+)(?![\p{L}\p{N}-]|\.[\p{L}\p{N}_$-])`, 'giu')
|
|
28
|
+
const NAMED = /\.(?:\p{L}{2,}|xn--[a-z0-9-]+)$/u
|
|
29
|
+
const IPV4 = /^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/u
|
|
30
|
+
// Hosts no code calls out to: this machine, the names kept for examples and
|
|
31
|
+
// tests (RFC 2606, RFC 6761) and local networks, and W3C's, whose URLs name
|
|
32
|
+
// XML namespaces.
|
|
33
|
+
const LOCAL = /^(?:localhost|.+\.(?:localhost|local|test|invalid|example|internal)|(?:.+\.)?example\.(?:com|net|org)|127(?:\.\d+){3}|0\.0\.0\.0|(?:.+\.)?w3\.org)$/u
|
|
34
|
+
|
|
35
|
+
// What a regular expression escapes in a URL, its slashes and dots
|
|
36
|
+
// (`/https:\/\/api\.example\.com/`), as a string may its slashes
|
|
37
|
+
// (`"https:\/\/api.example.com"`, as JSON can be written), read unescaped.
|
|
38
|
+
const ESCAPED = /\\([/.])/gu
|
|
39
|
+
|
|
40
|
+
// The pages github.com shows of a repository that a person reads, past its
|
|
41
|
+
// owner and name, as links and error messages name them: not its Actions,
|
|
42
|
+
// whose runs' artifacts and logs are downloads of what its workflows made.
|
|
43
|
+
const GITHUB_PAGES = new Set(['issues', 'pull', 'pulls', 'blob', 'tree', 'wiki', 'discussions', 'commit', 'commits', 'compare', 'blame',
|
|
44
|
+
'security', 'projects', 'labels', 'milestone', 'milestones', 'releases', 'tags', 'graphs', 'network', 'stargazers'])
|
|
45
|
+
// The paths past github.com that name no repository but a page of GitHub's
|
|
46
|
+
// own (`github.com/sponsors/someone`, `github.com/orgs/someone/people`).
|
|
47
|
+
const GITHUB_OWN = new Set(['sponsors', 'orgs', 'apps', 'marketplace', 'features', 'topics', 'collections', 'settings', 'login', 'search', 'explore', 'about'])
|
|
48
|
+
// How a github.com URL (`url`, as written from its scheme on, the punctuation
|
|
49
|
+
// a sentence ends it with aside) is named among a file's hosts, read as fetch
|
|
50
|
+
// reads it (WHATWG URL: a port, a trailing dot, backslashes as slashes, `..`
|
|
51
|
+
// resolved): `github.com` for its home or a person's, a page of GitHub's own
|
|
52
|
+
// (GITHUB_OWN), a page of a repository a person reads (GITHUB_PAGES), a
|
|
53
|
+
// release's page (`releases/tag/v1`, `releases/latest`) but not its assets'
|
|
54
|
+
// (`releases/latest/download/…`), a file's page but not the file raw
|
|
55
|
+
// (`blob/…?raw=true`, any `raw` asked), and a page but not its content in another format, as
|
|
56
|
+
// GitHub serves one by a suffix to its path past a file's (`pull/1.patch`,
|
|
57
|
+
// `commit/….diff`, `commits/main.atom`). Any other (a repository's own URL,
|
|
58
|
+
// which git clones, `raw/…`, `archive/…`, `tarball`, `repo.git`, a path GitHub
|
|
59
|
+
// may add, one read otherwise) leads to whatever a repository holds: named by
|
|
60
|
+
// it (`github.com/owner/repo`, in lower case, as GitHub's names are any), so
|
|
61
|
+
// that it is never taken for one of github.com's links to code and docs
|
|
62
|
+
// (compare.js ALLOWED_HOSTS).
|
|
63
|
+
const FILE_PATHS = new Set(['blob', 'tree', 'blame', 'wiki'])
|
|
64
|
+
const FORMAT = /\.(?:patch|diff|atom)$/iu
|
|
65
|
+
const GIT = /\.git$/iu
|
|
66
|
+
const decoded = part => { try { return decodeURIComponent(part) } catch { return part } }
|
|
67
|
+
function githubNamed(url) {
|
|
68
|
+
let parsed = null
|
|
69
|
+
try { parsed = new URL(url.replace(/^(\w+)\?:/u, '$1:').replace(/[)\]}>.,;:!]+$/u, '')) } catch {}
|
|
70
|
+
if (!parsed) return 'github.com/'
|
|
71
|
+
// Its path and query decoded, as GitHub routes them (`pull/1%2Epatch`,
|
|
72
|
+
// `?raw=%31`).
|
|
73
|
+
const segments = parsed.pathname.split('/').slice(1).map(decoded)
|
|
74
|
+
if (segments.length > 1 && segments.at(-1) === '') segments.pop()
|
|
75
|
+
const [owner, repo = '', section, ...rest] = segments
|
|
76
|
+
const repositoryPage = owner !== '' && repo !== '' && !GIT.test(repo) && GITHUB_PAGES.has(section)
|
|
77
|
+
&& !(section === 'releases' && rest.includes('download')) && !(section === 'blob' && parsed.searchParams.has('raw'))
|
|
78
|
+
&& !(!FILE_PATHS.has(section) && FORMAT.test(segments.at(-1)))
|
|
79
|
+
const page = parsed.hostname.replace(/\.$/u, '') === 'github.com' && (segments.length === 1 || GITHUB_OWN.has(owner) || repositoryPage)
|
|
80
|
+
return page ? 'github.com' : `github.com/${owner}/${repo.replace(GIT, '')}`.toLowerCase()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The hosts a script's strings name, each with the line it is first named on,
|
|
84
|
+
// in the order named, NPM_MAX_HOSTS at most; null for none, or for a file
|
|
85
|
+
// that is no script, by its name or as node runs it (`script`, npmIsScript).
|
|
86
|
+
export function npmHosts(path, text, script = false) {
|
|
87
|
+
if (!npmIsScript(path, text, script) || !(text.includes('://') || text.includes(':\\/\\/'))) return null
|
|
88
|
+
const hosts = new Map(), line = lineOf(text)
|
|
89
|
+
for (const { 1: token, index } of text.matchAll(JS_STRING_OR_COMMENT)) {
|
|
90
|
+
if (hosts.size >= NPM_MAX_HOSTS) break
|
|
91
|
+
// Read unescaped, its offsets as near: on the same line but in a template
|
|
92
|
+
// across lines; a regular expression without its closing slash and flags,
|
|
93
|
+
// as a string's quote ends its URL (`/https:\/\/github.com\/a\/b\/pull\/1.patch/i`).
|
|
94
|
+
const body = token?.startsWith('/') ? token.replace(/\/[a-z]*$/u, '') : token
|
|
95
|
+
const string = body?.includes('\\') ? body.replaceAll(ESCAPED, '$1') : body
|
|
96
|
+
if (!string?.includes('://')) continue
|
|
97
|
+
for (const { 1: name, index: at } of string.matchAll(URL_HOST)) {
|
|
98
|
+
const host = name.toLowerCase()
|
|
99
|
+
const named = host === 'github.com' ? githubNamed(/^[^\s'"\u0060]*/u.exec(string.slice(at))[0]) : host
|
|
100
|
+
if (!hosts.has(named) && (NAMED.test(host) || IPV4.test(host)) && !LOCAL.test(host)) hosts.set(named, line(index + at))
|
|
101
|
+
if (hosts.size >= NPM_MAX_HOSTS) break
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return hosts.size > 0 ? hosts : null
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// A host as it is written, under another or not (`m.webhook.site`), then a
|
|
108
|
+
// path on it where only that path is the service (`/api/webhooks`), on its
|
|
109
|
+
// own: not part of a longer name (`notwebhook.site`, `webhook.sites`), a
|
|
110
|
+
// name under another domain (`webhook.site.evil.example`, `webhook.site.рф`),
|
|
111
|
+
// nor another path (`/install.sh`, `/api/webhooks.json`), though a sentence
|
|
112
|
+
// may end after it. Its name first, so a text is searched for that alone.
|
|
113
|
+
const NAME_CHAR = String.raw`[\p{L}\p{N}_-]`
|
|
114
|
+
const host = (name, path = '') => new RegExp(String.raw`(?<!${NAME_CHAR})${name}${path}(?!\.?${NAME_CHAR})`, 'giu')
|
|
115
|
+
// One so like a file's name or code (`transfer.sh`, `file.io`) only as a
|
|
116
|
+
// URL's host: after the `//` that starts its authority (or `\/\/` as JSON can
|
|
117
|
+
// write it), where the URL starts, its scheme as URL_HOST takes one after the
|
|
118
|
+
// text's start, a blank, a quote, `(`, `=`, `,`, `<` or `>`, or without one
|
|
119
|
+
// after a quote, `(`, `=` or `,` (`"//file.io/x"`): not a URL's path, whatever
|
|
120
|
+
// it holds (`https://example.com/a//transfer.sh`, `/http://transfer.sh`); and
|
|
121
|
+
// after any user, not a user itself (`https://transfer.sh@example.com`).
|
|
122
|
+
const inUrl = name => new RegExp(String.raw`(?<=(?:(?:^|[\s'"\x60(=,<>])(?:https?|wss?|ftp)\??:|['"\x60(=,])\\?\/\\?\/(?:[^\s/@'"\x60]*@)?(?:${NAME_CHAR}+\.)*)${name}(?!\.?${NAME_CHAR}|(?::[^\s/@'"\x60]*)?@)`, 'giu')
|
|
123
|
+
// The tags the services go under, each with its severity (stamps.js
|
|
124
|
+
// SEVERITIES), as a change between versions raises it (npmHostSeverity):
|
|
125
|
+
// Exfiltration, `critical` (red), where nothing but catching what is sent
|
|
126
|
+
// has a use for it in a package's code; Remote, `high` (orange), where it
|
|
127
|
+
// could be fine; and IP lookup, `moderate` (yellow), where it usually is.
|
|
128
|
+
export const HOST_TAGS = new Map([['Exfiltration', 'critical'], ['Remote', 'high'], ['IP lookup', 'moderate']])
|
|
129
|
+
const [CATCHER, REMOTE, IP_LOOKUP] = [...HOST_TAGS.keys()].map(tag => ({ tag }))
|
|
130
|
+
// Services malicious packages send what they take to, fetch what they run
|
|
131
|
+
// from, or look the machine up with, each under its tag. Exfiltration's:
|
|
132
|
+
// request catchers, and out-of-band testing hosts (interactsh's, Burp
|
|
133
|
+
// Collaborator's, Canarytokens', DNS logs). Remote's: bot and webhook APIs,
|
|
134
|
+
// paste sites and file drops, tunnels, Pipedream's own API (its endpoints
|
|
135
|
+
// are `pipedream.net`), and the install script of Bun (`bun.sh/install`, now
|
|
136
|
+
// `bun.com/install`), which a worm ran its payload with. And IP lookups.
|
|
137
|
+
export const EXFILTRATION = new Map([
|
|
138
|
+
['webhook-site', { ...CATCHER, name: 'webhook.site', pattern: host(String.raw`webhook\.site`) }],
|
|
139
|
+
['pipedream', { ...CATCHER, name: 'Pipedream', pattern: host(String.raw`pipedream\.net`) }],
|
|
140
|
+
['requestbin', { ...CATCHER, name: 'RequestBin', pattern: host(String.raw`(?:requestbin\.(?:net|com)|requestb\.in)`) }],
|
|
141
|
+
['requestcatcher', { ...CATCHER, name: 'Request Catcher', pattern: host(String.raw`requestcatcher\.com`) }],
|
|
142
|
+
['requestrepo', { ...CATCHER, name: 'requestrepo', pattern: host(String.raw`requestrepo\.com`) }],
|
|
143
|
+
['beeceptor', { ...CATCHER, name: 'Beeceptor', pattern: host(String.raw`beeceptor\.com`) }],
|
|
144
|
+
['oast', { ...CATCHER, name: 'OAST', pattern: host(String.raw`(?:interact\.sh|interactsh\.com|oast\.(?:pro|live|site|online|fun|me)|oastify\.com|burpcollaborator\.net)`) }],
|
|
145
|
+
['canarytokens', { ...CATCHER, name: 'Canarytokens', pattern: host(String.raw`canarytokens\.(?:com|org)`) }],
|
|
146
|
+
['dnslog', { ...CATCHER, name: 'DNSLog', pattern: host(String.raw`dnslog\.cn`) }],
|
|
147
|
+
['ceye', { ...CATCHER, name: 'CEYE', pattern: host(String.raw`ceye\.io`) }],
|
|
148
|
+
['telegram', { ...REMOTE, name: 'Telegram', pattern: host(String.raw`api\.telegram\.org`) }],
|
|
149
|
+
['discord', { ...REMOTE, name: 'Discord webhook', pattern: host(String.raw`discord(?:app)?\.com`, String.raw`/api(?:/v\d+)?/webhooks`) }],
|
|
150
|
+
['slack', { ...REMOTE, name: 'Slack webhook', pattern: host(String.raw`hooks\.slack\.com`, '/(?:services|workflows|triggers)') }],
|
|
151
|
+
['pastebin', { ...REMOTE, name: 'Pastebin', pattern: host(String.raw`pastebin\.com`) }],
|
|
152
|
+
['paste-ee', { ...REMOTE, name: 'paste.ee', pattern: host(String.raw`paste\.ee`) }],
|
|
153
|
+
['transfer-sh', { ...REMOTE, name: 'transfer.sh', pattern: inUrl(String.raw`transfer\.sh`) }],
|
|
154
|
+
['file-io', { ...REMOTE, name: 'file.io', pattern: inUrl(String.raw`file\.io`) }],
|
|
155
|
+
['0x0', { ...REMOTE, name: '0x0.st', pattern: host(String.raw`0x0\.st`) }],
|
|
156
|
+
['ngrok', { ...REMOTE, name: 'ngrok', pattern: host(String.raw`ngrok(?:-free)?\.(?:io|app|dev)`) }],
|
|
157
|
+
['localtunnel', { ...REMOTE, name: 'localtunnel', pattern: host(String.raw`loca\.lt`) }],
|
|
158
|
+
['cloudflare-tunnel', { ...REMOTE, name: 'Cloudflare Tunnel', pattern: host(String.raw`trycloudflare\.com`) }],
|
|
159
|
+
['serveo', { ...REMOTE, name: 'Serveo', pattern: host(String.raw`serveo\.net`) }],
|
|
160
|
+
['pipedream-api', { ...REMOTE, name: 'Pipedream API', pattern: host(String.raw`pipedream\.com`) }],
|
|
161
|
+
['bun', { ...REMOTE, name: 'Bun install', pattern: host(String.raw`bun\.(?:sh|com)`, '/install') }],
|
|
162
|
+
['ipinfo', { ...IP_LOOKUP, name: 'ipinfo', pattern: host(String.raw`ipinfo\.io`) }],
|
|
163
|
+
['ipify', { ...IP_LOOKUP, name: 'ipify', pattern: host(String.raw`ipify\.org`) }],
|
|
164
|
+
['ifconfig-me', { ...IP_LOOKUP, name: 'ifconfig.me', pattern: host(String.raw`ifconfig\.me`) }],
|
|
165
|
+
['icanhazip', { ...IP_LOOKUP, name: 'icanhazip', pattern: host(String.raw`icanhazip\.com`) }],
|
|
166
|
+
['ip-api', { ...IP_LOOKUP, name: 'ip-api', pattern: host(String.raw`ip-api\.com`) }],
|
|
167
|
+
['ipapi', { ...IP_LOOKUP, name: 'ipapi', pattern: host(String.raw`ipapi\.com?`) }],
|
|
168
|
+
['checkip', { ...IP_LOOKUP, name: 'checkip', pattern: host(String.raw`checkip\.amazonaws\.com`) }],
|
|
169
|
+
])
|
|
170
|
+
// Any of them, as a text may say it: most say none, told at once.
|
|
171
|
+
const SAYS_ANY = new RegExp([...EXFILTRATION.values()].map(({ pattern }) => pattern.source).join('|'), 'iu')
|
|
172
|
+
|
|
173
|
+
// The services a file names, each with the lines it is named on, the first
|
|
174
|
+
// NPM_MAX_FOUND, in EXFILTRATION's order; null for none, or for prose or a
|
|
175
|
+
// source map by its name that node doesn't run as a script (`script`).
|
|
176
|
+
export function npmExfiltration(path, text, script = false) {
|
|
177
|
+
if (typeof text !== 'string' || (!script && (NPM_PROSE.test(path) || SOURCE_MAP.test(path))) || !SAYS_ANY.test(text)) return null
|
|
178
|
+
const found = new Map(), line = lineOf(text)
|
|
179
|
+
for (const [service, { pattern }] of EXFILTRATION) {
|
|
180
|
+
const lines = new Set()
|
|
181
|
+
for (const { index } of text.matchAll(pattern)) if (lines.add(line(index)).size >= NPM_MAX_FOUND) break
|
|
182
|
+
if (lines.size > 0) found.set(service, [...lines])
|
|
183
|
+
}
|
|
184
|
+
return found.size > 0 ? found : null
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The services of `found` under `tag` (HOST_TAGS), in their order; null for
|
|
188
|
+
// none.
|
|
189
|
+
export function npmHostsTagged(found, tag) {
|
|
190
|
+
const tagged = found && new Map([...found].filter(([service]) => EXFILTRATION.get(service).tag === tag))
|
|
191
|
+
return tagged?.size > 0 ? tagged : null
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// The services a file names (`found`) by their tag, in HOST_TAGS' order:
|
|
195
|
+
// `[tag, services]` each.
|
|
196
|
+
export const npmHostTags = found => [...HOST_TAGS.keys()].map(tag => [tag, npmHostsTagged(found, tag)]).filter(([, services]) => services)
|
|
197
|
+
|
|
198
|
+
// How severe a tag's `services` are: its own severity, or with `was` (null for
|
|
199
|
+
// a file that held none), where one of them the file didn't name, a level
|
|
200
|
+
// higher, never past `critical`, as a change between versions calls for more.
|
|
201
|
+
export function npmHostSeverity(tag, services, was) {
|
|
202
|
+
const levels = [...HOST_TAGS.values()]
|
|
203
|
+
const at = levels.indexOf(HOST_TAGS.get(tag))
|
|
204
|
+
return levels[was !== undefined && [...services.keys()].some(service => !was?.has(service)) ? Math.max(0, at - 1) : at]
|
|
205
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// How a file's text reads, for a reviewer: its category (binary, a source
|
|
2
|
+
// map, code with unexpectedly long lines or an inline map, minified, else
|
|
3
|
+
// ASCII or UTF-8), its control and invisible characters, its longest lines,
|
|
4
|
+
// an obfuscator's fingerprint, a large code file, and a file become
|
|
5
|
+
// unreadable between two versions.
|
|
6
|
+
import { CONTROLS, npmTextEncoding } from './characters.js'
|
|
7
|
+
import { MINIFIED_AVERAGE, minifiable, minifiedAverage } from './script.js'
|
|
8
|
+
|
|
9
|
+
// Lines longer than anyone writes by hand.
|
|
10
|
+
export const NPM_LONG_LINE = 1000
|
|
11
|
+
// Prose, which wraps where it is read: its long lines are paragraphs. By its
|
|
12
|
+
// extension (text, Markdown and MDX, and the markup GitHub renders a README
|
|
13
|
+
// from: `README.org`, `README.rdoc`), or its name alone (`LICENSE-MIT`,
|
|
14
|
+
// `CHANGES`; a dot in it only a version's, `LICENSE-LGPL2.1`,
|
|
15
|
+
// `CHANGES.2.0`; a prose extension after it is one), not code named alike
|
|
16
|
+
// (`lib/history.js`, `dist/notice.min.js`), which can be minified as any.
|
|
17
|
+
export const NPM_PROSE = /(?:\.(?:md|markdown|mdown|mkdn|mdx|txt|rst|adoc|asciidoc|asc|textile|rdoc|org|creole|mediawiki|wiki|pod)|(?:^|\/)(?:licen[cs]e|copying|notice|authors|contributors|readme|changelog|changes|history)(?:-[^/.]*)?(?:\.\d[^/.]*)*)$/iu
|
|
18
|
+
const SOURCE_MAP_COMMENT = /^\s*(?:\/\/|\/\*)[#@] sourceMappingURL=/u
|
|
19
|
+
// A line that is all one, the map in it as a data: URL, base64 or
|
|
20
|
+
// percent-encoded: not code that writes one.
|
|
21
|
+
const INLINE_SOURCE_MAP = /^\s*(?:\/\/|\/\*)[#@] sourceMappingURL=data:[^\s,]*,[\w+/=%.~-]*\s*(?:\*\/)?\s*$/u
|
|
22
|
+
export const SOURCE_MAP = /\.map$/iu
|
|
23
|
+
const MINIFIED_NAME = /\.min\.[^/.]+$/iu
|
|
24
|
+
// What javascript-obfuscator writes, and next to nothing else: its names,
|
|
25
|
+
// `_0x` and four to six hex digits, OBFUSCATED_NAMES of them or more, or the
|
|
26
|
+
// loop it turns its array of strings with, `while(!![])`, spaced or not.
|
|
27
|
+
const OBFUSCATED_NAME = /(?<![\p{ID_Continue}$])_0x[0-9a-f]{4,6}(?![\p{ID_Continue}$])/gu
|
|
28
|
+
export const OBFUSCATED_NAMES = 20
|
|
29
|
+
const OBFUSCATED_LOOP = /while\s*\(\s*!!\[\]\s*\)/u
|
|
30
|
+
// Names counted before a fingerprint's count stops, reading as that many or
|
|
31
|
+
// more: each is kept to tell it from the others, and a file can hold millions.
|
|
32
|
+
export const OBFUSCATED_COUNTED = 1000
|
|
33
|
+
// A text's obfuscator fingerprint, `{ names, loop }`: how many such names it
|
|
34
|
+
// has, up to OBFUSCATED_COUNTED, and whether it has the loop; null where it
|
|
35
|
+
// has neither enough names nor the loop.
|
|
36
|
+
export function npmObfuscation(text) {
|
|
37
|
+
const names = new Set()
|
|
38
|
+
for (const [name] of text.matchAll(OBFUSCATED_NAME)) {
|
|
39
|
+
names.add(name)
|
|
40
|
+
if (names.size === OBFUSCATED_COUNTED) break
|
|
41
|
+
}
|
|
42
|
+
const loop = OBFUSCATED_LOOP.test(text)
|
|
43
|
+
return names.size >= OBFUSCATED_NAMES || loop ? { names: names.size, loop } : null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// A code file this large is mostly a bundle, worth a look where a version
|
|
47
|
+
// adds it: JavaScript or TypeScript, not a declaration file, which holds no
|
|
48
|
+
// code that runs, or any file node runs as a script (`script`, npm/files.js
|
|
49
|
+
// npmLoadedScripts).
|
|
50
|
+
export const NPM_LARGE_CODE = 256 * 1024
|
|
51
|
+
const CODE = /\.(?:[cm]?[jt]s|[jt]sx)$/iu
|
|
52
|
+
const DECLARATION = /\.d\.[cm]?ts$/iu
|
|
53
|
+
export const npmLargeCode = (path, bytes, script = false) => typeof bytes === 'number' && bytes >= NPM_LARGE_CODE && (script || (CODE.test(path) && !DECLARATION.test(path)))
|
|
54
|
+
|
|
55
|
+
// A code file that isn't text (npmFileReadability's `binary`: not UTF-8, or
|
|
56
|
+
// holding a NUL), by its path and how it reads, a declaration file too, or
|
|
57
|
+
// any file node runs as a script (`script`, npm/files.js npmLoadedScripts):
|
|
58
|
+
// no one can read it in review, yet what reads it by its byte order mark can
|
|
59
|
+
// run it, or type with it, as UTF-16 (a browser's classic script, Windows
|
|
60
|
+
// Script Host, TypeScript), and node runs it decoded as UTF-8 whatever it
|
|
61
|
+
// holds past its code (`//` and a byte no UTF-8 has).
|
|
62
|
+
export const npmBinaryCode = (path, readability, script = false) => readability?.category === 'binary' && (script || CODE.test(path))
|
|
63
|
+
|
|
64
|
+
// A file with a line over UNREADABLE_LINE characters, by how it reads
|
|
65
|
+
// (`now`, npmFileReadability's), `path` its path: an inline source map's line
|
|
66
|
+
// counts for none, and prose and source maps, whose long lines the Long lines
|
|
67
|
+
// tag passes over, never are, but where node runs it as a script (`script`),
|
|
68
|
+
// nor is a file that isn't text. Then one that had no line over SHORT_LINES
|
|
69
|
+
// characters (`was`) and now has one over UNREADABLE_LINE, by how it reads on
|
|
70
|
+
// each side.
|
|
71
|
+
const SHORT_LINES = 200
|
|
72
|
+
const UNREADABLE_LINE = 2000
|
|
73
|
+
export const npmUnreadable = (path, now, script = false) => Boolean(now) && now.category !== 'binary' && (script || (!NPM_PROSE.test(path) && !SOURCE_MAP.test(path)))
|
|
74
|
+
&& now.longest > UNREADABLE_LINE
|
|
75
|
+
export const npmBecameUnreadable = (path, was, now, script = false) => Boolean(was) && was.category !== 'binary' && was.longest <= SHORT_LINES && npmUnreadable(path, now, script)
|
|
76
|
+
|
|
77
|
+
// How a file reads, as its `category`, the first that holds (READABILITY):
|
|
78
|
+
// binary (no text), map (a source map), long (code with some lines
|
|
79
|
+
// longer than anyone writes), inline-map (code with its source map in it, minified or
|
|
80
|
+
// not), minified (code mostly on long lines, or named .min., or minified
|
|
81
|
+
// into shorter lines: see MINIFIED_AVERAGE), else utf8 or ascii; and
|
|
82
|
+
// whatever it is, the control, bidirectional or invisible characters a text
|
|
83
|
+
// holds (`controls`), found in one pass, which count as a label of their own
|
|
84
|
+
// beside it each, control and invisible (npmReadabilityLabels). Prose is
|
|
85
|
+
// readable whatever its lines' lengths, and an inline source map's line
|
|
86
|
+
// counts for none, nor for how much of the code is on long lines. With
|
|
87
|
+
// npmTextEncoding's `kind` and `controls`, its `longest` line's length and
|
|
88
|
+
// `longLines`, its code's lines' `average` length where it is minified into
|
|
89
|
+
// short ones (strings and comments aside, see MINIFIED_AVERAGE; 0 otherwise),
|
|
90
|
+
// how long its inline map is (`inlineMap`, 0 for none), and its obfuscator
|
|
91
|
+
// fingerprint (`obfuscation`, npmObfuscation's; null for none, and for prose
|
|
92
|
+
// or a source map). One node runs as a script whatever its name (`script`,
|
|
93
|
+
// script.js npmIsScript) is read as code: no prose nor source map.
|
|
94
|
+
export function npmFileReadability(path, text, script = false) {
|
|
95
|
+
const encoding = npmTextEncoding(text)
|
|
96
|
+
if (encoding.kind === 'binary') return { ...encoding, category: 'binary', longest: 0, longLines: 0, average: 0, inlineMap: 0, obfuscation: null }
|
|
97
|
+
let inlineMap = 0, longChars = 0, longLines = 0, longest = 0
|
|
98
|
+
for (let at = 0; at <= text.length;) {
|
|
99
|
+
const next = text.indexOf('\n', at)
|
|
100
|
+
const end = next === -1 ? text.length : next
|
|
101
|
+
const length = end - at - (text[end - 1] === '\r' ? 1 : 0)
|
|
102
|
+
if (SOURCE_MAP_COMMENT.test(text.slice(at, at + 64)) && INLINE_SOURCE_MAP.test(text.slice(at, end))) inlineMap += length
|
|
103
|
+
else {
|
|
104
|
+
if (length > NPM_LONG_LINE) {
|
|
105
|
+
longLines++
|
|
106
|
+
longChars += length
|
|
107
|
+
}
|
|
108
|
+
longest = Math.max(longest, length)
|
|
109
|
+
}
|
|
110
|
+
at = end + 1
|
|
111
|
+
}
|
|
112
|
+
// A source map holds the names and sources of the code it maps, and prose
|
|
113
|
+
// its examples: neither runs.
|
|
114
|
+
const map = !script && SOURCE_MAP.test(path), prose = !script && NPM_PROSE.test(path)
|
|
115
|
+
const obfuscation = prose || map ? null : npmObfuscation(text)
|
|
116
|
+
const read = { ...encoding, longest, longLines, average: 0, inlineMap, obfuscation }
|
|
117
|
+
if (map) return { ...read, category: 'map' }
|
|
118
|
+
if (prose) return { ...read, category: inlineMap > 0 ? 'inline-map' : encoding.kind }
|
|
119
|
+
if (longLines === 0) {
|
|
120
|
+
// None of its lines longer than MINIFIED_AVERAGE, none of its code's can
|
|
121
|
+
// average more: told without reading its code.
|
|
122
|
+
const language = minifiable(path, script)
|
|
123
|
+
const average = language !== null && longest > MINIFIED_AVERAGE ? minifiedAverage(text, language) : 0
|
|
124
|
+
return { ...read, average, category: inlineMap > 0 ? 'inline-map' : average > 0 ? 'minified' : encoding.kind }
|
|
125
|
+
}
|
|
126
|
+
if (longChars / (text.length - inlineMap) < .5 && !MINIFIED_NAME.test(path)) return { ...read, category: 'long' }
|
|
127
|
+
return { ...read, category: inlineMap > 0 ? 'inline-map' : 'minified' }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The category a file's tag shows: for one with long lines, how its text is
|
|
131
|
+
// encoded.
|
|
132
|
+
export const npmTaggedCategory = readability => readability.category === 'long' ? readability.kind : readability.category
|
|
133
|
+
|
|
134
|
+
// What a file is labelled, in its tags and in the Overview's warning and
|
|
135
|
+
// chips, each finding it: its control characters, its invisible ones
|
|
136
|
+
// (characterLabels) and its long lines, where it holds them, beside its category (how its text is encoded, for one whose long
|
|
137
|
+
// lines are unexpected), but for ASCII or UTF-8, which a file that can't be
|
|
138
|
+
// read as it is counts under as none of them. A minified file's long lines
|
|
139
|
+
// are labelled too, as its inline map's are; prose's and a source map's
|
|
140
|
+
// never are.
|
|
141
|
+
export function npmReadabilityLabels(readability) {
|
|
142
|
+
const flags = [...characterLabels(readability.controls),
|
|
143
|
+
...readability.longLines > 0 && ['long', 'minified', 'inline-map'].includes(readability.category) ? ['long'] : []]
|
|
144
|
+
const category = npmTaggedCategory(readability)
|
|
145
|
+
return READABILITY.get(category).mark || flags.length === 0 ? [...flags, category] : flags
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// How a label is marked on a file: long lines as a warning where it is
|
|
149
|
+
// otherwise readable, as they are unexpected there, and as a notice in
|
|
150
|
+
// minified code, as minified code is; any other as its category is.
|
|
151
|
+
export const npmLabelMark = (readability, label) => label === 'long' && readability.category !== 'long' ? 'notice' : READABILITY.get(label).mark
|
|
152
|
+
|
|
153
|
+
// Each category: its name, its tag in a list of files or a file's head (and,
|
|
154
|
+
// `short`, in a file tree, where that is too long), and how it is marked,
|
|
155
|
+
// `warn` for what to look into, `notice` for what can be hard to review by
|
|
156
|
+
// reading it either way.
|
|
157
|
+
export const READABILITY = new Map([
|
|
158
|
+
['binary', { name: 'Binary', tag: 'Binary', mark: 'warn' }],
|
|
159
|
+
['controls', { name: 'Control chars', tag: 'Controls', mark: 'warn' }],
|
|
160
|
+
['invisible', { name: 'Invisible chars', tag: 'Invisible', mark: 'warn' }],
|
|
161
|
+
['long', { name: 'Long lines', tag: 'Long lines', mark: 'warn' }],
|
|
162
|
+
['minified', { name: 'Minified', tag: 'Minified', short: 'Min', mark: 'notice' }],
|
|
163
|
+
['map', { name: 'Source maps', tag: 'Map', mark: 'notice' }],
|
|
164
|
+
['inline-map', { name: 'Inline source maps', tag: 'Inline map', mark: 'notice' }],
|
|
165
|
+
['utf8', { name: 'UTF-8', tag: 'UTF-8', mark: null }],
|
|
166
|
+
['ascii', { name: 'ASCII', tag: 'ASCII', mark: null }],
|
|
167
|
+
])
|
|
168
|
+
|
|
169
|
+
// The characters a text holds of a label's kind, `controls` (C0, DEL, C1
|
|
170
|
+
// and bidirectional controls) or `invisible`, `[point, times]`, the most
|
|
171
|
+
// found first: those npmTextEncoding found in one pass, told apart by code
|
|
172
|
+
// point. The labels a text's characters take, of those two.
|
|
173
|
+
const CONTROL = new RegExp(CONTROLS.source, 'u')
|
|
174
|
+
export const charactersOf = (controls, label) => [...controls ?? []]
|
|
175
|
+
.filter(([point]) => CONTROL.test(String.fromCodePoint(point)) === (label === 'controls')).toSorted((a, b) => b[1] - a[1] || a[0] - b[0])
|
|
176
|
+
const characterLabels = controls => controls ? ['controls', 'invisible'].filter(label => charactersOf(controls, label).length > 0) : []
|
|
177
|
+
|