@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
|
@@ -71,8 +71,8 @@ export type ObjstoreRestDeps = {
|
|
|
71
71
|
// Cross-instance pub/sub for objstore-deleted — fired alongside the local
|
|
72
72
|
// `broadcast` after a successful REST delete mint, so peers on OTHER
|
|
73
73
|
// instances drop the resource in real time. Carries (tag, resourceTag,
|
|
74
|
-
// version) inline (the row is gone post-delete). SQLite mode passes a no-op.
|
|
75
|
-
publishObjDeleted: (tag: string, resourceTag: string, version: number) => void
|
|
74
|
+
// version, incarnation) inline (the row is gone post-delete). SQLite mode passes a no-op.
|
|
75
|
+
publishObjDeleted: (tag: string, resourceTag: string, version: number, incarnation: string) => void
|
|
76
76
|
// New-workspace operator gate for the REST put-begin mint — the
|
|
77
77
|
// connection-independent analog of the WS path's `authGate`. Returns
|
|
78
78
|
// `true` to DENY (a password is configured AND the workspace is
|
|
@@ -105,7 +105,7 @@ export type ObjstoreRestDeps = {
|
|
|
105
105
|
// concurrent same-token PUT is rejected (409) before it can open a
|
|
106
106
|
// second writer. The slot is held only across body + commit, released
|
|
107
107
|
// in a `finally`, and bounded by the REST idle-body timeout in
|
|
108
|
-
// server/http.ts so a slow-loris can't pin it. NOT a commit lock —
|
|
108
|
+
// server-e2e/http.ts so a slow-loris can't pin it. NOT a commit lock —
|
|
109
109
|
// commits stay lock-free on the version-CAS above. Per-process: the
|
|
110
110
|
// Vercel multi-replica path leans on `allowOverwrite: true` + the
|
|
111
111
|
// commit CAS + content-addressing for cross-replica correctness (a
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// dialect on the wire.
|
|
5
5
|
//
|
|
6
6
|
// `@neondatabase/serverless` is an OPTIONAL peer dep — selected by
|
|
7
|
-
// the
|
|
7
|
+
// the configured database URL branch in `server-e2e/index.ts`. The peer dep
|
|
8
8
|
// itself is loaded lazily inside `openNeonObjstore` below. A single
|
|
9
9
|
// Neon project / database holds both `workspace_revision` and the
|
|
10
10
|
// two objstore tables; each plane opens its own stateless
|
|
@@ -13,14 +13,10 @@
|
|
|
13
13
|
// release.
|
|
14
14
|
//
|
|
15
15
|
// Byte plane: passed in as a `BlobBackend` (./blob.ts). The
|
|
16
|
-
// supported
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
// alongside DATABASE_URL.
|
|
21
|
-
// - Neon + local FS (development / operator escape hatch — bytes
|
|
22
|
-
// still need to live on a shared filesystem if you run more
|
|
23
|
-
// than one replica).
|
|
16
|
+
// supported Neon pairing selected by server-e2e/index.ts is Vercel
|
|
17
|
+
// Blob Private Storage. DATABASE_URL or E2E_DATABASE_URL plus BLOB_READ_WRITE_TOKEN
|
|
18
|
+
// is required; the launcher never selects Neon + local FS. Tests
|
|
19
|
+
// can inject a local-FS backend directly through this adapter.
|
|
24
20
|
|
|
25
21
|
import type { BlobBackend } from './blob.ts'
|
|
26
22
|
import type { AllStmt, GetStmt, RunStmt } from '../db-stmt.ts'
|
|
@@ -309,7 +305,7 @@ export async function openNeonObjstore(connectionString: string, blob: BlobBacke
|
|
|
309
305
|
// local `../neon-driver.ts` re-export wrapper so the peer dep stays
|
|
310
306
|
// optional AND tests can mock the driver (a local path is always
|
|
311
307
|
// resolvable; the bare specifier isn't when the dep is absent). See
|
|
312
|
-
// `server/neon-driver.ts`. Cast through `unknown` because the
|
|
308
|
+
// `server-e2e/neon-driver.ts`. Cast through `unknown` because the
|
|
313
309
|
// wrapper's `export *` re-exports a `@ts-ignore`'d module.
|
|
314
310
|
const mod = (await import('../neon-driver.ts')) as unknown as { neon: (url: string) => NeonSql }
|
|
315
311
|
const sql: NeonSql = mod.neon(connectionString)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SQLite + filesystem-backed object store for the v1.objstore
|
|
2
|
-
// protocol extension. Sibling of `server/db.ts`; shares the
|
|
2
|
+
// protocol extension. Sibling of `server-e2e/db.ts`; shares the
|
|
3
3
|
// underlying DatabaseSync handle but keeps its own tables.
|
|
4
4
|
//
|
|
5
5
|
// workspace_object — one row per LIVE resource (no
|
|
@@ -150,7 +150,7 @@ export type DeleteResult =
|
|
|
150
150
|
| { ok: true; deletedVersion: number }
|
|
151
151
|
| { ok: false; reason: 'not-found' | 'conflict'; conflict?: ObjectRow }
|
|
152
152
|
|
|
153
|
-
// Async statement shapes are shared with server/db.ts via
|
|
153
|
+
// Async statement shapes are shared with server-e2e/db.ts via
|
|
154
154
|
// ../db-stmt.ts — same `.get/.all/.run` → Promise contract across
|
|
155
155
|
// both planes.
|
|
156
156
|
|
|
@@ -186,7 +186,7 @@ export type Handle = {
|
|
|
186
186
|
db?: DatabaseSync
|
|
187
187
|
// Byte-plane backend (local FS or Vercel Blob). All bytes-side
|
|
188
188
|
// operations go through this — there is no direct fs.* call in
|
|
189
|
-
// store / rest / reaper. Selected at boot in server/index.ts.
|
|
189
|
+
// store / rest / reaper. Selected at boot in server-e2e/index.ts.
|
|
190
190
|
blob: BlobBackend
|
|
191
191
|
// Storage root for the FS backend — set only when `blob` was
|
|
192
192
|
// constructed from `openFsBlobBackend(dir)`. Production code
|
|
@@ -247,7 +247,7 @@ export type Handle = {
|
|
|
247
247
|
// returned. The reaper passes `Date.now() - stagingTtlMs` so the
|
|
248
248
|
// index `workspace_object_staging_begun_at_idx` is used and the
|
|
249
249
|
// sweep is O(stale-rows) instead of O(in-flight-uploads-cluster-
|
|
250
|
-
// wide). DB-layout audit `server/objstore/store.ts:312`.
|
|
250
|
+
// wide). DB-layout audit `server-e2e/objstore/store.ts:312`.
|
|
251
251
|
listAllStaging: AllStmt<[number], { workspace_tag: string; resource_tag: string; staging_id: string; begun_at: number }>
|
|
252
252
|
listLiveTags: AllStmt<[], { workspace_tag: string }>
|
|
253
253
|
countLive: GetStmt<[string], { c: number }>
|
|
@@ -255,7 +255,7 @@ export type Handle = {
|
|
|
255
255
|
|
|
256
256
|
// Narrowing alias for the SQLite-backed Handle: `db` is guaranteed
|
|
257
257
|
// to be set. `openObjstore` returns this so call sites (production
|
|
258
|
-
// shutdown plumbing in `server/index.ts` + the entire SQLite-only
|
|
258
|
+
// shutdown plumbing in `server-e2e/index.ts` + the entire SQLite-only
|
|
259
259
|
// test suite in `tests/server-objstore.test.js`) can reach
|
|
260
260
|
// `handle.db.prepare(...)` without an optional-chain or non-null
|
|
261
261
|
// assertion. A Neon-backed Handle (`openNeonObjstore`) keeps the
|
|
@@ -352,7 +352,7 @@ export function openObjstore(db: DatabaseSync, dir: string): SqliteHandle {
|
|
|
352
352
|
mkdirSync(dir, { recursive: true })
|
|
353
353
|
db.exec(SCHEMA)
|
|
354
354
|
// Fail-loud on a pre-existing non-STRICT table — same rationale as
|
|
355
|
-
// server/db.ts: `CREATE TABLE IF NOT EXISTS … STRICT` doesn't
|
|
355
|
+
// server-e2e/db.ts: `CREATE TABLE IF NOT EXISTS … STRICT` doesn't
|
|
356
356
|
// upgrade an existing non-STRICT table, and dropping strict type
|
|
357
357
|
// affinity opens an operator-attack path. PR #4 review F3.
|
|
358
358
|
for (const name of ['workspace_object', 'workspace_object_staging']) {
|
|
@@ -362,7 +362,7 @@ export function openObjstore(db: DatabaseSync, dir: string): SqliteHandle {
|
|
|
362
362
|
const blob = openFsBlobBackend(dir)
|
|
363
363
|
// No `close` method on the returned Handle: the underlying
|
|
364
364
|
// `DatabaseSync` is owned by the caller (in production, the
|
|
365
|
-
// workspace_revision handle in `server/db.ts`, closed from
|
|
365
|
+
// workspace_revision handle in `server-e2e/db.ts`, closed from
|
|
366
366
|
// `shutdown()`; tests close their own DB). A `close()` here would
|
|
367
367
|
// mislead — it could only no-op or leak, never close the caller-
|
|
368
368
|
// owned connection.
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto'
|
|
25
25
|
import { Buffer } from 'node:buffer'
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const DEFAULT_TOKEN_TTL_MS = 5 * 60 * 1000
|
|
28
28
|
|
|
29
29
|
export type PutTokenPayload = {
|
|
30
30
|
op: 'put'
|
|
@@ -119,7 +119,7 @@ function isValidPayload(v: unknown): v is TokenPayload {
|
|
|
119
119
|
// different actual value, or — for `exp` — claim a
|
|
120
120
|
// `Number.MAX_SAFE_INTEGER + 1` expiry that compares ambiguously near
|
|
121
121
|
// the IEEE-754 boundary. Matches the codebase's other safe-int gates
|
|
122
|
-
// (server/objstore/sign.ts, rest.ts, handlers.ts).
|
|
122
|
+
// (server-e2e/objstore/sign.ts, rest.ts, handlers.ts).
|
|
123
123
|
if (!Number.isSafeInteger(o['exp']) || (o['exp'] as number) < 0) return false
|
|
124
124
|
if (o['op'] === 'put') {
|
|
125
125
|
return typeof o['sid'] === 'string'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Cross-instance pub/sub for real-time WS broadcasts. The triage-sync
|
|
2
|
-
// fan-out is an in-memory subscriber map (server/hub.ts) by design — it
|
|
2
|
+
// fan-out is an in-memory subscriber map (server-e2e/hub.ts) by design — it
|
|
3
3
|
// routes a commit only to peers on the SAME instance. A multi-instance
|
|
4
4
|
// deployment behind a load balancer needs commit-landed-on-A to reach
|
|
5
5
|
// peers-on-B with the same latency the hub gives same-instance peers.
|
|
@@ -57,15 +57,15 @@ function newSenderId(): string {
|
|
|
57
57
|
// - 'objput': objstore-put broadcast. `res` is the resource tag; the
|
|
58
58
|
// receiver SELECTs the live row by (tag, res) for the rest of the
|
|
59
59
|
// metadata fields.
|
|
60
|
-
// - 'objdel': objstore-deleted broadcast. `ver`
|
|
61
|
-
//
|
|
62
|
-
//
|
|
60
|
+
// - 'objdel': objstore-deleted broadcast. `ver` and `incarnation` identify
|
|
61
|
+
// the deleted row, which is gone from workspace_object after commit.
|
|
62
|
+
// Incarnation is optional only for messages from older relay instances.
|
|
63
63
|
export type BusMessage =
|
|
64
64
|
| { kind: 'rev'; tag: string; id: string }
|
|
65
65
|
| { kind: 'objput'; tag: string; res: string }
|
|
66
|
-
| { kind: 'objdel'; tag: string; res: string; ver: number }
|
|
66
|
+
| { kind: 'objdel'; tag: string; res: string; ver: number; incarnation?: string }
|
|
67
67
|
|
|
68
|
-
// Receiver wired up by the hub layer (see server/index.ts). Each handler
|
|
68
|
+
// Receiver wired up by the hub layer (see server-e2e/index.ts). Each handler
|
|
69
69
|
// runs once per remote message; failures are logged but don't crash the
|
|
70
70
|
// LISTEN loop — a missed broadcast surfaces to clients on reconnect
|
|
71
71
|
// (chain re-pull). Async because the workspace-revision handler does a
|
|
@@ -164,7 +164,7 @@ type NeonState = {
|
|
|
164
164
|
// In-flight bus-message handler promises. `dispatchNotification`
|
|
165
165
|
// fires handlers fire-and-forget, but `stop()` awaits this set before
|
|
166
166
|
// returning so the lifecycle's `handle.close()` (which runs after
|
|
167
|
-
// `pubsub.stop()` — see closeDb in server/index.ts) can't race a
|
|
167
|
+
// `pubsub.stop()` — see closeDb in server-e2e/index.ts) can't race a
|
|
168
168
|
// handler mid-`handle.revisionById.get` / `getLive`.
|
|
169
169
|
pendingHandlers: Set<Promise<void>>
|
|
170
170
|
}
|
|
@@ -333,7 +333,7 @@ export function createNeonPubSub(deps: NeonPubSubDeps): PubSub {
|
|
|
333
333
|
if (state.connectAttempt) { try { await state.connectAttempt } catch {} }
|
|
334
334
|
// Drain in-flight bus-message handlers BEFORE returning. The
|
|
335
335
|
// lifecycle teardown runs `pubsub.stop()` and THEN
|
|
336
|
-
// `handle.close()` (see closeDb in server/index.ts); a handler
|
|
336
|
+
// `handle.close()` (see closeDb in server-e2e/index.ts); a handler
|
|
337
337
|
// still in `handle.revisionById.get` / `getLive` would otherwise
|
|
338
338
|
// throw against a closed DB. `allSettled` so one handler's
|
|
339
339
|
// rejection doesn't abort the drain.
|
|
@@ -388,7 +388,10 @@ function parseBusMessage(raw: Record<string, unknown>): BusMessage | null {
|
|
|
388
388
|
const ver = raw['ver']
|
|
389
389
|
if (typeof res !== 'string') return null
|
|
390
390
|
if (typeof ver !== 'number' || !Number.isSafeInteger(ver)) return null
|
|
391
|
-
|
|
391
|
+
const incarnation = raw['incarnation']
|
|
392
|
+
if (incarnation === undefined) return { kind: 'objdel', tag, res, ver }
|
|
393
|
+
if (typeof incarnation !== 'string' || incarnation.length === 0) return null
|
|
394
|
+
return { kind: 'objdel', tag, res, ver, incarnation }
|
|
392
395
|
}
|
|
393
396
|
return null
|
|
394
397
|
}
|
|
@@ -92,7 +92,7 @@ export function canonicalSave(
|
|
|
92
92
|
// confusing diff in the canonical bytes rather than a clean drop.
|
|
93
93
|
// Mirrors the `isSafeNonNegativeInt` rigor that the objstore
|
|
94
94
|
// canonical builders apply. Input-validation audit
|
|
95
|
-
// `server/sign.ts:88`.
|
|
95
|
+
// `server-e2e/sign.ts:88`.
|
|
96
96
|
if (typeof workspaceTag !== 'string') throw new TypeError('canonicalSave: workspaceTag must be string')
|
|
97
97
|
if (typeof nonce !== 'string') throw new TypeError('canonicalSave: nonce must be string')
|
|
98
98
|
if (typeof ciphertext !== 'string') throw new TypeError('canonicalSave: ciphertext must be string')
|
|
@@ -122,7 +122,7 @@ function canonicalSubscribe(
|
|
|
122
122
|
return encodeUtf8([SUBSCRIBE_DOMAIN, workspaceTag as string, fromStr, connectionNonce].join('\n'))
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
// Exported because the v1.objstore signing module (server/objstore/sign.ts)
|
|
125
|
+
// Exported because the v1.objstore signing module (server-e2e/objstore/sign.ts)
|
|
126
126
|
// reuses it for its four verifiers — same workspaceTag-as-pubkey contract,
|
|
127
127
|
// same domain-separated canonical bytes. Keeping the WebCrypto plumbing
|
|
128
128
|
// in one place avoids drift between the triage-sync and objstore verify
|
|
@@ -157,7 +157,7 @@ export async function verifyEd25519(
|
|
|
157
157
|
// `{ ok: false, canonical: null }` on bad shape / bad sig;
|
|
158
158
|
// `{ ok: true, canonical: <bytes> }` on success.
|
|
159
159
|
//
|
|
160
|
-
// NOT used by `server/
|
|
160
|
+
// NOT used by `server-e2e/sync-handlers.ts handleSave`. Production composes
|
|
161
161
|
// the smaller helpers (`canonicalSave`, `computeRevisionIdFromCanonical`,
|
|
162
162
|
// `verifyEd25519`) separately so the dup-precheck via
|
|
163
163
|
// `revisionExists` can fire BEFORE Ed25519-verify and skip the
|
|
@@ -204,7 +204,7 @@ export async function computeRevisionIdFromCanonical(canonical: Uint8Array<Array
|
|
|
204
204
|
|
|
205
205
|
// `connectionNonce` is the per-socket challenge the server issued
|
|
206
206
|
// to the originating connection (see `Peer.challenge` in
|
|
207
|
-
// server/peer.ts). The client signs a canonical that includes the
|
|
207
|
+
// server-e2e/peer.ts). The client signs a canonical that includes the
|
|
208
208
|
// nonce; verifying against the SAME nonce here is what blocks
|
|
209
209
|
// cross-connection replay of a captured subscribe frame. Audit
|
|
210
210
|
// round-9 H2.
|
|
@@ -8,9 +8,10 @@
|
|
|
8
8
|
//
|
|
9
9
|
// One route, POSTs only:
|
|
10
10
|
//
|
|
11
|
-
// POST /api/sync/sse
|
|
11
|
+
// POST /api/sync/sse
|
|
12
12
|
// Request body:
|
|
13
|
-
// {
|
|
13
|
+
// { id?: string, — session continuation token
|
|
14
|
+
// password?: string, — cached client password
|
|
14
15
|
// frames?: Array<protocol-frame> — WS-style JSON frames
|
|
15
16
|
// }
|
|
16
17
|
// Response:
|
|
@@ -25,14 +26,23 @@
|
|
|
25
26
|
// carrying the WS protocol's JSON envelopes.
|
|
26
27
|
//
|
|
27
28
|
// Continuation: each POST replaces the previous POST's response as the
|
|
28
|
-
// session's downstream channel. If the
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
29
|
+
// session's downstream channel. If the body's `id` matches a session
|
|
30
|
+
// this replica knows, the session continues (new outbound stream
|
|
31
|
+
// attached, old one end()ed). If the id is unknown (different replica
|
|
32
|
+
// picked up the POST, or session expired), a fresh session with a new
|
|
33
|
+
// id is created and announced via the first `session` event; the
|
|
34
|
+
// client uses the new id on all subsequent POSTs and re-sends its
|
|
35
|
+
// subscribe frames on the next POST (its `frames` carry the signed
|
|
36
|
+
// subscribes — they always do, see client/sync/sse-transport.ts).
|
|
37
|
+
//
|
|
38
|
+
// The id rides the JSON body, NOT the URL: the sid is a live bearer
|
|
39
|
+
// capability (whoever presents it attaches to the session's downstream
|
|
40
|
+
// and inherits its operator-auth flag), and a query-string token leaks
|
|
41
|
+
// into proxy / LB access logs — the same reason the objstore bearer
|
|
42
|
+
// tokens ride the Authorization header, never the URL. A legacy
|
|
43
|
+
// `?id=<sid>` query form is still ACCEPTED (older client bundles sent
|
|
44
|
+
// it; rejecting would churn them through a fresh session per POST),
|
|
45
|
+
// but current clients never emit it.
|
|
36
46
|
//
|
|
37
47
|
// Why POSTs only: a long-lived GET pins the client to one replica via
|
|
38
48
|
// TCP affinity, which would mean POSTs from the same client must be
|
|
@@ -47,7 +57,7 @@ import { type PeerConnectionDeps, setupPeerConnection } from './ws-server.ts'
|
|
|
47
57
|
import { SseSession } from './sse-session.ts'
|
|
48
58
|
import { errMsg, randomId } from './util.ts'
|
|
49
59
|
|
|
50
|
-
// Same prefix the WS upgrade lives under (server/http.ts WS_UPGRADE_PATH
|
|
60
|
+
// Same prefix the WS upgrade lives under (server-e2e/http.ts WS_UPGRADE_PATH
|
|
51
61
|
// = '/api/sync'); subroute keeps the SSE plane sibling to the upgrade
|
|
52
62
|
// path so the same `location` block routes both.
|
|
53
63
|
export const SSE_OPEN_PATH = '/api/sync/sse'
|
|
@@ -75,7 +85,7 @@ export type SseServerDeps = {
|
|
|
75
85
|
// transport into it. Closure over the same handler / hub / objstore
|
|
76
86
|
// / track / debug surface the WS path uses.
|
|
77
87
|
peerDeps: PeerConnectionDeps
|
|
78
|
-
// Shutdown gate. Mirror of the REST + WS branches in server/http.ts:
|
|
88
|
+
// Shutdown gate. Mirror of the REST + WS branches in server-e2e/http.ts:
|
|
79
89
|
// an SSE POST arriving on an existing keep-alive socket after
|
|
80
90
|
// SIGTERM should be rejected, not dispatched against a draining DB.
|
|
81
91
|
isShuttingDown: () => boolean
|
|
@@ -83,7 +93,7 @@ export type SseServerDeps = {
|
|
|
83
93
|
// 503 the open request. Caps the SSE-side equivalent of `wss.clients`.
|
|
84
94
|
maxSessions: number
|
|
85
95
|
// Max body size for one POST. Matches the WS `maxPayload` in
|
|
86
|
-
// server/index.ts so the SSE plane can't accept frames the WS plane
|
|
96
|
+
// server-e2e/index.ts so the SSE plane can't accept frames the WS plane
|
|
87
97
|
// would reject. The POST body envelope can hold multiple frames so
|
|
88
98
|
// the per-frame budget is the same as the WS plane after the
|
|
89
99
|
// dispatcher splits them.
|
|
@@ -106,8 +116,10 @@ export type SseServer = {
|
|
|
106
116
|
// Inbound POST body. Every field optional — an empty-body POST is a
|
|
107
117
|
// valid "wake the session" probe (the response stream rides on every
|
|
108
118
|
// POST), and a body that carries only `password` or only `frames` is
|
|
109
|
-
// a normal partial update.
|
|
119
|
+
// a normal partial update. `id` is the session continuation token
|
|
120
|
+
// (see the header's "Continuation" note for why it rides the body).
|
|
110
121
|
type SseBody = {
|
|
122
|
+
id?: unknown
|
|
111
123
|
password?: unknown
|
|
112
124
|
frames?: unknown
|
|
113
125
|
}
|
|
@@ -116,12 +128,13 @@ export function installSseServer(deps: SseServerDeps): SseServer {
|
|
|
116
128
|
const { peerDeps, isShuttingDown, maxSessions, maxBodyBytes, debug } = deps
|
|
117
129
|
|
|
118
130
|
// Active SSE sessions, keyed by the random session id `createSession`
|
|
119
|
-
// mints on the first POST that
|
|
120
|
-
// replica doesn't recognise) and that subsequent POSTs echo
|
|
121
|
-
// continue the session. Bounded by
|
|
122
|
-
// POSTs get a 503. POSTs against an
|
|
123
|
-
// mint a fresh session instead, so a
|
|
124
|
-
// require sticky LB routing to
|
|
131
|
+
// mints on the first POST that carries no continuation id (or whose
|
|
132
|
+
// id this replica doesn't recognise) and that subsequent POSTs echo
|
|
133
|
+
// back (body `id` field) to continue the session. Bounded by
|
|
134
|
+
// `maxSessions` — over the cap, new POSTs get a 503. POSTs against an
|
|
135
|
+
// unknown id are NOT 404'd — they mint a fresh session instead, so a
|
|
136
|
+
// multi-replica deployment doesn't require sticky LB routing to
|
|
137
|
+
// recover.
|
|
125
138
|
const sessions = new Map<string, SseSession>()
|
|
126
139
|
|
|
127
140
|
function dropSession(sid: string): void {
|
|
@@ -251,6 +264,12 @@ export function installSseServer(deps: SseServerDeps): SseServer {
|
|
|
251
264
|
return
|
|
252
265
|
}
|
|
253
266
|
}
|
|
267
|
+
// Resolve the continuation token: the JSON body's `id` is the
|
|
268
|
+
// canonical carrier; the `?id=` query form is the legacy
|
|
269
|
+
// fallback for older client bundles (see the header note — a
|
|
270
|
+
// query sid leaks into access logs). Body wins when both are
|
|
271
|
+
// present (current clients only ever send one).
|
|
272
|
+
const sid = parseSid(body.id) ?? sidFromUrl
|
|
254
273
|
// Look up the session by id (if the client sent one). If found
|
|
255
274
|
// and alive, attach the new response and dispatch. If not (or
|
|
256
275
|
// session is closed), mint a fresh one — the response stream
|
|
@@ -265,8 +284,8 @@ export function installSseServer(deps: SseServerDeps): SseServer {
|
|
|
265
284
|
// through to createSession with `res` still header-virgin, so
|
|
266
285
|
// the new session can writeSseHeaders without ERR_HTTP_HEADERS_SENT.
|
|
267
286
|
let session: SseSession | null = null
|
|
268
|
-
if (
|
|
269
|
-
const existing = sessions.get(
|
|
287
|
+
if (sid) {
|
|
288
|
+
const existing = sessions.get(sid)
|
|
270
289
|
if (existing && existing.readyState === existing.OPEN && existing.attachResponse(res)) {
|
|
271
290
|
writeSseHeaders(res)
|
|
272
291
|
session = existing
|
|
@@ -333,25 +352,33 @@ export function installSseServer(deps: SseServerDeps): SseServer {
|
|
|
333
352
|
return { handle, sessions: () => sessions.values(), keepaliveTimer }
|
|
334
353
|
}
|
|
335
354
|
|
|
336
|
-
//
|
|
355
|
+
// Shape gate for a continuation token from either carrier (body `id`
|
|
356
|
+
// field or the legacy `?id=` query). The {1,64} bound is a
|
|
357
|
+
// deliberately lenient sanity gate: anything outside the base64url
|
|
358
|
+
// alphabet is rejected; an unrecognised sid just gets a fresh session
|
|
359
|
+
// from createSession (no failure mode), and the wide length window
|
|
360
|
+
// keeps a future randomId-length change from silently breaking old
|
|
361
|
+
// clients that round-trip a longer/shorter token. Returns null on
|
|
362
|
+
// missing / non-string / malformed.
|
|
363
|
+
function parseSid(v: unknown): string | null {
|
|
364
|
+
if (typeof v !== 'string') return null
|
|
365
|
+
if (!/^[A-Za-z0-9_-]{1,64}$/u.test(v)) return null
|
|
366
|
+
return v
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Bare-bones query parse for the LEGACY `id=<base64url>` carrier
|
|
370
|
+
// (older client bundles; current clients send the sid in the POST
|
|
371
|
+
// body — see the header's "Continuation" note). Avoids URLSearchParams
|
|
337
372
|
// (which decodes percent-escapes) — `randomId()` mints a 22-char
|
|
338
373
|
// base64url string echoed back unchanged, so no escapes are possible
|
|
339
|
-
// on the legitimate path.
|
|
340
|
-
// sanity gate: anything outside the base64url alphabet is rejected; an
|
|
341
|
-
// unrecognised sid just gets a fresh session from createSession (no
|
|
342
|
-
// failure mode), and the wide length window keeps a future
|
|
343
|
-
// randomId-length change from silently breaking old clients that
|
|
344
|
-
// round-trip a longer/shorter token. Returns null on missing /
|
|
345
|
-
// malformed.
|
|
374
|
+
// on the legitimate path.
|
|
346
375
|
function parseSidQuery(query: string | undefined): string | null {
|
|
347
376
|
if (typeof query !== 'string') return null
|
|
348
377
|
for (const part of query.split('&')) {
|
|
349
378
|
const eq = part.indexOf('=')
|
|
350
379
|
if (eq <= 0) continue
|
|
351
380
|
if (part.slice(0, eq) !== 'id') continue
|
|
352
|
-
|
|
353
|
-
if (!/^[A-Za-z0-9_-]{1,64}$/u.test(v)) return null
|
|
354
|
-
return v
|
|
381
|
+
return parseSid(part.slice(eq + 1))
|
|
355
382
|
}
|
|
356
383
|
return null
|
|
357
384
|
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// `join(staticDir, dirent.name)` from `readdirSync` at boot — the
|
|
7
7
|
// request URL is only used as a Map key, never joined with the
|
|
8
8
|
// filesystem — so the handler has no path-traversal surface at all:
|
|
9
|
-
// `..`, percent-encoded slashes
|
|
10
|
-
//
|
|
9
|
+
// `..`, percent-encoded slashes and absolute-form URIs all just
|
|
10
|
+
// produce a key that isn't in the map and 404.
|
|
11
11
|
//
|
|
12
12
|
// Compression: every entry whose extension is in COMPRESSIBLE gets
|
|
13
13
|
// pre-computed brotli + gzip at boot. The handler picks brotli over
|
|
@@ -38,6 +38,7 @@ import { readFileSync, readdirSync } from 'node:fs'
|
|
|
38
38
|
import { createHash } from 'node:crypto'
|
|
39
39
|
import { brotliCompressSync, gzipSync, constants as zlibConstants } from 'node:zlib'
|
|
40
40
|
import { extname, join } from 'node:path'
|
|
41
|
+
import { scanServerHtml } from '../server-common/scan-config.ts'
|
|
41
42
|
|
|
42
43
|
// MIME types for extensions the production UI bundle currently
|
|
43
44
|
// emits. Anything else falls through to `application/octet-stream`
|
|
@@ -64,15 +65,24 @@ const COMPRESSIBLE = new Set(['.html', '.css', '.js', '.svg', '.webmanifest'])
|
|
|
64
65
|
// navigated `image/svg+xml` icon into something script-executable.
|
|
65
66
|
// `no-referrer` keeps URLs of this (potentially sensitive) viewer out
|
|
66
67
|
// of outbound Referer headers, and `same-origin` CORP stops other
|
|
67
|
-
// origins embedding these bytes.
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
68
|
+
// origins embedding these bytes. COOP `same-origin` severs the
|
|
69
|
+
// window.opener link to any cross-origin opener/popup (so an external
|
|
70
|
+
// `target=_blank` GitHub/Claude link can't reach back into this context),
|
|
71
|
+
// and COEP `require-corp` bars the document from loading any cross-origin
|
|
72
|
+
// subresource that doesn't opt in via CORP/CORS. Together they also make
|
|
73
|
+
// the page cross-origin-isolated. Safe here because the bundle is fully
|
|
74
|
+
// same-origin (no external scripts/images/fonts/iframes) — switch COEP to
|
|
75
|
+
// `credentialless` if a cross-origin resource is ever added. CSP is
|
|
76
|
+
// deliberately NOT here: the HTML documents carry their own per-page
|
|
77
|
+
// `<meta http-equiv>` policy (and the three pages differ), so a blanket
|
|
78
|
+
// header CSP would just AND against the meta one and risk breaking a page
|
|
79
|
+
// — non-document assets get their own flat CSP via `StaticEntry.csp`.
|
|
72
80
|
const SECURITY_HEADERS = {
|
|
73
81
|
'x-content-type-options': 'nosniff',
|
|
74
82
|
'referrer-policy': 'no-referrer',
|
|
75
83
|
'cross-origin-resource-policy': 'same-origin',
|
|
84
|
+
'cross-origin-opener-policy': 'same-origin',
|
|
85
|
+
'cross-origin-embedder-policy': 'require-corp',
|
|
76
86
|
} as const
|
|
77
87
|
|
|
78
88
|
type StaticEntry = {
|
|
@@ -93,8 +103,10 @@ export type StaticHandler = (req: HttpRequest, res: ServerResponse) => boolean
|
|
|
93
103
|
// caller falls through to its next route. Missing `staticDir`
|
|
94
104
|
// (pre-build case) logs a warning and returns a handler that always
|
|
95
105
|
// answers false; the API/WS planes are unaffected.
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
type StaticOptions = { transformIndex?: (html: string) => string, indexOnly?: boolean }
|
|
107
|
+
|
|
108
|
+
export function loadStatic(staticDir: string, deepviewScanServer: string | null = null, options: StaticOptions = {}): StaticHandler {
|
|
109
|
+
const files = readStaticFiles(staticDir, deepviewScanServer, options)
|
|
98
110
|
return function handleStatic(req: HttpRequest, res: ServerResponse): boolean {
|
|
99
111
|
if (req.method !== 'GET' && req.method !== 'HEAD') return false
|
|
100
112
|
if (typeof req.url !== 'string') return false
|
|
@@ -142,7 +154,7 @@ export function loadStatic(staticDir: string): StaticHandler {
|
|
|
142
154
|
}
|
|
143
155
|
}
|
|
144
156
|
|
|
145
|
-
function readStaticFiles(staticDir: string): ReadonlyMap<string, StaticEntry> {
|
|
157
|
+
function readStaticFiles(staticDir: string, deepviewScanServer: string | null, options: StaticOptions): ReadonlyMap<string, StaticEntry> {
|
|
146
158
|
const files = new Map<string, StaticEntry>()
|
|
147
159
|
let entries
|
|
148
160
|
try { entries = readdirSync(staticDir, { withFileTypes: true }) } catch (err) {
|
|
@@ -156,18 +168,17 @@ function readStaticFiles(staticDir: string): ReadonlyMap<string, StaticEntry> {
|
|
|
156
168
|
throw err
|
|
157
169
|
}
|
|
158
170
|
for (const entry of entries) {
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (!entry.isFile()) continue
|
|
163
|
-
files.set(entry.name, buildEntry(staticDir, entry.name))
|
|
171
|
+
// Exclude subdirectories, symlinks and non-file entries.
|
|
172
|
+
if (!entry.isFile() || (options.indexOnly && entry.name !== 'index.html')) continue
|
|
173
|
+
files.set(entry.name, buildEntry(staticDir, entry.name, deepviewScanServer, options.transformIndex))
|
|
164
174
|
}
|
|
165
175
|
return files
|
|
166
176
|
}
|
|
167
177
|
|
|
168
|
-
function buildEntry(staticDir: string, name: string): StaticEntry {
|
|
178
|
+
function buildEntry(staticDir: string, name: string, deepviewScanServer: string | null = null, transformIndex: (html: string) => string = html => html): StaticEntry {
|
|
169
179
|
const ext = extname(name)
|
|
170
|
-
const
|
|
180
|
+
const source = readFileSync(join(staticDir, name))
|
|
181
|
+
const raw = name === 'index.html' ? Buffer.from(transformIndex(scanServerHtml(source.toString('utf8'), deepviewScanServer))) : source
|
|
171
182
|
const type = CONTENT_TYPE[ext] ?? 'application/octet-stream'
|
|
172
183
|
// HTML: lift `<link rel="(module)preload" …>` into a Link header and
|
|
173
184
|
// drop the tags from the served body. ETag + compression run against
|
|
@@ -183,13 +194,12 @@ function buildEntry(staticDir: string, name: string): StaticEntry {
|
|
|
183
194
|
// collision-resistance against the ~tens of files we load.
|
|
184
195
|
const etag = `"${createHash('sha256').update(identity).digest('hex').slice(0, 32)}"`
|
|
185
196
|
const isCompressible = COMPRESSIBLE.has(ext)
|
|
186
|
-
// Brotli quality
|
|
187
|
-
//
|
|
188
|
-
// request thereafter. text mode tells the encoder we're working
|
|
197
|
+
// Brotli quality 9 limits boot-time compression work, including on
|
|
198
|
+
// serverless cold starts. Text mode tells the encoder we're working
|
|
189
199
|
// on UTF-8 text (every COMPRESSIBLE entry is text-shaped).
|
|
190
200
|
const br = isCompressible ? brotliCompressSync(identity, {
|
|
191
201
|
params: {
|
|
192
|
-
[zlibConstants.BROTLI_PARAM_QUALITY]:
|
|
202
|
+
[zlibConstants.BROTLI_PARAM_QUALITY]: 9,
|
|
193
203
|
[zlibConstants.BROTLI_PARAM_MODE]: zlibConstants.BROTLI_MODE_TEXT,
|
|
194
204
|
},
|
|
195
205
|
}) : null
|