@preventive/triage 1.0.0-alpha.8 → 1.0.0-alpha.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +16 -78
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +6 -0
- package/common/bundle-compare-diff.js +377 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-imports.js +20 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +6 -0
- package/common/bundle-reasons.js +58 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +10 -0
- package/common/bundle-sources.js +374 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +66 -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 +63 -0
- package/common/finding-filters.js +313 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +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 +14 -0
- package/common/line-diff.js +181 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/directory-packages.ts +28 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +138 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +9 -0
- package/common/managed/npm-packages.js +63 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/review-view-routes.js +23 -0
- package/common/managed/risk-routes.js +30 -0
- package/common/managed/roles.ts +41 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +385 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/stasis-config.ts +7 -0
- package/common/managed/team-app.d.ts +19 -0
- package/common/managed/team-app.js +129 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/pretty-json.js +98 -0
- package/common/pretty-kinds.js +20 -0
- package/common/pretty-print.d.ts +6 -0
- package/common/pretty-print.js +36 -0
- package/common/pretty-sourcemap.js +70 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/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/sourcemap-listing.js +78 -0
- package/common/sourcemap-mappings.js +136 -0
- package/common/sourcemap-unlist.js +85 -0
- package/common/stasis-files.d.ts +5 -0
- package/common/stasis-files.js +20 -0
- package/common/stasis-tgz.d.ts +6 -0
- package/common/stasis-tgz.js +27 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/whitespace-insensitive.js +19 -0
- package/common/workspace-app.js +91 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +2 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-55YIWY3H.js +5 -0
- package/out/chunk-5AVGKFMR.js +1 -0
- package/out/chunk-5CJKUV53.js +1 -0
- package/out/chunk-5EAVJAD2.js +3 -0
- package/out/chunk-5M2X3QPK.js +6 -0
- package/out/chunk-5QWPKTCE.js +40 -0
- package/out/chunk-6CCSTJWB.js +1 -0
- package/out/chunk-6VOB5WXX.js +2 -0
- package/out/chunk-6Y6PZ2BU.js +9 -0
- package/out/chunk-74JZTGTO.js +11 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-7HP2VYIC.js +2 -0
- package/out/chunk-7YFJUT2P.js +1 -0
- package/out/chunk-7YO4QV5P.js +1 -0
- package/out/chunk-A4BBBHQU.js +1 -0
- package/out/chunk-B64CTMVU.js +4 -0
- package/out/chunk-BEKYZCPX.js +14 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-CU3FPB3P.js +1 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-DUASGS2O.js +8 -0
- package/out/chunk-DUS5ARE2.js +53 -0
- package/out/chunk-EEJA7JBI.js +13 -0
- package/out/chunk-FSU2PLJL.js +1 -0
- package/out/chunk-GBMAXAYK.js +3 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GX5UXWT4.js +1 -0
- package/out/chunk-ITUKKCCK.js +10 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-JXBRWLMA.js +4 -0
- package/out/chunk-K4XJHM2T.js +1 -0
- package/out/chunk-LBD3M3J6.js +1 -0
- package/out/chunk-LVSLM7HB.js +1 -0
- package/out/chunk-LVW7WWV4.js +1 -0
- package/out/chunk-MV66NL3G.js +3 -0
- package/out/chunk-N57OWFKY.js +15 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-OWSEQOL5.js +1 -0
- package/out/chunk-PKLVXUEI.js +11 -0
- package/out/chunk-PLGH63UC.js +2 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PTFYDJUP.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QD3IBSF4.js +7 -0
- package/out/chunk-QI66YA4F.js +1 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RPNO56H2.js +1 -0
- package/out/chunk-SSPDMA6D.js +1 -0
- package/out/chunk-SZWPYLPC.js +1 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UJP4PQJA.js +1 -0
- package/out/chunk-UJSJMXEG.js +1 -0
- package/out/chunk-UR4WYMIP.js +1 -0
- package/out/chunk-VHEXSGGP.js +1 -0
- package/out/chunk-VYYUMYVW.js +9 -0
- package/out/chunk-VZPPX6MV.js +1 -0
- package/out/chunk-WCDYSIKG.js +1 -0
- package/out/chunk-XM4RLC4A.js +2 -0
- package/out/chunk-YKCRCNYZ.js +266 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +37 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +26 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -4
- package/out/index.html +104 -24
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +367 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -147
- package/package.json +409 -64
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +287 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +94 -0
- package/risk/actions/workflow.js +183 -0
- package/risk/files/characters.js +341 -0
- package/risk/files/hosts.js +206 -0
- package/risk/files/readability.js +185 -0
- package/risk/files/runs-code.js +563 -0
- package/risk/files/script.js +402 -0
- package/risk/files/source-map-link.js +43 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +294 -0
- package/risk/index.js +12 -0
- package/risk/npm/assess.js +285 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +236 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +67 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +393 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +169 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +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 +18 -17
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +247 -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 +79 -0
- package/server-managed/bundle-advisory-inventory.ts +85 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +380 -0
- package/server-managed/bundle-build.ts +326 -0
- package/server-managed/bundle-cache.ts +261 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +91 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +151 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +78 -0
- package/server-managed/comparison.ts +51 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1914 -0
- package/server-managed/db-neon.ts +398 -0
- package/server-managed/db-schema.ts +263 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +149 -0
- package/server-managed/dependabot-access.ts +61 -0
- package/server-managed/dependabot-alerts.ts +180 -0
- package/server-managed/dependency-review-comments.ts +143 -0
- package/server-managed/dependency-reviews.ts +369 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +92 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +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 +181 -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 +6324 -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 +234 -0
- package/server-managed/lockfile-scope.ts +58 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +116 -0
- package/server-managed/npm-delta-worker.js +142 -0
- package/server-managed/npm-delta.ts +277 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +265 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +469 -0
- package/server-managed/npm-patch-paths.ts +86 -0
- package/server-managed/npm-patch.ts +455 -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 +127 -0
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +3 -0
- package/server-managed/pretty-format.js +13 -0
- package/server-managed/pretty-print.ts +442 -0
- package/server-managed/public-workspace.ts +243 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +370 -0
- package/server-managed/pull-dependency-reviews.ts +407 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/queue.ts +54 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +30 -0
- package/server-managed/rename-diff.ts +237 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-opening.ts +77 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +185 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +119 -0
- package/server-managed/repository-browser.ts +361 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +222 -0
- package/server-managed/repository-dependency-reviews.ts +182 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +428 -0
- package/server-managed/repository-issues.ts +293 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +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-caches.ts +37 -0
- package/server-managed/repository-risk-read.ts +260 -0
- package/server-managed/repository-risk-stasis.ts +61 -0
- package/server-managed/repository-risk-turn.ts +97 -0
- package/server-managed/repository-risk.ts +516 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +170 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +121 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +147 -0
- package/server-managed/stasis-dependencies.ts +221 -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 +56 -0
- package/server-managed/team-app.ts +156 -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 +368 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +161 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +135 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +256 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/strip-types-loader.js +13 -10
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Compose the existing HTTP apps on e2e's listener, including its WS/SSE
|
|
2
|
+
// transports and static UI. Managed handles its API, discovery and page HTML;
|
|
3
|
+
// assets and other requests fall through to the unchanged e2e HTTP handler.
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
|
+
import type { Server } from 'node:http'
|
|
6
|
+
import { withReap } from '../server-common/reap.ts'
|
|
7
|
+
import { loadConfig } from '../server-e2e/config.ts'
|
|
8
|
+
import { createE2eApp } from '../server-e2e/app.ts'
|
|
9
|
+
import { loadManagedConfig } from './config.ts'
|
|
10
|
+
import { LOGIN_PATH } from './github-oauth.ts'
|
|
11
|
+
import { createManagedApp, logManagedStartup } from './index.ts'
|
|
12
|
+
|
|
13
|
+
export async function init(mode: 'managed+e2e' | 'e2e+managed', { ui = true }: { ui?: boolean } = {}): Promise<Server> {
|
|
14
|
+
const config = loadManagedConfig({ combined: true })
|
|
15
|
+
const e2eConfig = loadConfig()
|
|
16
|
+
if (!e2eConfig.neonUrl && !config.neonUrl && config.dbPath !== ':memory:' && resolve(config.dbPath) === resolve(e2eConfig.dbPath)) {
|
|
17
|
+
throw new Error('MANAGED_DB_PATH must differ from e2e DB_PATH in combined mode.')
|
|
18
|
+
}
|
|
19
|
+
const e2e = await createE2eApp(e2eConfig, { ui })
|
|
20
|
+
// Replace the assembled server's single
|
|
21
|
+
// request listener; adding a second would write two responses per request.
|
|
22
|
+
const handlers = e2e.httpServer.listeners('request')
|
|
23
|
+
const next = handlers[0]
|
|
24
|
+
if (handlers.length !== 1 || !next) throw new Error('Expected one e2e HTTP request handler')
|
|
25
|
+
const managed = await createManagedApp(config, {
|
|
26
|
+
next: e2e.handleRequest,
|
|
27
|
+
isShuttingDown: e2e.isShuttingDown,
|
|
28
|
+
ui,
|
|
29
|
+
serverInfo: {
|
|
30
|
+
mode, managed: { loginPath: LOGIN_PATH, cookieName: config.sessionCookieName },
|
|
31
|
+
...(e2eConfig.deepviewScanServer ? { deepviewScanServer: e2eConfig.deepviewScanServer } : {}),
|
|
32
|
+
},
|
|
33
|
+
}).catch(async err => {
|
|
34
|
+
await e2e.httpServer[Symbol.asyncDispose]()
|
|
35
|
+
throw err
|
|
36
|
+
})
|
|
37
|
+
e2e.onShutdown(managed.close)
|
|
38
|
+
e2e.httpServer.removeListener('request', next)
|
|
39
|
+
e2e.httpServer.on('request', withReap(managed.handleRequest,
|
|
40
|
+
{ e2e: e2e.reap, managed: managed.reap }, { isShuttingDown: e2e.isShuttingDown }))
|
|
41
|
+
e2e.httpServer.once('listening', () => { logManagedStartup(config, e2e.httpServer, mode) })
|
|
42
|
+
return e2e.httpServer
|
|
43
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import type { DatabaseSync } from 'node:sqlite'
|
|
3
|
+
import { type ManagedComment, canDeleteComment } from '../common/managed/comments.ts'
|
|
4
|
+
import { type ManagedSql, sqliteTransaction } from './sql.ts'
|
|
5
|
+
|
|
6
|
+
export interface CommentInput {
|
|
7
|
+
findingId: string
|
|
8
|
+
body: string
|
|
9
|
+
// Runtime imports may omit authorship, including future admin UI imports.
|
|
10
|
+
// Ordinary comment posts always supply the authenticated user as author.
|
|
11
|
+
authorId: string | null
|
|
12
|
+
authorLogin: string | null
|
|
13
|
+
// The user performing an import need not be the author of its comments.
|
|
14
|
+
// Omitted for ordinary posts, where the author is also the acting user.
|
|
15
|
+
actor?: { id: string; login: string }
|
|
16
|
+
// Omitted dates default to the action time; null preserves unknown dates.
|
|
17
|
+
createdAt?: number | null
|
|
18
|
+
updatedAt?: number | null
|
|
19
|
+
reportId?: string | null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CommentStore {
|
|
23
|
+
listComments(findingIds: readonly string[]): Promise<ManagedComment[]>
|
|
24
|
+
listCommentedFindingIds(findingIds: readonly string[]): Promise<string[]>
|
|
25
|
+
getComment(id: string): Promise<ManagedComment | null>
|
|
26
|
+
createComment(input: CommentInput, now: number): Promise<ManagedComment>
|
|
27
|
+
editComment(id: string, authorId: string, authorLogin: string, body: string, version: number, reportId: string, now: number): Promise<ManagedComment | 'conflict' | 'forbidden' | null>
|
|
28
|
+
deleteComment(id: string, actorId: string, actorLogin: string, version: number, reportId: string, now: number): Promise<'deleted' | 'conflict' | 'forbidden' | null>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const COMMENT_COLUMNS = `id TEXT PRIMARY KEY, finding_id TEXT NOT NULL, body TEXT NOT NULL,
|
|
32
|
+
author_id TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
33
|
+
author_login TEXT, created_at INTEGER, updated_at INTEGER,
|
|
34
|
+
version INTEGER NOT NULL DEFAULT 1`
|
|
35
|
+
|
|
36
|
+
export const COMMENT_SCHEMA = `
|
|
37
|
+
CREATE TABLE IF NOT EXISTS managed_finding_comment (${COMMENT_COLUMNS}) STRICT;
|
|
38
|
+
CREATE INDEX IF NOT EXISTS finding_comment_finding_idx ON managed_finding_comment(finding_id, created_at, id);
|
|
39
|
+
CREATE TABLE IF NOT EXISTS managed_finding_comment_event (
|
|
40
|
+
seq INTEGER PRIMARY KEY, comment_id TEXT NOT NULL, finding_id TEXT NOT NULL,
|
|
41
|
+
actor_id TEXT REFERENCES managed_user(id) ON DELETE SET NULL,
|
|
42
|
+
actor_login TEXT, action TEXT NOT NULL, at INTEGER NOT NULL,
|
|
43
|
+
report_id TEXT, report TEXT, repo TEXT
|
|
44
|
+
) STRICT;
|
|
45
|
+
CREATE INDEX IF NOT EXISTS finding_comment_event_finding_idx ON managed_finding_comment_event(finding_id, seq);
|
|
46
|
+
CREATE INDEX IF NOT EXISTS finding_comment_event_actor_at_idx ON managed_finding_comment_event(actor_id, at);
|
|
47
|
+
CREATE INDEX IF NOT EXISTS finding_comment_event_at_idx ON managed_finding_comment_event(at, seq);
|
|
48
|
+
`
|
|
49
|
+
|
|
50
|
+
export function initCommentMethods(db: DatabaseSync): void {
|
|
51
|
+
db.exec(COMMENT_SCHEMA)
|
|
52
|
+
migrateCommentDates(db)
|
|
53
|
+
// updated_by belongs to the whole triage row, not necessarily its comment.
|
|
54
|
+
// Preserve legacy text without guessing an author. Clearing the old column
|
|
55
|
+
// in the same transaction makes the migration safe to restart. Use a fresh
|
|
56
|
+
// ID so a later legacy-server write cannot collide with an earlier import.
|
|
57
|
+
sqliteTransaction(db, 'BEGIN', () => db.exec(`INSERT INTO managed_finding_comment (id, finding_id, body, created_at, updated_at)
|
|
58
|
+
SELECT 'legacy:' || lower(hex(randomblob(16))), finding_id, comment, updated_at, updated_at
|
|
59
|
+
FROM managed_finding_triage WHERE comment IS NOT NULL AND comment != '';
|
|
60
|
+
UPDATE managed_finding_triage SET comment = NULL WHERE comment IS NOT NULL;`))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function commentMethods(db: ManagedSql): CommentStore {
|
|
64
|
+
// The author's login and name as they are now; one no longer a user keeps
|
|
65
|
+
// the login they wrote it under, and has no name.
|
|
66
|
+
const fields = `c.id, c.finding_id AS findingId, c.body, c.author_id AS authorId,
|
|
67
|
+
COALESCE(u.login, c.author_login) AS authorLogin, u.name AS authorName,
|
|
68
|
+
c.created_at AS createdAt, c.updated_at AS updatedAt, c.version`
|
|
69
|
+
const select = db.prepare(`SELECT ${fields} FROM managed_finding_comment c
|
|
70
|
+
LEFT JOIN managed_user u ON u.id = c.author_id WHERE c.id = ?`)
|
|
71
|
+
const list = db.prepare(`SELECT ${fields} FROM managed_finding_comment c
|
|
72
|
+
LEFT JOIN managed_user u ON u.id = c.author_id
|
|
73
|
+
WHERE c.finding_id IN (SELECT value FROM json_each(?)) ORDER BY c.created_at NULLS FIRST, c.id`)
|
|
74
|
+
const insert = db.prepare(`INSERT INTO managed_finding_comment
|
|
75
|
+
(id, finding_id, body, author_id, author_login, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
76
|
+
const update = db.prepare(`UPDATE managed_finding_comment SET body = ?, updated_at = ?, version = version + 1
|
|
77
|
+
WHERE id = ? AND author_id = ? AND version = ?`)
|
|
78
|
+
const remove = db.prepare('DELETE FROM managed_finding_comment WHERE id = ? AND (author_id = ? OR (author_id IS NULL AND ? IS NULL)) AND version = ?')
|
|
79
|
+
const userRole = db.prepare('SELECT role FROM managed_user WHERE id = ?')
|
|
80
|
+
// Deleted comments still have audit events which explicit annotation purges
|
|
81
|
+
// must find, including when no current triage/comment record remains.
|
|
82
|
+
const annotated = db.prepare(`SELECT finding_id AS id FROM managed_finding_comment WHERE finding_id IN (SELECT value FROM json_each(?))
|
|
83
|
+
UNION SELECT finding_id AS id FROM managed_finding_comment_event WHERE finding_id IN (SELECT value FROM json_each(?))`)
|
|
84
|
+
const event = db.prepare(`INSERT INTO managed_finding_comment_event
|
|
85
|
+
(comment_id, finding_id, actor_id, actor_login, action, at, report_id, report, repo)
|
|
86
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, (SELECT filename FROM managed_report WHERE id = ?),
|
|
87
|
+
(SELECT p.full_name FROM managed_report r JOIN managed_selected_repo p ON p.repo_id = r.repo_id WHERE r.id = ?))`)
|
|
88
|
+
const read = async (id: string) => (await select.get(id)) as ManagedComment | undefined
|
|
89
|
+
return {
|
|
90
|
+
async listComments(ids) { return ids.length > 0 ? (await list.all(JSON.stringify(ids))) as unknown as ManagedComment[] : [] },
|
|
91
|
+
async listCommentedFindingIds(ids) {
|
|
92
|
+
const json = JSON.stringify(ids)
|
|
93
|
+
return ((await annotated.all(json, json)) as { id: string }[]).map(row => row.id)
|
|
94
|
+
},
|
|
95
|
+
async getComment(id) { return (await read(id)) ?? null },
|
|
96
|
+
async createComment(input, now) {
|
|
97
|
+
const id = randomUUID()
|
|
98
|
+
const createdAt = input.createdAt === undefined ? now : input.createdAt
|
|
99
|
+
const updatedAt = input.updatedAt === undefined ? createdAt : input.updatedAt
|
|
100
|
+
await insert.run(id, input.findingId, input.body, input.authorId, input.authorLogin, createdAt, updatedAt)
|
|
101
|
+
await event.run(id, input.findingId, input.actor?.id ?? input.authorId, input.actor?.login ?? input.authorLogin, 'added a comment', now,
|
|
102
|
+
input.reportId ?? null, input.reportId ?? null, input.reportId ?? null)
|
|
103
|
+
return (await read(id))!
|
|
104
|
+
},
|
|
105
|
+
async editComment(id, authorId, authorLogin, body, version, reportId, now) {
|
|
106
|
+
// Identity/version checks and the event share the operation transaction.
|
|
107
|
+
const current = await read(id)
|
|
108
|
+
if (!current) return null
|
|
109
|
+
if (current.authorId !== authorId) return 'forbidden'
|
|
110
|
+
if (current.version !== version) return 'conflict'
|
|
111
|
+
if (current.body === body) return current
|
|
112
|
+
await update.run(body, now, id, authorId, version)
|
|
113
|
+
await event.run(id, current.findingId, authorId, authorLogin, 'edited a comment', now, reportId, reportId, reportId)
|
|
114
|
+
return (await read(id))!
|
|
115
|
+
},
|
|
116
|
+
async deleteComment(id, actorId, actorLogin, version, reportId, now) {
|
|
117
|
+
const current = await read(id)
|
|
118
|
+
const role = (await userRole.get(actorId) as { role: string } | undefined)?.role ?? 'none'
|
|
119
|
+
if (!current) return null
|
|
120
|
+
if (!canDeleteComment(current, { id: actorId, role })) return 'forbidden'
|
|
121
|
+
if (current.version !== version) return 'conflict'
|
|
122
|
+
await remove.run(id, current.authorId, current.authorId, version)
|
|
123
|
+
await event.run(id, current.findingId, actorId, actorLogin, 'deleted a comment', now, reportId, reportId, reportId)
|
|
124
|
+
return 'deleted'
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function migrateCommentDates(db: DatabaseSync): void {
|
|
130
|
+
const columns = db.prepare('PRAGMA table_info(managed_finding_comment)').all() as { name: string; notnull: number }[]
|
|
131
|
+
if (!columns.some(column => ['created_at', 'updated_at'].includes(column.name) && column.notnull)) return
|
|
132
|
+
sqliteTransaction(db, 'BEGIN', () => db.exec(`CREATE TABLE managed_finding_comment_nullable_dates (${COMMENT_COLUMNS}) STRICT;
|
|
133
|
+
INSERT INTO managed_finding_comment_nullable_dates (id, finding_id, body, author_id, author_login, created_at, updated_at, version)
|
|
134
|
+
SELECT id, finding_id, body, author_id, author_login, created_at, updated_at, version FROM managed_finding_comment;
|
|
135
|
+
DROP TABLE managed_finding_comment;
|
|
136
|
+
ALTER TABLE managed_finding_comment_nullable_dates RENAME TO managed_finding_comment;
|
|
137
|
+
CREATE INDEX finding_comment_finding_idx ON managed_finding_comment(finding_id, created_at, id);`))
|
|
138
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Who made a commit beside its author, as the Commits tab shows them
|
|
2
|
+
// (repository-history.ts): its co-authors, as its `Co-authored-by:` trailers
|
|
3
|
+
// name them, and the agents its message marks.
|
|
4
|
+
import { agentSignals, trailerBlock } from '../common/managed/agent-tasks.ts'
|
|
5
|
+
import { GITHUB_AGENTS, type GithubAgentId, emailAgent, githubAgent } from '../common/managed/github-agents.ts'
|
|
6
|
+
import { APP_AGENTS } from './app-agents.ts'
|
|
7
|
+
import { type NamedAccount, commitAccount } from './github-accounts.ts'
|
|
8
|
+
import { nameOf } from './github-values.ts'
|
|
9
|
+
|
|
10
|
+
export const MAX_COAUTHORS = 3
|
|
11
|
+
// The rules who a commit names beside its author is read by (coauthorFacts),
|
|
12
|
+
// and how they are kept: what was kept read by others (history pages,
|
|
13
|
+
// squashed pull requests) read again by these, once raised. The agents'
|
|
14
|
+
// accounts, addresses and names are none of them (coauthorsOf).
|
|
15
|
+
export const COAUTHORS_READ = 5
|
|
16
|
+
|
|
17
|
+
// One who made a commit beside its author: by name and account, as its
|
|
18
|
+
// author is, and the agent it is where known (common/managed/github-agents.ts),
|
|
19
|
+
// by its account, its commits' address or name, or the marks it leaves.
|
|
20
|
+
interface Coauthor { name: string | null; login: string | null; id: number | null; agent?: string }
|
|
21
|
+
|
|
22
|
+
// `Co-authored-by: <name> <address>` trailers, GitHub matching the key
|
|
23
|
+
// regardless of case; Cursor's agents' links, as their work carries them;
|
|
24
|
+
// the app agents known by the fingerprints they leave.
|
|
25
|
+
const COAUTHOR_TRAILER = /^co-authored-by:[ \t]*([^<\n]*?)[ \t]*<([^<>\s]+)>[ \t]*$/gimu
|
|
26
|
+
const CURSOR_AGENT = /https:\/\/cursor\.com\/(?:agents\?id=|background-agent\?bcId=)bc-/u
|
|
27
|
+
const FINGERPRINTED = APP_AGENTS.filter(agent => agent.fingerprint)
|
|
28
|
+
|
|
29
|
+
// One named as a commit's author or co-author: by name, the address its
|
|
30
|
+
// commit gives (where it is read), and account.
|
|
31
|
+
export type Maker = { name: unknown; email?: unknown; account: NamedAccount }
|
|
32
|
+
|
|
33
|
+
// Those a commit's message names in its `Co-authored-by:` trailers
|
|
34
|
+
// (agent-tasks.ts trailerBlock), each by name and address.
|
|
35
|
+
export const coauthorTrailers = (message: unknown) => typeof message === 'string'
|
|
36
|
+
? [...trailerBlock(message.replaceAll('\r\n', '\n')).matchAll(COAUTHOR_TRAILER)].map(([, name, email]) => ({ name: name!, email: email! })) : []
|
|
37
|
+
|
|
38
|
+
// The agent one who made a commit is: by their account, else the address
|
|
39
|
+
// their commit names them by; else, GitHub naming no account for them, by
|
|
40
|
+
// their name.
|
|
41
|
+
const makerAgent = ({ name, email, account }: Maker): GithubAgentId | null => githubAgent(account.login, account.id) ?? emailAgent(email)
|
|
42
|
+
?? (account.login ? null : githubAgent(null, null, typeof name === 'string' ? name : null))
|
|
43
|
+
|
|
44
|
+
// Who a commit names beside its author, as its history keeps them
|
|
45
|
+
// (repository-history.ts, `coauthorFacts`), its message never kept: its
|
|
46
|
+
// co-authors (`named`), those GitHub's GraphQL API lists past the author
|
|
47
|
+
// (`listed`, the addresses its `Co-authored-by:` trailers give, by the
|
|
48
|
+
// accounts GitHub knows them by), else its trailers (agent-tasks.ts
|
|
49
|
+
// trailerBlock), an account's no-reply address naming it, as many as
|
|
50
|
+
// MAX_NAMED, each by name, address and account; and the agents its message
|
|
51
|
+
// marks (`markedBy`), Claude's and Codex's as the Agents tab reads them
|
|
52
|
+
// (agent-tasks.ts agentSignals: their sessions' and tasks' links, Claude's
|
|
53
|
+
// co-author and "Generated with" lines), the app agents' by their
|
|
54
|
+
// fingerprints, Cursor's by its agents' links. Which of them are agents,
|
|
55
|
+
// and so the same as another, is told as they are answered (coauthorsOf), so
|
|
56
|
+
// that the agents' accounts, addresses and names change none kept.
|
|
57
|
+
export interface Named { name: string | null; email: string | null; login: string | null; id: number | null }
|
|
58
|
+
export const MAX_NAMED = 10
|
|
59
|
+
export function coauthorFacts(message: unknown, listed: Maker[] | null = null): { named: Named[]; markedBy: string[] } {
|
|
60
|
+
const text = typeof message === 'string' ? message.replaceAll('\r\n', '\n') : ''
|
|
61
|
+
const makers = listed ?? coauthorTrailers(text).map(({ name, email }) => ({ name, email, account: commitAccount({ email }) }))
|
|
62
|
+
const signals = agentSignals([text], FINGERPRINTED)
|
|
63
|
+
return {
|
|
64
|
+
named: makers.slice(0, MAX_NAMED).map(({ name, email, account }) => ({ name: nameOf(name), email: nameOf(email), login: account.login, id: account.id })),
|
|
65
|
+
markedBy: [...signals.claude || signals.sessions.length > 0 ? ['claude'] : [], ...signals.tasks.length > 0 || signals.codex ? ['codex'] : [],
|
|
66
|
+
...CURSOR_AGENT.test(text) ? ['cursor'] : [], ...signals.agents],
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// A commit as its history keeps it: its author by name, address and account,
|
|
71
|
+
// and who it names beside them (coauthorFacts), absent from pages kept before.
|
|
72
|
+
export interface CommitFacts { authorName: string | null; authorEmail?: string | null; authorLogin: string | null; authorId?: number | null; named?: Named[]
|
|
73
|
+
markedBy?: string[] }
|
|
74
|
+
|
|
75
|
+
// Who made a commit, past its author, as its history keeps them
|
|
76
|
+
// (`commit`, coauthorFacts): its co-authors, then the agents its message
|
|
77
|
+
// marks, each the agent it is where known, by the agents the app knows now,
|
|
78
|
+
// and once, the author none of them, as many as MAX_COAUTHORS: two are one by
|
|
79
|
+
// the first of their agent, account, address and name both name, two people
|
|
80
|
+
// of one name with accounts or addresses of their own two.
|
|
81
|
+
export function coauthorsOf({ authorName, authorEmail = null, authorLogin, authorId = null, named = [], markedBy = [] }: CommitFacts): Coauthor[] {
|
|
82
|
+
type Identity = { agent: string | null; login: string | null; email: string | null; name: string | null }
|
|
83
|
+
const identity = (agent: string | null, login: string | null, name: string | null, email: unknown = null): Identity => ({ agent, login: login?.toLowerCase() ?? null,
|
|
84
|
+
email: typeof email === 'string' && email.trim() ? email.trim().toLowerCase() : null, name: name?.toLowerCase() ?? null })
|
|
85
|
+
const same = (a: Identity, b: Identity) => a.agent && b.agent ? a.agent === b.agent : a.login && b.login ? a.login === b.login
|
|
86
|
+
: a.email && b.email ? a.email === b.email : a.name !== null && a.name === b.name
|
|
87
|
+
const author: Maker = { name: authorName, email: authorEmail, account: { login: authorLogin, id: authorId } }
|
|
88
|
+
const seen = [identity(makerAgent(author), authorLogin, nameOf(authorName), authorEmail)]
|
|
89
|
+
const coauthors: Coauthor[] = []
|
|
90
|
+
const add = (coauthor: Coauthor, email: unknown = null) => {
|
|
91
|
+
const who = identity(coauthor.agent ?? null, coauthor.login, coauthor.name, email)
|
|
92
|
+
if (seen.some(other => same(other, who)) || coauthors.length >= MAX_COAUTHORS || (!coauthor.login && !coauthor.name && !coauthor.agent)) return
|
|
93
|
+
seen.push(who)
|
|
94
|
+
coauthors.push(coauthor)
|
|
95
|
+
}
|
|
96
|
+
for (const { name, email, ...account } of named) {
|
|
97
|
+
const agent = makerAgent({ name, email, account })
|
|
98
|
+
// An agent known by its address where GitHub names someone else's
|
|
99
|
+
// account for it (Codex's), as itself, not that account.
|
|
100
|
+
const { login, id } = agent && account.login && githubAgent(account.login, account.id) !== agent ? { login: null, id: null } : account
|
|
101
|
+
add({ name, login, id, ...agent ? { agent } : {} }, email)
|
|
102
|
+
}
|
|
103
|
+
for (const agent of markedBy) if (Object.hasOwn(GITHUB_AGENTS, agent)) add({ name: GITHUB_AGENTS[agent as GithubAgentId].name, login: null, id: null, agent })
|
|
104
|
+
return coauthors
|
|
105
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// The versions a repository's lockfiles of npm's ecosystem lock at a commit,
|
|
2
|
+
// as their review reads them (pull-dependency-reviews.ts): every lockfile
|
|
3
|
+
// there (findRepoLockfiles) a review holds to (`held`, lockfile-scope.ts),
|
|
4
|
+
// read as a pull request's are (pull-dependencies.ts readLockfile), but kept
|
|
5
|
+
// by its blob, in this instance and beyond it (`kept`), as many as
|
|
6
|
+
// MAX_LOCKFILES of those, each's versions (`lockfiles`), and those its reader
|
|
7
|
+
// refuses, of Bun's, or past MAX_LOCKFILES (`unread`), as many read at once
|
|
8
|
+
// as READ_AT_ONCE; and those of some of them (lockedIn), each version once by
|
|
9
|
+
// what its reviews are held to (lockedWith), dev only where it is wherever it
|
|
10
|
+
// is locked. GitHub having none of a lockfile it lists there fails the
|
|
11
|
+
// whole, as it would for any file.
|
|
12
|
+
import { createClient } from '@preventive/upstream/github.js'
|
|
13
|
+
import { GithubApiError, upstreamGithub } from './github-errors.ts'
|
|
14
|
+
import { USER_AGENT } from './github-requests.ts'
|
|
15
|
+
import { type LockedPackage, patchedIn } from './locked-packages.ts'
|
|
16
|
+
import { type Lru, lru } from './lru.ts'
|
|
17
|
+
import { eachOf } from './queue.ts'
|
|
18
|
+
import { type GithubAsked, type ListedLockfile, type LockfileStore, lockedWith, lockfileFormat, readLockfile } from './pull-dependencies.ts'
|
|
19
|
+
|
|
20
|
+
const MAX_LOCKFILES = 100
|
|
21
|
+
const READ_AT_ONCE = 4
|
|
22
|
+
|
|
23
|
+
export interface CommitLockfiles { lockfiles: { path: string; packages: LockedPackage[] }[]; unread: string[] }
|
|
24
|
+
|
|
25
|
+
// The lockfiles at commit `sha` its review reads, by their paths, each with
|
|
26
|
+
// its format (pull-dependencies.ts lockfileFormat) and its blob's id, kept by
|
|
27
|
+
// the commit, in this instance and beyond it (`kept`); `asked` told where
|
|
28
|
+
// GitHub was.
|
|
29
|
+
const listings: Lru<ListedLockfile[]> = lru(20_000, listed => listed.length + 1)
|
|
30
|
+
export async function lockfilesAt(fullName: string, token: string, sha: string, kept: LockfileStore | null, asked?: GithubAsked) {
|
|
31
|
+
const key = `${fullName}\0${sha}`
|
|
32
|
+
const known = listings.get(key)
|
|
33
|
+
if (known) return known
|
|
34
|
+
const stored = await kept?.listings.read(sha)
|
|
35
|
+
if (stored) { listings.set(key, stored); return stored }
|
|
36
|
+
if (asked) asked.github = true
|
|
37
|
+
const { lockfiles } = await upstreamGithub(() => createClient({ token, userAgent: USER_AGENT }).findRepoLockfiles({ repo: fullName, sha }))
|
|
38
|
+
const listed = lockfiles.flatMap(({ path, sha: blob }) => { const format = lockfileFormat(path); return format ? [{ path, format, sha: blob }] : [] })
|
|
39
|
+
listings.set(key, listed)
|
|
40
|
+
await kept?.listings.write(sha, listed)
|
|
41
|
+
return listed
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function lockedAt(fullName: string, token: string, sha: string, kept: LockfileStore | null, held: (path: string) => boolean = () => true,
|
|
45
|
+
asked?: GithubAsked): Promise<CommitLockfiles> {
|
|
46
|
+
const listed = (await lockfilesAt(fullName, token, sha, kept, asked)).filter(({ path }) => held(path))
|
|
47
|
+
const unread = listed.slice(MAX_LOCKFILES).map(({ path }) => path)
|
|
48
|
+
const lockfiles: CommitLockfiles['lockfiles'] = []
|
|
49
|
+
const reading = listed.slice(0, MAX_LOCKFILES)
|
|
50
|
+
const reads = await eachOf(reading, READ_AT_ONCE, lockfile => readLockfile(fullName, token, sha, lockfile, kept, asked))
|
|
51
|
+
for (const [at, lockfile] of reading.entries()) {
|
|
52
|
+
const read = reads[at]!
|
|
53
|
+
if ('error' in read && read.error === 'github-not-found') throw new GithubApiError(404, 'github-not-found')
|
|
54
|
+
if ('error' in read) unread.push(lockfile.path)
|
|
55
|
+
else lockfiles.push({ path: lockfile.path, packages: read.packages })
|
|
56
|
+
}
|
|
57
|
+
return { lockfiles, unread: unread.toSorted() }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The versions those of `read`'s lockfiles `held` holds to lock, each once,
|
|
61
|
+
// each patch's file from the repository's root (patchedIn), the first of
|
|
62
|
+
// them that names one there, with the directory of the first lockfile that
|
|
63
|
+
// locks it so, and their paths.
|
|
64
|
+
export function lockedIn(read: CommitLockfiles, held: (path: string) => boolean = () => true) {
|
|
65
|
+
const packages = new Map<string, LockedPackage>()
|
|
66
|
+
const paths: string[] = []
|
|
67
|
+
for (const lockfile of read.lockfiles.filter(({ path }) => held(path))) {
|
|
68
|
+
paths.push(lockfile.path)
|
|
69
|
+
for (const pkg of lockfile.packages) {
|
|
70
|
+
const found = patchedIn(lockfile.path, { ...pkg })
|
|
71
|
+
const kept = packages.get(lockedWith(pkg))
|
|
72
|
+
if (!kept) { packages.set(lockedWith(pkg), found); continue }
|
|
73
|
+
if (kept.dev && !pkg.dev) delete kept.dev
|
|
74
|
+
if (kept.patchPath === undefined && found.patchPath !== undefined) kept.patchPath = found.patchPath
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { packages: [...packages.values()], paths }
|
|
78
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Compare's comparison of two managed bundles or two versions of an npm
|
|
2
|
+
// package, the one shown as a patch changes it where Review asks
|
|
3
|
+
// (GET /api/bundles/:id/comparison?other=, GET /api/npm/comparison):
|
|
4
|
+
// their files paired, at one path or renamed, with the sizes, resolutions,
|
|
5
|
+
// dependency versions and line counts its Overview and Code read beside them,
|
|
6
|
+
// as common/bundle-comparison.js prepareComparison works them out. The viewer
|
|
7
|
+
// of a managed bundle or a package has every comparison worked out here and
|
|
8
|
+
// loads none of the pairing itself. Answered as Brotli-encoded JSON, its
|
|
9
|
+
// `files.basePaths` (a Map) as `[path, as laid out]` pairs where the two
|
|
10
|
+
// sides' roots differ and none else, as the viewer reads none then. Access is
|
|
11
|
+
// the caller's to check.
|
|
12
|
+
import { Buffer } from 'node:buffer'
|
|
13
|
+
import { prepareComparison } from '../common/bundle-comparison.js'
|
|
14
|
+
import type { BundleDetails } from '../common/bundle-metadata.js'
|
|
15
|
+
import type { OpenedBlob } from './blob-store.ts'
|
|
16
|
+
import { encodeBrotli } from './brotli.ts'
|
|
17
|
+
import { type NpmPackageFile, type NpmVersionDocument, npmExecutablePaths, npmFileRows } from './npm-packages.ts'
|
|
18
|
+
import type { NpmPatch } from './npm-patch.ts'
|
|
19
|
+
import { opened } from './pretty-print.ts'
|
|
20
|
+
|
|
21
|
+
// A side with no files, as Review compares a package's first version with:
|
|
22
|
+
// one for each comparison, as working one out keeps its line counts on it.
|
|
23
|
+
export const emptySide = (): BundleDetails => ({ integrity: '(empty)', kind: 'sourcemap', size: 0, json: { version: 3, sources: [], sourcesContent: [] } })
|
|
24
|
+
|
|
25
|
+
// A version's files as the viewer reads them for a comparison (ui/view/npm-package.js
|
|
26
|
+
// npmPackageDetails): its texts, and those that are not text by their size and digest, a symlink's target too, and which are executable.
|
|
27
|
+
export function npmComparedSide(integrity: string, files: NpmPackageFile[]): BundleDetails & { npmBinaries: Map<string, { size: number; digest: string; link?: string }>; npmExecutable: Set<string> } {
|
|
28
|
+
const rows = npmFileRows(files)
|
|
29
|
+
return {
|
|
30
|
+
integrity, kind: 'sourcemap', size: 0, npmExecutable: new Set(npmExecutablePaths(files)),
|
|
31
|
+
json: { version: 3, sources: rows.map(([path]) => path), sourcesContent: rows.map(([, , text]) => text) },
|
|
32
|
+
npmBinaries: new Map(rows.flatMap(([path, size, text, digest, link]) => (text === null ? [[path, { size, digest: digest!, ...link === undefined ? {} : { link } }] as const] : []))),
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The comparison of `base` with `other`, within a reason `scope` where given, as sent.
|
|
37
|
+
export async function comparisonBody(base: BundleDetails, other: BundleDetails, scope = ''): Promise<OpenedBlob> {
|
|
38
|
+
const comparison = prepareComparison(base, other, scope)
|
|
39
|
+
const { files } = comparison
|
|
40
|
+
const json = JSON.stringify({ ...comparison, files: { ...files, basePaths: files.root ? [...files.basePaths] : [] } })
|
|
41
|
+
return opened(await encodeBrotli(Buffer.from(json)))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A version's `files` as `patch` changes them (npm-patch.ts patchedFiles), as
|
|
45
|
+
// the viewer reads a version's (npm-loads.ts loadNpmPackageBody), with the
|
|
46
|
+
// patch, as sent: `{ name, version, private, integrity, patch, files }`.
|
|
47
|
+
export async function patchedVersionBody(doc: NpmVersionDocument, patch: NpmPatch, files: NpmPackageFile[]): Promise<OpenedBlob> {
|
|
48
|
+
const json = JSON.stringify({ name: doc.name, version: doc.version, private: doc.private, integrity: doc.dist.integrity, patch, files: npmFileRows(files),
|
|
49
|
+
executable: npmExecutablePaths(files) })
|
|
50
|
+
return opened(await encodeBrotli(Buffer.from(json)))
|
|
51
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// Managed-server boot config. GitHub user authorization establishes identity;
|
|
2
|
+
// optional App installation credentials enable repository access. A single
|
|
3
|
+
// GitHub App can provide both flows, with repository grants at installation.
|
|
4
|
+
import { env } from 'node:process'
|
|
5
|
+
import { databaseUrls } from '../server-common/database-config.ts'
|
|
6
|
+
import { MAX_UPLOAD_BYTES } from './uploads.ts'
|
|
7
|
+
import { parseStorageKey } from '../server-common/storage-crypto.ts'
|
|
8
|
+
import { defaultCacheDir } from '@preventive/upstream/npm.js'
|
|
9
|
+
import { RESERVED_COOKIES } from './session.ts'
|
|
10
|
+
import { LOOPBACK_HOSTS } from '../server-common/origin.ts'
|
|
11
|
+
|
|
12
|
+
export interface ManagedConfig {
|
|
13
|
+
port: number
|
|
14
|
+
host: string
|
|
15
|
+
dbPath: string
|
|
16
|
+
neonUrl?: string | null
|
|
17
|
+
blobToken?: string | null
|
|
18
|
+
storageEncryptionKey?: string | null
|
|
19
|
+
storageEncryptionMigrate?: boolean
|
|
20
|
+
storageEncryptionMigrateMaxMs?: number
|
|
21
|
+
vercelPreview?: boolean
|
|
22
|
+
serverless?: boolean
|
|
23
|
+
// Upstream's disk cache (setCacheDir) for audits and bundle builds: its default
|
|
24
|
+
// location, or null for none, as on Vercel, where the database keeps listings.
|
|
25
|
+
upstreamCacheDir?: string | null
|
|
26
|
+
debug: boolean
|
|
27
|
+
allowShare: boolean
|
|
28
|
+
trustProxyEnv: string | undefined
|
|
29
|
+
// GitHub App user-authorization (identity) credentials — the App's client id
|
|
30
|
+
// + secret, used by the login flow.
|
|
31
|
+
githubClientId: string
|
|
32
|
+
githubClientSecret: string
|
|
33
|
+
// Preapproved GitHub identity promoted on login when it is the only user
|
|
34
|
+
// and its role is No access, including a login after registration.
|
|
35
|
+
initialAdminGithubId: number | null
|
|
36
|
+
// Absolute callback registered with GitHub, e.g.
|
|
37
|
+
// 'https://triage.example.com/api/oauth/github/callback'.
|
|
38
|
+
oauthCallbackUrl: string
|
|
39
|
+
// Whether cookies carry `Secure` (callback is https). Also gates the
|
|
40
|
+
// `__Host-` prefix, so loopback http dev can run with a plain cookie name.
|
|
41
|
+
cookieSecure: boolean
|
|
42
|
+
sessionCookieName: string
|
|
43
|
+
sessionTtlMs: number
|
|
44
|
+
// How long GitHub's answer on a user's access to a repository (its
|
|
45
|
+
// visibility, their permission) is kept for that user and repository
|
|
46
|
+
// (repository-browser.ts), asked again past it; 0 asks on every request
|
|
47
|
+
// (MANAGED_REPOSITORY_ACCESS_CACHE_MS, five minutes by default).
|
|
48
|
+
repositoryAccessCacheMs: number
|
|
49
|
+
// Optional installation credentials for the same GitHub App as login.
|
|
50
|
+
// Repository permissions are approved when connecting repositories.
|
|
51
|
+
githubAppId: string | null
|
|
52
|
+
githubAppPrivateKey: string | null
|
|
53
|
+
githubAppSlug: string | null
|
|
54
|
+
githubNewIssueLabels?: string
|
|
55
|
+
// Max accepted size (bytes) for an uploaded report on the "Manage reports"
|
|
56
|
+
// page, before storage compression (default 25 MiB).
|
|
57
|
+
maxReportBytes: number
|
|
58
|
+
// Max accepted size (bytes) for an uploaded bundle (sourcemap / stasis
|
|
59
|
+
// archive). Bundles run larger than reports, so a higher cap (default 200 MiB).
|
|
60
|
+
maxBundleBytes: number
|
|
61
|
+
// How many triage-trail events to keep per finding (managed_finding_triage_event):
|
|
62
|
+
// 0, the default, keeps everything — the trail is the record. An operator
|
|
63
|
+
// who would rather bound the store sets a positive count; older events of a
|
|
64
|
+
// finding are then trimmed as new ones land.
|
|
65
|
+
triageHistoryLimit: number
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function fail(msg: string): never {
|
|
69
|
+
throw new Error(msg)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function requireStr(name: string): string {
|
|
73
|
+
const v = env[name]
|
|
74
|
+
if (v == null || v === '') fail(`Missing required env ${name} (managed mode).`)
|
|
75
|
+
return v
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function intEnv(name: string, def: number, min: number, max: number): number {
|
|
79
|
+
const raw = env[name]
|
|
80
|
+
const n = raw == null ? def : Number(raw)
|
|
81
|
+
if (!Number.isSafeInteger(n) || n < min || n > max) {
|
|
82
|
+
fail(`Invalid ${name}: ${raw} — must be an integer in [${min}, ${max}].`)
|
|
83
|
+
}
|
|
84
|
+
return n
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function optionalGithubId(name: string): number | null {
|
|
88
|
+
const raw = env[name]
|
|
89
|
+
if (raw == null || raw === '') return null
|
|
90
|
+
const id = Number(raw)
|
|
91
|
+
if (!/^[1-9]\d*$/u.test(raw) || !Number.isSafeInteger(id)) {
|
|
92
|
+
fail(`Invalid ${name}: must be a single positive numeric GitHub user ID.`)
|
|
93
|
+
}
|
|
94
|
+
return id
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function urlOrFail(name: string, raw: string): URL {
|
|
98
|
+
try { return new URL(raw) } catch { fail(`${name} is not a valid URL: ${raw}`) }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function loadManagedConfig({ combined = false } = {}): ManagedConfig {
|
|
102
|
+
const serverless = env['VERCEL'] === '1'
|
|
103
|
+
const neonUrl = databaseUrls({ combined }).managed
|
|
104
|
+
const blobToken = env['BLOB_READ_WRITE_TOKEN'] || null
|
|
105
|
+
const storageEncryptionKey = env['MANAGED_STORAGE_ENCRYPTION_KEY'] || null
|
|
106
|
+
parseStorageKey(storageEncryptionKey)
|
|
107
|
+
const storageEncryptionMigrate = env['MANAGED_STORAGE_ENCRYPTION_MIGRATE'] === '1'
|
|
108
|
+
if (storageEncryptionMigrate && !storageEncryptionKey) fail('MANAGED_STORAGE_ENCRYPTION_MIGRATE requires MANAGED_STORAGE_ENCRYPTION_KEY.')
|
|
109
|
+
if (serverless && !neonUrl) fail('Vercel managed mode requires DATABASE_URL or MANAGED_DATABASE_URL.')
|
|
110
|
+
if (neonUrl && !blobToken) fail('Managed Neon mode requires BLOB_READ_WRITE_TOKEN.')
|
|
111
|
+
const host = env['HOST'] ?? '127.0.0.1'
|
|
112
|
+
const oauthCallbackUrl = requireStr('OAUTH_CALLBACK_URL')
|
|
113
|
+
const callback = urlOrFail('OAUTH_CALLBACK_URL', oauthCallbackUrl)
|
|
114
|
+
const cookieSecure = callback.protocol === 'https:'
|
|
115
|
+
// A `__Host-` cookie mandates `Secure`, so any non-loopback bind must be
|
|
116
|
+
// HTTPS — fail fast (mirrors server-e2e's boot check). Loopback dev over
|
|
117
|
+
// http is allowed with a non-prefixed cookie name.
|
|
118
|
+
if ((serverless || !LOOPBACK_HOSTS.has(host)) && !cookieSecure) {
|
|
119
|
+
fail(`Vercel or non-loopback HOST=${host} requires an https OAUTH_CALLBACK_URL — the session cookie needs Secure.`)
|
|
120
|
+
}
|
|
121
|
+
const sessionCookieName = env['SESSION_COOKIE_NAME'] ?? '__Host-dvsid'
|
|
122
|
+
if (sessionCookieName.startsWith('__Host-') && !cookieSecure) {
|
|
123
|
+
fail(`SESSION_COOKIE_NAME=${sessionCookieName} uses the __Host- prefix but the callback is not https. Use a non-prefixed name for loopback http dev.`)
|
|
124
|
+
}
|
|
125
|
+
if (RESERVED_COOKIES.includes(sessionCookieName.replace(/^__Host-/u, ''))) {
|
|
126
|
+
fail(`SESSION_COOKIE_NAME=${sessionCookieName} is reserved for another managed cookie. Choose a different name.`)
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
neonUrl, blobToken, serverless, storageEncryptionKey, storageEncryptionMigrate,
|
|
130
|
+
storageEncryptionMigrateMaxMs: intEnv('MANAGED_STORAGE_ENCRYPTION_MIGRATE_MAX_MS', 150_000, 1, serverless ? 240_000 : 3_600_000),
|
|
131
|
+
vercelPreview: env['VERCEL_ENV'] === 'preview',
|
|
132
|
+
upstreamCacheDir: serverless ? null : defaultCacheDir ?? null,
|
|
133
|
+
port: intEnv('PORT', 8765, 0, 65535),
|
|
134
|
+
host,
|
|
135
|
+
// DB_PATH belongs to e2e in a combined process. Keep the two stores apart.
|
|
136
|
+
dbPath: env['MANAGED_DB_PATH'] ?? (combined ? undefined : env['DB_PATH']) ?? 'server-managed/data/managed.db',
|
|
137
|
+
debug: env['DEBUG'] === '1' || env['DEBUG'] === 'true',
|
|
138
|
+
allowShare: env['DEEPVIEW_ALLOW_SHARE'] === '1',
|
|
139
|
+
trustProxyEnv: env['TRUST_PROXY'] ?? (serverless ? '1' : undefined),
|
|
140
|
+
githubClientId: requireStr('GITHUB_CLIENT_ID'),
|
|
141
|
+
githubClientSecret: requireStr('GITHUB_CLIENT_SECRET'),
|
|
142
|
+
initialAdminGithubId: optionalGithubId('MANAGED_INITIAL_ADMIN_GITHUB_ID'),
|
|
143
|
+
oauthCallbackUrl,
|
|
144
|
+
cookieSecure,
|
|
145
|
+
sessionCookieName,
|
|
146
|
+
sessionTtlMs: intEnv('SESSION_TTL_MS', 1_209_600_000, 60_000, 7_776_000_000),
|
|
147
|
+
repositoryAccessCacheMs: intEnv('MANAGED_REPOSITORY_ACCESS_CACHE_MS', 300_000, 0, 3_600_000),
|
|
148
|
+
githubAppId: env['GITHUB_APP_ID'] ?? null,
|
|
149
|
+
githubAppPrivateKey: normalizePem(env['GITHUB_APP_PRIVATE_KEY']),
|
|
150
|
+
githubAppSlug: env['GITHUB_APP_SLUG'] ?? null,
|
|
151
|
+
githubNewIssueLabels: env['GITHUB_NEW_ISSUE_LABELS'] ?? '',
|
|
152
|
+
maxReportBytes: intEnv('MAX_REPORT_BYTES', 26_214_400, 1, 104_857_600),
|
|
153
|
+
maxBundleBytes: intEnv('MAX_BUNDLE_BYTES', 209_715_200, 1, MAX_UPLOAD_BYTES),
|
|
154
|
+
triageHistoryLimit: intEnv('TRIAGE_HISTORY_LIMIT', 0, 0, 1_000_000_000),
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// PEM private keys are awkward in env vars; accept a literal multi-line value or
|
|
159
|
+
// one with escaped newlines (`\n`). Empty/absent → null (private repos off).
|
|
160
|
+
function normalizePem(raw: string | undefined): string | null {
|
|
161
|
+
if (raw == null || raw === '') return null
|
|
162
|
+
return raw.includes('\\n') ? raw.replaceAll('\\n', '\n') : raw
|
|
163
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ManagedDb, StoredUser } from './db.ts'
|
|
2
|
+
|
|
3
|
+
export type RepoScope = { repoId: number; path: string | null }
|
|
4
|
+
type Content = { repoId: number | null; repoDirectory?: string }
|
|
5
|
+
|
|
6
|
+
// Read grants for each request: neither the manager role nor a cached page
|
|
7
|
+
// confers repository access. Bundles have repository scope; reports also have
|
|
8
|
+
// a directory scope. Unassigned content is only available to administrators.
|
|
9
|
+
export async function contentAccess(db: Pick<ManagedDb, 'listRepoScopesForUser'>, user: StoredUser) {
|
|
10
|
+
const scopes = user.role === 'admin' ? null : await db.listRepoScopesForUser(user.id)
|
|
11
|
+
const bundle = (item: Content) => scopes == null || scopes.some(scope => scope.repoId === item.repoId)
|
|
12
|
+
const report = (item: Content) => scopes == null || scopes.some(scope => scope.repoId === item.repoId
|
|
13
|
+
&& (!scope.path || item.repoDirectory === scope.path || item.repoDirectory?.startsWith(scope.path + '/')))
|
|
14
|
+
return { scopes, bundle, report }
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Token helpers for the managed auth server. The raw session token lives ONLY
|
|
2
|
+
// in the cookie; the DB row id is its SHA-256 (see db.ts / session.ts), so a
|
|
3
|
+
// DB read can't reconstruct a live cookie. No HMAC pepper is needed — the
|
|
4
|
+
// tokens are 256-bit random, not guessable or reversible from their hash.
|
|
5
|
+
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto'
|
|
6
|
+
|
|
7
|
+
// 256-bit URL-safe random token: the session cookie value and the OAuth CSRF
|
|
8
|
+
// `state` nonce.
|
|
9
|
+
export function randomToken(): string {
|
|
10
|
+
return randomBytes(32).toString('base64url')
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// At-rest id for a session cookie token (stored as the managed_session PK).
|
|
14
|
+
export function hashToken(token: string): string {
|
|
15
|
+
return createHash('sha256').update(token, 'utf8').digest('base64url')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Constant-time equality for CSRF / OAuth-state checks. A length mismatch
|
|
19
|
+
// short-circuits (the length of these fixed-width tokens isn't a secret).
|
|
20
|
+
export function safeEqual(a: string, b: string): boolean {
|
|
21
|
+
const ab = Buffer.from(a, 'utf8')
|
|
22
|
+
const bb = Buffer.from(b, 'utf8')
|
|
23
|
+
if (ab.length !== bb.length) return false
|
|
24
|
+
return timingSafeEqual(ab, bb)
|
|
25
|
+
}
|