@preventive/triage 1.0.0-alpha.6 → 1.0.0-alpha.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +202 -0
- package/README.md +16 -0
- package/api/reap.ts +17 -0
- package/cli.js +6 -0
- package/client/dependency-paths.d.ts +3 -0
- package/client/dependency-paths.js +36 -0
- package/client/finding-link.js +305 -0
- package/client/linked-findings.d.ts +1 -0
- package/client/linked-findings.js +115 -0
- package/common/bundle-commit.d.ts +1 -0
- package/common/bundle-commit.js +4 -0
- package/common/bundle-compare-diff.d.ts +3 -0
- package/common/bundle-compare-diff.js +376 -0
- package/common/bundle-compare-inputs.d.ts +3 -0
- package/common/bundle-compare-inputs.js +141 -0
- package/common/bundle-compare-versions.js +172 -0
- package/common/bundle-comparison.d.ts +8 -0
- package/common/bundle-comparison.js +69 -0
- package/common/bundle-metadata.d.ts +15 -0
- package/common/bundle-metadata.js +226 -0
- package/common/bundle-pkg-of.d.ts +1 -0
- package/common/bundle-pkg-of.js +90 -0
- package/common/bundle-reasons.d.ts +2 -0
- package/common/bundle-reasons.js +21 -0
- package/common/bundle-source-links.d.ts +6 -0
- package/common/bundle-source-links.js +216 -0
- package/common/bundle-sourcemap.d.ts +10 -0
- package/common/bundle-sourcemap.js +100 -0
- package/common/bundle-sources.d.ts +7 -0
- package/common/bundle-sources.js +333 -0
- package/common/bundle-stats.js +41 -0
- package/common/bundle-tabs.js +1 -0
- package/common/code-language.js +65 -0
- package/common/default-scan-models.ts +36 -0
- package/common/dependency-reviews.d.ts +18 -0
- package/common/dependency-reviews.js +64 -0
- package/common/finding-duplicates.js +58 -0
- package/common/finding-filters.js +274 -0
- package/common/finding-id.js +47 -0
- package/common/finding-repo.d.ts +5 -0
- package/common/finding-repo.js +67 -0
- package/common/github-issue-labels.d.ts +1 -0
- package/common/github-issue-labels.js +11 -0
- package/common/github-pr.ts +56 -0
- package/common/gzip.js +59 -0
- package/common/line-diff.d.ts +8 -0
- package/common/line-diff.js +57 -0
- package/common/linked-workspace-groups.js +63 -0
- package/common/managed/agent-tasks.ts +292 -0
- package/common/managed/comments.ts +43 -0
- package/common/managed/finding-detail.d.ts +5 -0
- package/common/managed/finding-detail.js +75 -0
- package/common/managed/finding-values.d.ts +2 -0
- package/common/managed/finding-values.js +44 -0
- package/common/managed/github-agents.ts +114 -0
- package/common/managed/github-logins.ts +49 -0
- package/common/managed/lite-name.d.ts +2 -0
- package/common/managed/lite-name.js +20 -0
- package/common/managed/npm-packages.d.ts +7 -0
- package/common/managed/npm-packages.js +51 -0
- package/common/managed/permissions.ts +31 -0
- package/common/managed/report-content.ts +72 -0
- package/common/managed/report-filter.ts +120 -0
- package/common/managed/repository-alias.ts +65 -0
- package/common/managed/roles.ts +35 -0
- package/common/managed/routes.d.ts +2 -0
- package/common/managed/routes.js +363 -0
- package/common/managed/scan-models.ts +6 -0
- package/common/managed/team-app.d.ts +15 -0
- package/common/managed/team-app.js +100 -0
- package/common/managed/team-filters.js +26 -0
- package/common/managed/triage.ts +83 -0
- package/common/managed/upload-seal.ts +126 -0
- package/common/pretty-print.d.ts +5 -0
- package/common/pretty-print.js +24 -0
- package/common/repo-commit.d.ts +4 -0
- package/common/repo-commit.js +30 -0
- package/common/revalidation-conflicts.js +48 -0
- package/common/revalidation-input-groups.js +56 -0
- package/common/save-error-reason.ts +20 -7
- package/common/scan-server.ts +13 -0
- package/common/security-links.d.ts +5 -0
- package/common/security-links.js +33 -0
- package/common/server-info.ts +46 -0
- package/common/utf8.d.ts +3 -0
- package/common/utf8.js +45 -0
- package/common/workspace-app.js +71 -0
- package/common/workspace-groups.js +176 -0
- package/out/activity.js +4 -0
- package/out/brotli-fallback.js +3 -3
- package/out/chunk-2XUEZHIP.js +28 -0
- package/out/chunk-4EMM6UCD.js +1 -0
- package/out/chunk-4ISO5F7Y.js +7 -0
- package/out/chunk-4XIH7YTX.js +1 -0
- package/out/chunk-6CCSTJWB.js +1 -0
- package/out/chunk-74AEKRES.js +10 -0
- package/out/chunk-7BKKYVWR.js +7 -0
- package/out/chunk-7C7DWL7I.js +1 -0
- package/out/chunk-B3FNMHOE.js +1 -0
- package/out/chunk-BNH52UHC.js +2 -0
- package/out/chunk-BRO77PQY.js +42 -0
- package/out/chunk-C4Z6ZBXV.js +10 -0
- package/out/chunk-DEVAORP2.js +1 -0
- package/out/chunk-E3LFSUDJ.js +9 -0
- package/out/chunk-G3LY2FV4.js +1 -0
- package/out/chunk-GO7FT4OD.js +1 -0
- package/out/chunk-GRGIZOTP.js +4 -0
- package/out/chunk-HAZKDK4M.js +4 -0
- package/out/chunk-HOB3YPS5.js +1 -0
- package/out/chunk-IYPY47MC.js +1 -0
- package/out/chunk-IZ6MYRYB.js +3 -0
- package/out/chunk-J2FWBXFV.js +1 -0
- package/out/chunk-JCIIBLKR.js +1 -0
- package/out/chunk-JFL7WLRV.js +1 -0
- package/out/chunk-JJK5OZG2.js +15 -0
- package/out/chunk-JMG5DXII.js +2 -0
- package/out/chunk-JOXLZXMI.js +1 -0
- package/out/chunk-M37X4LCF.js +14 -0
- package/out/chunk-M3Y6SLC4.js +1 -0
- package/out/chunk-NRPC74AM.js +1 -0
- package/out/chunk-NXATZJQ2.js +1 -0
- package/out/chunk-OFZYEWBH.js +244 -0
- package/out/chunk-OIERSXON.js +1 -0
- package/out/chunk-OOJM4CTU.js +1 -0
- package/out/chunk-PAD2JHZT.js +1 -0
- package/out/chunk-PNHBZGDD.js +1 -0
- package/out/chunk-PTFQKLKO.js +1 -0
- package/out/chunk-PWFUOLZK.js +17 -0
- package/out/chunk-PXK7EU4V.js +1 -0
- package/out/chunk-QCOGVL37.js +52 -0
- package/out/chunk-QMVOEBWC.js +13 -0
- package/out/chunk-QRKFPLA4.js +80 -0
- package/out/chunk-R3NZFXVR.js +1 -0
- package/out/chunk-R5O6FAW4.js +2 -0
- package/out/chunk-RRBIJL2B.js +1 -0
- package/out/chunk-SYXT3SFP.js +2 -0
- package/out/chunk-TOXMUOIW.js +5 -0
- package/out/chunk-TUII34K2.js +1 -0
- package/out/chunk-UCP3JRE2.js +1 -0
- package/out/chunk-VFWMQ3LG.js +2 -0
- package/out/chunk-VRX2APNA.js +9 -0
- package/out/chunk-W3QFV4SP.js +3 -0
- package/out/chunk-W6VOKW2N.js +12 -0
- package/out/chunk-WCPJDAYA.js +10 -0
- package/out/chunk-WMFDQS2L.js +11 -0
- package/out/chunk-WREU7JAG.js +1 -0
- package/out/chunk-Y5ZHFNBD.js +2 -0
- package/out/chunk-YF4M5OCI.js +1 -0
- package/out/chunk-Z667U2UJ.js +1 -0
- package/out/chunk-ZQHLECTI.js +1 -0
- package/out/chunk-ZQNEWVGG.js +1 -0
- package/out/client-managed-import.js +4 -0
- package/out/client-managed.js +34 -0
- package/out/client-sync.js +11 -17
- package/out/compare.js +40 -0
- package/out/dialogs.js +40 -0
- package/out/github-issue-authorized.html +3 -0
- package/out/github-issue-authorized.js +1 -0
- package/out/graph.js +19 -4
- package/out/index.html +106 -8
- package/out/prism.js +14 -10
- package/out/scan.js +2 -0
- package/out/stasis.svg +20 -0
- package/out/terminal.js +366 -39
- package/out/view.css +1 -1
- package/out/view.js +19 -144
- package/package.json +383 -63
- package/risk/actions/findings.js +161 -0
- package/risk/actions/resolve.js +250 -0
- package/risk/actions/scripts/commands.js +182 -0
- package/risk/actions/scripts/grade.js +113 -0
- package/risk/actions/scripts/packages.js +123 -0
- package/risk/actions/scripts/shell.js +169 -0
- package/risk/actions/uses.js +76 -0
- package/risk/actions/workflow.js +110 -0
- package/risk/files/characters.js +196 -0
- package/risk/files/hosts.js +205 -0
- package/risk/files/readability.js +177 -0
- package/risk/files/runs-code.js +615 -0
- package/risk/files/script.js +118 -0
- package/risk/files/stamps.js +47 -0
- package/risk/index.d.ts +272 -0
- package/risk/index.js +11 -0
- package/risk/npm/assess.js +285 -0
- package/risk/npm/combined.js +68 -0
- package/risk/npm/compare.js +257 -0
- package/risk/npm/dependencies.js +172 -0
- package/risk/npm/diff.js +79 -0
- package/risk/npm/downloads.js +84 -0
- package/risk/npm/files.js +445 -0
- package/risk/npm/held.js +63 -0
- package/risk/npm/install-scripts.js +34 -0
- package/risk/npm/malware.js +38 -0
- package/risk/npm/manifest.js +65 -0
- package/risk/npm/new-dependency.js +60 -0
- package/risk/npm/old-version.js +108 -0
- package/risk/npm/registry.js +390 -0
- package/risk/npm/release.js +85 -0
- package/risk/npm/score.js +59 -0
- package/risk/npm/specs.js +124 -0
- package/risk/npm/tarball.js +96 -0
- package/server-common/database-config.ts +16 -0
- package/server-common/initialize.ts +18 -0
- package/server-common/npm-advisories.ts +101 -0
- package/{server → server-common}/origin.ts +5 -5
- package/server-common/reap.ts +48 -0
- package/server-common/scan-config.ts +19 -0
- package/server-common/standalone.ts +29 -0
- package/server-common/storage-crypto.ts +182 -0
- package/server-common/storage-log.ts +38 -0
- package/server-common/vercel-blob.ts +103 -0
- package/server-e2e/app.ts +487 -0
- package/{server → server-e2e}/bus-receiver.ts +2 -1
- package/{server → server-e2e}/cli.js +9 -4
- package/{server → server-e2e}/config.ts +50 -42
- package/{server → server-e2e}/db-neon.ts +2 -2
- package/{server → server-e2e}/db-revision-sql.ts +1 -1
- package/{server → server-e2e}/db-stmt.ts +2 -2
- package/{server → server-e2e}/db.ts +7 -7
- package/{server → server-e2e}/http.ts +44 -13
- package/{server → server-e2e}/hub.ts +40 -9
- package/server-e2e/index.ts +17 -0
- package/server-e2e/lifecycle.ts +95 -0
- package/{server → server-e2e}/neon-driver.ts +2 -2
- package/{server → server-e2e}/npm-proxy.ts +12 -145
- package/{server → server-e2e}/objstore/blob-vercel.ts +10 -114
- package/{server → server-e2e}/objstore/blob.ts +1 -1
- package/{server → server-e2e}/objstore/fetch-mint-guard.ts +2 -2
- package/{server → server-e2e}/objstore/handlers.ts +9 -8
- package/{server → server-e2e}/objstore/init.ts +19 -27
- package/{server → server-e2e}/objstore/reaper.ts +1 -1
- package/{server → server-e2e}/objstore/rest-deny.ts +1 -1
- package/{server → server-e2e}/objstore/rest-mint.ts +3 -3
- package/{server → server-e2e}/objstore/rest.ts +3 -3
- package/{server → server-e2e}/objstore/store-neon.ts +6 -10
- package/{server → server-e2e}/objstore/store.ts +7 -7
- package/{server → server-e2e}/objstore/tokens.ts +2 -2
- package/{server → server-e2e}/pubsub.ts +12 -9
- package/{server → server-e2e}/sign.ts +4 -4
- package/{server → server-e2e}/sse-server.ts +60 -33
- package/{server → server-e2e}/static.ts +31 -21
- package/{server → server-e2e}/sync-handlers.ts +64 -30
- package/{server → server-e2e}/ws-server.ts +20 -9
- package/server-managed/activity.ts +238 -0
- package/server-managed/agent-merges.ts +109 -0
- package/server-managed/app-agents.ts +23 -0
- package/server-managed/avatar-store.ts +13 -0
- package/server-managed/blob-store.ts +26 -0
- package/server-managed/brotli.ts +10 -0
- package/server-managed/bundle-advisories.ts +103 -0
- package/server-managed/bundle-advisory-inventory.ts +77 -0
- package/server-managed/bundle-build-diagnostics.d.ts +10 -0
- package/server-managed/bundle-build-diagnostics.js +23 -0
- package/server-managed/bundle-build-leases.ts +41 -0
- package/server-managed/bundle-build-worker.js +238 -0
- package/server-managed/bundle-build.ts +240 -0
- package/server-managed/bundle-cache.ts +199 -0
- package/server-managed/bundle-catalog.ts +29 -0
- package/server-managed/bundle-commits.ts +133 -0
- package/server-managed/bundle-dependency-reviews.ts +68 -0
- package/server-managed/bundle-store.ts +24 -0
- package/server-managed/bundle-summary-cache.ts +139 -0
- package/server-managed/bundle-validation.ts +33 -0
- package/server-managed/bundle.ts +119 -0
- package/server-managed/cache-storage.ts +20 -0
- package/server-managed/cli.js +21 -0
- package/server-managed/combined.ts +43 -0
- package/server-managed/comments.ts +138 -0
- package/server-managed/commit-coauthors.ts +105 -0
- package/server-managed/commit-lockfiles.ts +77 -0
- package/server-managed/comparison.ts +50 -0
- package/server-managed/config.ts +163 -0
- package/server-managed/content-access.ts +15 -0
- package/server-managed/crypto.ts +25 -0
- package/server-managed/db-methods.ts +1877 -0
- package/server-managed/db-neon.ts +388 -0
- package/server-managed/db-schema.ts +253 -0
- package/server-managed/db-table-names.ts +22 -0
- package/server-managed/db.ts +146 -0
- package/server-managed/dependabot-access.ts +61 -0
- package/server-managed/dependabot-alerts.ts +180 -0
- package/server-managed/dependency-review-comments.ts +92 -0
- package/server-managed/dependency-reviews.ts +363 -0
- package/server-managed/github-accounts.ts +59 -0
- package/server-managed/github-actions.ts +71 -0
- package/server-managed/github-app.ts +347 -0
- package/server-managed/github-errors.ts +70 -0
- package/server-managed/github-graphql.ts +42 -0
- package/server-managed/github-issue-links.ts +264 -0
- package/server-managed/github-issue-oauth.ts +30 -0
- package/server-managed/github-issues.ts +157 -0
- package/server-managed/github-link-oauth.ts +56 -0
- package/server-managed/github-links.ts +204 -0
- package/server-managed/github-metadata.ts +213 -0
- package/server-managed/github-oauth.ts +264 -0
- package/server-managed/github-pulls.ts +257 -0
- package/server-managed/github-requests.ts +179 -0
- package/server-managed/github-users.ts +30 -0
- package/server-managed/github-values.ts +26 -0
- package/server-managed/history-windows.ts +172 -0
- package/server-managed/http-response.ts +76 -0
- package/server-managed/http.ts +5796 -0
- package/server-managed/import-triage.ts +51 -0
- package/server-managed/index.ts +204 -0
- package/server-managed/kept-briefly.ts +37 -0
- package/server-managed/kept.ts +28 -0
- package/server-managed/link-reports.ts +149 -0
- package/server-managed/listed-activity.ts +39 -0
- package/server-managed/locked-packages.ts +152 -0
- package/server-managed/lockfile-scope.ts +49 -0
- package/server-managed/lru.ts +30 -0
- package/server-managed/managed-issues.ts +92 -0
- package/server-managed/management-catalog.ts +45 -0
- package/server-managed/management.ts +110 -0
- package/server-managed/npm-delta-worker.js +23 -0
- package/server-managed/npm-delta.ts +159 -0
- package/server-managed/npm-insights.ts +455 -0
- package/server-managed/npm-kept.ts +234 -0
- package/server-managed/npm-loads.ts +259 -0
- package/server-managed/npm-manifest.ts +117 -0
- package/server-managed/npm-packages.ts +462 -0
- package/server-managed/npm-patch.ts +317 -0
- package/server-managed/npm-provenance.ts +127 -0
- package/server-managed/npm-risk.ts +287 -0
- package/server-managed/object-storage-disk.ts +147 -0
- package/server-managed/object-storage-vercel.ts +71 -0
- package/server-managed/object-storage.ts +82 -0
- package/server-managed/package-entry-points.ts +79 -0
- package/server-managed/pretty-print.ts +425 -0
- package/server-managed/public-workspace.ts +242 -0
- package/server-managed/pull-comment-reviews.ts +161 -0
- package/server-managed/pull-dependencies.ts +340 -0
- package/server-managed/pull-dependency-reviews.ts +327 -0
- package/server-managed/pull-reviews.ts +202 -0
- package/server-managed/queue.ts +53 -0
- package/server-managed/release-commits.ts +85 -0
- package/server-managed/rename-diff-worker.js +26 -0
- package/server-managed/rename-diff.ts +236 -0
- package/server-managed/repo-path.ts +21 -0
- package/server-managed/report-migration.ts +32 -0
- package/server-managed/report-query.ts +10 -0
- package/server-managed/report-response.ts +16 -0
- package/server-managed/report-sources.ts +181 -0
- package/server-managed/report-store.ts +77 -0
- package/server-managed/repository-actions.ts +220 -0
- package/server-managed/repository-agents.ts +422 -0
- package/server-managed/repository-aliases.ts +85 -0
- package/server-managed/repository-browser.ts +303 -0
- package/server-managed/repository-changes.ts +280 -0
- package/server-managed/repository-code.ts +215 -0
- package/server-managed/repository-dependency-reviews.ts +159 -0
- package/server-managed/repository-discovery.ts +83 -0
- package/server-managed/repository-history.ts +428 -0
- package/server-managed/repository-issues.ts +224 -0
- package/server-managed/repository-policy.ts +27 -0
- package/server-managed/repository-pulls.ts +207 -0
- package/server-managed/repository-pulse.ts +477 -0
- package/server-managed/repository-risk-assess.ts +108 -0
- package/server-managed/repository-risk-audit.ts +78 -0
- package/server-managed/repository-risk-read.ts +170 -0
- package/server-managed/repository-risk.ts +483 -0
- package/server-managed/repository-squashes.ts +160 -0
- package/server-managed/repository-stamp.ts +41 -0
- package/server-managed/request-timing.ts +63 -0
- package/server-managed/reviewed-dependencies.ts +149 -0
- package/server-managed/revisions.ts +35 -0
- package/server-managed/scan-downloads.ts +87 -0
- package/server-managed/session.ts +132 -0
- package/server-managed/slugs.ts +38 -0
- package/server-managed/solidity-entry-points.ts +71 -0
- package/server-managed/sql-postgres.ts +34 -0
- package/server-managed/sql.ts +107 -0
- package/server-managed/stasis-config.ts +55 -0
- package/server-managed/static.ts +28 -0
- package/server-managed/storage-command.ts +16 -0
- package/server-managed/storage-db.ts +183 -0
- package/server-managed/storage-encryption.ts +288 -0
- package/server-managed/storage-maintenance.ts +259 -0
- package/server-managed/storage-payload.ts +121 -0
- package/server-managed/storage-stores.ts +91 -0
- package/server-managed/storage.ts +82 -0
- package/server-managed/team-app-summaries.ts +54 -0
- package/server-managed/team-app.ts +154 -0
- package/server-managed/team-catalog.ts +7 -0
- package/server-managed/team-feed.ts +180 -0
- package/server-managed/team-npm-scopes.ts +103 -0
- package/server-managed/team-reports.ts +351 -0
- package/server-managed/triage-response.ts +16 -0
- package/server-managed/type-only-proof.js +108 -0
- package/server-managed/type-only-worker.js +31 -0
- package/server-managed/type-only.ts +115 -0
- package/server-managed/uploads.ts +106 -0
- package/server-managed/upstream-cache.ts +250 -0
- package/server-managed/view-as.ts +58 -0
- package/server-managed/worker-turns.ts +76 -0
- package/server-managed/workspace-shares.ts +170 -0
- package/server.ts +70 -0
- package/server/index.ts +0 -480
- package/server/lifecycle.ts +0 -208
- /package/{LICENSE → LICENSE-MIT} +0 -0
- /package/{server → server-e2e}/auth.ts +0 -0
- /package/{server → server-e2e}/config.example.json +0 -0
- /package/{server → server-e2e}/objstore/blob-fs.ts +0 -0
- /package/{server → server-e2e}/objstore/fs.ts +0 -0
- /package/{server → server-e2e}/objstore/sign.ts +0 -0
- /package/{server → server-e2e}/peer.ts +0 -0
- /package/{server → server-e2e}/sse-session.ts +0 -0
- /package/{server → server-e2e}/util.ts +0 -0
- /package/{server → server-e2e}/validation.ts +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { inheritReportMeta, isAppFinding, reportEntries, revalidateKindOf } from '@preventive/report'
|
|
2
|
+
import { collectDuplicates } from '../../client/linked-findings.js'
|
|
3
|
+
import { dependencyDirectory, isDependencyFile } from '../../client/dependency-paths.js'
|
|
4
|
+
import { hasRevalidateStamp } from '../finding-filters.js'
|
|
5
|
+
import { workspaceApp, workspaceAppMetadata, workspaceAppRows } from '../workspace-app.js'
|
|
6
|
+
import { mergeReportGroups } from '../workspace-groups.js'
|
|
7
|
+
|
|
8
|
+
// The same classification as local workspaces, using only the complete,
|
|
9
|
+
// server-filtered published workspace: the reports of one team response and
|
|
10
|
+
// its `links`. The managed server classifies each team before sending its
|
|
11
|
+
// catalog, so the sidebar opens a team collapsed to its App findings at once.
|
|
12
|
+
// The server backfills finding IDs before building these envelopes.
|
|
13
|
+
export function managedTeamAppMetadata(workspace, options = {}) {
|
|
14
|
+
const { reports, duplicates } = viewReports(workspace)
|
|
15
|
+
return workspaceAppMetadata(reports, id => [...duplicates.get(id) ?? []], options)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Whether copies of one finding in the workspace disagree on what the
|
|
19
|
+
// revalidation pass said, which takes the App lens off a view of it
|
|
20
|
+
// (ui/view/render.js configureReportRevalidation). Asked of all its rows, so
|
|
21
|
+
// that a view of any of its reports holds none either.
|
|
22
|
+
export function managedTeamRevalidationConflicted(workspace) {
|
|
23
|
+
return mergeReportGroups(viewReports(workspace).reports).conflicts.size > 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The IDs of the findings the workspace's basic App view can show
|
|
27
|
+
// (common/workspace-app.js workspaceAppRows), or null.
|
|
28
|
+
export function managedTeamAppRows(workspace) {
|
|
29
|
+
const { reports, duplicates } = viewReports(workspace)
|
|
30
|
+
return workspaceAppRows(reports, id => [...duplicates.get(id) ?? []])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// What a view of the whole workspace offers beside the App view
|
|
34
|
+
// (ui/view/render.js), told by all its rows: whether the revalidation layer
|
|
35
|
+
// can come off (`drop`), whether its detail stop has rows to unfold
|
|
36
|
+
// (`detail`), and whether an upstream lens has ground (`upstream`).
|
|
37
|
+
export function managedTeamLens(workspace) {
|
|
38
|
+
const { reports } = viewReports(workspace)
|
|
39
|
+
return lensOf(reports, mergeReportGroups(reports).groups)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// One reading of a team's published workspace for all that is asked of it as
|
|
43
|
+
// its reports are built (server-managed/team-reports.ts), each worked out of
|
|
44
|
+
// the same rows: its classification (managedTeamAppMetadata, its findings
|
|
45
|
+
// counted, and of a team not App, how many of its reports open in App mode on
|
|
46
|
+
// their own), the rows its App view shows (managedTeamAppRows), and, asked
|
|
47
|
+
// only where wanted, whether copies contradict the pass
|
|
48
|
+
// (managedTeamRevalidationConflicted) and what its rows offer the toolbar
|
|
49
|
+
// (managedTeamLens).
|
|
50
|
+
export function managedTeamView(workspace) {
|
|
51
|
+
const { reports, duplicates, linked } = viewReports(workspace)
|
|
52
|
+
const { metadata, rows } = workspaceApp(reports, id => [...duplicates.get(id) ?? []], { countFindings: true })
|
|
53
|
+
// Each report alone, with the links the workspace has, not its link reports'.
|
|
54
|
+
const alone = id => [...linked.get(id) ?? []]
|
|
55
|
+
const app = metadata.appMode ? metadata : { ...metadata, appReports: reports.filter(report => workspaceAppMetadata([report], alone).appMode).length }
|
|
56
|
+
let merged = null
|
|
57
|
+
const plain = () => merged ??= mergeReportGroups(reports)
|
|
58
|
+
return { app, rows, conflicted: () => plain().conflicts.size > 0, lens: () => lensOf(reports, plain().groups) }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const RULED_OUT = new Set(['refuted', 'unreachable'])
|
|
62
|
+
|
|
63
|
+
function lensOf(reports, groups) {
|
|
64
|
+
const rows = reports.flatMap(report => report.groups.flat())
|
|
65
|
+
const directory = dependencyDirectory(reports)
|
|
66
|
+
const detail = groups.some(group => {
|
|
67
|
+
const kinds = group.map(revalidateKindOf)
|
|
68
|
+
return kinds.includes('partial') || kinds.includes('revalidation') && kinds.some(kind => kind !== 'revalidation' && !RULED_OUT.has(kind))
|
|
69
|
+
})
|
|
70
|
+
return {
|
|
71
|
+
drop: rows.some(hasRevalidateStamp),
|
|
72
|
+
detail,
|
|
73
|
+
upstream: rows.some(f => f.isUpstream === true || f.isApp === false && !('isUpstream' in f) && isDependencyFile(f.file, directory)),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The workspace's reports as a view holds them (ui/view/ingest.js), with the
|
|
78
|
+
// duplicates its links name, and those its own `links` name alone (`linked`).
|
|
79
|
+
function viewReports(workspace) {
|
|
80
|
+
const duplicates = new Map(), linked = new Map(), reports = []
|
|
81
|
+
collectDuplicates(workspace.links ?? [], duplicates)
|
|
82
|
+
collectDuplicates(workspace.links ?? [], linked)
|
|
83
|
+
for (const { filename, data } of workspace) {
|
|
84
|
+
if (data.source === 'links' && Array.isArray(data.links)) {
|
|
85
|
+
collectDuplicates(data.links, duplicates)
|
|
86
|
+
continue
|
|
87
|
+
}
|
|
88
|
+
const entries = (reportEntries(data) ?? []).map(entry => Array.isArray(entry) ? entry : [entry])
|
|
89
|
+
const judged = new Set(entries.flat().filter(hasRevalidateStamp).map(f => f.source ?? data.source ?? null))
|
|
90
|
+
const groups = entries.map(group => group.map(f => {
|
|
91
|
+
const finding = { ...f, _source: f.source ?? data.source ?? null }
|
|
92
|
+
inheritReportMeta(finding, data)
|
|
93
|
+
if (!('isApp' in finding)) finding.isApp = isAppFinding(finding, finding._source)
|
|
94
|
+
finding._sourcePass = judged.has(finding._source)
|
|
95
|
+
return finding
|
|
96
|
+
}))
|
|
97
|
+
reports.push({ fileName: filename, groups, treeDependencies: data.treeDependencies ?? null })
|
|
98
|
+
}
|
|
99
|
+
return { reports, duplicates, linked }
|
|
100
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SEVERITIES } from '@preventive/report'
|
|
2
|
+
|
|
3
|
+
// A team's board can be linked filtered by repository and severity, the
|
|
4
|
+
// two filters a link names: `/team/<slug>?repo=owner/name&severity=critical,high`,
|
|
5
|
+
// as `filters: { repo, severities }`. The repository is the key the
|
|
6
|
+
// Repository filter matches (ui/view/filters.js repoOfFinding); the
|
|
7
|
+
// severities are SEVERITIES' names, in their order. Only on the team's own
|
|
8
|
+
// page: a report's or a finding's link is about that instead.
|
|
9
|
+
const isRepoFilter = repo => typeof repo === 'string' && repo.length > 0 && repo.length <= 256 && !/[\p{Cc}]/u.test(repo)
|
|
10
|
+
|
|
11
|
+
export function filtersOf(params) {
|
|
12
|
+
const repo = params.get('repo')
|
|
13
|
+
const named = new Set((params.get('severity') ?? '').split(','))
|
|
14
|
+
const severities = SEVERITIES.filter(severity => named.has(severity))
|
|
15
|
+
const filters = { ...(isRepoFilter(repo) ? { repo } : {}), ...(severities.length > 0 ? { severities } : {}) }
|
|
16
|
+
return Object.keys(filters).length > 0 ? { filters } : {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function filtersQuery(filters) {
|
|
20
|
+
const severities = SEVERITIES.filter(severity => filters?.severities?.includes(severity))
|
|
21
|
+
const query = [
|
|
22
|
+
...(isRepoFilter(filters?.repo) ? [`repo=${encodeURIComponent(filters.repo).replaceAll('%2F', '/')}`] : []),
|
|
23
|
+
...(severities.length > 0 ? [`severity=${severities.join(',')}`] : []),
|
|
24
|
+
]
|
|
25
|
+
return query.length > 0 ? `?${query.join('&')}` : ''
|
|
26
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Per-finding triage annotations on a managed server — shared by the server
|
|
2
|
+
// (which stores one row per finding id, validates the wire shape, and decides
|
|
3
|
+
// per report which ids a viewer may read or write) and the managed client
|
|
4
|
+
// (which mirrors entries into its local triage map). Keyed by finding id
|
|
5
|
+
// alone, like that map: reports mostly repeat one another (a re-scan of the
|
|
6
|
+
// same code carries the same finding ids), and a finding's triage is shared by
|
|
7
|
+
// every report that carries it. A wire entry carries the four server-persisted
|
|
8
|
+
// fields below, or is null for a cleared entry (the server's tombstone); the
|
|
9
|
+
// client's `ignoredReports` deliberately does NOT ride this wire — the
|
|
10
|
+
// per-report ignore is a client-local concept keyed by report name.
|
|
11
|
+
export type TriageBucket = 'inprogress' | 'fixed' | 'invalid' | 'deleted' | 'ignored'
|
|
12
|
+
|
|
13
|
+
const TRIAGE_BUCKETS: readonly TriageBucket[] = ['inprogress', 'fixed', 'invalid', 'deleted', 'ignored']
|
|
14
|
+
|
|
15
|
+
// One finding's server-side triage entry (also the write shape — writes
|
|
16
|
+
// replace the whole entry). Absent fields are unset; `flagged` is tri-state:
|
|
17
|
+
// absent = never set, `true` = flagged, `false` = an explicit un-flag
|
|
18
|
+
// tombstone that must round-trip (see client/state.ts TriageEntry).
|
|
19
|
+
export type TriageEntryPatch = {
|
|
20
|
+
color?: string
|
|
21
|
+
triage?: TriageBucket
|
|
22
|
+
// Legacy triage history/migration only. New comments use separate records;
|
|
23
|
+
// the managed triage write endpoint rejects this field.
|
|
24
|
+
comment?: string
|
|
25
|
+
fix?: string
|
|
26
|
+
flagged?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Length caps enforced at the write endpoint so one entry can't balloon a row.
|
|
30
|
+
export const MAX_TRIAGE_TEXT = 10_000
|
|
31
|
+
export const MAX_TRIAGE_COLOR = 50
|
|
32
|
+
|
|
33
|
+
// Caps on one write request as a whole — shared with the client, which batches
|
|
34
|
+
// within them: entries per request, the finding-id length (real ids are 36-char
|
|
35
|
+
// uuids), and the JSON body (the server's small default is too small for entry
|
|
36
|
+
// batches, which carry free text).
|
|
37
|
+
export const MAX_TRIAGE_ENTRIES = 200
|
|
38
|
+
export const MAX_FINDING_ID = 100
|
|
39
|
+
export const MAX_TRIAGE_BODY_BYTES = 262_144
|
|
40
|
+
|
|
41
|
+
// The most trail events one history read returns (newest first). Retention is
|
|
42
|
+
// the server's: everything is kept unless its TRIAGE_HISTORY_LIMIT says
|
|
43
|
+
// otherwise.
|
|
44
|
+
export const MAX_TRIAGE_HISTORY = 200
|
|
45
|
+
|
|
46
|
+
export function isTriageBucket(x: unknown): x is TriageBucket {
|
|
47
|
+
return typeof x === 'string' && (TRIAGE_BUCKETS as readonly string[]).includes(x)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Coerce one wire entry (a request-body value) into a clean patch. `null`
|
|
51
|
+
// means "clear the entry"; a malformed value (wrong type, unknown bucket,
|
|
52
|
+
// over-cap string, non-boolean flagged) is 'invalid' so the endpoint 400s
|
|
53
|
+
// rather than store garbage. Null/empty-string fields count as absent (an
|
|
54
|
+
// absent field is cleared anyway under whole-entry replace); unknown keys are
|
|
55
|
+
// ignored.
|
|
56
|
+
export function parseTriageEntryPatch(x: unknown): TriageEntryPatch | null | 'invalid' {
|
|
57
|
+
if (x === null) return null
|
|
58
|
+
if (typeof x !== 'object' || Array.isArray(x)) return 'invalid'
|
|
59
|
+
const o = x as Record<string, unknown>
|
|
60
|
+
const out: TriageEntryPatch = {}
|
|
61
|
+
const color = o['color']
|
|
62
|
+
if (color != null) {
|
|
63
|
+
if (typeof color !== 'string' || color.length > MAX_TRIAGE_COLOR) return 'invalid'
|
|
64
|
+
if (color !== '') out.color = color
|
|
65
|
+
}
|
|
66
|
+
const triage = o['triage']
|
|
67
|
+
if (triage != null) {
|
|
68
|
+
if (!isTriageBucket(triage)) return 'invalid'
|
|
69
|
+
out.triage = triage
|
|
70
|
+
}
|
|
71
|
+
for (const key of ['comment', 'fix'] as const) {
|
|
72
|
+
const v = o[key]
|
|
73
|
+
if (v == null) continue
|
|
74
|
+
if (typeof v !== 'string' || v.length > MAX_TRIAGE_TEXT) return 'invalid'
|
|
75
|
+
if (v !== '') out[key] = v
|
|
76
|
+
}
|
|
77
|
+
const flagged = o['flagged']
|
|
78
|
+
if (flagged != null) {
|
|
79
|
+
if (typeof flagged !== 'boolean') return 'invalid'
|
|
80
|
+
out.flagged = flagged
|
|
81
|
+
}
|
|
82
|
+
return out
|
|
83
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Managed uploads cross TLS-terminating proxies (Cloudflare, corporate
|
|
2
|
+
// gateways) that would otherwise read report and bundle bytes in plaintext.
|
|
3
|
+
// The server sends each session an X25519 public key; the browser seals every
|
|
4
|
+
// upload to it with a fresh ephemeral key (X25519 → HKDF-SHA-256 →
|
|
5
|
+
// AES-256-GCM), so the content key itself never crosses the proxy. Text is
|
|
6
|
+
// gzipped before sealing; binary content is sealed as is.
|
|
7
|
+
//
|
|
8
|
+
// Sealed body: version(1) | flags(1) | ephemeral public key(32), then the
|
|
9
|
+
// payload in 1 MiB segments, each sealed under nonce = big-endian segment
|
|
10
|
+
// index with the last byte marking the final segment. The header is the HKDF
|
|
11
|
+
// salt, so altering it changes the key. Segments bound browser memory for
|
|
12
|
+
// large bundles, and their nonces reject reordered, truncated or extended
|
|
13
|
+
// bodies. Every upload derives its own key, so counter nonces never repeat.
|
|
14
|
+
|
|
15
|
+
import { gunzipBytes } from '../gzip.js'
|
|
16
|
+
import { encodeUtf8 } from '../utf8.js'
|
|
17
|
+
|
|
18
|
+
// Set (to the format version) on a request whose body is sealed.
|
|
19
|
+
export const UPLOAD_SEAL_HEADER = 'x-upload-encryption'
|
|
20
|
+
const VERSION = 1
|
|
21
|
+
const FLAG_GZIP = 1
|
|
22
|
+
const CURVE = { name: 'X25519' }
|
|
23
|
+
const HEADER_BYTES = 2 + 32
|
|
24
|
+
const TAG_BYTES = 16
|
|
25
|
+
const SEGMENT_BYTES = 1024 * 1024
|
|
26
|
+
const SNIFF_BYTES = 64 * 1024
|
|
27
|
+
const KEY_INFO = 'deepview-managed-upload.v1.content-key'
|
|
28
|
+
|
|
29
|
+
// The largest sealed body for `maxBytes` of content. Deflate can grow
|
|
30
|
+
// incompressible text slightly (its worst case is about 0.03%).
|
|
31
|
+
export function maxSealedBytes(maxBytes: number): number {
|
|
32
|
+
const payload = maxBytes + Math.ceil(maxBytes / 1024) + 64
|
|
33
|
+
return HEADER_BYTES + payload + TAG_BYTES * (Math.floor(payload / SEGMENT_BYTES) + 1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function nonce(index: number, final: boolean): Uint8Array<ArrayBuffer> {
|
|
37
|
+
const iv = new Uint8Array(12)
|
|
38
|
+
new DataView(iv.buffer).setUint32(7, index)
|
|
39
|
+
iv[11] = final ? 1 : 0
|
|
40
|
+
return iv
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function contentKey(secret: ArrayBuffer, header: Uint8Array<ArrayBuffer>, usage: KeyUsage): Promise<CryptoKey> {
|
|
44
|
+
const ikm = await crypto.subtle.importKey('raw', secret, 'HKDF', false, ['deriveKey'])
|
|
45
|
+
return await crypto.subtle.deriveKey({ name: 'HKDF', hash: 'SHA-256', salt: header, info: encodeUtf8(KEY_INFO) },
|
|
46
|
+
ikm, { name: 'AES-GCM', length: 256 }, false, [usage])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Archives and other binary content would only grow under gzip. A NUL byte or
|
|
50
|
+
// invalid UTF-8 in the first 64 KiB marks content as binary.
|
|
51
|
+
async function isText(blob: Blob): Promise<boolean> {
|
|
52
|
+
const head = new Uint8Array(await blob.slice(0, SNIFF_BYTES).arrayBuffer())
|
|
53
|
+
if (head.includes(0)) return false
|
|
54
|
+
try { new TextDecoder('utf-8', { fatal: true }).decode(head, { stream: true }); return true }
|
|
55
|
+
catch { return false }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Seal `blob` to the server's raw public key. Reads the input as a stream;
|
|
59
|
+
// sealed segments are kept as Blobs, which browsers may page to disk. An abort
|
|
60
|
+
// stops reading at the next chunk.
|
|
61
|
+
export async function sealUpload(blob: Blob, publicKey: Uint8Array<ArrayBuffer>, signal?: AbortSignal): Promise<Blob> {
|
|
62
|
+
const gzip = await isText(blob)
|
|
63
|
+
const [server, ephemeral] = await Promise.all([
|
|
64
|
+
crypto.subtle.importKey('raw', publicKey, CURVE, false, []),
|
|
65
|
+
crypto.subtle.generateKey(CURVE, false, ['deriveBits']) as Promise<CryptoKeyPair>,
|
|
66
|
+
])
|
|
67
|
+
const header = new Uint8Array(HEADER_BYTES)
|
|
68
|
+
header[0] = VERSION
|
|
69
|
+
header[1] = gzip ? FLAG_GZIP : 0
|
|
70
|
+
header.set(new Uint8Array(await crypto.subtle.exportKey('raw', ephemeral.publicKey)), 2)
|
|
71
|
+
const key = await contentKey(await crypto.subtle.deriveBits({ name: 'X25519', public: server }, ephemeral.privateKey, 256), header, 'encrypt')
|
|
72
|
+
const parts = [new Blob([header])], segment = new Uint8Array(SEGMENT_BYTES)
|
|
73
|
+
let filled = 0, index = 0
|
|
74
|
+
const seal = async (final: boolean) => {
|
|
75
|
+
parts.push(new Blob([await crypto.subtle.encrypt({ name: 'AES-GCM', iv: nonce(index++, final) }, key, segment.subarray(0, filled))]))
|
|
76
|
+
filled = 0
|
|
77
|
+
}
|
|
78
|
+
const stream: ReadableStream<Uint8Array> = gzip ? blob.stream().pipeThrough(new CompressionStream('gzip')) : blob.stream()
|
|
79
|
+
const reader = stream.getReader()
|
|
80
|
+
try {
|
|
81
|
+
for (let read = await reader.read(); !read.done; read = await reader.read()) {
|
|
82
|
+
signal?.throwIfAborted()
|
|
83
|
+
for (let offset = 0; offset < read.value.length;) {
|
|
84
|
+
// A full segment is final only if the input ends with it.
|
|
85
|
+
if (filled === SEGMENT_BYTES) await seal(false)
|
|
86
|
+
const length = Math.min(SEGMENT_BYTES - filled, read.value.length - offset)
|
|
87
|
+
segment.set(read.value.subarray(offset, offset + length), filled)
|
|
88
|
+
filled += length
|
|
89
|
+
offset += length
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
await reader.cancel(err).catch(() => {})
|
|
94
|
+
throw err
|
|
95
|
+
}
|
|
96
|
+
await seal(true)
|
|
97
|
+
return new Blob(parts)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Open a sealed body with the session's private JWK. Throws 'too-large' when
|
|
101
|
+
// the content exceeds `maxBytes`, else 'bad-upload' for any invalid body.
|
|
102
|
+
export async function openUpload(sealed: Uint8Array<ArrayBuffer>, privateKey: JsonWebKey, maxBytes: number): Promise<Uint8Array<ArrayBuffer>> {
|
|
103
|
+
// Every segment but the last is full, so the layout follows from the length.
|
|
104
|
+
const rest = sealed.length - HEADER_BYTES
|
|
105
|
+
const count = Math.ceil(rest / (SEGMENT_BYTES + TAG_BYTES))
|
|
106
|
+
const last = rest - (count - 1) * (SEGMENT_BYTES + TAG_BYTES)
|
|
107
|
+
if (rest < TAG_BYTES || last < TAG_BYTES || sealed[0] !== VERSION || (sealed[1]! & ~FLAG_GZIP) !== 0) throw new Error('bad-upload')
|
|
108
|
+
const gzip = sealed[1] === FLAG_GZIP, plain = new Uint8Array(rest - count * TAG_BYTES)
|
|
109
|
+
if (!gzip && plain.length > maxBytes) throw new Error('too-large')
|
|
110
|
+
try {
|
|
111
|
+
const header = sealed.slice(0, HEADER_BYTES)
|
|
112
|
+
const [key, peer] = await Promise.all([
|
|
113
|
+
crypto.subtle.importKey('jwk', privateKey, CURVE, false, ['deriveBits']),
|
|
114
|
+
crypto.subtle.importKey('raw', header.slice(2), CURVE, false, []),
|
|
115
|
+
])
|
|
116
|
+
const content = await contentKey(await crypto.subtle.deriveBits({ name: 'X25519', public: peer }, key, 256), header, 'decrypt')
|
|
117
|
+
for (let index = 0; index < count; index++) {
|
|
118
|
+
const start = HEADER_BYTES + index * (SEGMENT_BYTES + TAG_BYTES)
|
|
119
|
+
const segment = sealed.subarray(start, Math.min(start + SEGMENT_BYTES + TAG_BYTES, sealed.length))
|
|
120
|
+
plain.set(new Uint8Array(await crypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce(index, index === count - 1) }, content, segment)), index * SEGMENT_BYTES)
|
|
121
|
+
}
|
|
122
|
+
} catch (err) { throw new Error('bad-upload', { cause: err }) }
|
|
123
|
+
if (!gzip) return plain
|
|
124
|
+
try { return await gunzipBytes(plain, { maxBytes }) }
|
|
125
|
+
catch (err) { throw new Error(err instanceof RangeError ? 'too-large' : 'bad-upload', { cause: err }) }
|
|
126
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// Type declarations for `common/pretty-print.js`, for `.ts` callers.
|
|
2
|
+
|
|
3
|
+
export const MAX_PRETTY_BYTES: number
|
|
4
|
+
export function prettyExtension(path: string): string | null
|
|
5
|
+
export function needsPrettyPrint(path: string, text: string, read?: () => { category: string }): boolean
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Minified files pretty-printed by the server (server-managed/pretty-print.ts)
|
|
2
|
+
// for the viewer (ui/view/pretty-source.js).
|
|
3
|
+
import { npmFileReadability } from '../risk/files/readability.js'
|
|
4
|
+
import { utf8ByteLength } from './utf8.js'
|
|
5
|
+
|
|
6
|
+
// The extensions formatted, each parsed as the language it names.
|
|
7
|
+
const PRETTY_EXTENSIONS = new Set(['js', 'mjs', 'cjs', 'jsx', 'ts', 'mts', 'cts', 'tsx', 'css', 'json'])
|
|
8
|
+
|
|
9
|
+
// The largest file formatted, in UTF-8 bytes: formatting holds a syntax tree
|
|
10
|
+
// a hundred times the file's size.
|
|
11
|
+
export const MAX_PRETTY_BYTES = 4 * 1024 * 1024
|
|
12
|
+
|
|
13
|
+
// The extension a path is formatted as, or null for one that isn't.
|
|
14
|
+
export function prettyExtension(path) {
|
|
15
|
+
const extension = /\.([a-z]+)$/iu.exec(path)?.[1]?.toLowerCase()
|
|
16
|
+
return PRETTY_EXTENSIONS.has(extension) ? extension : null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Whether a file's text is pretty-printed: in a language formatted, no larger
|
|
20
|
+
// than formatted, and minified, as risk reads it, `read` reading that where
|
|
21
|
+
// the reader keeps it.
|
|
22
|
+
export function needsPrettyPrint(path, text, read = () => npmFileReadability(path, text)) {
|
|
23
|
+
return prettyExtension(path) !== null && utf8ByteLength(text) <= MAX_PRETTY_BYTES && read().category === 'minified'
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { reportRepoGithub } from '@preventive/report'
|
|
2
|
+
|
|
3
|
+
// A git commit hash as a report writes one, short or full, either case:
|
|
4
|
+
// the rule @preventive/report's parsers read `auditedCommit` with.
|
|
5
|
+
// Empty for anything else, so a link falls back to HEAD.
|
|
6
|
+
export function asCommit(value) {
|
|
7
|
+
const commit = typeof value === 'string' ? value.trim() : ''
|
|
8
|
+
return /^[0-9a-f]{7,64}$/iu.test(commit) ? commit : ''
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// The revision a `repo` declaration names beside its `github`, as a
|
|
12
|
+
// deepview report's header does: `"repo": { "github", "directory",
|
|
13
|
+
// "commit" }`. Older reports carry no `commit`, some no `repo` at all.
|
|
14
|
+
export function repoCommit(repo) {
|
|
15
|
+
return asCommit(repo?.commit)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// GitHub repository names ignore case, and the slug a report writes need
|
|
19
|
+
// not match the case GitHub reports for the same repository.
|
|
20
|
+
export function sameRepoSlug(a, b) {
|
|
21
|
+
return typeof a === 'string' && typeof b === 'string' && a !== '' && a.toLowerCase() === b.toLowerCase()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// The commit a report read its repository at, stamped on its findings
|
|
25
|
+
// as `_repoCommit`, but only while `github` (the repo its links resolve
|
|
26
|
+
// against) is the one the report names: it says nothing about a repo
|
|
27
|
+
// typed in later or assigned in its place.
|
|
28
|
+
export function reportCommit(data, github) {
|
|
29
|
+
return sameRepoSlug(github, reportRepoGithub(data)) ? repoCommit(data?.repo) : ''
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { REVALIDATE_KINDS, revalidateKindOf } from '@preventive/report'
|
|
2
|
+
|
|
3
|
+
// Keep only the pass's fields, before gap-filling changes the survivor.
|
|
4
|
+
// In particular, a verdict borrowed from report B must never be attributed
|
|
5
|
+
// to an unstamped copy from report A when report C later contradicts it.
|
|
6
|
+
function fieldsOf(finding) {
|
|
7
|
+
return Object.fromEntries(Object.entries(finding).filter(([key, value]) =>
|
|
8
|
+
key.startsWith('revalidate') && value != null))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function recordRevalidationCopies(survivor, duplicate, reportName) {
|
|
12
|
+
const fields = fieldsOf(duplicate)
|
|
13
|
+
if (!survivor._revalidationCopies) {
|
|
14
|
+
const own = fieldsOf(survivor)
|
|
15
|
+
if (Object.keys(own).length === 0 && Object.keys(fields).length === 0) return []
|
|
16
|
+
survivor._revalidationCopies = Object.keys(own).length > 0
|
|
17
|
+
? [{ reportName: survivor._reportName ?? '', fields: own }]
|
|
18
|
+
: []
|
|
19
|
+
}
|
|
20
|
+
if (Object.keys(fields).length > 0) survivor._revalidationCopies.push({ reportName, fields })
|
|
21
|
+
return survivor._revalidationCopies
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Same comparisons as mergeDuplicateFields: missing values are gaps, stamps
|
|
25
|
+
// are normalized, and prose ignores surrounding whitespace. Group agreeing
|
|
26
|
+
// reports together, retaining every distinct answer rather than just a pair.
|
|
27
|
+
export function revalidationDifferences(copies) {
|
|
28
|
+
const byField = new Map()
|
|
29
|
+
const knownKinds = new Set(REVALIDATE_KINDS)
|
|
30
|
+
for (const { reportName, fields } of copies) {
|
|
31
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
32
|
+
if (value == null) continue
|
|
33
|
+
const normalized = key === 'revalidate'
|
|
34
|
+
? revalidateKindOf(fields) || String(value).trim().toLowerCase()
|
|
35
|
+
: String(value).trim()
|
|
36
|
+
if (key === 'revalidate' && !normalized) continue
|
|
37
|
+
if (key === 'revalidate' && !knownKinds.has(normalized)) continue
|
|
38
|
+
if (!byField.has(key)) byField.set(key, new Map())
|
|
39
|
+
const variants = byField.get(key)
|
|
40
|
+
if (!variants.has(normalized)) variants.set(normalized, new Set())
|
|
41
|
+
variants.get(normalized).add(reportName)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [...byField].filter(([, variants]) => variants.size > 1).map(([field, variants]) => ({
|
|
45
|
+
field,
|
|
46
|
+
variants: [...variants].map(([value, reports]) => ({ value, reports: [...reports] })),
|
|
47
|
+
}))
|
|
48
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Recover source-level row boundaries before hiding the App layer. App
|
|
2
|
+
// deduplication alone does not make the underlying code findings equivalent.
|
|
3
|
+
// Only split when every source ID is accounted for and every referenced input
|
|
4
|
+
// exists in this row. Missing input lists are empty, not missing evidence for
|
|
5
|
+
// an otherwise complete partition. Original findings and rows stay untouched.
|
|
6
|
+
export function splitRevalidationInputs(group, appFindings = null) {
|
|
7
|
+
const app = appFindings ?? group.filter((f) => f.isApp)
|
|
8
|
+
const source = group.filter((f) => !f.isApp)
|
|
9
|
+
if (app.length === 0 || source.length === 0) return [group]
|
|
10
|
+
// A surviving App finding means this is not a pure non-App projection;
|
|
11
|
+
// never move it into a source-only partition.
|
|
12
|
+
if (appFindings && group.some((f) => f.isApp)) return [group]
|
|
13
|
+
if (source.some((f) => typeof f.id !== 'string' || !f.id)) return [group]
|
|
14
|
+
|
|
15
|
+
const sourceIds = new Set(source.map((f) => f.id))
|
|
16
|
+
const inputsByApp = new Map()
|
|
17
|
+
const covered = new Set()
|
|
18
|
+
for (const f of app) {
|
|
19
|
+
const inputs = f.revalidateInputs === undefined ? [] : f.revalidateInputs
|
|
20
|
+
if (!Array.isArray(inputs)) return [group]
|
|
21
|
+
for (const id of inputs) {
|
|
22
|
+
if (!sourceIds.has(id)) return [group]
|
|
23
|
+
covered.add(id)
|
|
24
|
+
}
|
|
25
|
+
inputsByApp.set(f, inputs)
|
|
26
|
+
}
|
|
27
|
+
if (covered.size !== sourceIds.size) return [group]
|
|
28
|
+
|
|
29
|
+
const parent = new Map([...sourceIds].map((id) => [id, id]))
|
|
30
|
+
const find = (id) => {
|
|
31
|
+
let root = id
|
|
32
|
+
while (parent.get(root) !== root) root = parent.get(root)
|
|
33
|
+
while (parent.get(id) !== root) {
|
|
34
|
+
const next = parent.get(id)
|
|
35
|
+
parent.set(id, root)
|
|
36
|
+
id = next
|
|
37
|
+
}
|
|
38
|
+
return root
|
|
39
|
+
}
|
|
40
|
+
for (const inputs of inputsByApp.values()) {
|
|
41
|
+
if (inputs.length === 0) continue
|
|
42
|
+
const root = find(inputs[0])
|
|
43
|
+
for (const id of inputs) parent.set(find(id), root)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const components = new Map()
|
|
47
|
+
for (const f of group) {
|
|
48
|
+
const inputs = inputsByApp.get(f)
|
|
49
|
+
// Keep an App finding with its inputs until the caller projects the lens.
|
|
50
|
+
// App findings without inputs stand alone; hiding them then drops the row.
|
|
51
|
+
const key = inputs ? inputs.length > 0 ? find(inputs[0]) : f : find(f.id)
|
|
52
|
+
if (!components.has(key)) components.set(key, [])
|
|
53
|
+
components.get(key).push(f)
|
|
54
|
+
}
|
|
55
|
+
return components.size === 1 ? [group] : [...components.values()]
|
|
56
|
+
}
|
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
// `session.error` until `dismissError()`.
|
|
16
16
|
// `busy` — per-socket inflight cap dropped the save
|
|
17
17
|
// (transport backpressure). Recoverable; the
|
|
18
|
-
// client clears `pending
|
|
19
|
-
//
|
|
18
|
+
// client clears `pending`, re-arms `pendingSave`,
|
|
19
|
+
// and schedules a short timed retry — without the
|
|
20
|
+
// timer an idle client (no further edit /
|
|
21
|
+
// broadcast / reconnect) would strand its last
|
|
22
|
+
// edit unsynced indefinitely.
|
|
20
23
|
// `stale-base` — concurrent commit advanced the head past the
|
|
21
24
|
// client's claimed base. The server emits the
|
|
22
25
|
// typed frame AFTER a `workspace-state` catch-up
|
|
@@ -25,11 +28,21 @@
|
|
|
25
28
|
// and this frame's handler then early-returns
|
|
26
29
|
// on the missing pending. So `stale-base` is
|
|
27
30
|
// NOT in the recoverable set: in the happy path
|
|
28
|
-
// the recoverable branch is unreachable
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
31
|
+
// the recoverable branch is unreachable. When
|
|
32
|
+
// `pending` DOES survive to this frame — the
|
|
33
|
+
// catch-up was empty (chain gone: wiped /
|
|
34
|
+
// migrated DB) or didn't apply (chain rebuilt
|
|
35
|
+
// past the client's base) — the client answers
|
|
36
|
+
// with ONE full-state-push reset per recovery
|
|
37
|
+
// cycle (re-anchor at base=null; safe because
|
|
38
|
+
// the server's null-safe head CAS rejects a
|
|
39
|
+
// base=null root against any non-empty chain;
|
|
40
|
+
// see `staleResetAttempted` in triage-sync.ts).
|
|
41
|
+
// A repeat within the cycle marks the session
|
|
42
|
+
// errored (visible via UI + recoverable via
|
|
43
|
+
// `dismissError()`) rather than looping
|
|
44
|
+
// full-state saves against a relay that keeps
|
|
45
|
+
// rejecting them.
|
|
33
46
|
|
|
34
47
|
export type SaveErrorReason = 'too-large' | 'busy' | 'stale-base'
|
|
35
48
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const DEFAULT_SCAN_SERVER = 'http://127.0.0.1:3123/'
|
|
2
|
+
|
|
3
|
+
// Discovery is optional: malformed scan configuration must never prevent
|
|
4
|
+
// opening local data or recognizing the server's sync protocol.
|
|
5
|
+
export function normalizeScanServer(value: unknown): string | null {
|
|
6
|
+
if (typeof value !== 'string' || !value.trim()) return null
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(value)
|
|
9
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) return null
|
|
10
|
+
url.pathname = url.pathname.replace(/\/+$/u, '') + '/'
|
|
11
|
+
return url.href
|
|
12
|
+
} catch { return null }
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Links as stampSecurityGroups reads them, shared by the managed server's
|
|
2
|
+
// permission filter and the view's security lens. A star per link is enough
|
|
3
|
+
// for transitive propagation, without a quadratic expansion for large links.
|
|
4
|
+
// `add` extends the lookup while a stamp is running: rows the finding index
|
|
5
|
+
// returns can carry links of their own.
|
|
6
|
+
export function securityLinks(links = []) {
|
|
7
|
+
const edges = new Map()
|
|
8
|
+
const connect = (a, b) => {
|
|
9
|
+
if (!edges.has(a)) edges.set(a, new Set())
|
|
10
|
+
edges.get(a).add(b)
|
|
11
|
+
}
|
|
12
|
+
const add = (ids) => {
|
|
13
|
+
for (const id of ids.slice(1)) { connect(ids[0], id); connect(id, ids[0]) }
|
|
14
|
+
}
|
|
15
|
+
for (const ids of links) add(ids)
|
|
16
|
+
return { add, linkedIds: (id) => edges.get(id) ?? [] }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// An App finding can name the source findings it revalidated only by ID, in
|
|
20
|
+
// another row or report. The App view counts those as represented by it, so
|
|
21
|
+
// they are one issue for security too: hiding one side alone would leave the
|
|
22
|
+
// App answer to a hidden security finding, or a source row without its App row.
|
|
23
|
+
// Only App findings: the view ignores inputs on any other finding
|
|
24
|
+
// (finding-filters.js confirmedCoverage, revalidation-input-groups.js).
|
|
25
|
+
export function revalidationLinks(findings) {
|
|
26
|
+
const links = []
|
|
27
|
+
for (const finding of findings) {
|
|
28
|
+
const inputs = finding?.revalidateInputs
|
|
29
|
+
if (finding?.isApp !== true || typeof finding.id !== 'string' || !Array.isArray(inputs)) continue
|
|
30
|
+
links.push([finding.id, ...inputs.filter((id) => typeof id === 'string' && id !== '')])
|
|
31
|
+
}
|
|
32
|
+
return links
|
|
33
|
+
}
|